@boarteam/boar-pack-common-frontend 2.3.0 → 2.4.0
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.
|
|
3
|
+
"version": "2.4.0",
|
|
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>",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"scripts": {
|
|
47
47
|
"yalc:push": "yalc push"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "29f4f6c6598c7422bef8e02dfd1e679b471a4aa4"
|
|
50
50
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { Tag, Input, InputNumber, Space, Button } from "antd";
|
|
1
|
+
import { Tag, Input, InputNumber, Space, Button, Switch, Descriptions, Checkbox, Typography } from "antd";
|
|
2
2
|
import { ColumnFilterItem, FilterDropdownProps } from "antd/es/table/interface";
|
|
3
3
|
import { ReactNode, useEffect, useState } from "react";
|
|
4
4
|
|
|
5
|
+
const { Text } = Typography;
|
|
6
|
+
|
|
5
7
|
export const booleanFilters: ColumnFilterItem[] = [
|
|
6
8
|
{ text: <Tag color='red'>Disabled</Tag>, value: 0 },
|
|
7
9
|
{ text: <Tag color='green'>Enabled</Tag>, value: 1 },
|
|
@@ -22,9 +24,45 @@ export function NumberFilterDropdown({ setSelectedKeys, selectedKeys, confirm, c
|
|
|
22
24
|
)
|
|
23
25
|
}
|
|
24
26
|
|
|
27
|
+
export function SwitchFilterDropdown({ setSelectedKeys, selectedKeys, confirm, clearFilters, close }: FilterDropdownProps) {
|
|
28
|
+
return (
|
|
29
|
+
<DynamicOptionsFilterDropdown confirm={confirm} clearFilters={clearFilters}>
|
|
30
|
+
<Descriptions
|
|
31
|
+
style={{ margin: '8px 16px', width: 200 }}
|
|
32
|
+
items={[
|
|
33
|
+
{
|
|
34
|
+
label: 'Only filled values',
|
|
35
|
+
children: <Switch
|
|
36
|
+
checked={selectedKeys.length ? Boolean(selectedKeys[0]) : undefined}
|
|
37
|
+
onChange={(value) => setSelectedKeys([value as any])}
|
|
38
|
+
/>,
|
|
39
|
+
style: { padding: 0 },
|
|
40
|
+
contentStyle: { justifyContent: 'flex-end' },
|
|
41
|
+
}
|
|
42
|
+
]}
|
|
43
|
+
/>
|
|
44
|
+
</DynamicOptionsFilterDropdown>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function CheckboxFilterDropdown({ setSelectedKeys, selectedKeys, confirm, clearFilters, close }: FilterDropdownProps) {
|
|
49
|
+
return (
|
|
50
|
+
<DynamicOptionsFilterDropdown confirm={confirm} clearFilters={clearFilters}>
|
|
51
|
+
<Checkbox
|
|
52
|
+
checked={selectedKeys.length ? Boolean(selectedKeys[0]) : undefined}
|
|
53
|
+
onChange={(event) => setSelectedKeys([event.target.checked as any])}
|
|
54
|
+
indeterminate={selectedKeys.length === 0}
|
|
55
|
+
style={{ margin: '8px 16px', width: 250 }}
|
|
56
|
+
>
|
|
57
|
+
{selectedKeys.length ? (selectedKeys[0] ? 'Will show only filled values' : 'Will show only empty values') : <Text type="secondary">Click to filter</Text>}
|
|
58
|
+
</Checkbox>
|
|
59
|
+
</DynamicOptionsFilterDropdown>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
25
63
|
export function NumberRangeFilterDropdown({ setSelectedKeys, selectedKeys, confirm, clearFilters, close }: FilterDropdownProps) {
|
|
26
64
|
const [range, updateRange] = useState<[number, number] | undefined>(selectedKeys);
|
|
27
|
-
|
|
65
|
+
|
|
28
66
|
useEffect(() => {
|
|
29
67
|
updateRange(selectedKeys);
|
|
30
68
|
}, [selectedKeys]);
|
|
@@ -71,8 +109,8 @@ export function StringFilterDropdown({ setSelectedKeys, selectedKeys, confirm, c
|
|
|
71
109
|
|
|
72
110
|
export const DynamicOptionsFilterDropdown = ({
|
|
73
111
|
children,
|
|
74
|
-
confirm,
|
|
75
|
-
clearFilters,
|
|
112
|
+
confirm,
|
|
113
|
+
clearFilters,
|
|
76
114
|
}: Partial<FilterDropdownProps> & { children: ReactNode}) => {
|
|
77
115
|
return (
|
|
78
116
|
<div style={{ display: 'flex', flexDirection: 'column' }} onKeyDown={(e) => e.stopPropagation()}>
|
|
@@ -80,8 +118,8 @@ export const DynamicOptionsFilterDropdown = ({
|
|
|
80
118
|
<Space className="ant-table-filter-dropdown-btns">
|
|
81
119
|
<Button
|
|
82
120
|
type="link"
|
|
83
|
-
onClick={() => {
|
|
84
|
-
clearFilters();
|
|
121
|
+
onClick={() => {
|
|
122
|
+
clearFilters();
|
|
85
123
|
confirm();
|
|
86
124
|
}}
|
|
87
125
|
size="small"
|
|
@@ -20,19 +20,44 @@ export function getFiltersSearch({
|
|
|
20
20
|
let operator = col.filterOperator || col.operator;
|
|
21
21
|
let value = filters[colDataIndex] || baseFilters[colDataIndex];
|
|
22
22
|
filterKeys.delete(colDataIndex);
|
|
23
|
-
if (
|
|
23
|
+
if (value === '' || value === undefined || col.numeric && !Number.isFinite(Number(value))) {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
switch (operator) {
|
|
28
|
+
case Operators.between:
|
|
29
|
+
if (Array.isArray(value)) {
|
|
30
|
+
if (value?.[0] === undefined) {
|
|
31
|
+
operator = Operators.lowerOrEquals;
|
|
32
|
+
value = value?.[1];
|
|
33
|
+
} else if (value?.[1] === undefined) {
|
|
34
|
+
operator = Operators.greaterOrEquals;
|
|
35
|
+
value = value?.[0];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
break;
|
|
39
|
+
|
|
40
|
+
case Operators.isNull:
|
|
41
|
+
if (Array.isArray(value)) {
|
|
42
|
+
value = value[0];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (value !== true) {
|
|
46
|
+
operator = Operators.notNull;
|
|
47
|
+
value = true;
|
|
48
|
+
}
|
|
49
|
+
break;
|
|
50
|
+
|
|
51
|
+
case Operators.notNull:
|
|
52
|
+
if (Array.isArray(value)) {
|
|
53
|
+
value = value[0];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (value !== true) {
|
|
57
|
+
operator = Operators.isNull;
|
|
58
|
+
value = true;
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
36
61
|
}
|
|
37
62
|
|
|
38
63
|
search.$and?.push({ [field]: { [operator]: value } });
|
|
@@ -54,6 +79,8 @@ export const Operators = {
|
|
|
54
79
|
between: CondOperator.BETWEEN,
|
|
55
80
|
greaterOrEquals: CondOperator.GREATER_THAN_EQUALS,
|
|
56
81
|
lowerOrEquals: CondOperator.LOWER_THAN_EQUALS,
|
|
82
|
+
isNull: CondOperator.IS_NULL,
|
|
83
|
+
notNull: CondOperator.NOT_NULL,
|
|
57
84
|
} as const;
|
|
58
85
|
|
|
59
86
|
export function applyKeywordToSearch(
|