@gravity-ui/dynamic-forms 4.13.0 → 4.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,14 +11,14 @@ const helpers_1 = require("../../helpers");
11
11
  const Controller_1 = require("./Controller");
12
12
  const hooks_1 = require("./hooks");
13
13
  const utils_1 = require("./utils");
14
- const DynamicField = ({ name, spec, config, Monaco, generateRandomValue, search, withoutInsertFFDebounce, destroyOnUnregister = true, mutators: externalMutators, __mirror, }) => {
14
+ const DynamicField = ({ name, spec, config, Monaco, generateRandomValue, search, withoutInsertFFDebounce, destroyOnUnregister = true, mutators: externalMutators, shared: externalShared, __mirror, }) => {
15
15
  const DynamicFormsCtx = (0, hooks_1.useCreateContext)();
16
16
  const SearchContext = (0, hooks_1.useCreateSearchContext)();
17
17
  const { tools, store } = (0, hooks_1.useStore)(name);
18
18
  const watcher = (0, hooks_1.useIntegrationFF)(store, withoutInsertFFDebounce, destroyOnUnregister);
19
19
  const { mutatorsStore, mutateDFState } = (0, hooks_1.useMutators)(externalMutators);
20
20
  const { store: searchStore, setField, removeField, isHiddenField } = (0, hooks_1.useSearchStore)();
21
- const shared = (0, hooks_1.useFormSharedStore)();
21
+ const shared = (0, hooks_1.useFormSharedStore)(externalShared);
22
22
  const context = react_1.default.useMemo(() => ({
23
23
  config,
24
24
  Monaco: (0, react_is_1.isValidElementType)(Monaco) ? Monaco : undefined,
@@ -3,9 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useFormSharedStore = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
- const useFormSharedStore = () => {
7
- const [store, setStore] = react_1.default.useState({});
6
+ const useFormSharedStore = (shared) => {
7
+ const firstRender = react_1.default.useRef(true);
8
+ const [store, setStore] = react_1.default.useState(shared || {});
8
9
  const onChangeShared = react_1.default.useCallback((name, value) => setStore((s) => (Object.assign(Object.assign({}, s), { [name]: value }))), [setStore]);
10
+ react_1.default.useEffect(() => {
11
+ if (firstRender.current) {
12
+ firstRender.current = false;
13
+ }
14
+ else if (shared) {
15
+ setStore(Object.assign(Object.assign({}, store), shared));
16
+ }
17
+ }, [shared]);
9
18
  return { store, onChangeShared };
10
19
  };
11
20
  exports.useFormSharedStore = useFormSharedStore;
@@ -8,9 +8,9 @@ const helpers_1 = require("../../helpers");
8
8
  const ViewController_1 = require("./ViewController");
9
9
  const helpers_2 = require("./helpers");
10
10
  const hooks_1 = require("./hooks");
11
- const DynamicView = ({ value, spec, config, Link, Monaco, showLayoutDescription, }) => {
11
+ const DynamicView = ({ value, spec, config, Link, Monaco, showLayoutDescription, shared: externalShared, }) => {
12
12
  const DynamicFormsCtx = (0, hooks_1.useCreateContext)();
13
- const shared = (0, hooks_1.useViewSharedStore)();
13
+ const shared = (0, hooks_1.useViewSharedStore)(externalShared);
14
14
  const context = react_1.default.useMemo(() => ({
15
15
  config,
16
16
  value,
@@ -3,9 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useViewSharedStore = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
- const useViewSharedStore = () => {
7
- const [store, setStore] = react_1.default.useState({});
6
+ const useViewSharedStore = (shared) => {
7
+ const firstRender = react_1.default.useRef(true);
8
+ const [store, setStore] = react_1.default.useState(shared || {});
8
9
  const onChangeShared = react_1.default.useCallback((name, value) => setStore((s) => (Object.assign(Object.assign({}, s), { [name]: value }))), [setStore]);
10
+ react_1.default.useEffect(() => {
11
+ if (firstRender.current) {
12
+ firstRender.current = false;
13
+ }
14
+ else if (shared) {
15
+ setStore(Object.assign(Object.assign({}, store), shared));
16
+ }
17
+ }, [shared]);
9
18
  return { store, onChangeShared };
10
19
  };
11
20
  exports.useViewSharedStore = useViewSharedStore;
@@ -6,11 +6,12 @@ const react_1 = tslib_1.__importStar(require("react"));
6
6
  const date_components_1 = require("@gravity-ui/date-components");
7
7
  const date_utils_1 = require("@gravity-ui/date-utils");
8
8
  const utils_1 = require("../../../utils");
9
- exports.DEFAULT_DATE_FORMAT = 'DD-MM-YYYY';
9
+ exports.DEFAULT_DATE_FORMAT = 'DD.MM.YYYY HH:mm';
10
10
  const b = (0, utils_1.block)('date-input');
11
11
  const DateInput = ({ name, input, spec, inputProps, }) => {
12
12
  const { value, onChange, onBlur, onFocus } = input;
13
13
  const dateInput = spec.viewSpec.dateInput;
14
+ const timeZone = (dateInput === null || dateInput === void 0 ? void 0 : dateInput.timeZone) && (0, date_utils_1.isValidTimeZone)(dateInput.timeZone) ? dateInput.timeZone : undefined;
14
15
  const outputFormat = dateInput === null || dateInput === void 0 ? void 0 : dateInput.outputFormat;
15
16
  const onUpdate = (0, react_1.useCallback)((date) => {
16
17
  if (!date) {
@@ -42,8 +43,11 @@ const DateInput = ({ name, input, spec, inputProps, }) => {
42
43
  }
43
44
  }, [outputFormat]);
44
45
  const props = Object.assign(Object.assign({ hasClear: true, format: (dateInput === null || dateInput === void 0 ? void 0 : dateInput.printFormat) || exports.DEFAULT_DATE_FORMAT }, inputProps), { onBlur: onBlur, onFocus: onFocus, value: value
45
- ? (0, date_utils_1.dateTimeParse)(value.seconds ? value.seconds * 1000 : value) || null
46
- : null, onUpdate, disabled: spec.viewSpec.disabled, placeholder: spec.viewSpec.placeholder });
46
+ ? (0, date_utils_1.dateTimeParse)(value.seconds ? value.seconds * 1000 : value, {
47
+ format: dateInput === null || dateInput === void 0 ? void 0 : dateInput.outputFormat,
48
+ timeZone,
49
+ }) || null
50
+ : null, onUpdate, disabled: spec.viewSpec.disabled, placeholder: spec.viewSpec.placeholder, timeZone });
47
51
  return react_1.default.createElement(date_components_1.DatePicker, Object.assign({ className: b(), "data-qa": name }, props));
48
52
  };
49
53
  exports.DateInput = DateInput;
@@ -7,15 +7,17 @@ const components_1 = require("../../../components");
7
7
  const date_utils_1 = require("@gravity-ui/date-utils");
8
8
  const isObject_1 = tslib_1.__importDefault(require("lodash/isObject"));
9
9
  const DateView = (_a) => {
10
- var _b, _c, _d;
11
10
  var { value, spec } = _a, restProps = tslib_1.__rest(_a, ["value", "spec"]);
12
- let formatedValue = value && (0, isObject_1.default)(value) && value.seconds
13
- ? (value === null || value === void 0 ? void 0 : value.seconds) * 1000
14
- : value;
15
- const localSpec = spec.viewSpec;
16
- const format = ((_b = localSpec.inputProps) === null || _b === void 0 ? void 0 : _b.format) || ((_c = localSpec.dateInput) === null || _c === void 0 ? void 0 : _c.printFormat) || components_1.DEFAULT_DATE_FORMAT;
17
- if (formatedValue && format) {
18
- formatedValue = ((_d = (0, date_utils_1.dateTimeParse)(formatedValue)) === null || _d === void 0 ? void 0 : _d.format(format)) || formatedValue;
11
+ const { printFormat = components_1.DEFAULT_DATE_FORMAT, outputFormat, timeZone, } = spec.viewSpec.dateInput || {};
12
+ let formatedValue = value;
13
+ if ((0, isObject_1.default)(value) && value.seconds) {
14
+ formatedValue = Number(value.seconds) * 1000;
15
+ }
16
+ if (formatedValue) {
17
+ const date = (0, date_utils_1.dateTimeParse)(formatedValue, { format: outputFormat, timeZone });
18
+ if (date) {
19
+ formatedValue = date.format(printFormat);
20
+ }
19
21
  }
20
22
  return react_1.default.createElement(components_1.BaseView, Object.assign({ spec: spec, value: String(formatedValue) }, restProps));
21
23
  };
@@ -12,6 +12,7 @@ export interface DynamicFieldProps {
12
12
  withoutInsertFFDebounce?: boolean;
13
13
  destroyOnUnregister?: boolean;
14
14
  mutators?: DynamicFormMutators;
15
+ shared?: Record<string, any>;
15
16
  __mirror?: WonderMirror;
16
17
  }
17
18
  export declare const DynamicField: React.FC<DynamicFieldProps>;
@@ -7,14 +7,14 @@ import { isCorrectSpec } from '../../helpers';
7
7
  import { Controller } from './Controller';
8
8
  import { useCreateContext, useCreateSearchContext, useDynamicFieldMirror, useFormSharedStore, useIntegrationFF, useMutators, useSearchStore, useStore, } from './hooks';
9
9
  import { getDefaultSearchFunction, isCorrectConfig } from './utils';
10
- export const DynamicField = ({ name, spec, config, Monaco, generateRandomValue, search, withoutInsertFFDebounce, destroyOnUnregister = true, mutators: externalMutators, __mirror, }) => {
10
+ export const DynamicField = ({ name, spec, config, Monaco, generateRandomValue, search, withoutInsertFFDebounce, destroyOnUnregister = true, mutators: externalMutators, shared: externalShared, __mirror, }) => {
11
11
  const DynamicFormsCtx = useCreateContext();
12
12
  const SearchContext = useCreateSearchContext();
13
13
  const { tools, store } = useStore(name);
14
14
  const watcher = useIntegrationFF(store, withoutInsertFFDebounce, destroyOnUnregister);
15
15
  const { mutatorsStore, mutateDFState } = useMutators(externalMutators);
16
16
  const { store: searchStore, setField, removeField, isHiddenField } = useSearchStore();
17
- const shared = useFormSharedStore();
17
+ const shared = useFormSharedStore(externalShared);
18
18
  const context = React.useMemo(() => ({
19
19
  config,
20
20
  Monaco: isValidElementType(Monaco) ? Monaco : undefined,
@@ -1,4 +1,4 @@
1
- export declare const useFormSharedStore: () => {
2
- store: {};
1
+ export declare const useFormSharedStore: (shared?: Record<string, any>) => {
2
+ store: Record<string, any>;
3
3
  onChangeShared: (name: string, value: any) => void;
4
4
  };
@@ -1,6 +1,15 @@
1
1
  import React from 'react';
2
- export const useFormSharedStore = () => {
3
- const [store, setStore] = React.useState({});
2
+ export const useFormSharedStore = (shared) => {
3
+ const firstRender = React.useRef(true);
4
+ const [store, setStore] = React.useState(shared || {});
4
5
  const onChangeShared = React.useCallback((name, value) => setStore((s) => (Object.assign(Object.assign({}, s), { [name]: value }))), [setStore]);
6
+ React.useEffect(() => {
7
+ if (firstRender.current) {
8
+ firstRender.current = false;
9
+ }
10
+ else if (shared) {
11
+ setStore(Object.assign(Object.assign({}, store), shared));
12
+ }
13
+ }, [shared]);
5
14
  return { store, onChangeShared };
6
15
  };
@@ -12,5 +12,6 @@ export interface DynamicViewProps {
12
12
  }>;
13
13
  Monaco?: React.ComponentType<MonacoEditorProps>;
14
14
  showLayoutDescription?: boolean;
15
+ shared?: Record<string, any>;
15
16
  }
16
- export declare const DynamicView: ({ value, spec, config, Link, Monaco, showLayoutDescription, }: DynamicViewProps) => JSX.Element | null;
17
+ export declare const DynamicView: ({ value, spec, config, Link, Monaco, showLayoutDescription, shared: externalShared, }: DynamicViewProps) => JSX.Element | null;
@@ -4,9 +4,9 @@ import { isCorrectSpec } from '../../helpers';
4
4
  import { ViewController } from './ViewController';
5
5
  import { isCorrectViewConfig } from './helpers';
6
6
  import { useCreateContext, useViewSharedStore } from './hooks';
7
- export const DynamicView = ({ value, spec, config, Link, Monaco, showLayoutDescription, }) => {
7
+ export const DynamicView = ({ value, spec, config, Link, Monaco, showLayoutDescription, shared: externalShared, }) => {
8
8
  const DynamicFormsCtx = useCreateContext();
9
- const shared = useViewSharedStore();
9
+ const shared = useViewSharedStore(externalShared);
10
10
  const context = React.useMemo(() => ({
11
11
  config,
12
12
  value,
@@ -1,4 +1,4 @@
1
- export declare const useViewSharedStore: () => {
2
- store: {};
1
+ export declare const useViewSharedStore: (shared?: Record<string, any>) => {
2
+ store: Record<string, any>;
3
3
  onChangeShared: (name: string, value: any) => void;
4
4
  };
@@ -1,6 +1,15 @@
1
1
  import React from 'react';
2
- export const useViewSharedStore = () => {
3
- const [store, setStore] = React.useState({});
2
+ export const useViewSharedStore = (shared) => {
3
+ const firstRender = React.useRef(true);
4
+ const [store, setStore] = React.useState(shared || {});
4
5
  const onChangeShared = React.useCallback((name, value) => setStore((s) => (Object.assign(Object.assign({}, s), { [name]: value }))), [setStore]);
6
+ React.useEffect(() => {
7
+ if (firstRender.current) {
8
+ firstRender.current = false;
9
+ }
10
+ else if (shared) {
11
+ setStore(Object.assign(Object.assign({}, store), shared));
12
+ }
13
+ }, [shared]);
5
14
  return { store, onChangeShared };
6
15
  };
@@ -158,6 +158,7 @@ export interface StringSpec<LinkType = any, InputComponentProps extends Record<s
158
158
  dateInput?: {
159
159
  outputFormat?: string;
160
160
  printFormat?: string;
161
+ timeZone?: string;
161
162
  };
162
163
  copy?: boolean;
163
164
  selectParams?: {
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { DatePickerProps } from '@gravity-ui/date-components';
3
3
  import { StringInputProps } from '../../../../core';
4
4
  import './DateInput.css';
5
- export declare const DEFAULT_DATE_FORMAT = "DD-MM-YYYY";
5
+ export declare const DEFAULT_DATE_FORMAT = "DD.MM.YYYY HH:mm";
6
6
  export interface DateProps extends Omit<DatePickerProps, 'value' | 'disabled' | 'placeholder' | 'qa'> {
7
7
  }
8
8
  export declare const DateInput: React.FC<StringInputProps<DateProps>>;
@@ -1,13 +1,14 @@
1
1
  import React, { useCallback } from 'react';
2
2
  import { DatePicker } from '@gravity-ui/date-components';
3
- import { dateTimeParse } from '@gravity-ui/date-utils';
3
+ import { dateTimeParse, isValidTimeZone } from '@gravity-ui/date-utils';
4
4
  import { block } from '../../../utils';
5
5
  import './DateInput.css';
6
- export const DEFAULT_DATE_FORMAT = 'DD-MM-YYYY';
6
+ export const DEFAULT_DATE_FORMAT = 'DD.MM.YYYY HH:mm';
7
7
  const b = block('date-input');
8
8
  export const DateInput = ({ name, input, spec, inputProps, }) => {
9
9
  const { value, onChange, onBlur, onFocus } = input;
10
10
  const dateInput = spec.viewSpec.dateInput;
11
+ const timeZone = (dateInput === null || dateInput === void 0 ? void 0 : dateInput.timeZone) && isValidTimeZone(dateInput.timeZone) ? dateInput.timeZone : undefined;
11
12
  const outputFormat = dateInput === null || dateInput === void 0 ? void 0 : dateInput.outputFormat;
12
13
  const onUpdate = useCallback((date) => {
13
14
  if (!date) {
@@ -39,8 +40,11 @@ export const DateInput = ({ name, input, spec, inputProps, }) => {
39
40
  }
40
41
  }, [outputFormat]);
41
42
  const props = Object.assign(Object.assign({ hasClear: true, format: (dateInput === null || dateInput === void 0 ? void 0 : dateInput.printFormat) || DEFAULT_DATE_FORMAT }, inputProps), { onBlur: onBlur, onFocus: onFocus, value: value
42
- ? dateTimeParse(value.seconds ? value.seconds * 1000 : value) || null
43
- : null, onUpdate, disabled: spec.viewSpec.disabled, placeholder: spec.viewSpec.placeholder });
43
+ ? dateTimeParse(value.seconds ? value.seconds * 1000 : value, {
44
+ format: dateInput === null || dateInput === void 0 ? void 0 : dateInput.outputFormat,
45
+ timeZone,
46
+ }) || null
47
+ : null, onUpdate, disabled: spec.viewSpec.disabled, placeholder: spec.viewSpec.placeholder, timeZone });
44
48
  return React.createElement(DatePicker, Object.assign({ className: b(), "data-qa": name }, props));
45
49
  };
46
50
  export default DateInput;
@@ -4,15 +4,17 @@ import { BaseView, DEFAULT_DATE_FORMAT } from '../../../components';
4
4
  import { dateTimeParse } from '@gravity-ui/date-utils';
5
5
  import isObject from 'lodash/isObject';
6
6
  export const DateView = (_a) => {
7
- var _b, _c, _d;
8
7
  var { value, spec } = _a, restProps = __rest(_a, ["value", "spec"]);
9
- let formatedValue = value && isObject(value) && value.seconds
10
- ? (value === null || value === void 0 ? void 0 : value.seconds) * 1000
11
- : value;
12
- const localSpec = spec.viewSpec;
13
- const format = ((_b = localSpec.inputProps) === null || _b === void 0 ? void 0 : _b.format) || ((_c = localSpec.dateInput) === null || _c === void 0 ? void 0 : _c.printFormat) || DEFAULT_DATE_FORMAT;
14
- if (formatedValue && format) {
15
- formatedValue = ((_d = dateTimeParse(formatedValue)) === null || _d === void 0 ? void 0 : _d.format(format)) || formatedValue;
8
+ const { printFormat = DEFAULT_DATE_FORMAT, outputFormat, timeZone, } = spec.viewSpec.dateInput || {};
9
+ let formatedValue = value;
10
+ if (isObject(value) && value.seconds) {
11
+ formatedValue = Number(value.seconds) * 1000;
12
+ }
13
+ if (formatedValue) {
14
+ const date = dateTimeParse(formatedValue, { format: outputFormat, timeZone });
15
+ if (date) {
16
+ formatedValue = date.format(printFormat);
17
+ }
16
18
  }
17
19
  return React.createElement(BaseView, Object.assign({ spec: spec, value: String(formatedValue) }, restProps));
18
20
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dynamic-forms",
3
- "version": "4.13.0",
3
+ "version": "4.14.1",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "main": "build/cjs/index.js",
@@ -46,8 +46,8 @@
46
46
  "dependencies": {
47
47
  "@bem-react/classname": "^1.6.0",
48
48
  "@gravity-ui/components": "^3.0.0",
49
- "@gravity-ui/date-components": "^2.4.0",
50
- "@gravity-ui/date-utils": "^2.4.0",
49
+ "@gravity-ui/date-components": "^2.10.3",
50
+ "@gravity-ui/date-utils": "^2.5.5",
51
51
  "@gravity-ui/i18n": "^1.2.0",
52
52
  "@gravity-ui/icons": "^2.8.1",
53
53
  "lodash": "^4.17.20"