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

DateTime picker implementation #4689

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"sass-loader": "6.0.6",
"shortid": "2.2.8",
"style-loader": "0.20.2",
"superdesk-ui-framework": "^3.1.28",
"superdesk-ui-framework": "^4.0.3",
"ts-loader": "3.5.0",
"typescript": "4.9.5",
"uuid": "8.3.1",
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 @@ -16,6 +16,7 @@ import {geDurationField} from './duration';
import {getArticlesInPackageField} from './package-items';
import {getTagInputField} from './tag-input';
import {getDatelineField} from './dateline';
import {getDatetimeField} from './time copy';

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

Expand Down Expand Up @@ -45,6 +46,7 @@ export function registerAuthoringReactFields() {
getEditor3Field(),
getDropdownField(),
getDateField(),
getDatetimeField(),
getTimeField(),
geDurationField(),
getUrlsField(),
Expand Down
20 changes: 20 additions & 0 deletions scripts/apps/authoring-react/fields/time copy/difference.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import {IDifferenceComponentProps, ITimeFieldConfig, ITimeValueOperational} from 'superdesk-api';
import {DifferenceGeneric} from '../difference-generic';

type IProps = IDifferenceComponentProps<ITimeValueOperational, ITimeFieldConfig>;

export class Difference extends React.PureComponent<IProps> {
render() {
const {value1, value2} = this.props;

return (
<DifferenceGeneric
items1={value1 == null ? [] : [value1]}
items2={value2 == null ? [] : [value2]}
getId={(item) => item}
template={({item}) => <span>{item}</span>}
/>
);
}
}
37 changes: 37 additions & 0 deletions scripts/apps/authoring-react/fields/time copy/editor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import {DateTimePicker} from 'superdesk-ui-framework/react';
import {
ITimeValueOperational,
ITimeFieldConfig,
ITimeUserPreferences,
IEditorComponentProps,
} from 'superdesk-api';
import {gettext} from 'core/utils';

type IProps = IEditorComponentProps<ITimeValueOperational, ITimeFieldConfig, ITimeUserPreferences>;

export class Editor extends React.PureComponent<IProps> {
render() {
const Container = this.props.container;

return (
<Container>
<DateTimePicker
dateFormat='MM/DD/YYYY'
Copy link
Member

Choose a reason for hiding this comment

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

do not hardcode format - use the one from appConfig

label={gettext("Date time (AUTHORING-REACT)")}
onChange={(value) => {
this.props.onChange(value);
}}
value={(() => {
const {value} = this.props;
const parsedVal = value != null && (value.length > 0) ? new Date(value) : null;

return parsedVal;
})()}
disabled={this.props.config.readOnly}
width={this.props.config.width}
/>
</Container>
);
}
}
32 changes: 32 additions & 0 deletions scripts/apps/authoring-react/fields/time copy/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
ICustomFieldType,
ITimeValueOperational,
ITimeValueStorage,
ITimeFieldConfig,
ITimeUserPreferences,
} from 'superdesk-api';
import {gettext} from 'core/utils';
import {Editor} from './editor';
import {Preview} from './preview';
import {Difference} from './difference';

export const DATETIME_FIELD_ID = 'datetime';

export function getDatetimeField()
: ICustomFieldType<ITimeValueOperational, ITimeValueStorage, ITimeFieldConfig, ITimeUserPreferences> {
const field: ICustomFieldType<ITimeValueOperational, ITimeValueStorage, ITimeFieldConfig, ITimeUserPreferences> = {
id: DATETIME_FIELD_ID,
label: gettext('Datetime (authoring-react)'),
editorComponent: Editor,
previewComponent: Preview,
generic: true,

hasValue: (valueOperational) => valueOperational != null,
getEmptyValue: () => null,

differenceComponent: Difference,
configComponent: null,
};

return field;
}
28 changes: 28 additions & 0 deletions scripts/apps/authoring-react/fields/time copy/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {gettext} from 'core/utils';
import {noop} from 'lodash';
import React from 'react';
import {IPreviewComponentProps, ITimeFieldConfig, ITimeValueOperational} from 'superdesk-api';
import {DateTimePicker} from 'superdesk-ui-framework/react';

type IProps = IPreviewComponentProps<ITimeValueOperational, ITimeFieldConfig>;

export class Preview extends React.PureComponent<IProps> {
render() {
return (
<DateTimePicker
dateFormat='MM/DD/YYYY'
label={gettext("Date time (AUTHORING-REACT)")}
onChange={noop}
preview={true}
value={(() => {
const {value} = this.props;
const parsedVal = value != null && (value.length > 0) ? new Date(value) : null;

return parsedVal;
})()}
disabled={this.props.config.readOnly}
width={this.props.config.width}
/>
);
}
}
Loading