@teselagen/ui 0.7.34 → 0.7.36
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/isBeingCalledExcessively.js +2 -0
- package/package.json +1 -1
- package/style.css +26 -10
- package/DataTable/utils/filterLocalEntitiesToHasura.d.ts +0 -5
- package/DataTable/utils/initializeHasuraWhereAndFilter.d.ts +0 -2
- package/DataTable/utils/tableQueryParamsToHasuraClauses.d.ts +0 -26
- package/src/AdvancedOptions.js +0 -33
- package/src/AdvancedOptions.spec.js +0 -26
- package/src/AssignDefaultsModeContext.js +0 -22
- package/src/AsyncValidateFieldSpinner/index.js +0 -12
- package/src/BlueprintError/index.js +0 -14
- package/src/BounceLoader/index.js +0 -16
- package/src/BounceLoader/style.css +0 -45
- package/src/CollapsibleCard/index.js +0 -68
- package/src/CollapsibleCard/style.css +0 -23
- package/src/DNALoader/index.js +0 -20
- package/src/DNALoader/style.css +0 -251
- package/src/DataTable/CellDragHandle.js +0 -132
- package/src/DataTable/ColumnFilterMenu.js +0 -62
- package/src/DataTable/Columns.js +0 -979
- package/src/DataTable/DisabledLoadingComponent.js +0 -15
- package/src/DataTable/DisplayOptions.js +0 -199
- package/src/DataTable/DropdownCell.js +0 -61
- package/src/DataTable/EditableCell.js +0 -44
- package/src/DataTable/FilterAndSortMenu.js +0 -388
- package/src/DataTable/PagingTool.js +0 -225
- package/src/DataTable/RenderCell.js +0 -191
- package/src/DataTable/SearchBar.js +0 -69
- package/src/DataTable/SortableColumns.js +0 -100
- package/src/DataTable/TableFormTrackerContext.js +0 -10
- package/src/DataTable/ThComponent.js +0 -44
- package/src/DataTable/dataTableEnhancer.js +0 -41
- package/src/DataTable/defaultFormatters.js +0 -32
- package/src/DataTable/defaultValidators.js +0 -40
- package/src/DataTable/editCellHelper.js +0 -44
- package/src/DataTable/getCellVal.js +0 -20
- package/src/DataTable/getVals.js +0 -8
- package/src/DataTable/index.js +0 -3209
- package/src/DataTable/isTruthy.js +0 -12
- package/src/DataTable/isValueEmpty.js +0 -3
- package/src/DataTable/style.css +0 -608
- package/src/DataTable/utils/convertSchema.js +0 -69
- package/src/DataTable/utils/filterLocalEntitiesToHasura.js +0 -236
- package/src/DataTable/utils/filterLocalEntitiesToHasura.test.js +0 -587
- package/src/DataTable/utils/formatPasteData.js +0 -16
- package/src/DataTable/utils/getAllRows.js +0 -11
- package/src/DataTable/utils/getCellCopyText.js +0 -7
- package/src/DataTable/utils/getCellInfo.js +0 -36
- package/src/DataTable/utils/getFieldPathToField.js +0 -7
- package/src/DataTable/utils/getIdOrCodeOrIndex.js +0 -9
- package/src/DataTable/utils/getLastSelectedEntity.js +0 -11
- package/src/DataTable/utils/getNewEntToSelect.js +0 -25
- package/src/DataTable/utils/getRowCopyText.js +0 -28
- package/src/DataTable/utils/getTableConfigFromStorage.js +0 -5
- package/src/DataTable/utils/handleCopyColumn.js +0 -21
- package/src/DataTable/utils/handleCopyHelper.js +0 -15
- package/src/DataTable/utils/handleCopyRows.js +0 -23
- package/src/DataTable/utils/handleCopyTable.js +0 -16
- package/src/DataTable/utils/index.js +0 -55
- package/src/DataTable/utils/initializeHasuraWhereAndFilter.js +0 -26
- package/src/DataTable/utils/isBottomRightCornerOfRectangle.js +0 -20
- package/src/DataTable/utils/isEntityClean.js +0 -15
- package/src/DataTable/utils/primarySelectedValue.js +0 -1
- package/src/DataTable/utils/queryParams.js +0 -350
- package/src/DataTable/utils/removeCleanRows.js +0 -22
- package/src/DataTable/utils/rowClick.js +0 -181
- package/src/DataTable/utils/selection.js +0 -8
- package/src/DataTable/utils/tableQueryParamsToHasuraClauses.js +0 -253
- package/src/DataTable/utils/tableQueryParamsToHasuraClauses.test.js +0 -206
- package/src/DataTable/utils/useTableEntities.js +0 -38
- package/src/DataTable/utils/utils.js +0 -37
- package/src/DataTable/utils/withSelectedEntities.js +0 -65
- package/src/DataTable/utils/withTableParams.js +0 -288
- package/src/DataTable/validateTableWideErrors.js +0 -160
- package/src/DataTable/viewColumn.js +0 -97
- package/src/DialogFooter/index.js +0 -86
- package/src/DialogFooter/style.css +0 -9
- package/src/DropdownButton.js +0 -36
- package/src/FillWindow.css +0 -6
- package/src/FillWindow.js +0 -69
- package/src/FormComponents/FormSeparator.js +0 -9
- package/src/FormComponents/LoadingDots.js +0 -14
- package/src/FormComponents/Uploader.js +0 -1278
- package/src/FormComponents/getNewName.js +0 -31
- package/src/FormComponents/index.js +0 -1266
- package/src/FormComponents/itemUpload.js +0 -84
- package/src/FormComponents/sortify.js +0 -73
- package/src/FormComponents/style.css +0 -275
- package/src/FormComponents/tryToMatchSchemas.js +0 -264
- package/src/FormComponents/utils.js +0 -6
- package/src/HotkeysDialog/index.js +0 -79
- package/src/HotkeysDialog/style.css +0 -54
- package/src/InfoHelper/index.js +0 -78
- package/src/InfoHelper/style.css +0 -7
- package/src/IntentText/index.js +0 -18
- package/src/Loading/index.js +0 -70
- package/src/Loading/style.css +0 -4
- package/src/MatchHeaders.js +0 -234
- package/src/MenuBar/index.js +0 -423
- package/src/MenuBar/style.css +0 -45
- package/src/PromptUnsavedChanges/index.js +0 -38
- package/src/ResizableDraggableDialog/index.js +0 -141
- package/src/ResizableDraggableDialog/style.css +0 -42
- package/src/ScrollToTop/index.js +0 -72
- package/src/SimpleStepViz.js +0 -22
- package/src/Tag.js +0 -112
- package/src/TagSelect/index.js +0 -69
- package/src/TagSelect/style.css +0 -13
- package/src/TgHtmlSelect/index.js +0 -20
- package/src/TgSelect/index.js +0 -537
- package/src/TgSelect/style.css +0 -61
- package/src/TgSuggest/index.js +0 -124
- package/src/Timeline/TimelineEvent.js +0 -31
- package/src/Timeline/index.js +0 -15
- package/src/Timeline/style.css +0 -29
- package/src/UploadCsvWizard.css +0 -4
- package/src/UploadCsvWizard.js +0 -719
- package/src/autoTooltip.js +0 -201
- package/src/constants.js +0 -1
- package/src/customIcons.js +0 -361
- package/src/enhancers/withDialog/index.js +0 -196
- package/src/enhancers/withDialog/tg_modalState.js +0 -47
- package/src/enhancers/withField.js +0 -20
- package/src/enhancers/withFields.js +0 -11
- package/src/enhancers/withLocalStorage.js +0 -11
- package/src/index.js +0 -88
- package/src/rerenderOnWindowResize.js +0 -26
- package/src/showAppSpinner.js +0 -12
- package/src/showConfirmationDialog/index.js +0 -148
- package/src/showDialogOnDocBody.js +0 -33
- package/src/style.css +0 -265
- package/src/throwFormError.js +0 -16
- package/src/toastr.js +0 -148
- package/src/typeToCommonType.js +0 -6
- package/src/useDialog.js +0 -63
- package/src/utils/adHoc.js +0 -10
- package/src/utils/basicHandleActionsWithFullState.js +0 -14
- package/src/utils/browserUtils.js +0 -3
- package/src/utils/combineReducersWithFullState.js +0 -14
- package/src/utils/commandControls.js +0 -82
- package/src/utils/commandUtils.js +0 -112
- package/src/utils/determineBlackOrWhiteTextColor.js +0 -4
- package/src/utils/getDayjsFormatter.js +0 -35
- package/src/utils/getTextFromEl.js +0 -28
- package/src/utils/handlerHelpers.js +0 -24
- package/src/utils/hooks/index.js +0 -1
- package/src/utils/hooks/useDeepEqualMemo.js +0 -15
- package/src/utils/hooks/useStableReference.js +0 -9
- package/src/utils/hotkeyUtils.js +0 -131
- package/src/utils/isBeingCalledExcessively.js +0 -24
- package/src/utils/menuUtils.js +0 -433
- package/src/utils/popoverOverflowModifiers.js +0 -11
- package/src/utils/pureNoFunc.js +0 -31
- package/src/utils/renderOnDoc.js +0 -32
- package/src/utils/showProgressToast.js +0 -22
- package/src/utils/tagUtils.js +0 -45
- package/src/utils/tgFormValues.js +0 -35
- package/src/utils/useTraceUpdate.js +0 -19
- package/src/utils/withSelectTableRecords.js +0 -43
- package/src/utils/withStore.js +0 -10
- package/src/wrapDialog.js +0 -116
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { isEmpty, forEach, range } from "lodash-es";
|
|
2
|
-
import { getSelectedRowsFromEntities } from "./selection";
|
|
3
|
-
import { getIdOrCodeOrIndex } from "./getIdOrCodeOrIndex";
|
|
4
|
-
import { getRecordsFromIdMap } from "./withSelectedEntities";
|
|
5
|
-
|
|
6
|
-
export default function rowClick(
|
|
7
|
-
e,
|
|
8
|
-
rowInfo,
|
|
9
|
-
entities,
|
|
10
|
-
{
|
|
11
|
-
reduxFormSelectedEntityIdMap,
|
|
12
|
-
isSingleSelect,
|
|
13
|
-
noSelect,
|
|
14
|
-
onRowClick,
|
|
15
|
-
isEntityDisabled,
|
|
16
|
-
withCheckboxes,
|
|
17
|
-
onDeselect,
|
|
18
|
-
onSingleRowSelect,
|
|
19
|
-
onMultiRowSelect,
|
|
20
|
-
noDeselectAll,
|
|
21
|
-
onRowSelect,
|
|
22
|
-
change
|
|
23
|
-
}
|
|
24
|
-
) {
|
|
25
|
-
const entity = rowInfo.original;
|
|
26
|
-
onRowClick(e, entity, rowInfo);
|
|
27
|
-
if (noSelect || isEntityDisabled(entity)) return;
|
|
28
|
-
const rowId = getIdOrCodeOrIndex(entity, rowInfo.index);
|
|
29
|
-
if (rowId === undefined) return;
|
|
30
|
-
const ctrl = e.metaKey || e.ctrlKey || (withCheckboxes && !e.shiftKey);
|
|
31
|
-
const oldIdMap = reduxFormSelectedEntityIdMap || {};
|
|
32
|
-
const rowSelected = oldIdMap[rowId];
|
|
33
|
-
let newIdMap = {
|
|
34
|
-
[rowId]: {
|
|
35
|
-
time: Date.now(),
|
|
36
|
-
entity
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
if (isSingleSelect) {
|
|
41
|
-
if (rowSelected) newIdMap = {};
|
|
42
|
-
} else if (rowSelected && e.shiftKey) return;
|
|
43
|
-
else if (rowSelected && ctrl) {
|
|
44
|
-
newIdMap = {
|
|
45
|
-
...oldIdMap
|
|
46
|
-
};
|
|
47
|
-
delete newIdMap[rowId];
|
|
48
|
-
} else if (rowSelected) {
|
|
49
|
-
newIdMap = {};
|
|
50
|
-
} else if (ctrl) {
|
|
51
|
-
newIdMap = {
|
|
52
|
-
...oldIdMap,
|
|
53
|
-
...newIdMap
|
|
54
|
-
};
|
|
55
|
-
} else if (e.shiftKey && !isEmpty(oldIdMap)) {
|
|
56
|
-
newIdMap = {
|
|
57
|
-
[rowId]: {
|
|
58
|
-
entity,
|
|
59
|
-
time: Date.now()
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
const currentlySelectedRowIndices = getSelectedRowsFromEntities(
|
|
63
|
-
entities,
|
|
64
|
-
oldIdMap
|
|
65
|
-
);
|
|
66
|
-
if (currentlySelectedRowIndices.length) {
|
|
67
|
-
let timeToBeat = {
|
|
68
|
-
id: null,
|
|
69
|
-
time: null
|
|
70
|
-
};
|
|
71
|
-
forEach(oldIdMap, ({ time }, key) => {
|
|
72
|
-
if (time && time > timeToBeat.time)
|
|
73
|
-
timeToBeat = {
|
|
74
|
-
id: key,
|
|
75
|
-
time
|
|
76
|
-
};
|
|
77
|
-
});
|
|
78
|
-
const mostRecentlySelectedIndex = entities.findIndex((e, i) => {
|
|
79
|
-
let id = getIdOrCodeOrIndex(e, i);
|
|
80
|
-
if (!id && id !== 0) id = "";
|
|
81
|
-
return id.toString() === timeToBeat.id;
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
if (mostRecentlySelectedIndex !== -1) {
|
|
85
|
-
const highRange =
|
|
86
|
-
rowInfo.index < mostRecentlySelectedIndex
|
|
87
|
-
? mostRecentlySelectedIndex - 1
|
|
88
|
-
: rowInfo.index;
|
|
89
|
-
const lowRange =
|
|
90
|
-
rowInfo.index > mostRecentlySelectedIndex
|
|
91
|
-
? mostRecentlySelectedIndex + 1
|
|
92
|
-
: rowInfo.index;
|
|
93
|
-
range(lowRange, highRange + 1).forEach(i => {
|
|
94
|
-
if (isEntityDisabled && isEntityDisabled(entities[i])) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
const recordId = entities[i] && getIdOrCodeOrIndex(entities[i], i);
|
|
98
|
-
if (recordId || recordId === 0)
|
|
99
|
-
// newIdMap[recordId] = { entity: entities[i] };
|
|
100
|
-
newIdMap[recordId] = { entity: entities[i], time: Date.now() };
|
|
101
|
-
});
|
|
102
|
-
newIdMap = {
|
|
103
|
-
...oldIdMap,
|
|
104
|
-
...newIdMap
|
|
105
|
-
};
|
|
106
|
-
if (newIdMap[rowId]) {
|
|
107
|
-
//the entity we just clicked on should have the "freshest" time
|
|
108
|
-
newIdMap[rowId].time = Date.now() + 1;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
finalizeSelection({
|
|
115
|
-
idMap: newIdMap,
|
|
116
|
-
entities,
|
|
117
|
-
props: {
|
|
118
|
-
onDeselect,
|
|
119
|
-
onSingleRowSelect,
|
|
120
|
-
onMultiRowSelect,
|
|
121
|
-
noDeselectAll,
|
|
122
|
-
onRowSelect,
|
|
123
|
-
noSelect,
|
|
124
|
-
change
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export function changeSelectedEntities({ idMap, entities = [], change }) {
|
|
130
|
-
const newIdMap = { ...idMap };
|
|
131
|
-
const entityIdToIndex = {};
|
|
132
|
-
entities.forEach((e, i) => {
|
|
133
|
-
entityIdToIndex[getIdOrCodeOrIndex(e, 0)] = i;
|
|
134
|
-
});
|
|
135
|
-
// we want to store the index of the entity so that it can be used to preserve order in selection
|
|
136
|
-
Object.keys(newIdMap).forEach(key => {
|
|
137
|
-
if (!newIdMap[key]) return;
|
|
138
|
-
const rowIndex =
|
|
139
|
-
entityIdToIndex[getIdOrCodeOrIndex(newIdMap[key].entity, 0)];
|
|
140
|
-
newIdMap[key] = {
|
|
141
|
-
...newIdMap[key],
|
|
142
|
-
rowIndex: rowIndex === undefined ? 10000000 : rowIndex
|
|
143
|
-
};
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
change("reduxFormSelectedEntityIdMap", newIdMap);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export function finalizeSelection({
|
|
150
|
-
idMap,
|
|
151
|
-
entities,
|
|
152
|
-
props: {
|
|
153
|
-
onDeselect,
|
|
154
|
-
onSingleRowSelect,
|
|
155
|
-
onMultiRowSelect,
|
|
156
|
-
noDeselectAll,
|
|
157
|
-
onRowSelect,
|
|
158
|
-
noSelect,
|
|
159
|
-
change
|
|
160
|
-
}
|
|
161
|
-
}) {
|
|
162
|
-
if (noSelect) return;
|
|
163
|
-
if (
|
|
164
|
-
noDeselectAll &&
|
|
165
|
-
Object.keys(idMap).filter(id => {
|
|
166
|
-
return idMap[id];
|
|
167
|
-
}).length === 0
|
|
168
|
-
) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
changeSelectedEntities({ idMap, entities, change });
|
|
173
|
-
const selectedRecords = getRecordsFromIdMap(idMap);
|
|
174
|
-
onRowSelect(selectedRecords);
|
|
175
|
-
|
|
176
|
-
selectedRecords.length === 0
|
|
177
|
-
? onDeselect()
|
|
178
|
-
: selectedRecords.length > 1
|
|
179
|
-
? onMultiRowSelect(selectedRecords)
|
|
180
|
-
: onSingleRowSelect(selectedRecords[0]);
|
|
181
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { getIdOrCodeOrIndex } from "./getIdOrCodeOrIndex";
|
|
2
|
-
|
|
3
|
-
export const getSelectedRowsFromEntities = (entities, idMap) => {
|
|
4
|
-
if (!idMap) return [];
|
|
5
|
-
return entities.reduce((acc, entity, i) => {
|
|
6
|
-
return idMap[getIdOrCodeOrIndex(entity, i)] ? acc.concat(i) : acc;
|
|
7
|
-
}, []);
|
|
8
|
-
};
|
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import { camelCase, set } from "lodash-es";
|
|
2
|
-
|
|
3
|
-
export function tableQueryParamsToHasuraClauses({
|
|
4
|
-
page,
|
|
5
|
-
pageSize,
|
|
6
|
-
searchTerm,
|
|
7
|
-
filters,
|
|
8
|
-
order,
|
|
9
|
-
schema, // Add schema as a parameter
|
|
10
|
-
additionalFilter
|
|
11
|
-
}) {
|
|
12
|
-
const ccFields = getFieldsMappedByCCDisplayName(schema);
|
|
13
|
-
let where = {};
|
|
14
|
-
const order_by = {};
|
|
15
|
-
const limit = pageSize || 25;
|
|
16
|
-
const offset = page && pageSize ? (page - 1) * pageSize : 0;
|
|
17
|
-
|
|
18
|
-
if (searchTerm) {
|
|
19
|
-
const searchTermFilters = [];
|
|
20
|
-
schema.fields.forEach(field => {
|
|
21
|
-
const { type, path, searchDisabled } = field;
|
|
22
|
-
if (searchDisabled || field.filterDisabled || type === "color") return;
|
|
23
|
-
const filterValue = searchTerm; // No cleaning needed here, we're using _ilike
|
|
24
|
-
|
|
25
|
-
if (type === "string" || type === "lookup") {
|
|
26
|
-
const o = set({}, path, { _ilike: `%${filterValue}%` });
|
|
27
|
-
searchTermFilters.push(o);
|
|
28
|
-
} else if (type === "boolean") {
|
|
29
|
-
let regex;
|
|
30
|
-
try {
|
|
31
|
-
regex = new RegExp("^" + searchTerm, "ig");
|
|
32
|
-
} catch (error) {
|
|
33
|
-
//ignore
|
|
34
|
-
}
|
|
35
|
-
if (regex) {
|
|
36
|
-
if ("true".replace(regex, "") !== "true") {
|
|
37
|
-
const o = set({}, path, { _eq: true });
|
|
38
|
-
searchTermFilters.push(o);
|
|
39
|
-
} else if ("false".replace(regex, "") !== "false") {
|
|
40
|
-
const o = set({}, path, { _eq: false });
|
|
41
|
-
searchTermFilters.push(o);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
} else if (
|
|
45
|
-
(type === "number" || type === "integer") &&
|
|
46
|
-
!isNaN(filterValue)
|
|
47
|
-
) {
|
|
48
|
-
const o = set({}, path, { _eq: parseFloat(filterValue) });
|
|
49
|
-
searchTermFilters.push(o);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
if (searchTermFilters.length > 0) {
|
|
53
|
-
if (Object.keys(where).length > 0) {
|
|
54
|
-
where = { _and: [where, { _or: searchTermFilters }] };
|
|
55
|
-
} else {
|
|
56
|
-
where = { _or: searchTermFilters };
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (filters && filters.length > 0) {
|
|
62
|
-
const filterClauses = filters
|
|
63
|
-
.map(filter => {
|
|
64
|
-
let { selectedFilter, filterOn, filterValue } = filter;
|
|
65
|
-
const fieldSchema = ccFields[filterOn] || {};
|
|
66
|
-
|
|
67
|
-
const { path, reference, type } = fieldSchema;
|
|
68
|
-
let stringFilterValue =
|
|
69
|
-
filterValue && filterValue.toString
|
|
70
|
-
? filterValue.toString()
|
|
71
|
-
: filterValue;
|
|
72
|
-
if (stringFilterValue === false) {
|
|
73
|
-
// we still want to be able to search for the string "false" which will get parsed to false
|
|
74
|
-
stringFilterValue = "false";
|
|
75
|
-
} else {
|
|
76
|
-
stringFilterValue = stringFilterValue || "";
|
|
77
|
-
}
|
|
78
|
-
const arrayFilterValue = Array.isArray(filterValue)
|
|
79
|
-
? filterValue
|
|
80
|
-
: stringFilterValue.split(";");
|
|
81
|
-
|
|
82
|
-
if (type === "number" || type === "integer") {
|
|
83
|
-
filterValue = Array.isArray(filterValue)
|
|
84
|
-
? filterValue.map(val => Number(val))
|
|
85
|
-
: Number(filterValue);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (fieldSchema.normalizeFilter) {
|
|
89
|
-
filterValue = fieldSchema.normalizeFilter(
|
|
90
|
-
filterValue,
|
|
91
|
-
selectedFilter,
|
|
92
|
-
filterOn
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (reference) {
|
|
97
|
-
filterOn = reference.sourceField;
|
|
98
|
-
} else {
|
|
99
|
-
filterOn = path || filterOn;
|
|
100
|
-
}
|
|
101
|
-
switch (selectedFilter) {
|
|
102
|
-
case "none":
|
|
103
|
-
return {};
|
|
104
|
-
case "startsWith":
|
|
105
|
-
return { [filterOn]: { _ilike: `${filterValue}%` } };
|
|
106
|
-
case "endsWith":
|
|
107
|
-
return { [filterOn]: { _ilike: `%${filterValue}` } };
|
|
108
|
-
case "contains":
|
|
109
|
-
return { [filterOn]: { _ilike: `%${filterValue}%` } };
|
|
110
|
-
case "notContains":
|
|
111
|
-
return { [filterOn]: { _not_ilike: `%${filterValue}%` } };
|
|
112
|
-
case "isExactly":
|
|
113
|
-
return { [filterOn]: { _eq: filterValue } };
|
|
114
|
-
case "isEmpty":
|
|
115
|
-
return {
|
|
116
|
-
_or: [
|
|
117
|
-
{ [filterOn]: { _eq: "" } },
|
|
118
|
-
{ [filterOn]: { _is_null: true } }
|
|
119
|
-
]
|
|
120
|
-
};
|
|
121
|
-
case "notEmpty":
|
|
122
|
-
return {
|
|
123
|
-
_and: [
|
|
124
|
-
{ [filterOn]: { _neq: "" } },
|
|
125
|
-
{ [filterOn]: { _is_null: false } }
|
|
126
|
-
]
|
|
127
|
-
};
|
|
128
|
-
case "inList":
|
|
129
|
-
return { [filterOn]: { _in: filterValue } };
|
|
130
|
-
case "notInList":
|
|
131
|
-
return { [filterOn]: { _nin: filterValue } };
|
|
132
|
-
case "true":
|
|
133
|
-
return { [filterOn]: { _eq: true } };
|
|
134
|
-
case "false":
|
|
135
|
-
return { [filterOn]: { _eq: false } };
|
|
136
|
-
case "dateIs":
|
|
137
|
-
return { [filterOn]: { _eq: filterValue } };
|
|
138
|
-
case "notBetween":
|
|
139
|
-
return {
|
|
140
|
-
_or: [
|
|
141
|
-
{
|
|
142
|
-
[filterOn]: {
|
|
143
|
-
_lt: new Date(arrayFilterValue[0])
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
[filterOn]: {
|
|
148
|
-
_gt: new Date(
|
|
149
|
-
new Date(arrayFilterValue[1]).setHours(23, 59)
|
|
150
|
-
)
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
]
|
|
154
|
-
};
|
|
155
|
-
case "isBetween":
|
|
156
|
-
return {
|
|
157
|
-
[filterOn]: {
|
|
158
|
-
_gte: new Date(arrayFilterValue[0]),
|
|
159
|
-
_lte: new Date(new Date(arrayFilterValue[1]).setHours(23, 59))
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
case "isBefore":
|
|
163
|
-
return { [filterOn]: { _lt: new Date(filterValue) } };
|
|
164
|
-
case "isAfter":
|
|
165
|
-
return { [filterOn]: { _gt: new Date(filterValue) } };
|
|
166
|
-
case "greaterThan":
|
|
167
|
-
return { [filterOn]: { _gt: parseFloat(filterValue) } };
|
|
168
|
-
case "lessThan":
|
|
169
|
-
return { [filterOn]: { _lt: parseFloat(filterValue) } };
|
|
170
|
-
case "inRange":
|
|
171
|
-
return {
|
|
172
|
-
[filterOn]: {
|
|
173
|
-
_gte: parseFloat(arrayFilterValue[0]),
|
|
174
|
-
_lte: parseFloat(arrayFilterValue[1])
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
case "outsideRange":
|
|
178
|
-
return {
|
|
179
|
-
_or: [
|
|
180
|
-
{
|
|
181
|
-
[filterOn]: {
|
|
182
|
-
_lt: parseFloat(arrayFilterValue[0])
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
{
|
|
186
|
-
[filterOn]: {
|
|
187
|
-
_gt: parseFloat(arrayFilterValue[1])
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
]
|
|
191
|
-
};
|
|
192
|
-
case "equalTo":
|
|
193
|
-
return { [filterOn]: { _eq: parseFloat(filterValue) } };
|
|
194
|
-
case "regex":
|
|
195
|
-
return { [filterOn]: { _regex: filterValue } };
|
|
196
|
-
default:
|
|
197
|
-
console.warn(`Unsupported filter type: ${selectedFilter}`);
|
|
198
|
-
return {};
|
|
199
|
-
}
|
|
200
|
-
})
|
|
201
|
-
.map(filter => {
|
|
202
|
-
const o = {};
|
|
203
|
-
set(o, Object.keys(filter)[0], filter[Object.keys(filter)[0]]);
|
|
204
|
-
return o;
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
if (filterClauses.length > 0) {
|
|
208
|
-
if (Object.keys(where).length > 0) {
|
|
209
|
-
where = { _and: [where, ...filterClauses] };
|
|
210
|
-
} else {
|
|
211
|
-
where = { _and: filterClauses };
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
if (order && order.length > 0) {
|
|
217
|
-
order.forEach(item => {
|
|
218
|
-
const field = item.startsWith("-") ? item.substring(1) : item;
|
|
219
|
-
const direction = item.startsWith("-") ? "desc" : "asc";
|
|
220
|
-
order_by[field] = direction;
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
if (additionalFilter) {
|
|
225
|
-
where = { _and: [where, additionalFilter] };
|
|
226
|
-
}
|
|
227
|
-
return { where, order_by, limit, offset };
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Takes a schema and returns an object with the fields mapped by their camelCased display name.
|
|
232
|
-
* If the displayName is not set or is a jsx element, the path is used instead.
|
|
233
|
-
* The same conversion must be done when using the result of this method
|
|
234
|
-
*/
|
|
235
|
-
export function getFieldsMappedByCCDisplayName(schema) {
|
|
236
|
-
if (!schema || !schema.fields) return {};
|
|
237
|
-
return schema.fields.reduce((acc, field) => {
|
|
238
|
-
const ccDisplayName = getCCDisplayName(field);
|
|
239
|
-
acc[ccDisplayName] = field;
|
|
240
|
-
return acc;
|
|
241
|
-
}, {});
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
*
|
|
246
|
-
* @param {object} field
|
|
247
|
-
* @returns the camelCase display name of the field, to be used for filters, sorting, etc
|
|
248
|
-
*/
|
|
249
|
-
export function getCCDisplayName(field) {
|
|
250
|
-
return camelCase(
|
|
251
|
-
typeof field.displayName === "string" ? field.displayName : field.path
|
|
252
|
-
);
|
|
253
|
-
}
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import { tableQueryParamsToHasuraClauses } from "./tableQueryParamsToHasuraClauses";
|
|
2
|
-
|
|
3
|
-
describe("tableQueryParamsToHasuraClauses", () => {
|
|
4
|
-
const schema = {
|
|
5
|
-
fields: [
|
|
6
|
-
{ path: "name", type: "string" },
|
|
7
|
-
{ path: "age", type: "number" },
|
|
8
|
-
{ path: "isActive", type: "boolean" },
|
|
9
|
-
{ path: "email", type: "string" }
|
|
10
|
-
]
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
it("should handle empty query params", () => {
|
|
14
|
-
const result = tableQueryParamsToHasuraClauses({});
|
|
15
|
-
expect(result).toEqual({
|
|
16
|
-
where: {},
|
|
17
|
-
order_by: {},
|
|
18
|
-
limit: 25,
|
|
19
|
-
offset: 0
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("should handle page and pageSize", () => {
|
|
24
|
-
const result = tableQueryParamsToHasuraClauses({ page: 2, pageSize: 10 });
|
|
25
|
-
expect(result).toEqual({
|
|
26
|
-
where: {},
|
|
27
|
-
order_by: {},
|
|
28
|
-
limit: 10,
|
|
29
|
-
offset: 10
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("should handle searchTerm with string fields", () => {
|
|
34
|
-
const result = tableQueryParamsToHasuraClauses({
|
|
35
|
-
searchTerm: "test",
|
|
36
|
-
schema
|
|
37
|
-
});
|
|
38
|
-
expect(result).toEqual({
|
|
39
|
-
where: {
|
|
40
|
-
_or: [{ name: { _ilike: "%test%" } }, { email: { _ilike: "%test%" } }]
|
|
41
|
-
},
|
|
42
|
-
order_by: {},
|
|
43
|
-
limit: 25,
|
|
44
|
-
offset: 0
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("should handle searchTerm with number fields", () => {
|
|
49
|
-
const result = tableQueryParamsToHasuraClauses({
|
|
50
|
-
searchTerm: "30",
|
|
51
|
-
schema
|
|
52
|
-
});
|
|
53
|
-
expect(result).toEqual({
|
|
54
|
-
where: {
|
|
55
|
-
_or: [
|
|
56
|
-
{ name: { _ilike: "%30%" } },
|
|
57
|
-
{ age: { _eq: 30 } },
|
|
58
|
-
{ email: { _ilike: "%30%" } }
|
|
59
|
-
]
|
|
60
|
-
},
|
|
61
|
-
order_by: {},
|
|
62
|
-
limit: 25,
|
|
63
|
-
offset: 0
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("should handle searchTerm with boolean fields", () => {
|
|
68
|
-
const result = tableQueryParamsToHasuraClauses({
|
|
69
|
-
searchTerm: "true",
|
|
70
|
-
schema
|
|
71
|
-
});
|
|
72
|
-
expect(result).toEqual({
|
|
73
|
-
where: {
|
|
74
|
-
_or: [
|
|
75
|
-
{ name: { _ilike: "%true%" } },
|
|
76
|
-
{ isActive: { _eq: true } },
|
|
77
|
-
{ email: { _ilike: "%true%" } }
|
|
78
|
-
]
|
|
79
|
-
},
|
|
80
|
-
order_by: {},
|
|
81
|
-
limit: 25,
|
|
82
|
-
offset: 0
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("should handle searchTerm with multiple field types", () => {
|
|
87
|
-
const result = tableQueryParamsToHasuraClauses({
|
|
88
|
-
searchTerm: "test",
|
|
89
|
-
schema
|
|
90
|
-
});
|
|
91
|
-
expect(result).toEqual({
|
|
92
|
-
where: {
|
|
93
|
-
_or: [{ name: { _ilike: "%test%" } }, { email: { _ilike: "%test%" } }]
|
|
94
|
-
},
|
|
95
|
-
order_by: {},
|
|
96
|
-
limit: 25,
|
|
97
|
-
offset: 0
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("should handle contains filter", () => {
|
|
102
|
-
const result = tableQueryParamsToHasuraClauses({
|
|
103
|
-
filters: [
|
|
104
|
-
{
|
|
105
|
-
selectedFilter: "contains",
|
|
106
|
-
filterOn: "name",
|
|
107
|
-
filterValue: "test"
|
|
108
|
-
}
|
|
109
|
-
]
|
|
110
|
-
});
|
|
111
|
-
expect(result).toEqual({
|
|
112
|
-
where: { _and: [{ name: { _ilike: "%test%" } }] },
|
|
113
|
-
order_by: {},
|
|
114
|
-
limit: 25,
|
|
115
|
-
offset: 0
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it("should handle equalTo filter for number", () => {
|
|
120
|
-
const result = tableQueryParamsToHasuraClauses({
|
|
121
|
-
filters: [
|
|
122
|
-
{ selectedFilter: "equalTo", filterOn: "age", filterValue: "30" }
|
|
123
|
-
],
|
|
124
|
-
schema
|
|
125
|
-
});
|
|
126
|
-
expect(result).toEqual({
|
|
127
|
-
where: { _and: [{ age: { _eq: 30 } }] },
|
|
128
|
-
order_by: {},
|
|
129
|
-
limit: 25,
|
|
130
|
-
offset: 0
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it("should handle order", () => {
|
|
135
|
-
const result = tableQueryParamsToHasuraClauses({ order: ["name", "-age"] });
|
|
136
|
-
expect(result).toEqual({
|
|
137
|
-
where: {},
|
|
138
|
-
order_by: { name: "asc", age: "desc" },
|
|
139
|
-
limit: 25,
|
|
140
|
-
offset: 0
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it("should combine all params", () => {
|
|
145
|
-
const result = tableQueryParamsToHasuraClauses({
|
|
146
|
-
page: 2,
|
|
147
|
-
pageSize: 10,
|
|
148
|
-
searchTerm: "test",
|
|
149
|
-
filters: [
|
|
150
|
-
{
|
|
151
|
-
selectedFilter: "greaterThan",
|
|
152
|
-
filterOn: "age",
|
|
153
|
-
filterValue: "30"
|
|
154
|
-
}
|
|
155
|
-
],
|
|
156
|
-
order: ["name"],
|
|
157
|
-
schema
|
|
158
|
-
});
|
|
159
|
-
expect(result).toEqual({
|
|
160
|
-
where: {
|
|
161
|
-
_and: [
|
|
162
|
-
{
|
|
163
|
-
_or: [
|
|
164
|
-
{ name: { _ilike: "%test%" } },
|
|
165
|
-
{ email: { _ilike: "%test%" } }
|
|
166
|
-
]
|
|
167
|
-
},
|
|
168
|
-
{ age: { _gt: 30 } }
|
|
169
|
-
]
|
|
170
|
-
},
|
|
171
|
-
order_by: { name: "asc" },
|
|
172
|
-
limit: 10,
|
|
173
|
-
offset: 10
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it("should combine searchTerm and filters", () => {
|
|
178
|
-
const result = tableQueryParamsToHasuraClauses({
|
|
179
|
-
searchTerm: "test",
|
|
180
|
-
filters: [
|
|
181
|
-
{
|
|
182
|
-
selectedFilter: "greaterThan",
|
|
183
|
-
filterOn: "age",
|
|
184
|
-
filterValue: "30"
|
|
185
|
-
}
|
|
186
|
-
],
|
|
187
|
-
schema
|
|
188
|
-
});
|
|
189
|
-
expect(result).toEqual({
|
|
190
|
-
where: {
|
|
191
|
-
_and: [
|
|
192
|
-
{
|
|
193
|
-
_or: [
|
|
194
|
-
{ name: { _ilike: "%test%" } },
|
|
195
|
-
{ email: { _ilike: "%test%" } }
|
|
196
|
-
]
|
|
197
|
-
},
|
|
198
|
-
{ age: { _gt: 30 } }
|
|
199
|
-
]
|
|
200
|
-
},
|
|
201
|
-
order_by: {},
|
|
202
|
-
limit: 25,
|
|
203
|
-
offset: 0
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { useCallback } from "react";
|
|
2
|
-
import { useDispatch, useSelector } from "react-redux";
|
|
3
|
-
import { change, initialize } from "redux-form";
|
|
4
|
-
|
|
5
|
-
export const useTableEntities = tableFormName => {
|
|
6
|
-
const dispatch = useDispatch();
|
|
7
|
-
const selectTableEntities = useCallback(
|
|
8
|
-
(entities = []) => {
|
|
9
|
-
initialize(tableFormName, {}, true, {
|
|
10
|
-
keepDirty: true,
|
|
11
|
-
updateUnregisteredFields: true,
|
|
12
|
-
keepValues: true
|
|
13
|
-
});
|
|
14
|
-
const selectedEntityIdMap = {};
|
|
15
|
-
entities.forEach(entity => {
|
|
16
|
-
selectedEntityIdMap[entity.id] = {
|
|
17
|
-
entity,
|
|
18
|
-
time: Date.now()
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
dispatch(
|
|
22
|
-
change(
|
|
23
|
-
tableFormName,
|
|
24
|
-
"reduxFormSelectedEntityIdMap",
|
|
25
|
-
selectedEntityIdMap
|
|
26
|
-
)
|
|
27
|
-
);
|
|
28
|
-
},
|
|
29
|
-
[dispatch, tableFormName]
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
const { allOrderedEntities, selectedEntities } = useSelector(state => ({
|
|
33
|
-
allOrderedEntities: state.form?.[tableFormName]?.values?.allOrderedEntities,
|
|
34
|
-
selectedEntities:
|
|
35
|
-
state.form?.[tableFormName]?.values?.reduxFormSelectedEntityIdMap
|
|
36
|
-
}));
|
|
37
|
-
return { selectTableEntities, allOrderedEntities, selectedEntities };
|
|
38
|
-
};
|