Skip to content

Commit

Permalink
Cosmetic metadata widget changes, persist changes on full width toggl… (
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc authored Nov 1, 2024
1 parent 95aa992 commit 72d8679
Show file tree
Hide file tree
Showing 15 changed files with 358 additions and 290 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"sass-loader": "6.0.6",
"shortid": "2.2.8",
"style-loader": "0.20.2",
"superdesk-ui-framework": "^3.1.23",
"superdesk-ui-framework": "^3.1.28",
"ts-loader": "3.5.0",
"typescript": "4.9.5",
"uuid": "8.3.1",
Expand Down
2 changes: 2 additions & 0 deletions scripts/api/content-profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import {dataStore} from 'data-store';

interface IContentProfilesApi {
get(id: IContentProfile['_id']): IContentProfile;
getAll(): Array<IContentProfile>;
}

export const contentProfiles: IContentProfilesApi = {
get: (id) => dataStore.contentProfiles.get(id),
getAll: () => dataStore.contentProfiles.toArray(),
};
232 changes: 103 additions & 129 deletions scripts/apps/authoring-react/article-widgets/metadata/metadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class MetadataWidget extends React.PureComponent<IArticleSideWidgetComponentType

render() {
const {article} = this.props;

const {
flags,
usageterms,
Expand Down Expand Up @@ -87,10 +86,10 @@ class MetadataWidget extends React.PureComponent<IArticleSideWidgetComponentType
versioncreator,
rewritten_by,
} = article;

const {onItemChange} = this.props;

const allVocabularies = sdApi.vocabularies.getAll();
const hasGenre = allVocabularies.map((v) => v.schema_field).includes('genre') === false;
const hasPlace = allVocabularies.map((v) => v.schema_field).includes('place') === false;

return (
<AuthoringWidgetLayout
Expand Down Expand Up @@ -212,54 +211,52 @@ class MetadataWidget extends React.PureComponent<IArticleSideWidgetComponentType
/>
)}

{
<>
<Spacer h gap="64" justifyContent="space-between" noWrap>
<Heading type="h6">
{gettext('State').toUpperCase()}
</Heading>
<Spacer h gap="4" justifyContent="start" noWrap style={{flexWrap: 'wrap'}} >
<StateComponent item={article} />
{article.embargo && (
<Label
style="hollow"
type="alert"
text={gettext('embargo')}
/>
)}
{flags.marked_for_not_publication && (
<Label
text={gettext('Not For Publication')}
style="hollow"
type="alert"
/>
)}
{flags.marked_for_legal && (
<Label
text={gettext('Legal')}
style="hollow"
type="alert"
/>
)}
{flags.marked_for_sms && (
<Label
text={gettext('Sms')}
style="hollow"
type="alert"
/>
)}
{(rewritten_by?.length ?? 0) > 0 && (
<Label
text={gettext('Updated')}
style="hollow"
type="alert"
/>
)}
</Spacer>
{<>
<Spacer h gap="64" justifyContent="space-between" noWrap>
<Heading type="h6">
{gettext('State').toUpperCase()}
</Heading>
<Spacer h gap="4" justifyContent="start" noWrap style={{flexWrap: 'wrap'}} >
<StateComponent item={article} />
{article.embargo && (
<Label
style="hollow"
type="alert"
text={gettext('embargo')}
/>
)}
{flags.marked_for_not_publication && (
<Label
text={gettext('Not For Publication')}
style="hollow"
type="alert"
/>
)}
{flags.marked_for_legal && (
<Label
text={gettext('Legal')}
style="hollow"
type="alert"
/>
)}
{flags.marked_for_sms && (
<Label
text={gettext('Sms')}
style="hollow"
type="alert"
/>
)}
{(rewritten_by?.length ?? 0) > 0 && (
<Label
text={gettext('Updated')}
style="hollow"
type="alert"
/>
)}
</Spacer>
<ContentDivider border type="dotted" margin="x-small" />
</>
}
</Spacer>
<ContentDivider border type="dotted" margin="x-small" />
</>}

{ingest_provider != null && (
<MetadataItem
Expand All @@ -268,19 +265,17 @@ class MetadataWidget extends React.PureComponent<IArticleSideWidgetComponentType
/>
)}

{
(ingest_provider_sequence?.length ?? 0) > 0 && (
<MetadataItem
label={gettext('Ingest sequence')}
value={ingest_provider_sequence}
/>
)
}
{(ingest_provider_sequence?.length ?? 0) > 0 && (
<MetadataItem
label={gettext('Ingest sequence')}
value={ingest_provider_sequence}
/>
)}

{expiry && (
<MetadataItem
label={gettext('Expiry')}
value={<Datetime datetime={expiry} />}
value={<DateTime dateTime={expiry} />}
/>
)}

Expand All @@ -303,67 +298,52 @@ class MetadataWidget extends React.PureComponent<IArticleSideWidgetComponentType

<MetadataItem label={gettext('Take key')} value={anpa_take_key} />

{
signal && (
<MetadataItem
label={gettext('Signal')}
value={(
<div>
{(signal.map(({name, qcode}) => (
<Fragment key={name}>{name ?? qcode}</Fragment>
)))}
</div>
)}
/>
)
}
{signal && (
<MetadataItem
label={gettext('Signal')}
value={(
<div>
{(signal.map(({name, qcode}) => (
<Fragment key={name}>{name ?? qcode}</Fragment>
)))}
</div>
)}
/>
)}

{anpa_category?.name != null && (
<MetadataItem
label={gettext('Category')}
value={sdApi.vocabularies.vocabularyItemsToString(anpa_category, 'name')}
/>
)}

{
anpa_category?.name != null && (
{allVocabularies.filter((cv) => article[cv.schema_field] != null).toArray()
.map((vocabulary) => (
<MetadataItem
label={gettext('Category')}
value={sdApi.vocabularies.vocabularyItemsToString(anpa_category, 'name')}
key={vocabulary._id}
label={vocabulary.display_name}
value={vocabularies.getVocabularyItemLabel(
article[vocabulary.schema_field],
article,
)}
/>
)
))
}

{
allVocabularies
.filter((cv) => article[cv.schema_field] != null)
.toArray()
.map((vocabulary) => (
<MetadataItem
key={vocabulary._id}
label={vocabulary.display_name}
value={vocabularies.getVocabularyItemLabel(
article[vocabulary.schema_field],
article,
)}
/>
))
}

{
(genre.length ?? 0) > 0
&& allVocabularies.map((v) => v.schema_field).includes('genre') === false
&& (
<MetadataItem
label={gettext('Genre')}
value={sdApi.vocabularies.vocabularyItemsToString(genre, 'name')}
/>
)
}
{(genre?.length ?? 0) > 0 && hasGenre && (
<MetadataItem
label={gettext('Genre')}
value={sdApi.vocabularies.vocabularyItemsToString(genre, 'name')}
/>
)}

{
(place.length ?? 0) > 0
&& allVocabularies.map((v) => v.schema_field).includes('place') === false
&& (
<MetadataItem
label={gettext('Place')}
value={sdApi.vocabularies.vocabularyItemsToString(place, 'name')}
/>
)
}
{(place?.length ?? 0) > 0 && hasPlace && (
<MetadataItem
label={gettext('Place')}
value={sdApi.vocabularies.vocabularyItemsToString(place, 'name')}
/>
)}

{(ednote?.length ?? 0) > 0 && <MetadataItem label={gettext('Editorial note')} value={ednote} />}

Expand Down Expand Up @@ -438,22 +418,16 @@ class MetadataWidget extends React.PureComponent<IArticleSideWidgetComponentType

<MetadataItem label={gettext('Type')} value={type} />

{
renditions?.original != null && (
<MetadataItem
label={gettext('Type')}
value={`${renditions.original.width} x ${renditions.original.height}`}
/>
)
}
{renditions?.original != null && (
<MetadataItem
label={gettext('Type')}
value={`${renditions.original.width} x ${renditions.original.height}`}
/>
)}

{
article.type === 'picture'
&& article.archive_description !== article.description_text
&& (
<AnnotationsPreview article={article} />
)
}
{article.type === 'picture' && article.archive_description !== article.description_text && (
<AnnotationsPreview article={article} />
)}
</Spacer>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ function getInlineToolbarActions(
priority: 0.1,
component: () => (
<ToggleFullWidth
setFullWidth={() => setFullWidth()}
setFullWidth={() => {
options.authoringStorage.autosave.flush().then(() => {
setFullWidth();
});
}}
fullWidth={fullWidth}
/>
),
Expand Down
14 changes: 9 additions & 5 deletions scripts/apps/authoring-react/authoring-integration-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {WidgetStatePersistenceHOC, widgetState} from './widget-persistance-hoc';
import {PINNED_WIDGET_USER_PREFERENCE_SETTINGS, closedIntentionally} from 'apps/authoring/widgets/widgets';
import {AuthoringIntegrationWrapperSidebar} from './authoring-integration-wrapper-sidebar';
import {assertNever} from 'core/helpers/typescript-helpers';
import {ContentProfileDropdown} from './subcomponents/content-profile-dropdown';

export function getWidgetsFromExtensions(article: IArticle): Array<IArticleSideWidget> {
return Object.values(extensions)
Expand All @@ -51,7 +52,12 @@ export function getWidgetsFromExtensions(article: IArticle): Array<IArticleSideW
.sort((a, b) => a.order - b.order);
}

const defaultToolbarItems: Array<React.ComponentType<{article: IArticle}>> = [CreatedModifiedInfo];
const defaultToolbarItems: Array<React.ComponentType<{
article: IArticle;
reinitialize: (itemWithChanges: IArticle) => void;
}>> = [
CreatedModifiedInfo,
];

interface IProps {
itemId: IArticle['_id'];
Expand Down Expand Up @@ -317,10 +323,8 @@ export class AuthoringIntegrationWrapper extends React.PureComponent<IPropsWrapp
const secondaryToolbarWidgetsFromExtensions = Object.values(extensions)
.flatMap(({activationResult}) => activationResult?.contributions?.authoringTopbar2Widgets ?? []);

const secondaryToolbarWidgetsReady: Array<React.ComponentType<{item: IArticle}>> =
defaultToolbarItems.concat(secondaryToolbarWidgetsFromExtensions).map(
(Component) => (props: {item: IArticle}) => <Component article={props.item} />,
);
const secondaryToolbarWidgetsReady = defaultToolbarItems.concat(secondaryToolbarWidgetsFromExtensions)
.map((Component) => (props) => <Component reinitialize={props.reinitialize} article={props.item} />);

return (
<WithInteractiveArticleActionsPanel location="authoring">
Expand Down
Loading

0 comments on commit 72d8679

Please sign in to comment.