Skip to content

Commit

Permalink
Merge branch 'authoring-react-post-broadcasting' into dateline-field
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaskikutis committed Feb 17, 2023
2 parents bc8f31f + 4024eed commit 2d899c4
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
10 changes: 10 additions & 0 deletions scripts/apps/authoring-react/data-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ICommonFieldConfig,
IAuthoringStorage,
IFieldsAdapter,
IEditor3Config,
} from 'superdesk-api';
import ng from 'core/services/ng';
import {httpRequestJsonLocal} from 'core/helpers/network';
Expand All @@ -22,6 +23,7 @@ import {sdApi} from 'api';
import {getArticleAdapter} from './article-adapter';
import {gettext} from 'core/utils';
import {PACKAGE_ITEMS_FIELD_ID} from './fields/package-items';
import {description_text, DESCRIPTION_TEXT_FIELD_ID} from './field-adapters/description_text';

function getArticleContentProfile<T>(item: IArticle, fieldsAdapter: IFieldsAdapter<T>): Promise<IContentProfileV2> {
interface IFakeScope {
Expand Down Expand Up @@ -122,6 +124,14 @@ function getArticleContentProfile<T>(item: IArticle, fieldsAdapter: IFieldsAdapt
}
}

// TODO: write an upgrade script and remove hardcoding
// after angular based authoring is removed from the codebase
if (['picture', 'audio', 'video', 'graphic'].includes(item.type)) {
const description_field = description_text.getFieldV2(fakeScope.editor, fakeScope.schema);

contentFields = contentFields.set(description_field.id, description_field);
}

const profile: IContentProfileV2 = {
id: item.profile,
name: 'test content profile',
Expand Down
48 changes: 48 additions & 0 deletions scripts/apps/authoring-react/field-adapters/description_text.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {IArticle, IAuthoringFieldV2, IFieldAdapter, IEditor3Config} from 'superdesk-api';
import {gettext} from 'core/utils';
import {retrieveStoredValueEditor3Generic, storeEditor3ValueBase} from '.';

export const DESCRIPTION_TEXT_FIELD_ID = 'description_text';

export const description_text: IFieldAdapter<IArticle> = {
getFieldV2: (fieldEditor, fieldSchema) => {
const fieldConfig: IEditor3Config = {
editorFormat: [],
minLength: fieldSchema?.minlength,
maxLength: fieldSchema?.maxlength,
cleanPastedHtml: fieldEditor?.cleanPastedHTML,
singleLine: true,
disallowedCharacters: [],
};

const fieldV2: IAuthoringFieldV2 = {
id: DESCRIPTION_TEXT_FIELD_ID,
name: gettext('Description'),
fieldType: 'editor3',
fieldConfig,
};

return fieldV2;
},

retrieveStoredValue: (item: IArticle, authoringStorage) => retrieveStoredValueEditor3Generic(
DESCRIPTION_TEXT_FIELD_ID,
item,
authoringStorage,
),

storeValue: (value, item, config) => {
const result = storeEditor3ValueBase(
DESCRIPTION_TEXT_FIELD_ID,
item,
value,
config,
);

const articleUpdated = {...result.article};

articleUpdated.description_text = result.stringValue;

return articleUpdated;
},
};
2 changes: 2 additions & 0 deletions scripts/apps/authoring-react/field-adapters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {computeEditor3Output} from './utilities/compute-editor3-output';
import {package_items} from './package_items';
import {LINKED_ITEMS_FIELD_TYPE} from '../fields/linked-items';
import {dateline} from './dateline';
import {description_text} from './description_text';

export function getBaseFieldsAdapter(): IFieldsAdapter<IArticle> {
const adapter: IFieldsAdapter<IArticle> = {
Expand All @@ -72,6 +73,7 @@ export function getBaseFieldsAdapter(): IFieldsAdapter<IArticle> {
usageterms: usageterms,
groups: package_items,
dateline: dateline,
description_text: description_text,
};

return adapter;
Expand Down

0 comments on commit 2d899c4

Please sign in to comment.