@boarteam/boar-pack-common-frontend 2.6.0-alpha.5 → 2.6.0-alpha.7

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": "@boarteam/boar-pack-common-frontend",
3
- "version": "2.6.0-alpha.5",
3
+ "version": "2.6.0-alpha.7",
4
4
  "description": "Common frontend package for Boar Pack",
5
5
  "repository": "git@github.com:boarteam/boar-pack.git",
6
6
  "author": "Andrew Balakirev <balakirev.andrey@gmail.com>",
@@ -26,7 +26,8 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@nestjsx/crud-request": "^5.0.0-alpha.3",
29
- "lodash": "^4.17.21"
29
+ "lodash": "^4.17.21",
30
+ "uuid": "^11.1.0"
30
31
  },
31
32
  "devDependencies": {
32
33
  "@ant-design/icons": "^4.8.3",
@@ -46,5 +47,5 @@
46
47
  "scripts": {
47
48
  "yalc:push": "yalc push"
48
49
  },
49
- "gitHead": "1505d30b815618afd075af7d97e3945d15c5129b"
50
+ "gitHead": "b50c6748aef6069eb9e1fa919f42fdde0a886090"
50
51
  }
@@ -36,6 +36,7 @@ const Table = <Entity extends Record<string | symbol, any>,
36
36
  onDelete,
37
37
  onDeleteMany,
38
38
  exportUrl,
39
+ exportParams,
39
40
  onImport,
40
41
  pathParams,
41
42
  idColumnName = 'id',
@@ -123,6 +124,7 @@ const Table = <Entity extends Record<string | symbol, any>,
123
124
 
124
125
  const { exportButton, importButton, setLastQueryParams } = useImportExport<TPathParams>({
125
126
  exportUrl,
127
+ exportParams,
126
128
  onImport,
127
129
  })
128
130
 
@@ -1,4 +1,5 @@
1
1
  import { CondOperator, QueryJoin, SCondition } from "@nestjsx/crud-request";
2
+ import { validate as uuidValidate } from 'uuid';
2
3
  import { IWithId, TFilters, TSearchableColumn } from "./tableTypes";
3
4
  import React, { Key } from "react";
4
5
  import { TColumnsStates } from "./useColumnsSets";
@@ -20,7 +21,12 @@ export function getFiltersSearch({
20
21
  let operator = col.filterOperator || col.operator;
21
22
  let value = filters[colDataIndex] || baseFilters[colDataIndex];
22
23
  filterKeys.delete(colDataIndex);
23
- if (value === '' || value === undefined || col.numeric && !Number.isFinite(Number(value))) {
24
+ if (
25
+ value === '' ||
26
+ value === undefined ||
27
+ col.numeric && !Number.isFinite(Number(value)) ||
28
+ col.uuid && (typeof value !== 'string' || !uuidValidate(value))
29
+ ) {
24
30
  return;
25
31
  }
26
32
 
@@ -126,7 +132,10 @@ export function applyKeywordToSearch(
126
132
  const field = col.searchField || (Array.isArray(col.field) ? col.field.join('.') : col.field);
127
133
  const operator = col.operator;
128
134
 
129
- if (!col.numeric || Number.isFinite(Number(word))) {
135
+ const wrongNumeric = col.numeric && !Number.isFinite(Number(word));
136
+ const wrongUuid = col.uuid && (typeof word !== 'string' || !uuidValidate(word));
137
+
138
+ if (!wrongNumeric && !wrongUuid) {
130
139
  keywordSearch.$or.push({ [field]: { [operator]: word } });
131
140
  }
132
141
  });
@@ -78,6 +78,7 @@ export type TSearchableColumn = {
78
78
  filterField?: string,
79
79
  filterOperator?: typeof Operators[keyof typeof Operators],
80
80
  numeric?: boolean,
81
+ uuid?: boolean,
81
82
  }
82
83
 
83
84
  interface BaseProps<Entity,
@@ -108,6 +109,9 @@ export interface EditableProps<Entity, CreateDto, UpdateDto, TPathParams = {}> {
108
109
  afterSave?: (record: Entity) => Promise<void>;
109
110
  onCreate?: ({}: { requestBody: CreateDto } & TPathParams) => Promise<Entity>;
110
111
  exportUrl?: string;
112
+ exportParams?: {
113
+ [key: string]: string | number
114
+ };
111
115
  onImport?: (event: React.ChangeEvent<HTMLInputElement>) => Promise<any>;
112
116
  onUpdate: ({}: Partial<Entity> & {
113
117
  requestBody: UpdateDto,
@@ -6,9 +6,13 @@ import { Link } from "react-router-dom";
6
6
 
7
7
  export function useImportExport<TPathParams = {}>({
8
8
  exportUrl,
9
+ exportParams,
9
10
  onImport
10
11
  }: {
11
12
  exportUrl?: string;
13
+ exportParams?: {
14
+ [key: string]: string | number
15
+ }
12
16
  onImport?: (event: React.ChangeEvent<HTMLInputElement>) => Promise<any>;
13
17
  }) {
14
18
  const [isLoadingImport, setIsLoadingImport] = useState(false);
@@ -25,10 +29,15 @@ export function useImportExport<TPathParams = {}>({
25
29
  });
26
30
  }
27
31
 
28
- const url = exportUrl + (lastQueryParams ? '?' + new URLSearchParams({
29
- s: lastQueryParams.s,
30
- sort: lastQueryParams.sort?.[0],
31
- }).toString() : '');
32
+ const params = {
33
+ ...(lastQueryParams && {
34
+ s: lastQueryParams.s,
35
+ sort: lastQueryParams.sort?.[0],
36
+ }),
37
+ ...exportParams
38
+ }
39
+
40
+ const url = exportUrl + (Object.keys(params).length ? '?' + new URLSearchParams(params).toString() : '');
32
41
  const exportButton = <Tooltip title="Export">
33
42
  <Link to={url} target={'_blank'}>
34
43
  <Button icon={<DownloadOutlined />}/>