Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

description_text field react #4194

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 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_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,28 @@ 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 (item.type === 'picture' || item.type === 'audio' || item.type === 'video') {
const fieldConfig: IEditor3Config = {
editorFormat: [],
minLength: fakeScope.schema?.minlength,
maxLength: fakeScope.schema?.maxlength,
cleanPastedHtml: fakeScope.editor?.cleanPastedHTML,
singleLine: false,
disallowedCharacters: [],
};

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

contentFields = contentFields.set(description_text.id, description_text);
thecalcc marked this conversation as resolved.
Show resolved Hide resolved
}

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 @@ -47,6 +47,7 @@ import {ContentState, convertToRaw, RawDraftContentState} from 'draft-js';
import {computeEditor3Output} from './utilities/compute-editor3-output';
import {package_items} from './package_items';
import {LINKED_ITEMS_FIELD_TYPE} from '../fields/linked-items';
import {description_text} from './description_text';

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

return adapter;
Expand Down