-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Related items implementation (#1931)
* 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
1 parent
c6cbcd6
commit 2d4849c
Showing
15 changed files
with
1,202 additions
and
116 deletions.
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
client/components/fields/editor/EventRelatedArticles/EditorFieldEventRelatedItems.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,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> | ||
); | ||
} | ||
} |
Oops, something went wrong.