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

Move boolean field to core project #4706

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {ICommonFieldConfig, IEditorComponentProps} from 'superdesk-api';
import {IBooleanFieldValueOperational, ICommonFieldConfig, IEditorComponentProps} from 'superdesk-api';
import * as React from 'react';
import {Switch} from 'superdesk-ui-framework/react';
import {IValueOperational} from './interfaces';

type IProps = IEditorComponentProps<IValueOperational, ICommonFieldConfig, never>;
type IProps = IEditorComponentProps<IBooleanFieldValueOperational, ICommonFieldConfig, never>;

export class Editor extends React.PureComponent<IProps> {
render() {
Expand Down
30 changes: 30 additions & 0 deletions scripts/apps/authoring-react/fields/boolean/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
IBooleanFieldUserPreferences,
IBooleanFieldValueOperational,
IBooleanFieldValueStorage,
ICommonFieldConfig,
ICustomFieldType,
} from 'superdesk-api';
import {gettext} from 'core/utils';
import {Editor} from './editor';
import {Preview} from './preview';

type IBooleanField = ICustomFieldType<
IBooleanFieldValueOperational,
IBooleanFieldValueStorage,
ICommonFieldConfig,
IBooleanFieldUserPreferences
>;

export const getBooleanField = (): IBooleanField => {
return {
id: 'boolean',
generic: true,
label: gettext('Boolean'),
editorComponent: Editor,
previewComponent: Preview,
hasValue: (val) => val != null,
getEmptyValue: () => null,
};
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move interfaces to api-d.ts next to IDateValueOperational so it could be imported from extensions outside of this repo

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import {ICommonFieldConfig, IPreviewComponentProps} from 'superdesk-api';
import {IValueOperational} from './interfaces';
import {IBooleanFieldValueOperational, ICommonFieldConfig, IPreviewComponentProps} from 'superdesk-api';
import {Switch} from 'superdesk-ui-framework/react';
import {noop} from 'lodash';

export class Preview extends React.PureComponent<IPreviewComponentProps<IValueOperational, ICommonFieldConfig>> {
export class Preview extends React.PureComponent<
IPreviewComponentProps<IBooleanFieldValueOperational, ICommonFieldConfig>
> {
render() {
return (
<Switch
Expand Down
2 changes: 2 additions & 0 deletions scripts/apps/authoring-react/fields/register-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {getArticlesInPackageField} from './package-items';
import {getTagInputField} from './tag-input';
import {getDatelineField} from './dateline';
import {getDatetimeField} from './datetime';
import {getBooleanField} from './boolean';

export const AUTHORING_REACT_FIELDS = 'authoring-react--fields';

Expand Down Expand Up @@ -57,6 +58,7 @@ export function registerAuthoringReactFields() {
getArticlesInPackageField(),
getTagInputField(),
getDatelineField(),
getBooleanField(),
],
},
};
Expand Down
5 changes: 5 additions & 0 deletions scripts/core/superdesk-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ declare module 'superdesk-api' {
export type IAttachmentsUserPreferences = never;
export type IAttachmentsConfig = ICommonFieldConfig;

// AUTHORING-REACT FIELD TYPES - boolean
export type IBooleanFieldValueOperational = boolean | null;
export type IBooleanFieldValueStorage = IValueOperational;
export type IBooleanFieldUserPreferences = never;

// AUTHORING-REACT FIELD TYPES - date

export type IDateValueOperational = string;
Expand Down
1 change: 0 additions & 1 deletion scripts/extensions/booleanField/.gitignore

This file was deleted.

Loading
Loading