Skip to content

Commit

Permalink
Related items implementation (#1931)
Browse files Browse the repository at this point in the history
* Add frontend support for related_items field

* Implement related_items archive search modal

* Code cleanup, fix modal

* Temporary changes so related_items appears

* Remove implementation from planing, move to superdesk-belga

* Use UIF helper classes, move components from belga repo

* 1. Reimplement layout, so preview panel stretches properly and we follow design guidelines, and component reusability
2. Use `getSortedFieldsFiltered` to improve performance by not iterating 2 more times on the same object

* Remove dead code, properly get available languages for filter, move ContentDivider so it appears in the UI

* Adjust styles

* Move client-core import to SuperdeskAPI
Also:
* Fix search language for Belga archive
* Use appConfig.planning.event_related_item_search_provider_name instead of hard coded url for search_provider
* Remove all fields from related_items that aren't in the db schema
* Add search_provider ID to article when adding it to list of articles to add

---------

Co-authored-by: Mark Pittaway <[email protected]>
  • Loading branch information
thecalcc and MarkLark86 authored Mar 28, 2024
1 parent c6cbcd6 commit 2d4849c
Show file tree
Hide file tree
Showing 15 changed files with 1,202 additions and 116 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import * as React from 'react';

import {IArticle} from 'superdesk-api';
import {IEditorFieldProps, IEventItem, IProfileSchemaTypeList} from 'interfaces';
import {superdeskApi} from '../../../../superdeskApi';

import {cleanArticlesFields} from './utils';

import {ButtonGroup, Button, Spacer} from 'superdesk-ui-framework/react';
import {showModal} from '@superdesk/common';
import {EventsRelatedArticlesModal} from './EventsRelatedArticlesModal';
import {RelatedArticlesListComponent} from './RelatedArticlesListComponent';
import {Row} from '../../../UI/Form';

import '../EventRelatedPlannings/style.scss';

interface IProps extends IEditorFieldProps {
item: IEventItem;
schema?: IProfileSchemaTypeList;
}

interface IState {
selectedRelatedArticles: Array<Partial<IArticle>>;
}

export class EditorFieldEventRelatedItems extends React.PureComponent<IProps, IState> {
constructor(props: IProps) {
super(props);

this.state = {
selectedRelatedArticles: this.props.item.related_items as Array<Partial<IArticle>>,
};
}

componentDidUpdate(prevProps: Readonly<IProps>): void {
const relatedItemsUpdated = this.props.item.related_items as Array<Partial<IArticle>>;

if (JSON.stringify(relatedItemsUpdated) !== JSON.stringify(prevProps.item.related_items)) {
// eslint-disable-next-line react/no-did-update-set-state
this.setState({
selectedRelatedArticles: relatedItemsUpdated,
});
}
}

render() {
const disabled = this.props.disabled || this.props.schema?.read_only;
const {gettext} = superdeskApi.localization;

return (
<div className="related-plannings">
<Row flex={true} noPadding={true}>
<label className="InputArray__label side-panel__heading side-panel__heading--big">
{gettext('Related Articles')}
</label>
{disabled ? null : (
<ButtonGroup align="end">
<Button
type="primary"
icon="plus-large"
text="plus-large"
shape="round"
size="small"
iconOnly={true}
onClick={() =>
showModal(({closeModal}) => (
<EventsRelatedArticlesModal
onChange={(value) => {
this.props.onChange(this.props.field, cleanArticlesFields(value));
}}
selectedArticles={this.state.selectedRelatedArticles}
closeModal={() => {
closeModal();
}}
/>
))
}
/>
</ButtonGroup>
)}
</Row>
{(this.props.item.related_items?.length ?? 0) < 1 ? (
<Row>
<div style={{width: '100%'}} className="info-box--dashed">
<label>{gettext('No related articles yet')}</label>
</div>
</Row>
) : (
<Spacer v gap="4" justifyContent="center" alignItems="center" noWrap>
{
(this.state.selectedRelatedArticles ?? []).map((relItem) => (
<RelatedArticlesListComponent
key={relItem.guid}
editorPreview
removeArticle={(articleId) => {
this.props.onChange(
this.props.field,
cleanArticlesFields(
[...(this.state.selectedRelatedArticles ?? [])]
.filter(({guid}) => guid !== articleId)
)
);
}}
article={relItem}
/>
))
}
</Spacer>
)}
</div>
);
}
}
Loading

0 comments on commit 2d4849c

Please sign in to comment.