Skip to content

Commit

Permalink
Move client-core import to SuperdeskAPI
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MarkLark86 committed Mar 28, 2024
1 parent 8cde1e5 commit 68ae907
Show file tree
Hide file tree
Showing 12 changed files with 296 additions and 227 deletions.
8 changes: 0 additions & 8 deletions client/components/ContentProfiles/FieldTab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ interface IState {
}

export class FieldTab extends React.Component<IProps, IState> {
profile: any;
constructor(props) {
super(props);

Expand All @@ -51,13 +50,6 @@ export class FieldTab extends React.Component<IProps, IState> {
this.updateFieldOrder = this.updateFieldOrder.bind(this);
this.insertField = this.insertField.bind(this);
this.removeField = this.removeField.bind(this);
this.profile = {
...this.props.profile,
editor: {
...this.props.profile.editor,
related_items: {enabled: false}
}
};
}

openEditor(field: IProfileFieldEntry) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
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 '../EventRelatedPlannings/style.scss';
import {showModal} from '@superdesk/common';
import {EventsRelatedArticlesModal} from './EventsRelatedArticlesModal';
import {IArticle} from 'superdesk-api';
import {cleanArticlesFields} from './utils';
import {RelatedArticlesListComponent} from './RelatedArticlesListComponent';
import {IEditorFieldProps, IEventItem, IProfileSchemaTypeList} from 'interfaces';
import {Row} from 'superdesk-core/scripts/core/ui/components/List';
import {gettext} from 'superdesk-core/scripts/core/utils';
import {Row} from '../../../UI/Form';

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

interface IProps extends IEditorFieldProps {
item: IEventItem;
Expand Down Expand Up @@ -41,6 +45,7 @@ export class EditorFieldEventRelatedItems extends React.PureComponent<IProps, IS

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

return (
<div className="related-plannings">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import React from 'react';

import {IArticle, IRestApiResponse, ISuperdeskQuery} from 'superdesk-api';
import {IPlanningConfig} from '../../../../interfaces';
import {superdeskApi} from '../../../../superdeskApi';
import {appConfig as config} from 'appConfig';

import {cleanArticlesFields} from './utils';

import {
SearchBar,
Modal,
Expand All @@ -17,15 +25,12 @@ import {
RightPanel,
SubNav,
} from 'superdesk-ui-framework/react';
import {getProjectedFieldsArticle, gettext} from 'superdesk-core/scripts/core/utils';
import {httpRequestJsonLocal} from 'superdesk-core/scripts/core/helpers/network';
import {toElasticQuery} from 'superdesk-core/scripts/core/query-formatting';
import {IArticle, IRestApiResponse, ISuperdeskQuery} from 'superdesk-api';
import {cleanArticlesFields} from './utils';
import {RelatedArticlesListComponent} from './RelatedArticlesListComponent';
import '../../../../components/Archive/ArchivePreview/style.scss';
import {PreviewArticle} from './PreviewArticle';
import {getLanguageVocabulary} from 'superdesk-core/scripts/core/helpers/business-logic';

import '../../../../components/Archive/ArchivePreview/style.scss';

const appConfig = config as IPlanningConfig;

interface IProps {
closeModal: () => void;
Expand Down Expand Up @@ -62,27 +67,34 @@ export class EventsRelatedArticlesModal extends React.Component<IProps, IState>
}

componentDidMount() {
httpRequestJsonLocal<IRestApiResponse<any>>({
method: 'GET',
path: '/search_providers',
urlParams: {
manage: 1,
}
}).then((result) => {
const repoId = result._items.find((provider) =>
provider.source === 'http://wss-01.staging.belga.be:9000/archivenewsobjects')._id;
const {httpRequestJsonLocal} = superdeskApi;
const {getLanguageVocabulary} = superdeskApi.entities.vocabulary;
const searchProviderName = appConfig.planning.event_related_item_search_provider_name;

this.setState({
repo: repoId,
languages: [
...getLanguageVocabulary().items.map(({name, qcode}) => ({label: name, code: qcode})),
{
label: 'All languages',
code: ''
}
]
if (searchProviderName != null) {
httpRequestJsonLocal<IRestApiResponse<any>>({
method: 'GET',
path: '/search_providers',
urlParams: {
manage: 1,
}
}).then((result) => {
const repoId = result._items.find((provider) => (
provider.search_provider === searchProviderName
))?._id;

this.setState({
repo: repoId,
languages: [
...getLanguageVocabulary().items.map(({name, qcode}) => ({label: name, code: qcode})),
{
label: 'All languages',
code: ''
}
]
});
});
});
}
}

componentDidUpdate(_prevProps: Readonly<IProps>, prevState: Readonly<IState>): void {
Expand All @@ -99,6 +111,10 @@ export class EventsRelatedArticlesModal extends React.Component<IProps, IState>

render(): React.ReactNode {
const {closeModal} = this.props;
const {gettext} = superdeskApi.localization;
const {getProjectedFieldsArticle} = superdeskApi.entities.article;
const {httpRequestJsonLocal} = superdeskApi;
const {superdeskToElasticQuery} = superdeskApi.helpers;

return (
<Modal
Expand Down Expand Up @@ -172,33 +188,38 @@ export class EventsRelatedArticlesModal extends React.Component<IProps, IState>
key={this.state.activeLanguage.code + this.state.searchQuery + this.state.repo}
pageSize={20}
getItems={(pageNo, pageSize, signal) => {
const query: Partial<ISuperdeskQuery> = {
if (this.state.repo == null) {
return Promise.resolve({items: [], itemCount: 0});
}

const query: ISuperdeskQuery = {
filter: {},
page: pageNo,
max_results: pageSize,
sort: [{versioncreated: 'desc'}],
};
const urlParams: {[key: string]: any} = {
aggregations: 0,
es_highlight: 1,
repo: this.state.repo,
projections: JSON.stringify(getProjectedFieldsArticle()),
};

if (this.state.activeLanguage.code !== '') {
query.filter = {$and: [{language: {$eq: this.state.activeLanguage.code}}]};
query.filter.language = {$eq: this.state.activeLanguage.code};
urlParams.params = {languages: this.state.activeLanguage.code};
}

if (this.state.searchQuery !== '') {
query.fullTextSearch = this.state.searchQuery.toLowerCase();
}

if (this.state.repo == null) {
return Promise.resolve({items: [], itemCount: 0});
}

return httpRequestJsonLocal<IRestApiResponse<Partial<IArticle>>>({
method: 'GET',
path: '/search_providers_proxy',
urlParams: {
aggregations: 0,
es_highlight: 1,
repo: this.state.repo,
projections: JSON.stringify(getProjectedFieldsArticle()),
...toElasticQuery(query as ISuperdeskQuery),
...urlParams,
...superdeskToElasticQuery(query),
},
abortSignal: signal,
})
Expand Down Expand Up @@ -246,7 +267,10 @@ export class EventsRelatedArticlesModal extends React.Component<IProps, IState>
this.setState({
currentlySelectedArticles: [
...(this.state.currentlySelectedArticles ?? []),
article,
{
...article,
search_provider: this.state.repo,
},
]
});
}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import React from 'react';

import {IArticle, IVocabulary} from 'superdesk-api';
import {PreviewFieldType} from 'superdesk-core/scripts/apps/authoring/preview/previewFieldByType';
import {getCustomFieldVocabularies} from 'superdesk-core/scripts/core/helpers/business-logic';
import {getLabelNameResolver} from 'superdesk-core/scripts/apps/workspace/helpers/getLabelForFieldId';
import {appConfig} from 'superdesk-core/scripts/appConfig';
import {gettext} from 'superdesk-core/scripts/core/utils';
import {formatDate} from 'superdesk-core/scripts/core/get-superdesk-api-implementation';
import {getSortedFields, getSortedFieldsFiltered} from 'superdesk-core/scripts/apps/authoring/preview/utils';
import {fakeEditor} from './utils';
import {superdeskApi} from '../../../../superdeskApi';
import {appConfig} from 'appConfig';

import {ContentDivider, Heading} from 'superdesk-ui-framework/react';
import {fakeEditor} from './utils';

interface IProps {
item: Partial<IArticle>;
Expand All @@ -34,6 +31,9 @@ export class PreviewArticle extends React.PureComponent<IProps, IState> {
}

componentDidMount(): void {
const {getLabelNameResolver} = superdeskApi.entities.article;
const {getCustomFieldVocabularies} = superdeskApi.entities.vocabulary;

getLabelNameResolver().then((getLabel: (fieldId: string) => string) => {
const customFieldVocabularies = getCustomFieldVocabularies();

Expand All @@ -47,6 +47,10 @@ export class PreviewArticle extends React.PureComponent<IProps, IState> {
}

render() {
const {gettext, formatDate} = superdeskApi.localization;
const {PreviewFieldType} = superdeskApi.components.authoring;
const {getSortedFields, getSortedFieldsFiltered} = superdeskApi.entities.article;

const {allFields, extractedFields} = getSortedFieldsFiltered(
'content',
fakeEditor,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import {ReactNode} from 'react';

import {IArticle} from 'superdesk-api';
import {gettext} from 'superdesk-core/scripts/core/utils';
import {superdeskApi} from '../../../../superdeskApi';

import {ContentListItem, IconButton, Label, Spacer} from 'superdesk-ui-framework/react';

interface IProps {
Expand Down Expand Up @@ -33,7 +34,8 @@ export class RelatedArticlesListComponent extends React.PureComponent<IProps, IS
};
}

render(): ReactNode {
render() {
const {gettext} = superdeskApi.localization;
const {
article,
editorPreview,
Expand Down
54 changes: 22 additions & 32 deletions client/components/fields/editor/EventRelatedArticles/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,40 +157,30 @@ export const fakeEditor: any = {
};

export function cleanArticlesFields(articles: Array<Partial<IArticle>>) {
const fieldsToCleanup: Array<keyof IArticle> = [
'_created',
'_etag',
'_fetchable',
'_id',
'_links',
'_type',
'_updated',
'authors',
'body_html',
'creditline',
'description_text',
'ednote',
'extra',
'fetch_endpoint',
'firstcreated',
'ingest_provider',
'keywords',

// needed because proxy preprocessing adds mimetype to
// each article, while technically it's not a part of its interface
'mimetype' as any,
'profile',
'renditions',
'sign_off',
'profile',
'subject',
const fieldsToKeep: Array<keyof IArticle> = [
'guid',
'type',
'state',
'version',
'headline',
'slugline',
'versioncreated',
'source',
'pubstatus',
'language',
'word_count',
'search_provider',
];

fieldsToCleanup.forEach((field) => {
articles.forEach((article) => {
delete article[field];
});
});
for (let i = 0; i < articles.length; i++) {
let field: keyof IArticle;

for (field in articles[i]) {
if (!fieldsToKeep.includes(field)) {
delete articles[i][field];
}
}
}

return articles;
}
Expand Down
1 change: 0 additions & 1 deletion client/components/fields/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ const PREVIEW_GROUPS: IPreviewGroups = {
'definition_long',
'internal_note',
'ednote',
'related_items',
'registration_details',
'invitation_details',
'accreditation_info',
Expand Down
4 changes: 0 additions & 4 deletions client/components/fields/preview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,6 @@ const fieldOptions: {[key: string]: IPreviewHocOptions} = {
getValue: getValueFromCV('news_coverage_status'),
mapStateToProps: (state) => ({news_coverage_status: selectors.general.newsCoverageStatus(state)}),
},
related_items: {
props: () => ({label: superdeskApi.localization.gettext('Related Articles')}),
getValue: getPreviewString,
},
};

const multilingualFieldOptions: {[key: string]: IPreviewHocOptions} = {
Expand Down
Loading

0 comments on commit 68ae907

Please sign in to comment.