-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
377 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* eslint-disable react/require-default-props */ | ||
import React from 'react'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import { | ||
Button, | ||
Tab, | ||
Tabs, | ||
Stack, | ||
} from '@openedx/paragon'; | ||
|
||
import { ComponentMenu } from '../components'; | ||
import messages from './messages'; | ||
|
||
interface ComponentInfoProps { | ||
usageKey: string; | ||
} | ||
|
||
const ComponentInfo = ({ usageKey } : ComponentInfoProps) => { | ||
const intl = useIntl(); | ||
|
||
return ( | ||
<Stack> | ||
<Stack direction="horizontal" className="d-flex justify-content-around"> | ||
<Button disabled variant="outline-primary rounded-0"> | ||
{intl.formatMessage(messages.editComponentButtonTitle)} | ||
</Button> | ||
<Button disabled variant="outline-primary rounded-0"> | ||
{intl.formatMessage(messages.publishComponentButtonTitle)} | ||
</Button> | ||
<ComponentMenu usageKey={usageKey} /> | ||
</Stack> | ||
<Tabs | ||
variant="tabs" | ||
className="my-3 d-flex justify-content-around" | ||
defaultActiveKey="preview" | ||
> | ||
<Tab eventKey="preview" title={intl.formatMessage(messages.previewTabTitle)}> | ||
Preview tab placeholder | ||
</Tab> | ||
<Tab eventKey="manage" title={intl.formatMessage(messages.manageTabTitle)}> | ||
Manage tab placeholder | ||
</Tab> | ||
<Tab eventKey="details" title={intl.formatMessage(messages.detailsTabTitle)}> | ||
Details tab placeholder | ||
</Tab> | ||
</Tabs> | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default ComponentInfo; |
109 changes: 109 additions & 0 deletions
109
src/library-authoring/component-info/ComponentInfoHeader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* eslint-disable react/require-default-props */ | ||
import React, { useState, useContext, useCallback } from 'react'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import { | ||
Icon, | ||
IconButton, | ||
Stack, | ||
Form, | ||
} from '@openedx/paragon'; | ||
import { Edit } from '@openedx/paragon/icons'; | ||
|
||
import { LoadingSpinner } from '../../generic/Loading'; | ||
import AlertError from '../../generic/alert-error'; | ||
import { ToastContext } from '../../generic/toast-context'; | ||
import { useUpdateXBlockFields, useXBlockFields } from '../data/apiHooks'; | ||
import messages from './messages'; | ||
|
||
interface ComponentInfoHeaderProps { | ||
usageKey: string; | ||
} | ||
|
||
const ComponentInfoHeader = ({ usageKey }: ComponentInfoHeaderProps) => { | ||
const intl = useIntl(); | ||
const [inputIsActive, setIsActive] = useState(false); | ||
|
||
const { | ||
data: xblockFields, | ||
isError, | ||
error, | ||
isLoading, | ||
} = useXBlockFields(usageKey); | ||
|
||
const updateMutation = useUpdateXBlockFields(usageKey); | ||
const { showToast } = useContext(ToastContext); | ||
|
||
const handleSaveDisplayName = useCallback( | ||
(event) => { | ||
const newDisplayName = event.target.value; | ||
if (newDisplayName && newDisplayName !== xblockFields?.displayName) { | ||
updateMutation.mutateAsync({ | ||
metadata: { | ||
display_name: newDisplayName, | ||
}, | ||
}).then(() => { | ||
showToast(intl.formatMessage(messages.updateComponentSuccessMsg)); | ||
}).catch(() => { | ||
showToast(intl.formatMessage(messages.updateComponentErrorMsg)); | ||
}); | ||
} | ||
setIsActive(false); | ||
}, | ||
[xblockFields, showToast, intl], | ||
); | ||
|
||
const handleClick = () => { | ||
setIsActive(true); | ||
}; | ||
|
||
const hanldeOnKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => { | ||
if (event.key === 'Enter') { | ||
handleSaveDisplayName(event); | ||
} else if (event.key === 'Escape') { | ||
setIsActive(false); | ||
} | ||
}; | ||
|
||
if (isError) { | ||
return <AlertError error={error} />; | ||
} | ||
|
||
if (isLoading) { | ||
return <LoadingSpinner />; | ||
} | ||
|
||
return ( | ||
<Stack direction="horizontal"> | ||
{ inputIsActive | ||
? ( | ||
<Form.Control | ||
autoFocus | ||
name="displayName" | ||
id="displayName" | ||
type="text" | ||
aria-label="Display name input" | ||
defaultValue={xblockFields.displayName} | ||
onBlur={handleSaveDisplayName} | ||
onKeyDown={hanldeOnKeyDown} | ||
/> | ||
) | ||
: ( | ||
<> | ||
<span className="font-weight-bold m-1.5"> | ||
{xblockFields.displayName} | ||
</span> | ||
{true && ( // Add condition to check if user has permission to edit | ||
<IconButton | ||
src={Edit} | ||
iconAs={Icon} | ||
alt={intl.formatMessage(messages.editNameButtonAlt)} | ||
onClick={handleClick} | ||
/> | ||
)} | ||
</> | ||
)} | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default ComponentInfoHeader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as ComponentInfo } from './ComponentInfo'; | ||
export { default as ComponentInfoHeader } from './ComponentInfoHeader'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { defineMessages as _defineMessages } from '@edx/frontend-platform/i18n'; | ||
import type { defineMessages as defineMessagesType } from 'react-intl'; | ||
|
||
// frontend-platform currently doesn't provide types... do it ourselves. | ||
const defineMessages = _defineMessages as typeof defineMessagesType; | ||
|
||
const messages = defineMessages({ | ||
editNameButtonAlt: { | ||
id: 'course-authoring.library-authoring.component.edit-name.alt', | ||
defaultMessage: 'Edit componet name', | ||
description: 'Alt text for edit component name icon button', | ||
}, | ||
updateComponentSuccessMsg: { | ||
id: 'course-authoring.library-authoring.component.update.success', | ||
defaultMessage: 'Component updated successfully.', | ||
description: 'Message when the component is updated successfully', | ||
}, | ||
updateComponentErrorMsg: { | ||
id: 'course-authoring.library-authoring.component.update.error', | ||
defaultMessage: 'There was an error updating the component.', | ||
description: 'Message when there is an error when updating the component', | ||
}, | ||
editComponentButtonTitle: { | ||
id: 'course-authoring.library-authoring.component.edit.title', | ||
defaultMessage: 'Edit component', | ||
description: 'Title for edit component button', | ||
}, | ||
publishComponentButtonTitle: { | ||
id: 'course-authoring.library-authoring.component.publish.title', | ||
defaultMessage: 'Publish component', | ||
description: 'Title for publish component button', | ||
}, | ||
previewTabTitle: { | ||
id: 'course-authoring.library-authoring.component.preview-tab.title', | ||
defaultMessage: 'Preview', | ||
description: 'Title for preview tab', | ||
}, | ||
manageTabTitle: { | ||
id: 'course-authoring.library-authoring.component.manage-tab.title', | ||
defaultMessage: 'Manage', | ||
description: 'Title for manage tab', | ||
}, | ||
detailsTabTitle: { | ||
id: 'course-authoring.library-authoring.component.details-tab.title', | ||
defaultMessage: 'Details', | ||
description: 'Title for details tab', | ||
}, | ||
}); | ||
|
||
export default messages; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export { default as LibraryComponents } from './LibraryComponents'; | ||
export { ComponentMenu } from './ComponentCard'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.