@controleonline/ui-default 1.0.263 → 1.0.265
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/AGENTS.md +47 -45
- package/package.json +20 -20
- package/src/react/components/errors/DefaultErrors.js +307 -325
- package/src/react/components/files/DefaultFile.js +46 -46
- package/src/react/components/filters/CompactFilterSelector.js +78 -24
- package/src/react/components/filters/CompactFilterSelector.styles.js +17 -5
- package/src/react/components/filters/DefaultColumnFilter.js +191 -57
- package/src/react/components/filters/DefaultExternalFilters.js +245 -182
- package/src/react/components/filters/DefaultSearch.js +131 -92
- package/src/react/components/filters/DefaultSearch.styles.js +65 -70
- package/src/react/components/form/DefaultForm.js +172 -151
- package/src/react/components/form/DefaultForm.styles.js +71 -66
- package/src/react/components/help/DefaultTooltip.js +87 -87
- package/src/react/components/help/DefaultTooltip.styles.js +61 -61
- package/src/react/components/inputs/DefaultDateInput.js +150 -0
- package/src/react/components/inputs/DefaultInput.js +162 -127
- package/src/react/components/inputs/DefaultInput.styles.js +6 -0
- package/src/react/components/inputs/DefaultSelect.js +320 -152
- package/src/react/components/inputs/defaultInputUtils.js +40 -19
- package/src/react/components/map/DefaultGoogleMap.styles.js +115 -9
- package/src/react/components/map/DefaultGoogleMap.web.js +560 -446
- package/src/react/components/map/DefaultMap.native.js +73 -71
- package/src/react/components/map/DefaultMap.styles.js +16 -16
- package/src/react/components/map/DefaultMap.web.js +68 -66
- package/src/react/components/map/DefaultNativeMap.native.js +307 -183
- package/src/react/components/map/DefaultNativeMap.shared.js +439 -340
- package/src/react/components/map/DefaultNativeMap.styles.js +156 -122
- package/src/react/components/table/DefaultColumnMenu.js +108 -0
- package/src/react/components/table/DefaultDebug.js +233 -0
- package/src/react/components/table/DefaultFiltersModal.js +142 -0
- package/src/react/components/table/DefaultModalButton.js +18 -0
- package/src/react/components/table/DefaultSearchModal.js +49 -0
- package/src/react/components/table/DefaultTable.js +345 -1846
- package/src/react/components/table/DefaultTable.styles.js +247 -136
- package/src/react/components/table/DefaultTable.utils.js +502 -0
- package/src/react/components/table/DefaultTableBody.js +26 -0
- package/src/react/components/table/DefaultTableCards.js +171 -0
- package/src/react/components/table/DefaultTableControls.js +208 -0
- package/src/react/components/table/DefaultTableEmptyState.js +22 -0
- package/src/react/components/table/DefaultTableFooter.js +172 -0
- package/src/react/components/table/DefaultTableInput.js +145 -0
- package/src/react/components/table/DefaultTableRows.js +340 -0
- package/src/react/components/table/DefaultTableSearch.js +100 -0
- package/src/react/components/table/DefaultTableToolbar.js +98 -0
- package/src/react/components/table/DefaultToolbarAction.js +56 -0
- package/src/react/components/table/useDefaultTablePagination.js +370 -0
- package/src/react/components/table/useDefaultTableSorting.js +126 -0
- package/src/react/components/table/useDefaultTableTheme.js +58 -0
- package/src/react/index.js +10 -10
- package/src/react/utils/tableVisibleColumnsPreferences.js +239 -211
- package/src/store/default/actions.js +51 -13
- package/src/store/default/getters.js +10 -8
- package/src/store/default/mutation_types.js +4 -2
- package/src/store/default/mutations.js +10 -1
- package/src/tests/react/components/errors/DefaultErrors.test.js +162 -162
- package/src/tests/react/components/files/DefaultFile.test.js +80 -80
- package/src/tests/react/components/form/DefaultForm.test.js +81 -0
- package/src/tests/react/components/inputs/DefaultSelect.test.js +185 -0
- package/src/tests/react/components/table/DefaultTable.test.js +1183 -0
- package/src/tests/react/store/defaultActions.test.js +59 -0
- package/src/tests/react/utils/tableVisibleColumnsPreferences.test.js +247 -168
|
@@ -1,122 +1,156 @@
|
|
|
1
|
-
import {StyleSheet} from 'react-native';
|
|
2
|
-
|
|
3
|
-
export default StyleSheet.create({
|
|
4
|
-
mapContainer: {
|
|
5
|
-
width: '100%',
|
|
6
|
-
height: '100%',
|
|
7
|
-
position: 'relative',
|
|
8
|
-
backgroundColor: '#E5EEF5',
|
|
9
|
-
},
|
|
10
|
-
mapViewport: {
|
|
11
|
-
width: '100%',
|
|
12
|
-
height: '100%',
|
|
13
|
-
},
|
|
14
|
-
mapOverlay: {
|
|
15
|
-
...StyleSheet.absoluteFillObject,
|
|
16
|
-
alignItems: 'center',
|
|
17
|
-
justifyContent: 'center',
|
|
18
|
-
paddingHorizontal: 24,
|
|
19
|
-
backgroundColor: 'rgba(248, 250, 252, 0.9)',
|
|
20
|
-
gap: 12,
|
|
21
|
-
},
|
|
22
|
-
mapOverlayText: {
|
|
23
|
-
fontSize: 14,
|
|
24
|
-
lineHeight: 20,
|
|
25
|
-
color: '#0F172A',
|
|
26
|
-
textAlign: 'center',
|
|
27
|
-
fontWeight: '600',
|
|
28
|
-
},
|
|
29
|
-
markerWrap: {
|
|
30
|
-
width: 44,
|
|
31
|
-
height: 44,
|
|
32
|
-
alignItems: 'center',
|
|
33
|
-
justifyContent: 'center',
|
|
34
|
-
},
|
|
35
|
-
markerIcon: {
|
|
36
|
-
width: 42,
|
|
37
|
-
height: 42,
|
|
38
|
-
},
|
|
39
|
-
calloutCard: {
|
|
40
|
-
minWidth: 228,
|
|
41
|
-
maxWidth: 288,
|
|
42
|
-
borderRadius: 18,
|
|
43
|
-
paddingHorizontal: 14,
|
|
44
|
-
paddingVertical: 14,
|
|
45
|
-
backgroundColor: '#FFFFFF',
|
|
46
|
-
shadowColor: '#0F172A',
|
|
47
|
-
shadowOpacity: 0.18,
|
|
48
|
-
shadowRadius: 16,
|
|
49
|
-
shadowOffset: {
|
|
50
|
-
width: 0,
|
|
51
|
-
height: 8,
|
|
52
|
-
},
|
|
53
|
-
elevation: 10,
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
fontSize:
|
|
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
|
-
color: '#
|
|
121
|
-
},
|
|
122
|
-
|
|
1
|
+
import {StyleSheet} from 'react-native';
|
|
2
|
+
|
|
3
|
+
export default StyleSheet.create({
|
|
4
|
+
mapContainer: {
|
|
5
|
+
width: '100%',
|
|
6
|
+
height: '100%',
|
|
7
|
+
position: 'relative',
|
|
8
|
+
backgroundColor: '#E5EEF5',
|
|
9
|
+
},
|
|
10
|
+
mapViewport: {
|
|
11
|
+
width: '100%',
|
|
12
|
+
height: '100%',
|
|
13
|
+
},
|
|
14
|
+
mapOverlay: {
|
|
15
|
+
...StyleSheet.absoluteFillObject,
|
|
16
|
+
alignItems: 'center',
|
|
17
|
+
justifyContent: 'center',
|
|
18
|
+
paddingHorizontal: 24,
|
|
19
|
+
backgroundColor: 'rgba(248, 250, 252, 0.9)',
|
|
20
|
+
gap: 12,
|
|
21
|
+
},
|
|
22
|
+
mapOverlayText: {
|
|
23
|
+
fontSize: 14,
|
|
24
|
+
lineHeight: 20,
|
|
25
|
+
color: '#0F172A',
|
|
26
|
+
textAlign: 'center',
|
|
27
|
+
fontWeight: '600',
|
|
28
|
+
},
|
|
29
|
+
markerWrap: {
|
|
30
|
+
width: 44,
|
|
31
|
+
height: 44,
|
|
32
|
+
alignItems: 'center',
|
|
33
|
+
justifyContent: 'center',
|
|
34
|
+
},
|
|
35
|
+
markerIcon: {
|
|
36
|
+
width: 42,
|
|
37
|
+
height: 42,
|
|
38
|
+
},
|
|
39
|
+
calloutCard: {
|
|
40
|
+
minWidth: 228,
|
|
41
|
+
maxWidth: 288,
|
|
42
|
+
borderRadius: 18,
|
|
43
|
+
paddingHorizontal: 14,
|
|
44
|
+
paddingVertical: 14,
|
|
45
|
+
backgroundColor: '#FFFFFF',
|
|
46
|
+
shadowColor: '#0F172A',
|
|
47
|
+
shadowOpacity: 0.18,
|
|
48
|
+
shadowRadius: 16,
|
|
49
|
+
shadowOffset: {
|
|
50
|
+
width: 0,
|
|
51
|
+
height: 8,
|
|
52
|
+
},
|
|
53
|
+
elevation: 10,
|
|
54
|
+
},
|
|
55
|
+
headerRow: {
|
|
56
|
+
flexDirection: 'row',
|
|
57
|
+
alignItems: 'center',
|
|
58
|
+
gap: 12,
|
|
59
|
+
marginBottom: 12,
|
|
60
|
+
},
|
|
61
|
+
logoWrap: {
|
|
62
|
+
width: 58,
|
|
63
|
+
height: 58,
|
|
64
|
+
borderRadius: 16,
|
|
65
|
+
borderWidth: 1,
|
|
66
|
+
overflow: 'hidden',
|
|
67
|
+
alignItems: 'center',
|
|
68
|
+
justifyContent: 'center',
|
|
69
|
+
flexShrink: 0,
|
|
70
|
+
},
|
|
71
|
+
logoImage: {
|
|
72
|
+
width: '100%',
|
|
73
|
+
height: '100%',
|
|
74
|
+
},
|
|
75
|
+
logoFallback: {
|
|
76
|
+
fontSize: 18,
|
|
77
|
+
fontWeight: '800',
|
|
78
|
+
letterSpacing: 0.8,
|
|
79
|
+
},
|
|
80
|
+
headerContent: {
|
|
81
|
+
flex: 1,
|
|
82
|
+
minWidth: 0,
|
|
83
|
+
},
|
|
84
|
+
companyName: {
|
|
85
|
+
fontSize: 11,
|
|
86
|
+
fontWeight: '700',
|
|
87
|
+
textTransform: 'uppercase',
|
|
88
|
+
letterSpacing: 0.6,
|
|
89
|
+
color: '#0369A1',
|
|
90
|
+
marginBottom: 6,
|
|
91
|
+
},
|
|
92
|
+
title: {
|
|
93
|
+
fontSize: 16,
|
|
94
|
+
fontWeight: '700',
|
|
95
|
+
color: '#0F172A',
|
|
96
|
+
marginBottom: 8,
|
|
97
|
+
},
|
|
98
|
+
line: {
|
|
99
|
+
fontSize: 13,
|
|
100
|
+
lineHeight: 19,
|
|
101
|
+
color: '#0F172A',
|
|
102
|
+
marginBottom: 4,
|
|
103
|
+
},
|
|
104
|
+
summaryText: {
|
|
105
|
+
marginTop: 10,
|
|
106
|
+
fontSize: 12,
|
|
107
|
+
fontWeight: '700',
|
|
108
|
+
},
|
|
109
|
+
metaList: {
|
|
110
|
+
marginTop: 10,
|
|
111
|
+
gap: 6,
|
|
112
|
+
},
|
|
113
|
+
metaRow: {
|
|
114
|
+
flexDirection: 'row',
|
|
115
|
+
justifyContent: 'space-between',
|
|
116
|
+
gap: 10,
|
|
117
|
+
},
|
|
118
|
+
metaLabel: {
|
|
119
|
+
fontSize: 12,
|
|
120
|
+
color: '#64748B',
|
|
121
|
+
},
|
|
122
|
+
metaValue: {
|
|
123
|
+
flex: 1,
|
|
124
|
+
fontSize: 12,
|
|
125
|
+
color: '#334155',
|
|
126
|
+
textAlign: 'right',
|
|
127
|
+
},
|
|
128
|
+
actionsRow: {
|
|
129
|
+
flexDirection: 'row',
|
|
130
|
+
gap: 8,
|
|
131
|
+
marginTop: 14,
|
|
132
|
+
},
|
|
133
|
+
actionButton: {
|
|
134
|
+
flex: 1,
|
|
135
|
+
minHeight: 38,
|
|
136
|
+
borderRadius: 999,
|
|
137
|
+
borderWidth: 1,
|
|
138
|
+
borderColor: '#CBD5E1',
|
|
139
|
+
alignItems: 'center',
|
|
140
|
+
justifyContent: 'center',
|
|
141
|
+
paddingHorizontal: 12,
|
|
142
|
+
backgroundColor: '#FFFFFF',
|
|
143
|
+
},
|
|
144
|
+
actionButtonPrimary: {
|
|
145
|
+
borderColor: 'transparent',
|
|
146
|
+
backgroundColor: '#0EA5E9',
|
|
147
|
+
},
|
|
148
|
+
actionText: {
|
|
149
|
+
fontSize: 12,
|
|
150
|
+
fontWeight: '700',
|
|
151
|
+
color: '#0F172A',
|
|
152
|
+
},
|
|
153
|
+
actionTextPrimary: {
|
|
154
|
+
color: '#FFFFFF',
|
|
155
|
+
},
|
|
156
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Modal, ScrollView, Text, TouchableOpacity, View } from 'react-native';
|
|
3
|
+
import Icon from 'react-native-vector-icons/Feather';
|
|
4
|
+
import { useStore } from '@store';
|
|
5
|
+
import { formatStoreColumnLabel } from '@controleonline/ui-common/src/react/utils/storeColumns';
|
|
6
|
+
import { getColumnKey } from '../inputs/defaultInputUtils';
|
|
7
|
+
import {
|
|
8
|
+
persistVisibleColumnsPreference,
|
|
9
|
+
resolveDefaultTablePreferenceScope,
|
|
10
|
+
sanitizeVisibleColumnsPreference,
|
|
11
|
+
} from '../../utils/tableVisibleColumnsPreferences';
|
|
12
|
+
import styles from './DefaultTable.styles';
|
|
13
|
+
import { shouldIncludeColumn } from './DefaultTable.utils';
|
|
14
|
+
import useDefaultTableTheme from './useDefaultTableTheme';
|
|
15
|
+
|
|
16
|
+
const DefaultColumnMenu = ({ storeName, visible = false, onClose }) => {
|
|
17
|
+
const store = useStore(storeName);
|
|
18
|
+
const columns = Array.isArray(store?.getters?.columns) ? store.getters.columns : [];
|
|
19
|
+
const visibleColumns = store?.getters?.visibleColumns || {};
|
|
20
|
+
const configs = store?.getters?.configs || {};
|
|
21
|
+
const tablePreferenceScope =
|
|
22
|
+
configs.tablePreferenceScope ||
|
|
23
|
+
resolveDefaultTablePreferenceScope({ storeName });
|
|
24
|
+
const availableColumns = columns.filter(column => shouldIncludeColumn(column));
|
|
25
|
+
const {
|
|
26
|
+
checkboxBorderColor: resolvedCheckboxBorderColor,
|
|
27
|
+
checkboxSelectedMarkColor: resolvedCheckboxSelectedMarkColor,
|
|
28
|
+
modalColors,
|
|
29
|
+
} = useDefaultTableTheme();
|
|
30
|
+
if (!visible) return null;
|
|
31
|
+
|
|
32
|
+
const {
|
|
33
|
+
backgroundColor,
|
|
34
|
+
borderColor,
|
|
35
|
+
closeIconColor,
|
|
36
|
+
headerTextColor,
|
|
37
|
+
overlayColor,
|
|
38
|
+
textColor,
|
|
39
|
+
} = modalColors;
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<Modal visible transparent animationType="fade" onRequestClose={onClose}>
|
|
43
|
+
<View style={[styles.modalOverlay, { backgroundColor: overlayColor }]}>
|
|
44
|
+
<View style={[styles.modalCard, styles.columnMenuModalCard, { borderColor, backgroundColor }]}>
|
|
45
|
+
<View style={[styles.modalHeader, { borderBottomColor: borderColor }]}>
|
|
46
|
+
<Text style={[styles.modalTitle, { color: headerTextColor }]} numberOfLines={1}>
|
|
47
|
+
{global.t?.t(storeName, 'label', 'columns')}
|
|
48
|
+
</Text>
|
|
49
|
+
<TouchableOpacity
|
|
50
|
+
style={[styles.modalCloseButton, { borderColor, backgroundColor }]}
|
|
51
|
+
activeOpacity={0.82}
|
|
52
|
+
onPress={onClose}
|
|
53
|
+
>
|
|
54
|
+
<Icon name="x" size={16} color={closeIconColor} />
|
|
55
|
+
</TouchableOpacity>
|
|
56
|
+
</View>
|
|
57
|
+
<ScrollView style={styles.columnMenuModalBody} contentContainerStyle={styles.columnMenuModalList}>
|
|
58
|
+
{availableColumns.map(column => {
|
|
59
|
+
const fieldName = getColumnKey(column);
|
|
60
|
+
const label = formatStoreColumnLabel({
|
|
61
|
+
columns,
|
|
62
|
+
fieldName,
|
|
63
|
+
fallbackLabel: column?.label || fieldName,
|
|
64
|
+
storeName,
|
|
65
|
+
});
|
|
66
|
+
const checked = visibleColumns[fieldName] !== false;
|
|
67
|
+
const toggleColumn = () => {
|
|
68
|
+
const nextVisibleColumns = sanitizeVisibleColumnsPreference({
|
|
69
|
+
columns,
|
|
70
|
+
visibleColumns: {
|
|
71
|
+
...visibleColumns,
|
|
72
|
+
[fieldName]: visibleColumns[fieldName] === false,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
persistVisibleColumnsPreference(tablePreferenceScope, nextVisibleColumns);
|
|
77
|
+
|
|
78
|
+
if (typeof store?.actions?.setVisibleColumns === 'function') {
|
|
79
|
+
store.actions.setVisibleColumns(nextVisibleColumns);
|
|
80
|
+
} else if (store?.getters) {
|
|
81
|
+
store.getters.visibleColumns = nextVisibleColumns;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<TouchableOpacity
|
|
87
|
+
key={fieldName}
|
|
88
|
+
style={styles.columnMenuItem}
|
|
89
|
+
activeOpacity={0.82}
|
|
90
|
+
onPress={toggleColumn}
|
|
91
|
+
>
|
|
92
|
+
<Icon
|
|
93
|
+
name={checked ? 'check-square' : 'square'}
|
|
94
|
+
size={16}
|
|
95
|
+
color={checked ? resolvedCheckboxSelectedMarkColor : resolvedCheckboxBorderColor}
|
|
96
|
+
/>
|
|
97
|
+
<Text style={[styles.columnMenuText, { color: textColor }]} numberOfLines={1}>{label}</Text>
|
|
98
|
+
</TouchableOpacity>
|
|
99
|
+
);
|
|
100
|
+
})}
|
|
101
|
+
</ScrollView>
|
|
102
|
+
</View>
|
|
103
|
+
</View>
|
|
104
|
+
</Modal>
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export default DefaultColumnMenu;
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
2
|
+
import { Modal, ScrollView, Text, TouchableOpacity, View } from 'react-native';
|
|
3
|
+
import Icon from 'react-native-vector-icons/Feather';
|
|
4
|
+
import { useStore } from '@store';
|
|
5
|
+
import { useMessage } from '@controleonline/ui-common/src/react/components/MessageService';
|
|
6
|
+
import { normalizeText } from '../inputs/defaultInputUtils';
|
|
7
|
+
import styles from './DefaultTable.styles';
|
|
8
|
+
import useDefaultTableTheme from './useDefaultTableTheme';
|
|
9
|
+
|
|
10
|
+
const isObject = value =>
|
|
11
|
+
value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
12
|
+
|
|
13
|
+
const formatDebugValue = value => {
|
|
14
|
+
if (value === undefined) return '';
|
|
15
|
+
if (typeof value === 'string') return value;
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
return JSON.stringify(value, null, 2);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return normalizeText(value);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const copyTextToClipboard = async text => {
|
|
25
|
+
const normalizedText = normalizeText(text);
|
|
26
|
+
if (!normalizedText) return false;
|
|
27
|
+
|
|
28
|
+
if (
|
|
29
|
+
typeof navigator !== 'undefined' &&
|
|
30
|
+
navigator.clipboard &&
|
|
31
|
+
typeof navigator.clipboard.writeText === 'function'
|
|
32
|
+
) {
|
|
33
|
+
await navigator.clipboard.writeText(normalizedText);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return false;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const DebugCopyButton = ({ borderColor, color, onPress }) => (
|
|
41
|
+
<TouchableOpacity
|
|
42
|
+
style={[styles.debugCopyButton, { borderColor }]}
|
|
43
|
+
activeOpacity={0.82}
|
|
44
|
+
onPress={onPress}
|
|
45
|
+
>
|
|
46
|
+
<Icon name="copy" size={13} color={color} />
|
|
47
|
+
<Text style={[styles.debugCopyButtonText, { color }]}>Copiar</Text>
|
|
48
|
+
</TouchableOpacity>
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const DebugSection = ({ borderColor, children, copyText, onCopy, textColor, title }) => (
|
|
52
|
+
<>
|
|
53
|
+
<View style={styles.debugSectionHeader}>
|
|
54
|
+
<Text style={[styles.debugSectionTitle, { color: textColor }]}>{title}</Text>
|
|
55
|
+
<DebugCopyButton
|
|
56
|
+
borderColor={borderColor}
|
|
57
|
+
color={textColor}
|
|
58
|
+
onPress={() => onCopy(copyText)}
|
|
59
|
+
/>
|
|
60
|
+
</View>
|
|
61
|
+
<Text selectable style={[styles.debugCodeBlock, { color: textColor, borderColor }]}>
|
|
62
|
+
{children}
|
|
63
|
+
</Text>
|
|
64
|
+
</>
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const DefaultDebug = ({
|
|
68
|
+
storeName,
|
|
69
|
+
}) => {
|
|
70
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
71
|
+
const store = useStore(storeName);
|
|
72
|
+
const configs = store?.getters?.configs || {};
|
|
73
|
+
const { showError, showSuccess } = useMessage();
|
|
74
|
+
const { modalColors, resolvedAccentColor, tableButtonColors } = useDefaultTableTheme();
|
|
75
|
+
|
|
76
|
+
const resolvedDebug = isObject(store?.getters?.debug) ? store.getters.debug : {};
|
|
77
|
+
const debugQuery = normalizeText(resolvedDebug?.query);
|
|
78
|
+
const debugFilledQuery = normalizeText(
|
|
79
|
+
resolvedDebug?.filledQuery || resolvedDebug?.interpolatedQuery,
|
|
80
|
+
);
|
|
81
|
+
const hasDebugQuery = debugQuery !== '';
|
|
82
|
+
const debugParameters = isObject(resolvedDebug?.parameters)
|
|
83
|
+
? resolvedDebug.parameters
|
|
84
|
+
: configs.debugFallbackParameters || null;
|
|
85
|
+
const debugParametersText = useMemo(
|
|
86
|
+
() => formatDebugValue(debugParameters),
|
|
87
|
+
[debugParameters],
|
|
88
|
+
);
|
|
89
|
+
const debugCopyText = useMemo(
|
|
90
|
+
() =>
|
|
91
|
+
[
|
|
92
|
+
'Query:',
|
|
93
|
+
debugQuery,
|
|
94
|
+
'',
|
|
95
|
+
'Parameters:',
|
|
96
|
+
debugParametersText,
|
|
97
|
+
'',
|
|
98
|
+
'Filled query:',
|
|
99
|
+
debugFilledQuery,
|
|
100
|
+
].join('\n'),
|
|
101
|
+
[debugFilledQuery, debugParametersText, debugQuery],
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const requestCopyText = useCallback(
|
|
105
|
+
text =>
|
|
106
|
+
copyTextToClipboard(text)
|
|
107
|
+
.then(copied => {
|
|
108
|
+
if (copied) {
|
|
109
|
+
showSuccess?.('Copiado');
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
showError?.('Nao foi possivel copiar automaticamente.');
|
|
114
|
+
})
|
|
115
|
+
.catch(() => {
|
|
116
|
+
showError?.('Nao foi possivel copiar automaticamente.');
|
|
117
|
+
}),
|
|
118
|
+
[showError, showSuccess],
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
if (!hasDebugQuery) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const {
|
|
126
|
+
backgroundColor,
|
|
127
|
+
borderColor,
|
|
128
|
+
closeIconColor,
|
|
129
|
+
headerTextColor,
|
|
130
|
+
overlayColor,
|
|
131
|
+
textColor,
|
|
132
|
+
} = modalColors;
|
|
133
|
+
const {
|
|
134
|
+
backgroundColor: buttonBackgroundColor,
|
|
135
|
+
borderColor: buttonBorderColor,
|
|
136
|
+
iconColor,
|
|
137
|
+
pressedBackgroundColor,
|
|
138
|
+
pressedBorderColor,
|
|
139
|
+
pressedIconColor,
|
|
140
|
+
} = tableButtonColors;
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<>
|
|
144
|
+
<TouchableOpacity
|
|
145
|
+
accessibilityLabel="Debug query"
|
|
146
|
+
accessibilityRole="button"
|
|
147
|
+
style={[
|
|
148
|
+
styles.toolbarButton,
|
|
149
|
+
{ borderColor: buttonBorderColor, backgroundColor: buttonBackgroundColor },
|
|
150
|
+
isOpen
|
|
151
|
+
? { backgroundColor: pressedBackgroundColor, borderColor: pressedBorderColor }
|
|
152
|
+
: null,
|
|
153
|
+
]}
|
|
154
|
+
activeOpacity={0.82}
|
|
155
|
+
onPress={() => setIsOpen(true)}
|
|
156
|
+
>
|
|
157
|
+
<Icon name="code" size={14} color={isOpen ? pressedIconColor : iconColor} />
|
|
158
|
+
</TouchableOpacity>
|
|
159
|
+
|
|
160
|
+
{isOpen ? (
|
|
161
|
+
<Modal visible transparent animationType="fade" onRequestClose={() => setIsOpen(false)}>
|
|
162
|
+
<View style={[styles.modalOverlay, { backgroundColor: overlayColor }]}>
|
|
163
|
+
<View style={[styles.modalCard, styles.debugModalCard, { borderColor, backgroundColor }]}>
|
|
164
|
+
<View style={[styles.modalHeader, { borderBottomColor: borderColor }]}>
|
|
165
|
+
<Text style={[styles.modalTitle, { color: headerTextColor }]} numberOfLines={1}>
|
|
166
|
+
Debug query
|
|
167
|
+
</Text>
|
|
168
|
+
<TouchableOpacity
|
|
169
|
+
style={[styles.modalCloseButton, { borderColor, backgroundColor }]}
|
|
170
|
+
activeOpacity={0.82}
|
|
171
|
+
onPress={() => setIsOpen(false)}
|
|
172
|
+
>
|
|
173
|
+
<Icon name="x" size={16} color={closeIconColor} />
|
|
174
|
+
</TouchableOpacity>
|
|
175
|
+
</View>
|
|
176
|
+
|
|
177
|
+
<ScrollView style={styles.debugModalBody} contentContainerStyle={styles.debugModalContent}>
|
|
178
|
+
<DebugSection
|
|
179
|
+
borderColor={borderColor}
|
|
180
|
+
copyText={debugQuery}
|
|
181
|
+
onCopy={requestCopyText}
|
|
182
|
+
textColor={textColor}
|
|
183
|
+
title="Query"
|
|
184
|
+
>
|
|
185
|
+
{debugQuery}
|
|
186
|
+
</DebugSection>
|
|
187
|
+
|
|
188
|
+
<DebugSection
|
|
189
|
+
borderColor={borderColor}
|
|
190
|
+
copyText={debugParametersText}
|
|
191
|
+
onCopy={requestCopyText}
|
|
192
|
+
textColor={textColor}
|
|
193
|
+
title="Parametros"
|
|
194
|
+
>
|
|
195
|
+
{debugParametersText}
|
|
196
|
+
</DebugSection>
|
|
197
|
+
|
|
198
|
+
<DebugSection
|
|
199
|
+
borderColor={borderColor}
|
|
200
|
+
copyText={debugFilledQuery}
|
|
201
|
+
onCopy={requestCopyText}
|
|
202
|
+
textColor={textColor}
|
|
203
|
+
title="Query preenchida"
|
|
204
|
+
>
|
|
205
|
+
{debugFilledQuery}
|
|
206
|
+
</DebugSection>
|
|
207
|
+
</ScrollView>
|
|
208
|
+
|
|
209
|
+
<View style={[styles.modalActions, { borderTopColor: borderColor }]}>
|
|
210
|
+
<TouchableOpacity
|
|
211
|
+
style={[styles.secondaryButton, { borderColor }]}
|
|
212
|
+
activeOpacity={0.82}
|
|
213
|
+
onPress={() => requestCopyText(debugCopyText)}
|
|
214
|
+
>
|
|
215
|
+
<Text style={[styles.secondaryButtonText, { color: textColor }]}>Copiar tudo</Text>
|
|
216
|
+
</TouchableOpacity>
|
|
217
|
+
<TouchableOpacity
|
|
218
|
+
style={[styles.primaryButton, { backgroundColor: resolvedAccentColor }]}
|
|
219
|
+
activeOpacity={0.82}
|
|
220
|
+
onPress={() => setIsOpen(false)}
|
|
221
|
+
>
|
|
222
|
+
<Text style={styles.primaryButtonText}>Fechar</Text>
|
|
223
|
+
</TouchableOpacity>
|
|
224
|
+
</View>
|
|
225
|
+
</View>
|
|
226
|
+
</View>
|
|
227
|
+
</Modal>
|
|
228
|
+
) : null}
|
|
229
|
+
</>
|
|
230
|
+
);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
export default DefaultDebug;
|