@dartech/arsenal-ui 1.2.5 → 1.2.6

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": "@dartech/arsenal-ui",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "author": "DAR",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -3,64 +3,37 @@ import SvgIcon from '@mui/material/SvgIcon';
3
3
  import Tooltip from '@mui/material/Tooltip';
4
4
  import { CopyButton, Status } from '../lib';
5
5
  import { format } from 'date-fns';
6
- import { StatusVariant, TableDataType } from '../interfaces';
6
+ import { StatusVariant } from '../interfaces';
7
7
  import JsonTypeCell from '../lib/Table/DataGrid/JsonTypeCell';
8
8
 
9
9
  export const formatTableRowValue = ({
10
10
  value,
11
- type,
12
- copyText,
13
- status,
11
+ canCopy,
12
+ copyValue,
13
+ shortId,
14
+ fullText,
15
+ textParams: { displayAs = 'text', dateFormat, statusVariant },
14
16
  }: {
15
17
  value: any;
16
- type?: TableDataType;
17
- copyText?: string;
18
- status?: StatusVariant;
18
+ canCopy?: boolean;
19
+ copyValue?: string;
20
+ shortId?: boolean;
21
+ fullText?: boolean;
22
+ textParams?: {
23
+ displayAs?:
24
+ | 'text'
25
+ | 'boolean'
26
+ | 'date'
27
+ | 'status'
28
+ | 'json_text'
29
+ | 'json_code'
30
+ | 'array'
31
+ | 'number';
32
+ dateFormat?: string[];
33
+ statusVariant?: StatusVariant;
34
+ };
19
35
  }) => {
20
- switch (type) {
21
- case 'id':
22
- return (
23
- <Box display="flex" alignItems="center" minWidth="100%">
24
- <Tooltip title={value}>
25
- <Box mr="auto">
26
- {value
27
- ? `${(value as string).slice(0, 6)}...${(value as string).slice(
28
- -6
29
- )}`
30
- : '...'}
31
- </Box>
32
- </Tooltip>
33
-
34
- <CopyButton copyText={(copyText ? copyText : value) as string} />
35
- </Box>
36
- );
37
- case 'JSON_copy':
38
- return <JsonTypeCell value={value} copyButton />;
39
- case 'JSON':
40
- return <JsonTypeCell value={value} />;
41
- case 'JSON_text':
42
- return <JsonTypeCell value={value} textField />;
43
- case 'copy':
44
- return (
45
- <Box display="flex" alignItems="center" minWidth="100%">
46
- <Tooltip title={value}>
47
- <Box
48
- mr="auto"
49
- overflow="hidden"
50
- textOverflow="ellipsis"
51
- whiteSpace="nowrap"
52
- >
53
- {value?.length > 12
54
- ? `${(value as string).slice(0, 6)}...${(value as string).slice(
55
- -6
56
- )}`
57
- : value}
58
- </Box>
59
- </Tooltip>
60
-
61
- <CopyButton copyText={(copyText ? copyText : value) as string} />
62
- </Box>
63
- );
36
+ switch (displayAs) {
64
37
  case 'boolean':
65
38
  return value ? (
66
39
  <SvgIcon color="primary" fontSize="small">
@@ -73,15 +46,32 @@ export const formatTableRowValue = ({
73
46
  );
74
47
  case 'date':
75
48
  return value ? (
76
- <div>
77
- <div>{format(new Date(value as string), 'dd.MM.yyyy')}</div>
78
- <div>{format(new Date(value as string), 'HH:mm:ss')}</div>
79
- </div>
49
+ dateFormat ? (
50
+ <Box>
51
+ {dateFormat.map((formatString) => (
52
+ <Box>{format(new Date(value as string), formatString)}</Box>
53
+ ))}
54
+ </Box>
55
+ ) : (
56
+ <Box>
57
+ <Box>{format(new Date(value as string), 'dd.MM.yyyy')}</Box>
58
+ <Box>{format(new Date(value as string), 'HH:mm:ss')}</Box>
59
+ </Box>
60
+ )
80
61
  ) : (
81
62
  ''
82
63
  );
83
64
  case 'status':
84
- return <Status text={value as string} status={status} />;
65
+ return (
66
+ <Status
67
+ text={value as string}
68
+ status={statusVariant ? statusVariant : 'default'}
69
+ />
70
+ );
71
+ case 'json_text':
72
+ return <JsonTypeCell value={value} textField />;
73
+ case 'json_code':
74
+ return <JsonTypeCell value={value} copyButton />;
85
75
  case 'array':
86
76
  return (
87
77
  <Box>
@@ -90,13 +80,53 @@ export const formatTableRowValue = ({
90
80
  ))}
91
81
  </Box>
92
82
  );
93
- default:
83
+ case 'number':
94
84
  return (
95
- <Tooltip title={value}>
96
- <div className="MuiDataGrid-cellContent" title={value}>
97
- {value}
98
- </div>
99
- </Tooltip>
85
+ <Box display="flex" justifyContent="flex-end">
86
+ <Box>
87
+ {value.toLocaleString('ru-Ru', { minimumFractionDigits: 2 })}
88
+ </Box>
89
+ </Box>
90
+ );
91
+ case 'text':
92
+ default:
93
+ return value ? (
94
+ <Box display="flex" alignItems="center" width="100%">
95
+ {shortId ? (
96
+ <Tooltip title={value}>
97
+ <Box mr="auto">
98
+ {value
99
+ ? `${(value as string).slice(0, 6)}...${(
100
+ value as string
101
+ ).slice(-6)}`
102
+ : '...'}
103
+ </Box>
104
+ </Tooltip>
105
+ ) : fullText ? (
106
+ <Box sx={{ whiteSpace: 'normal' }} title={value}>
107
+ {typeof value === 'string' ? value : JSON.stringify(value)}
108
+ </Box>
109
+ ) : (
110
+ <Tooltip title={value}>
111
+ <Box className="MuiDataGrid-cellContent" title={value}>
112
+ {typeof value === 'string' ? value : JSON.stringify(value)}
113
+ </Box>
114
+ </Tooltip>
115
+ )}
116
+ {canCopy && (
117
+ <CopyButton
118
+ copyText={
119
+ copyValue
120
+ ? typeof copyValue === 'string'
121
+ ? copyValue
122
+ : JSON.stringify(copyValue)
123
+ : value
124
+ }
125
+ />
126
+ )}
127
+ </Box>
128
+ ) : (
129
+ ''
100
130
  );
101
131
  }
102
132
  };