Skip to content

Commit

Permalink
Improve documentation of generic fields (#4651)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaskikutis authored Nov 6, 2024
1 parent a73fcec commit 7024a6c
Show file tree
Hide file tree
Showing 20 changed files with 43 additions and 4 deletions.
10 changes: 10 additions & 0 deletions scripts/apps/authoring-react/fields/attachments/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ export const ATTACHMENTS_WIDGET_ID = 'attachments';
export function getAttachmentsField(): IAttachmentsField {
const field: IAttachmentsField = {
id: ATTACHMENTS_FIELD_ID,

/**
* Not generic due to:
* - having a hardcoded fieldId in a side-widget
*
* Could be made generic by getting rid of side-widget
* or changing side-widget to support multiple fields.
*/
generic: false,

label: gettext('Attachments (authoring-react)'),
editorComponent: Editor,
previewComponent: Preview,
Expand Down
1 change: 1 addition & 0 deletions scripts/apps/authoring-react/fields/date/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function getDateField()
: ICustomFieldType<IDateValueOperational, IDateValueStorage, IDateFieldConfig, IDateUserPreferences> {
const field: ICustomFieldType<IDateValueOperational, IDateValueStorage, IDateFieldConfig, IDateUserPreferences> = {
id: DATE_FIELD_ID,
generic: true,
label: gettext('Date (authoring-react)'),
editorComponent: Editor,
previewComponent: Preview,
Expand Down
1 change: 1 addition & 0 deletions scripts/apps/authoring-react/fields/dateline/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function getDatelineField()
: DatelineFieldType {
const field: DatelineFieldType = {
id: DATELINE_FIELD_ID,
generic: true,
label: gettext('Dateline (authoring-react)'),
editorComponent: Editor,
previewComponent: Preview,
Expand Down
1 change: 1 addition & 0 deletions scripts/apps/authoring-react/fields/dropdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const DROPDOWN_FIELD_ID = 'dropdown';
export function getDropdownField(): ICustomFieldType<IDropdownValue, IDropdownValue, IDropdownConfig, never> {
const field: ICustomFieldType<IDropdownValue, IDropdownValue, IDropdownConfig, never> = {
id: 'dropdown',
generic: true,
label: gettext('Dropdown (authoring-react)'),
editorComponent: Editor,
previewComponent: Preview,
Expand Down
1 change: 1 addition & 0 deletions scripts/apps/authoring-react/fields/duration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function geDurationField()
: ICustomFieldType<IDurationValueOperational, IDurationValueStorage, IDurationFieldConfig, IDurationUserPreferences> {
const field: ReturnType<typeof geDurationField> = {
id: DURATION_FIELD_ID,
generic: true,
label: gettext('Duration (authoring-react)'),
editorComponent: Editor,
previewComponent: Preview,
Expand Down
1 change: 1 addition & 0 deletions scripts/apps/authoring-react/fields/editor3/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function getEditor3Field()
: ICustomFieldType<IEditor3ValueOperational, IEditor3ValueStorage, IEditor3Config, IUserPreferences> {
const field: ICustomFieldType<IEditor3ValueOperational, IEditor3ValueStorage, IEditor3Config, IUserPreferences> = {
id: EDITOR_3_FIELD_TYPE,
generic: true,
label: gettext('Editor3 (authoring-react)'),
editorComponent: Editor,
previewComponent: Preview,
Expand Down
1 change: 1 addition & 0 deletions scripts/apps/authoring-react/fields/embed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function getEmbedField()
: ICustomFieldType<IEmbedValueOperational, IEmbedValueStorage, IEmbedConfig, IEmbedUserPreferences> {
const field: ReturnType<typeof getEmbedField> = {
id: 'embed',
generic: true,
label: gettext('Embed (authoring-react)'),
editorComponent: Editor,
previewComponent: Preview,
Expand Down
1 change: 1 addition & 0 deletions scripts/apps/authoring-react/fields/linked-items/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const LINKED_ITEMS_FIELD_TYPE = 'linked-items';
export function getLinkedItemsField(): ILinkedItemsField {
const field: ILinkedItemsField = {
id: LINKED_ITEMS_FIELD_TYPE,
generic: true,
label: gettext('Linked items (authoring-react)'),
editorComponent: Editor,
previewComponent: Preview,
Expand Down
1 change: 1 addition & 0 deletions scripts/apps/authoring-react/fields/media/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export function getMediaField()
: ICustomFieldType<IMediaValueOperational, IMediaValueStorage, IMediaConfig, IMediaUserPreferences> {
const field: ReturnType<typeof getMediaField> = {
id: MEDIA_FIELD_ID,
generic: true,
label: gettext('Media (authoring-react)'),
editorComponent: Editor,
previewComponent: Preview,
Expand Down
11 changes: 11 additions & 0 deletions scripts/apps/authoring-react/fields/package-items/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ export const PACKAGE_ITEMS_FIELD_ID = 'package_items';
export function getArticlesInPackageField(): IPackageItemsField {
const field: IPackageItemsField = {
id: PACKAGE_ITEMS_FIELD_ID,

/**
* 'linked_items' is a very similar field, but generic.
* It appears this field type was implemented to save time in comparison to
* creating configuration options for linked_items.
*
* It looks though there would only be 1 config needed,
* so I think we should do the config and drop this one in the future.
*/
generic: false,

label: gettext('Package items (authoring-react)'),

editorComponent: Editor,
Expand Down
1 change: 1 addition & 0 deletions scripts/apps/authoring-react/fields/tag-input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type TagInputFieldType = ICustomFieldType<
export function getTagInputField(): TagInputFieldType {
const field: TagInputFieldType = {
id: TAG_INPUT_FIELD_ID,
generic: true,
label: gettext('Tag-input (authoring-react)'),
editorComponent: Editor,
previewComponent: Preview,
Expand Down
1 change: 1 addition & 0 deletions scripts/apps/authoring-react/fields/time/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function getTimeField()
: ICustomFieldType<ITimeValueOperational, ITimeValueStorage, ITimeFieldConfig, ITimeUserPreferences> {
const field: ICustomFieldType<ITimeValueOperational, ITimeValueStorage, ITimeFieldConfig, ITimeUserPreferences> = {
id: TIME_FIELD_ID,
generic: true,
label: gettext('Time (authoring-react)'),
editorComponent: Editor,
previewComponent: Preview,
Expand Down
1 change: 1 addition & 0 deletions scripts/apps/authoring-react/fields/urls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function getUrlsField()
: ICustomFieldType<IUrlsFieldValueOperational, IUrlsFieldValueStorage, IUrlsFieldConfig, IUrlsFieldUserPreferences> {
const field: ReturnType<typeof getUrlsField> = {
id: URL_FIELD_ID,
generic: true,
label: gettext('Urls (authoring-react)'),
editorComponent: Editor,
previewComponent: Preview,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class TestEditorComponent extends React.PureComponent<IEditorComponentProps<stri

const customField: ICustomFieldType<string, string, string, never> = {
id: 'test-custom-authoring-field',
generic: true,
label: 'Test Field',
editorComponent: TestEditorComponent,
previewComponent: () => null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export function VocabularyEditController(

const fields = getFields();

$scope.customFieldTypes = Object.keys(fields).filter((id) => fields[id].private !== true).map((id) => ({
$scope.customFieldTypes = Object.keys(fields).filter((id) => fields[id].generic === true).map((id) => ({
id: id,
label: fields[id].label,
}));
Expand Down
7 changes: 5 additions & 2 deletions scripts/core/superdesk-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3700,9 +3700,12 @@ declare module 'superdesk-api' {
previewComponent: React.ComponentType<IPreviewComponentProps<IValueOperational, IConfig>>;

/**
* Allows for the field to be hidden from custom field type config
* Field types should be made generic when possible.
* Making field types generic means multiple fields of the same type can be enabled in the same editing view.
* Generic fields will be available for adding to content profile via user interface (settings).
*/
private?: boolean;
generic: boolean;

/**
* Must return `true` if not empty.
*/
Expand Down
1 change: 1 addition & 0 deletions scripts/extensions/booleanField/src/extension.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {gettext} = superdesk.localization;

const booleanField: ICustomFieldType<IValueOperational, IValueStorage, ICommonFieldConfig, IUserPreferences> = {
id: 'boolean',
generic: true,
label: gettext('Boolean'),
editorComponent: Editor,
previewComponent: Preview,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function getSubItemsField(): ISubItemsFieldType {
editorComponent: Editor,
previewComponent: Preview,

private: true,
generic: false,
hasValue: (valueOperational) => valueOperational != null && Object.keys(valueOperational).length > 0,
getEmptyValue: () => [],

Expand Down
1 change: 1 addition & 0 deletions scripts/extensions/datetimeField/src/extension.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function onTemplateCreate(_value: string, config: IConfig) {
const datetimeField: ICustomFieldType<IValueOperational, IValueStorage, IConfig, IUserPreferences> = {
id: 'datetime',
label: gettext('Datetime'),
generic: true,
editorComponent: Editor,
previewComponent: Preview,
configComponent: Config,
Expand Down
1 change: 1 addition & 0 deletions scripts/extensions/predefinedTextField/src/extension.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {gettext} = superdesk.localization;
const predefinedField: ICustomFieldType<IValueOperational, IValueStorage, IConfig, IUserPreferences> = {
id: 'predefined-text',
label: gettext('Predefined text field'),
generic: true,
editorComponent: Editor,
previewComponent: Preview,
configComponent: Config,
Expand Down

0 comments on commit 7024a6c

Please sign in to comment.