@controleonline/ui-default 1.0.265 → 1.0.266
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 +1 -1
- package/src/react/components/table/DefaultDebug.js +234 -233
- package/src/react/components/table/DefaultTable.js +429 -396
- package/src/react/components/table/DefaultTable.styles.js +17 -5
- package/src/react/components/table/DefaultTableControls.js +205 -208
- package/src/react/components/table/DefaultTableRows.js +344 -340
- package/src/react/components/table/useDefaultTableTheme.js +52 -58
- package/src/tests/react/components/table/DefaultTable.test.js +376 -241
|
@@ -123,11 +123,23 @@ const styles = StyleSheet.create({
|
|
|
123
123
|
},
|
|
124
124
|
toolbarButtonActive: {
|
|
125
125
|
},
|
|
126
|
-
toolbarAddButton: {
|
|
127
|
-
minWidth: 30,
|
|
128
|
-
width: 30,
|
|
129
|
-
paddingHorizontal: 0,
|
|
130
|
-
},
|
|
126
|
+
toolbarAddButton: {
|
|
127
|
+
minWidth: 30,
|
|
128
|
+
width: 30,
|
|
129
|
+
paddingHorizontal: 0,
|
|
130
|
+
},
|
|
131
|
+
floatingAddButton: {
|
|
132
|
+
position: 'absolute',
|
|
133
|
+
right: 16,
|
|
134
|
+
bottom: 16,
|
|
135
|
+
width: 52,
|
|
136
|
+
height: 52,
|
|
137
|
+
borderRadius: 26,
|
|
138
|
+
alignItems: 'center',
|
|
139
|
+
justifyContent: 'center',
|
|
140
|
+
zIndex: 30,
|
|
141
|
+
...shadow,
|
|
142
|
+
},
|
|
131
143
|
toolbarBadgeText: {
|
|
132
144
|
fontSize: 10,
|
|
133
145
|
fontWeight: '900',
|
|
@@ -1,208 +1,205 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Text, TouchableOpacity } from 'react-native';
|
|
3
|
-
import Icon from 'react-native-vector-icons/Feather';
|
|
4
|
-
import { useStore } from '@store';
|
|
5
|
-
import DefaultColumnMenu from './DefaultColumnMenu';
|
|
6
|
-
import DefaultDebug from './DefaultDebug';
|
|
7
|
-
import DefaultFiltersModal from './DefaultFiltersModal';
|
|
8
|
-
import DefaultModalButton from './DefaultModalButton';
|
|
9
|
-
import styles from './DefaultTable.styles';
|
|
10
|
-
import { normalizeText } from '../inputs/defaultInputUtils';
|
|
11
|
-
import {
|
|
12
|
-
persistTableViewModePreference,
|
|
13
|
-
resolveDefaultTablePreferenceScope,
|
|
14
|
-
} from '../../utils/tableVisibleColumnsPreferences';
|
|
15
|
-
import { shouldIncludeColumn } from './DefaultTable.utils';
|
|
16
|
-
import useDefaultTableTheme from './useDefaultTableTheme';
|
|
17
|
-
|
|
18
|
-
const DefaultTableControls = ({ storeName }) => {
|
|
19
|
-
const store = useStore(storeName);
|
|
20
|
-
const configs = store?.getters?.configs || {};
|
|
21
|
-
const effectiveViewMode =
|
|
22
|
-
configs.effectiveViewMode ||
|
|
23
|
-
configs.viewMode ||
|
|
24
|
-
configs.initialViewMode ||
|
|
25
|
-
'table';
|
|
26
|
-
const tablePreferenceScope =
|
|
27
|
-
configs.tablePreferenceScope ||
|
|
28
|
-
resolveDefaultTablePreferenceScope({ storeName });
|
|
29
|
-
const columns = Array.isArray(store?.getters?.columns) ? store.getters.columns : [];
|
|
30
|
-
const filters = store?.getters?.filters || {};
|
|
31
|
-
const hasFilterableColumns = columns.some(
|
|
32
|
-
column =>
|
|
33
|
-
configs.showColumnFiltersButton !== false &&
|
|
34
|
-
shouldIncludeColumn(column) &&
|
|
35
|
-
column?.filter !== false &&
|
|
36
|
-
column?.filters !== false,
|
|
37
|
-
);
|
|
38
|
-
const tableFiltersVisible = Boolean(configs.tableFiltersVisible);
|
|
39
|
-
const activeFilterCount = Object.values(filters).filter(value => normalizeText(value) !== '').length;
|
|
40
|
-
const addConfig = store?.getters?.add;
|
|
41
|
-
const shouldRenderAddButton =
|
|
42
|
-
(addConfig === true || configs.add === true) &&
|
|
43
|
-
(typeof configs.onAdd === 'function' || typeof store?.actions?.save === 'function');
|
|
44
|
-
const { tableButtonColors } = useDefaultTableTheme();
|
|
45
|
-
const {
|
|
46
|
-
backgroundColor,
|
|
47
|
-
borderColor,
|
|
48
|
-
iconColor,
|
|
49
|
-
pressedBackgroundColor,
|
|
50
|
-
pressedBorderColor,
|
|
51
|
-
pressedIconColor,
|
|
52
|
-
textColor,
|
|
53
|
-
} = tableButtonColors;
|
|
54
|
-
|
|
55
|
-
const buttonStyle = [
|
|
56
|
-
styles.toolbarButton,
|
|
57
|
-
{ borderColor, backgroundColor },
|
|
58
|
-
];
|
|
59
|
-
const pressedStyle = {
|
|
60
|
-
backgroundColor: pressedBackgroundColor,
|
|
61
|
-
borderColor: pressedBorderColor,
|
|
62
|
-
};
|
|
63
|
-
const updateConfigs = nextConfigs => {
|
|
64
|
-
if (typeof store?.actions?.setConfigs === 'function') {
|
|
65
|
-
store.actions.setConfigs(nextConfigs);
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (store?.getters) {
|
|
70
|
-
store.getters.configs = nextConfigs;
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
{
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
export default DefaultTableControls;
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Text, TouchableOpacity } from 'react-native';
|
|
3
|
+
import Icon from 'react-native-vector-icons/Feather';
|
|
4
|
+
import { useStore } from '@store';
|
|
5
|
+
import DefaultColumnMenu from './DefaultColumnMenu';
|
|
6
|
+
import DefaultDebug from './DefaultDebug';
|
|
7
|
+
import DefaultFiltersModal from './DefaultFiltersModal';
|
|
8
|
+
import DefaultModalButton from './DefaultModalButton';
|
|
9
|
+
import styles from './DefaultTable.styles';
|
|
10
|
+
import { normalizeText } from '../inputs/defaultInputUtils';
|
|
11
|
+
import {
|
|
12
|
+
persistTableViewModePreference,
|
|
13
|
+
resolveDefaultTablePreferenceScope,
|
|
14
|
+
} from '../../utils/tableVisibleColumnsPreferences';
|
|
15
|
+
import { shouldIncludeColumn } from './DefaultTable.utils';
|
|
16
|
+
import useDefaultTableTheme from './useDefaultTableTheme';
|
|
17
|
+
|
|
18
|
+
const DefaultTableControls = ({ storeName }) => {
|
|
19
|
+
const store = useStore(storeName);
|
|
20
|
+
const configs = store?.getters?.configs || {};
|
|
21
|
+
const effectiveViewMode =
|
|
22
|
+
configs.effectiveViewMode ||
|
|
23
|
+
configs.viewMode ||
|
|
24
|
+
configs.initialViewMode ||
|
|
25
|
+
'table';
|
|
26
|
+
const tablePreferenceScope =
|
|
27
|
+
configs.tablePreferenceScope ||
|
|
28
|
+
resolveDefaultTablePreferenceScope({ storeName });
|
|
29
|
+
const columns = Array.isArray(store?.getters?.columns) ? store.getters.columns : [];
|
|
30
|
+
const filters = store?.getters?.filters || {};
|
|
31
|
+
const hasFilterableColumns = columns.some(
|
|
32
|
+
column =>
|
|
33
|
+
configs.showColumnFiltersButton !== false &&
|
|
34
|
+
shouldIncludeColumn(column) &&
|
|
35
|
+
column?.filter !== false &&
|
|
36
|
+
column?.filters !== false,
|
|
37
|
+
);
|
|
38
|
+
const tableFiltersVisible = Boolean(configs.tableFiltersVisible);
|
|
39
|
+
const activeFilterCount = Object.values(filters).filter(value => normalizeText(value) !== '').length;
|
|
40
|
+
const addConfig = store?.getters?.add;
|
|
41
|
+
const shouldRenderAddButton =
|
|
42
|
+
(addConfig === true || configs.add === true) &&
|
|
43
|
+
(typeof configs.onAdd === 'function' || typeof store?.actions?.save === 'function');
|
|
44
|
+
const { tableButtonColors } = useDefaultTableTheme();
|
|
45
|
+
const {
|
|
46
|
+
backgroundColor,
|
|
47
|
+
borderColor,
|
|
48
|
+
iconColor,
|
|
49
|
+
pressedBackgroundColor,
|
|
50
|
+
pressedBorderColor,
|
|
51
|
+
pressedIconColor,
|
|
52
|
+
textColor,
|
|
53
|
+
} = tableButtonColors;
|
|
54
|
+
|
|
55
|
+
const buttonStyle = [
|
|
56
|
+
styles.toolbarButton,
|
|
57
|
+
{ borderColor, backgroundColor },
|
|
58
|
+
];
|
|
59
|
+
const pressedStyle = {
|
|
60
|
+
backgroundColor: pressedBackgroundColor,
|
|
61
|
+
borderColor: pressedBorderColor,
|
|
62
|
+
};
|
|
63
|
+
const updateConfigs = nextConfigs => {
|
|
64
|
+
if (typeof store?.actions?.setConfigs === 'function') {
|
|
65
|
+
store.actions.setConfigs(nextConfigs);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (store?.getters) {
|
|
70
|
+
store.getters.configs = nextConfigs;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const nextViewMode = effectiveViewMode === 'table' ? 'cards' : 'table';
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<>
|
|
77
|
+
<DefaultDebug storeName={storeName} />
|
|
78
|
+
{hasFilterableColumns && effectiveViewMode === 'table' ? (
|
|
79
|
+
<TouchableOpacity
|
|
80
|
+
style={[
|
|
81
|
+
...buttonStyle,
|
|
82
|
+
tableFiltersVisible ? pressedStyle : null,
|
|
83
|
+
]}
|
|
84
|
+
activeOpacity={0.82}
|
|
85
|
+
onPress={() =>
|
|
86
|
+
updateConfigs({
|
|
87
|
+
...configs,
|
|
88
|
+
tableFiltersVisible: !tableFiltersVisible,
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
>
|
|
92
|
+
<Icon
|
|
93
|
+
name="filter"
|
|
94
|
+
size={14}
|
|
95
|
+
color={tableFiltersVisible ? pressedIconColor : textColor}
|
|
96
|
+
/>
|
|
97
|
+
{activeFilterCount > 0 ? (
|
|
98
|
+
<Text
|
|
99
|
+
style={[
|
|
100
|
+
styles.toolbarBadgeText,
|
|
101
|
+
{ color: tableFiltersVisible ? pressedIconColor : textColor },
|
|
102
|
+
]}
|
|
103
|
+
>
|
|
104
|
+
{activeFilterCount}
|
|
105
|
+
</Text>
|
|
106
|
+
) : null}
|
|
107
|
+
</TouchableOpacity>
|
|
108
|
+
) : null}
|
|
109
|
+
{hasFilterableColumns && effectiveViewMode === 'cards' ? (
|
|
110
|
+
<DefaultModalButton
|
|
111
|
+
renderButton={({ isOpen, open }) => (
|
|
112
|
+
<TouchableOpacity
|
|
113
|
+
style={[
|
|
114
|
+
...buttonStyle,
|
|
115
|
+
isOpen ? pressedStyle : null,
|
|
116
|
+
]}
|
|
117
|
+
activeOpacity={0.82}
|
|
118
|
+
onPress={open}
|
|
119
|
+
>
|
|
120
|
+
<Icon
|
|
121
|
+
name="filter"
|
|
122
|
+
size={14}
|
|
123
|
+
color={isOpen ? pressedIconColor : textColor}
|
|
124
|
+
/>
|
|
125
|
+
{activeFilterCount > 0 ? (
|
|
126
|
+
<Text
|
|
127
|
+
style={[
|
|
128
|
+
styles.toolbarBadgeText,
|
|
129
|
+
{ color: isOpen ? pressedIconColor : textColor },
|
|
130
|
+
]}>
|
|
131
|
+
{activeFilterCount}
|
|
132
|
+
</Text>
|
|
133
|
+
) : null}
|
|
134
|
+
</TouchableOpacity>
|
|
135
|
+
)}
|
|
136
|
+
>
|
|
137
|
+
{({ close, isOpen }) => (
|
|
138
|
+
<DefaultFiltersModal
|
|
139
|
+
storeName={storeName}
|
|
140
|
+
visible={isOpen}
|
|
141
|
+
onClose={close}
|
|
142
|
+
/>
|
|
143
|
+
)}
|
|
144
|
+
</DefaultModalButton>
|
|
145
|
+
) : null}
|
|
146
|
+
<TouchableOpacity
|
|
147
|
+
style={buttonStyle}
|
|
148
|
+
activeOpacity={0.82}
|
|
149
|
+
onPress={() => {
|
|
150
|
+
const nextConfigs = {
|
|
151
|
+
...configs,
|
|
152
|
+
effectiveViewMode: nextViewMode,
|
|
153
|
+
viewMode: nextViewMode,
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
persistTableViewModePreference(tablePreferenceScope, nextConfigs.viewMode);
|
|
157
|
+
updateConfigs(nextConfigs);
|
|
158
|
+
}}
|
|
159
|
+
>
|
|
160
|
+
<Icon
|
|
161
|
+
name={nextViewMode === 'cards' ? 'grid' : 'list'}
|
|
162
|
+
size={14}
|
|
163
|
+
color={textColor}
|
|
164
|
+
/>
|
|
165
|
+
</TouchableOpacity>
|
|
166
|
+
<DefaultModalButton
|
|
167
|
+
renderButton={({ isOpen, toggle }) => (
|
|
168
|
+
<TouchableOpacity
|
|
169
|
+
style={[
|
|
170
|
+
...buttonStyle,
|
|
171
|
+
isOpen ? pressedStyle : null,
|
|
172
|
+
]}
|
|
173
|
+
activeOpacity={0.82}
|
|
174
|
+
onPress={toggle}
|
|
175
|
+
>
|
|
176
|
+
<Icon name="columns" size={14} color={isOpen ? pressedIconColor : textColor} />
|
|
177
|
+
</TouchableOpacity>
|
|
178
|
+
)}
|
|
179
|
+
>
|
|
180
|
+
{({ close, isOpen }) => (
|
|
181
|
+
<DefaultColumnMenu
|
|
182
|
+
storeName={storeName}
|
|
183
|
+
visible={isOpen}
|
|
184
|
+
onClose={close}
|
|
185
|
+
/>
|
|
186
|
+
)}
|
|
187
|
+
</DefaultModalButton>
|
|
188
|
+
{shouldRenderAddButton ? (
|
|
189
|
+
<TouchableOpacity
|
|
190
|
+
style={[
|
|
191
|
+
styles.toolbarButton,
|
|
192
|
+
styles.toolbarAddButton,
|
|
193
|
+
{ backgroundColor: backgroundColor, borderColor: backgroundColor },
|
|
194
|
+
]}
|
|
195
|
+
activeOpacity={0.85}
|
|
196
|
+
onPress={() => configs.onAdd?.()}
|
|
197
|
+
>
|
|
198
|
+
<Icon name="plus" size={16} color={textColor} />
|
|
199
|
+
</TouchableOpacity>
|
|
200
|
+
) : null}
|
|
201
|
+
</>
|
|
202
|
+
);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
export default DefaultTableControls;
|