@dartech/arsenal-ui 1.4.10 → 1.4.12

Sign up to get free protection for your applications and to get access to all the features.
package/index.js CHANGED
@@ -2306,23 +2306,29 @@ const ControlArrayInput = ({
2306
2306
  required,
2307
2307
  defaultValue: _defaultValue = null
2308
2308
  }) => {
2309
- var _a, _b, _c;
2309
+ var _a, _b;
2310
2310
  const [localValue, setLoacalValue] = useState('');
2311
2311
  const [error, setError] = useState(null);
2312
- const {
2313
- field: {
2312
+ const _c = useController({
2313
+ control,
2314
+ name,
2315
+ defaultValue: _defaultValue,
2316
+ rules: {
2317
+ required: required && DEFAULT_REQUIRED_ERROR_TEXT
2318
+ }
2319
+ }),
2320
+ _d = _c.field,
2321
+ {
2314
2322
  onChange,
2315
2323
  value: values
2316
- },
2317
- // fieldState: { error },
2318
- formState: {
2319
- errors
2320
- }
2321
- } = useController({
2322
- control,
2323
- name,
2324
- defaultValue: _defaultValue
2325
- });
2324
+ } = _d,
2325
+ fieldData = __rest(_d, ["onChange", "value"]),
2326
+ {
2327
+ // fieldState: { error },
2328
+ formState: {
2329
+ errors
2330
+ }
2331
+ } = _c;
2326
2332
  const handleInputChange = useCallback(e => {
2327
2333
  const {
2328
2334
  value
@@ -2330,15 +2336,16 @@ const ControlArrayInput = ({
2330
2336
  setLoacalValue(value);
2331
2337
  }, []);
2332
2338
  const handleAdd = useCallback(() => {
2333
- var _a;
2334
2339
  setError(null);
2335
- if (localValue && !((_a = errors[name]) === null || _a === void 0 ? void 0 : _a.message) && !(Array.isArray(values) && values.includes(localValue))) {
2340
+ if (localValue &&
2341
+ // !errors[name]?.message &&
2342
+ !(Array.isArray(values) && values.includes(localValue))) {
2336
2343
  onChange([...(values !== null && values !== void 0 ? values : []), localValue]);
2337
2344
  setLoacalValue('');
2338
2345
  } else if (Array.isArray(values) && values.includes(localValue)) {
2339
2346
  setError('This value already exists');
2340
2347
  }
2341
- }, [localValue, errors, name, onChange, values]);
2348
+ }, [localValue, onChange, values]);
2342
2349
  const handleDelete = useCallback(value => {
2343
2350
  onChange(values.filter(code => code !== value));
2344
2351
  }, [values, onChange]);
@@ -2376,9 +2383,10 @@ const ControlArrayInput = ({
2376
2383
  }, index))
2377
2384
  })), jsx("input", Object.assign({
2378
2385
  type: "hidden"
2379
- }, control.register(name, {
2380
- required: required && 'Please, add a value'
2381
- }))), jsx(TextField, {
2386
+ }, control.register(name), {
2387
+ onChange: onChange,
2388
+ value: values
2389
+ }, fieldData)), jsx(TextField, {
2382
2390
  fullWidth: true,
2383
2391
  variant: "outlined",
2384
2392
  size: "small",
@@ -2392,8 +2400,7 @@ const ControlArrayInput = ({
2392
2400
  InputProps: {
2393
2401
  endAdornment: jsx(IconButton, Object.assign({
2394
2402
  size: "small",
2395
- onClick: handleAdd,
2396
- disabled: !!((_c = errors[name]) === null || _c === void 0 ? void 0 : _c.message)
2403
+ onClick: handleAdd
2397
2404
  }, {
2398
2405
  children: jsx(SvgIcon, {
2399
2406
  children: jsx("path", {
@@ -3026,6 +3033,7 @@ function TableInner({
3026
3033
  pagination = true,
3027
3034
  loading = false,
3028
3035
  onRowClick,
3036
+ emptyDataText,
3029
3037
  verticalAlign = 'middle'
3030
3038
  }, ref) {
3031
3039
  const {
@@ -3079,7 +3087,7 @@ function TableInner({
3079
3087
  })
3080
3088
  })
3081
3089
  }), jsx(TableBody, {
3082
- children: rows.map((row, index) => jsx(TableRow, Object.assign({
3090
+ children: rows.length ? rows.map((row, index) => jsx(TableRow, Object.assign({
3083
3091
  hover: true,
3084
3092
  onClick: onRowClick ? () => onRowClick(row) : row.onClick,
3085
3093
  sx: {
@@ -3094,7 +3102,18 @@ function TableInner({
3094
3102
  }, {
3095
3103
  children: column.renderCell ? column.renderCell(row, index) : row[column.id]
3096
3104
  }), idx))
3097
- }), index))
3105
+ }), index)) : jsx(TableRow, Object.assign({
3106
+ sx: {
3107
+ verticalAlign
3108
+ }
3109
+ }, {
3110
+ children: jsx(TableCell, Object.assign({
3111
+ align: "center",
3112
+ colSpan: columns.length
3113
+ }, {
3114
+ children: emptyDataText !== null && emptyDataText !== void 0 ? emptyDataText : 'Нет данных'
3115
+ }))
3116
+ }))
3098
3117
  }), pagination || children ? jsx(TableFooter, {
3099
3118
  children: jsxs(TableRow, {
3100
3119
  children: [children && jsx(TableCell, Object.assign({
@@ -3106,7 +3125,7 @@ function TableInner({
3106
3125
  }
3107
3126
  }, {
3108
3127
  children: children
3109
- })), pagination && rows.length && jsx(MuiTablePagination, {
3128
+ })), pagination && !!rows.length ? jsx(MuiTablePagination, {
3110
3129
  rowsPerPageOptions: [5, 10, 25],
3111
3130
  count: totalCount,
3112
3131
  rowsPerPage: +size,
@@ -3116,7 +3135,7 @@ function TableInner({
3116
3135
  },
3117
3136
  onPageChange: (_, page) => onPageChange(page),
3118
3137
  onRowsPerPageChange: event => onSizeChange(+event.target.value)
3119
- })]
3138
+ }) : null]
3120
3139
  })
3121
3140
  }) : null]
3122
3141
  }))]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dartech/arsenal-ui",
3
- "version": "1.4.10",
3
+ "version": "1.4.12",
4
4
  "author": "DAR",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -9,8 +9,9 @@ interface Props<T> {
9
9
  onRowClick?: (row: Row<T>) => void;
10
10
  children?: ReactNode;
11
11
  verticalAlign?: 'top' | 'middle' | 'bottom' | 'sub' | 'baseline';
12
+ emptyDataText?: string;
12
13
  }
13
- declare function TableInner<T>({ columns, rows, totalCount, children, pagination, loading, onRowClick, verticalAlign }: Props<T>, ref: ForwardedRef<HTMLTableElement>): JSX.Element;
14
+ declare function TableInner<T>({ columns, rows, totalCount, children, pagination, loading, onRowClick, emptyDataText, verticalAlign }: Props<T>, ref: ForwardedRef<HTMLTableElement>): JSX.Element;
14
15
  export declare const SimpleTable: <T>(props: Props<T> & {
15
16
  ref?: ForwardedRef<HTMLTableElement>;
16
17
  }) => ReturnType<typeof TableInner>;