@true-engineering/true-react-common-ui-kit 3.52.0 → 3.53.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@true-engineering/true-react-common-ui-kit",
3
- "version": "3.52.0",
3
+ "version": "3.53.1",
4
4
  "description": "True Engineering React UI Kit with theming support",
5
5
  "author": "True Engineering (https://trueengineering.ru)",
6
6
  "keywords": [
@@ -70,7 +70,8 @@ type ConfigValues = {
70
70
  custom: string;
71
71
  };
72
72
 
73
- interface IFiltersPaneWithCustomProps<Values, Content> extends IFiltersPaneProps<Values, Content> {
73
+ interface IFiltersPaneWithCustomProps<Values extends Record<string, unknown>, Content>
74
+ extends IFiltersPaneProps<Values, Content> {
74
75
  containerWidth: number;
75
76
  isSearchDisabled: boolean;
76
77
  isSearchAutosizeable: boolean;
@@ -81,7 +82,7 @@ interface IFiltersPaneWithCustomProps<Values, Content> extends IFiltersPaneProps
81
82
  isClearableFields: boolean;
82
83
  }
83
84
 
84
- function FiltersPaneWithCustomProps<Values, Content>({
85
+ function FiltersPaneWithCustomProps<Values extends Record<string, unknown>, Content>({
85
86
  containerWidth,
86
87
  isSearchDisabled,
87
88
  isSearchAutosizeable,
@@ -292,6 +293,7 @@ Default.args = {
292
293
  hasClearButton: true,
293
294
  isClearableFields: false,
294
295
  isDisabled: false,
296
+ shouldRenderDataId: false,
295
297
  containerWidth: 400,
296
298
  withFieldNameInLabel: true,
297
299
  isGroupingEnabled: true,
@@ -10,7 +10,7 @@ import { getLocale } from './helpers';
10
10
  import { ConfigType, IFilterLocaleKey, IPartialFilterLocale } from './types';
11
11
  import { useStyles, IFiltersPaneStyles, clearButtonStyles } from './FiltersPane.styles';
12
12
 
13
- export interface IFiltersPaneProps<Values, Content = Values>
13
+ export interface IFiltersPaneProps<Values extends Record<string, unknown>, Content = Values>
14
14
  extends ICommonProps<IFiltersPaneStyles> {
15
15
  filtersConfig: ConfigType<Values>;
16
16
  enabledFilters?: Array<keyof ConfigType<Values>>;
@@ -23,6 +23,8 @@ export interface IFiltersPaneProps<Values, Content = Values>
23
23
  isDisabled?: boolean;
24
24
  /** @default true */
25
25
  hasClearButton?: boolean;
26
+ /** @default false */
27
+ shouldRenderDataId?: boolean;
26
28
  onChangeFilters: (values: Partial<Values>) => void;
27
29
  onSettingsButtonClick?: () => void;
28
30
  onClear?: () => void;
@@ -39,6 +41,7 @@ export function FiltersPane<Values extends Record<string, unknown>, Content = Va
39
41
  search,
40
42
  isDisabled = false,
41
43
  hasClearButton = true,
44
+ shouldRenderDataId = false,
42
45
  testId,
43
46
  onChangeFilters,
44
47
  onSettingsButtonClick,
@@ -61,7 +64,7 @@ export function FiltersPane<Values extends Record<string, unknown>, Content = Va
61
64
 
62
65
  const translates = useMemo(() => getLocale(localeKey, locale), [localeKey, locale]);
63
66
 
64
- const filtersKeys = enabledFilters || Object.keys(filtersConfig);
67
+ const filtersKeys = enabledFilters ?? Object.keys(filtersConfig);
65
68
 
66
69
  const handleClear = () => {
67
70
  if (onClear !== undefined) {
@@ -122,10 +125,11 @@ export function FiltersPane<Values extends Record<string, unknown>, Content = Va
122
125
  {/* Filters */}
123
126
  {filtersKeys.map((key, index) => {
124
127
  const isLast = index === filtersKeys.length - 1;
125
- const currentValue = values[key];
126
- const filter = filtersConfig[key];
128
+ const filterKey = String(key);
129
+ const currentValue = values[filterKey];
130
+ const filter = filtersConfig[filterKey];
127
131
  if (filter === undefined) {
128
- console.error(`enabledFilters содержит фильтр ${String(key)}, не описанный в конфиге`);
132
+ console.error(`enabledFilters содержит фильтр ${filterKey}, не описанный в конфиге`);
129
133
  if (isLast) {
130
134
  return clearButton;
131
135
  }
@@ -137,18 +141,19 @@ export function FiltersPane<Values extends Record<string, unknown>, Content = Va
137
141
  filter={filter}
138
142
  locale={locale}
139
143
  localeKey={localeKey}
140
- onChange={(value) => onChangeFilters({ ...values, [key]: value })}
144
+ onChange={(value) => onChangeFilters({ ...values, [filterKey]: value })}
141
145
  value={currentValue}
142
- key={key as string}
146
+ key={filterKey}
143
147
  isDisabled={isDisabled || filter?.requiredFilledFilters?.some((item) => !values[item])}
144
148
  tweakStyles={tweakFilterWrapperStyles}
145
- testId={getTestId(testId, `filter-${String(key)}`)}
149
+ data={shouldRenderDataId ? { id: filterKey } : undefined}
150
+ testId={getTestId(testId, `filter-${filterKey}`)}
146
151
  />
147
152
  );
148
153
 
149
154
  if (isLast) {
150
155
  return (
151
- <div className={classes.filterWithClearButton} key={key as string}>
156
+ <div className={classes.filterWithClearButton} key={filterKey}>
152
157
  {filterWrapper}
153
158
  {shouldShowClearButton && <>{clearButton}</>}
154
159
  </div>
@@ -1,20 +1,20 @@
1
1
  import { useMemo } from 'react';
2
2
  import { getLocale } from '../../helpers';
3
- import { IFilterMultiSelectValues, IFilterWithDatesValue, IPeriod } from '../../types';
4
3
  import { FilterInterval } from '../FilterInterval';
5
4
  import { FilterMultiSelect } from '../FilterMultiSelect';
6
5
  import { FilterSelect } from '../FilterSelect';
7
6
  import { FilterWithDates } from '../FilterWithDates';
8
7
  import { FilterWithPeriod } from '../FilterWithPeriod';
9
8
  import type { IFilterWrapperProps } from '../FilterWrapper';
9
+ import { isDatePeriodValue, isMultiSelectValue, isPeriodValue } from './helpers';
10
10
 
11
- export interface IFilterProps<Values, Key extends keyof Values>
11
+ export interface IFilterProps<Values extends Record<string, unknown>, Key extends keyof Values>
12
12
  extends IFilterWrapperProps<Values, Key> {
13
13
  onChange: <V>(v: V) => void;
14
14
  onClose?: () => void;
15
15
  }
16
16
 
17
- export function Filter<Values, Key extends keyof Values>(
17
+ export function Filter<Values extends Record<string, unknown>, Key extends keyof Values>(
18
18
  props: IFilterProps<Values, Key>,
19
19
  ): JSX.Element | null {
20
20
  const { filter, value, onChange, onClose, localeKey, locale, testId } = props;
@@ -39,9 +39,11 @@ export function Filter<Values, Key extends keyof Values>(
39
39
  }
40
40
 
41
41
  if (filter.type === 'dateRange') {
42
+ const preparedValue = isPeriodValue(value) ? { ...value } : undefined;
43
+
42
44
  return (
43
45
  <FilterWithPeriod
44
- value={{ ...value } as IPeriod}
46
+ value={preparedValue}
45
47
  onChange={onChange}
46
48
  onClose={onClose}
47
49
  localeKey={translatesLocaleKey}
@@ -53,25 +55,27 @@ export function Filter<Values, Key extends keyof Values>(
53
55
  }
54
56
 
55
57
  if (filter.type === 'dateRangeWithoutPeriod') {
58
+ const preparedValue = isDatePeriodValue(value) ? value : undefined;
59
+
56
60
  return (
57
- <div style={{ width: 320 }}>
58
- <FilterWithDates
59
- value={value as unknown as IFilterWithDatesValue}
60
- onChange={(v) => onChange({ ...v, periodType: 'CUSTOM' })}
61
- onEndBtnSubmit={() => onChange(undefined)}
62
- localeKey={translatesLocaleKey}
63
- locale={translates}
64
- testId={testId !== undefined ? `${testId}-dates` : undefined}
65
- {...filter}
66
- />
67
- </div>
61
+ <FilterWithDates
62
+ value={preparedValue}
63
+ onChange={(v) => onChange({ ...v, periodType: 'CUSTOM' })}
64
+ onEndBtnSubmit={() => onChange(undefined)}
65
+ localeKey={translatesLocaleKey}
66
+ locale={translates}
67
+ testId={testId !== undefined ? `${testId}-dates` : undefined}
68
+ {...filter}
69
+ />
68
70
  );
69
71
  }
70
72
 
71
73
  if (filter.type === 'multiSelect') {
74
+ const preparedValue = isMultiSelectValue<any>(value) ? value : undefined;
75
+
72
76
  return (
73
77
  <FilterMultiSelect
74
- value={value as unknown as IFilterMultiSelectValues<any>}
78
+ value={preparedValue}
75
79
  onChange={onChange}
76
80
  onClose={onClose}
77
81
  localeKey={translatesLocaleKey}
@@ -83,9 +87,11 @@ export function Filter<Values, Key extends keyof Values>(
83
87
  }
84
88
 
85
89
  if (filter.type === 'interval') {
90
+ const preparedValue = Array.isArray(value) ? (value as number[]) : undefined;
91
+
86
92
  return (
87
93
  <FilterInterval
88
- value={value as unknown as number[]}
94
+ value={preparedValue}
89
95
  onChange={onChange}
90
96
  localeKey={translatesLocaleKey}
91
97
  locale={translates}
@@ -102,6 +108,7 @@ export function Filter<Values, Key extends keyof Values>(
102
108
 
103
109
  if (filter.type === 'custom' && filter.component) {
104
110
  const Component = filter.component;
111
+
105
112
  return <Component {...props} filter={filter} />;
106
113
  }
107
114
 
@@ -0,0 +1,18 @@
1
+ import { isEmpty, isString } from '@true-engineering/true-react-platform-helpers';
2
+ import { IDatePeriod, IFilterMultiSelectValues, IPeriod } from '../../types';
3
+
4
+ const isDateOrEmpty = (value: unknown): value is Date | null | undefined =>
5
+ isEmpty(value) || value instanceof Date;
6
+
7
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
8
+ export const isDatePeriodValue = (value: any): value is IDatePeriod =>
9
+ isDateOrEmpty(value?.from) && isDateOrEmpty(value?.to);
10
+
11
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
12
+ export const isPeriodValue = (value: any): value is IPeriod =>
13
+ isString(value?.periodType) && isDatePeriodValue(value);
14
+
15
+ export const isMultiSelectValue = <T extends string>(
16
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
17
+ value: any,
18
+ ): value is IFilterMultiSelectValues<T> => Array.isArray(value?.include);
@@ -9,14 +9,17 @@ import { IDateRangeConfigItem, IFilterWithDatesValue, IPeriod } from '../../type
9
9
  import type { IFilterWrapperProps } from '../FilterWrapper';
10
10
  import { IFilterValueViewStyles, useStyles } from './FilterValueView.styles';
11
11
 
12
- export function FilterValueView<Values, Key extends keyof Values>({
12
+ export interface IFilterValueView<Values extends Record<string, unknown>, Key extends keyof Values>
13
+ extends Omit<IFilterWrapperProps<Values, Key>, 'filtersPaneRef' | 'tweakStyles' | 'onChange'>,
14
+ ICommonProps<IFilterValueViewStyles> {}
15
+
16
+ export function FilterValueView<Values extends Record<string, unknown>, Key extends keyof Values>({
17
+ value,
18
+ filter,
13
19
  locale,
14
20
  localeKey,
15
- filter,
16
- value,
17
21
  tweakStyles,
18
- }: Omit<IFilterWrapperProps<Values, Key>, 'onChange' | 'filtersPaneRef' | 'tweakStyles'> &
19
- ICommonProps<IFilterValueViewStyles>): JSX.Element {
22
+ }: IFilterValueView<Values, Key>): JSX.Element {
20
23
  const classes = useStyles({ theme: tweakStyles });
21
24
 
22
25
  const translatesLocaleKey = filter.localeKey ?? localeKey;
@@ -6,6 +6,7 @@ import { innerTextButtonStyles } from '../../FiltersPane.styles';
6
6
 
7
7
  export const useStyles = createThemedStyles('FilterWithDates', {
8
8
  root: {
9
+ width: 320,
9
10
  background: colors.CLASSIC_WHITE,
10
11
  position: 'relative',
11
12
  zIndex: 20,
@@ -151,7 +151,7 @@ export const FilterWithPeriod: FC<IFilterWithPeriodProps> = ({
151
151
  </div>
152
152
  )}
153
153
  {isDatePickerShown && (
154
- <div className={classes.picker} style={{ width: 320 }} ref={refDatePicker}>
154
+ <div className={classes.picker} ref={refDatePicker}>
155
155
  <FilterWithDates
156
156
  onStartBtnSubmit={() => {
157
157
  setIsDatePickerShown(false);
@@ -12,8 +12,10 @@ import { FilterValueView } from '../FilterValueView';
12
12
  import { isContentNotEmpty } from './helpers';
13
13
  import { useStyles, IFilterWrapperStyles } from './FilterWrapper.styles';
14
14
 
15
- export interface IFilterWrapperProps<Values, Key extends keyof Values>
16
- extends ICommonProps<IFilterWrapperStyles> {
15
+ export interface IFilterWrapperProps<
16
+ Values extends Record<string, unknown>,
17
+ Key extends keyof Values,
18
+ > extends ICommonProps<IFilterWrapperStyles> {
17
19
  filter: ConfigItem<Values[Key]>;
18
20
  value?: Values[Key];
19
21
  isDisabled?: boolean;
@@ -22,7 +24,7 @@ export interface IFilterWrapperProps<Values, Key extends keyof Values>
22
24
  onChange: <V>(value: V) => void;
23
25
  }
24
26
 
25
- export function FilterWrapper<Values, Key extends keyof Values>({
27
+ export function FilterWrapper<Values extends Record<string, unknown>, Key extends keyof Values>({
26
28
  filter,
27
29
  value,
28
30
  isDisabled,
@@ -105,8 +107,8 @@ export function FilterWrapper<Values, Key extends keyof Values>({
105
107
  <FilterValueView
106
108
  value={value}
107
109
  filter={filter}
108
- localeKey={localeKey}
109
110
  locale={locale}
111
+ localeKey={localeKey}
110
112
  testId={getTestId(testId, 'value')}
111
113
  tweakStyles={tweakFilterValueViewStyles}
112
114
  />
@@ -137,8 +139,8 @@ export function FilterWrapper<Values, Key extends keyof Values>({
137
139
  <Filter
138
140
  value={value}
139
141
  filter={filter}
140
- localeKey={localeKey}
141
142
  locale={locale}
143
+ localeKey={localeKey}
142
144
  onClose={onClose}
143
145
  onChange={onChange}
144
146
  testId={testId}
@@ -74,10 +74,6 @@ export const inputStyles: IInputStyles = {
74
74
  inputWrapper: {
75
75
  paddingLeft: COUNTRY_SELECT_WIDTH,
76
76
  },
77
-
78
- label: {
79
- marginLeft: COUNTRY_SELECT_WIDTH,
80
- },
81
77
  };
82
78
 
83
79
  export type IPhoneInputStyles = ITweakStyles<
@@ -44,6 +44,8 @@ export const inputStyles: IInputStyles = {
44
44
  },
45
45
 
46
46
  label: {
47
+ '--label-max-width': '100%',
48
+
47
49
  left: 0,
48
50
  fontSize: 14,
49
51
  },