@teselagen/ui 0.7.33-beta.1 → 0.7.33-beta.2
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/AdvancedOptions.js +33 -0
- package/src/AssignDefaultsModeContext.js +22 -0
- package/src/CellDragHandle.js +132 -0
- package/src/ColumnFilterMenu.js +62 -0
- package/src/Columns.js +979 -0
- package/src/DisabledLoadingComponent.js +15 -0
- package/src/DisplayOptions.js +199 -0
- package/src/DropdownButton.js +36 -0
- package/src/DropdownCell.js +61 -0
- package/src/EditableCell.js +44 -0
- package/src/FillWindow.css +6 -0
- package/src/FillWindow.js +69 -0
- package/src/FilterAndSortMenu.js +388 -0
- package/src/FormSeparator.js +9 -0
- package/src/LoadingDots.js +14 -0
- package/src/MatchHeaders.js +234 -0
- package/src/PagingTool.js +225 -0
- package/src/RenderCell.js +191 -0
- package/src/SearchBar.js +69 -0
- package/src/SimpleStepViz.js +22 -0
- package/src/SortableColumns.js +100 -0
- package/src/TableFormTrackerContext.js +10 -0
- package/src/Tag.js +112 -0
- package/src/ThComponent.js +44 -0
- package/src/TimelineEvent.js +31 -0
- package/src/UploadCsvWizard.css +4 -0
- package/src/UploadCsvWizard.js +719 -0
- package/src/Uploader.js +1278 -0
- package/src/adHoc.js +10 -0
- package/src/autoTooltip.js +201 -0
- package/src/basicHandleActionsWithFullState.js +14 -0
- package/src/browserUtils.js +3 -0
- package/src/combineReducersWithFullState.js +14 -0
- package/src/commandControls.js +82 -0
- package/src/commandUtils.js +112 -0
- package/src/constants.js +1 -0
- package/src/convertSchema.js +69 -0
- package/src/customIcons.js +361 -0
- package/src/dataTableEnhancer.js +41 -0
- package/src/defaultFormatters.js +32 -0
- package/src/defaultValidators.js +40 -0
- package/src/determineBlackOrWhiteTextColor.js +4 -0
- package/src/editCellHelper.js +44 -0
- package/src/filterLocalEntitiesToHasura.js +216 -0
- package/src/formatPasteData.js +16 -0
- package/src/getAllRows.js +11 -0
- package/src/getCellCopyText.js +7 -0
- package/src/getCellInfo.js +36 -0
- package/src/getCellVal.js +20 -0
- package/src/getDayjsFormatter.js +35 -0
- package/src/getFieldPathToField.js +7 -0
- package/src/getIdOrCodeOrIndex.js +9 -0
- package/src/getLastSelectedEntity.js +11 -0
- package/src/getNewEntToSelect.js +25 -0
- package/src/getNewName.js +31 -0
- package/src/getRowCopyText.js +28 -0
- package/src/getTableConfigFromStorage.js +5 -0
- package/src/getTextFromEl.js +28 -0
- package/src/getVals.js +8 -0
- package/src/handleCopyColumn.js +21 -0
- package/src/handleCopyHelper.js +15 -0
- package/src/handleCopyRows.js +23 -0
- package/src/handleCopyTable.js +16 -0
- package/src/handlerHelpers.js +24 -0
- package/src/hotkeyUtils.js +131 -0
- package/src/index.js +1 -0
- package/src/initializeHasuraWhereAndFilter.js +27 -0
- package/src/isBeingCalledExcessively.js +24 -0
- package/src/isBottomRightCornerOfRectangle.js +20 -0
- package/src/isEntityClean.js +15 -0
- package/src/isTruthy.js +12 -0
- package/src/isValueEmpty.js +3 -0
- package/src/itemUpload.js +84 -0
- package/src/menuUtils.js +433 -0
- package/src/popoverOverflowModifiers.js +11 -0
- package/src/primarySelectedValue.js +1 -0
- package/src/pureNoFunc.js +31 -0
- package/src/queryParams.js +336 -0
- package/src/removeCleanRows.js +22 -0
- package/src/renderOnDoc.js +32 -0
- package/src/rerenderOnWindowResize.js +26 -0
- package/src/rowClick.js +181 -0
- package/src/selection.js +8 -0
- package/src/showAppSpinner.js +12 -0
- package/src/showDialogOnDocBody.js +33 -0
- package/src/showProgressToast.js +22 -0
- package/src/simplifyHasuraWhere.js +80 -0
- package/src/sortify.js +73 -0
- package/src/style.css +29 -0
- package/src/tableQueryParamsToHasuraClauses.js +113 -0
- package/src/tagUtils.js +45 -0
- package/src/tgFormValues.js +35 -0
- package/src/tg_modalState.js +47 -0
- package/src/throwFormError.js +16 -0
- package/src/toastr.js +148 -0
- package/src/tryToMatchSchemas.js +264 -0
- package/src/typeToCommonType.js +6 -0
- package/src/useDeepEqualMemo.js +15 -0
- package/src/useDialog.js +63 -0
- package/src/useStableReference.js +9 -0
- package/src/useTableEntities.js +38 -0
- package/src/useTraceUpdate.js +19 -0
- package/src/utils.js +37 -0
- package/src/validateTableWideErrors.js +160 -0
- package/src/viewColumn.js +97 -0
- package/src/withField.js +20 -0
- package/src/withFields.js +11 -0
- package/src/withLocalStorage.js +11 -0
- package/src/withSelectTableRecords.js +43 -0
- package/src/withSelectedEntities.js +65 -0
- package/src/withStore.js +10 -0
- package/src/withTableParams.js +288 -0
- package/src/wrapDialog.js +116 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isEmpty,
|
|
3
|
+
every,
|
|
4
|
+
some,
|
|
5
|
+
isEqual,
|
|
6
|
+
isString,
|
|
7
|
+
isNull,
|
|
8
|
+
isArray,
|
|
9
|
+
includes,
|
|
10
|
+
isObject,
|
|
11
|
+
has,
|
|
12
|
+
orderBy
|
|
13
|
+
} from "lodash-es";
|
|
14
|
+
|
|
15
|
+
export function filterLocalEntitiesToHasura(
|
|
16
|
+
records,
|
|
17
|
+
{ where, order_by, limit, offset, isInfinite } = {}
|
|
18
|
+
) {
|
|
19
|
+
let filteredRecords = [...records];
|
|
20
|
+
|
|
21
|
+
// Apply where clause if it exists
|
|
22
|
+
if (where) {
|
|
23
|
+
filteredRecords = applyWhereClause(filteredRecords, where);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Apply order_by if it exists
|
|
27
|
+
if (order_by) {
|
|
28
|
+
filteredRecords = applyOrderBy(filteredRecords, order_by);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Store the complete filtered and ordered records for pagination info
|
|
32
|
+
const allFilteredRecords = [...filteredRecords];
|
|
33
|
+
|
|
34
|
+
// Apply limit and offset
|
|
35
|
+
if (!isInfinite && offset !== undefined) {
|
|
36
|
+
filteredRecords = filteredRecords.slice(offset);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!isInfinite && limit !== undefined) {
|
|
40
|
+
filteredRecords = filteredRecords.slice(0, limit);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// For consistency, always return an object with entities, entitiesAcrossPages, and entityCount
|
|
44
|
+
return {
|
|
45
|
+
entities: filteredRecords,
|
|
46
|
+
entitiesAcrossPages: allFilteredRecords,
|
|
47
|
+
entityCount: allFilteredRecords.length
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function applyWhereClause(records, where) {
|
|
52
|
+
function applyFilter(record, filter) {
|
|
53
|
+
if (isEmpty(filter)) {
|
|
54
|
+
return true; // No filter, all records pass
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
for (const key in filter) {
|
|
58
|
+
if (key === "_and") {
|
|
59
|
+
if (!every(filter[key], subFilter => applyFilter(record, subFilter))) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
} else if (key === "_or") {
|
|
63
|
+
if (!some(filter[key], subFilter => applyFilter(record, subFilter))) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
} else if (key === "_not") {
|
|
67
|
+
if (applyFilter(record, filter[key])) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
const value = record[key];
|
|
72
|
+
const conditions = filter[key];
|
|
73
|
+
|
|
74
|
+
for (const operator in conditions) {
|
|
75
|
+
const conditionValue = conditions[operator];
|
|
76
|
+
|
|
77
|
+
// Handle range conditions (_gt/_lt or _gte/_lte combinations)
|
|
78
|
+
if (operator === "_gt" && conditions._lt) {
|
|
79
|
+
if (!(value > conditionValue && value < conditions._lt))
|
|
80
|
+
return false;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (operator === "_gte" && conditions._lte) {
|
|
84
|
+
if (!(value >= conditionValue && value <= conditions._lte))
|
|
85
|
+
return false;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
switch (operator) {
|
|
90
|
+
case "_eq":
|
|
91
|
+
if (!isEqual(value, conditionValue)) return false;
|
|
92
|
+
break;
|
|
93
|
+
case "_neq":
|
|
94
|
+
if (isEqual(value, conditionValue)) return false;
|
|
95
|
+
break;
|
|
96
|
+
case "_gt":
|
|
97
|
+
if (!(value > conditionValue)) return false;
|
|
98
|
+
break;
|
|
99
|
+
case "_gte":
|
|
100
|
+
if (!(value >= conditionValue)) return false;
|
|
101
|
+
break;
|
|
102
|
+
case "_lt":
|
|
103
|
+
if (!(value < conditionValue)) return false;
|
|
104
|
+
break;
|
|
105
|
+
case "_lte":
|
|
106
|
+
if (!(value <= conditionValue)) return false;
|
|
107
|
+
break;
|
|
108
|
+
case "_like":
|
|
109
|
+
if (
|
|
110
|
+
!isString(value) ||
|
|
111
|
+
!new RegExp(conditionValue.replace(/%/g, ".*")).test(value)
|
|
112
|
+
)
|
|
113
|
+
return false;
|
|
114
|
+
break;
|
|
115
|
+
case "_ilike":
|
|
116
|
+
if (
|
|
117
|
+
!isString(value) ||
|
|
118
|
+
!new RegExp(conditionValue.replace(/%/g, ".*"), "i").test(value)
|
|
119
|
+
)
|
|
120
|
+
return false;
|
|
121
|
+
break;
|
|
122
|
+
case "_nlike":
|
|
123
|
+
if (
|
|
124
|
+
!isString(value) ||
|
|
125
|
+
new RegExp(conditionValue.replace(/%/g, ".*")).test(value)
|
|
126
|
+
)
|
|
127
|
+
return false;
|
|
128
|
+
break;
|
|
129
|
+
case "_nilike":
|
|
130
|
+
if (
|
|
131
|
+
!isString(value) ||
|
|
132
|
+
new RegExp(conditionValue.replace(/%/g, ".*"), "i").test(value)
|
|
133
|
+
)
|
|
134
|
+
return false;
|
|
135
|
+
break;
|
|
136
|
+
case "_starts_with":
|
|
137
|
+
if (!isString(value) || !value.startsWith(conditionValue))
|
|
138
|
+
return false;
|
|
139
|
+
break;
|
|
140
|
+
case "_ends_with":
|
|
141
|
+
if (!isString(value) || !value.endsWith(conditionValue))
|
|
142
|
+
return false;
|
|
143
|
+
break;
|
|
144
|
+
case "_is_null":
|
|
145
|
+
if (
|
|
146
|
+
(conditionValue && !isNull(value)) ||
|
|
147
|
+
(!conditionValue && isNull(value))
|
|
148
|
+
)
|
|
149
|
+
return false;
|
|
150
|
+
break;
|
|
151
|
+
case "_contains":
|
|
152
|
+
if (
|
|
153
|
+
!isArray(value) ||
|
|
154
|
+
!every(conditionValue, item => includes(value, item))
|
|
155
|
+
)
|
|
156
|
+
return false;
|
|
157
|
+
break;
|
|
158
|
+
case "_contained_in":
|
|
159
|
+
if (
|
|
160
|
+
!isArray(value) ||
|
|
161
|
+
!every(value, item => includes(conditionValue, item))
|
|
162
|
+
)
|
|
163
|
+
return false;
|
|
164
|
+
break;
|
|
165
|
+
case "_has_key":
|
|
166
|
+
if (!isObject(value) || !has(value, conditionValue)) return false;
|
|
167
|
+
break;
|
|
168
|
+
case "_has_keys_any":
|
|
169
|
+
if (
|
|
170
|
+
!isObject(value) ||
|
|
171
|
+
!some(conditionValue, item => has(value, item))
|
|
172
|
+
)
|
|
173
|
+
return false;
|
|
174
|
+
break;
|
|
175
|
+
case "_has_keys_all":
|
|
176
|
+
if (
|
|
177
|
+
!isObject(value) ||
|
|
178
|
+
!every(conditionValue, item => has(value, item))
|
|
179
|
+
)
|
|
180
|
+
return false;
|
|
181
|
+
break;
|
|
182
|
+
case "_similar":
|
|
183
|
+
if (
|
|
184
|
+
!isString(value) ||
|
|
185
|
+
!new RegExp(conditionValue.replace(/%/g, ".*")).test(value)
|
|
186
|
+
)
|
|
187
|
+
return false;
|
|
188
|
+
break;
|
|
189
|
+
default:
|
|
190
|
+
if (operator.startsWith("_")) {
|
|
191
|
+
console.warn(`Unsupported operator: ${operator}`);
|
|
192
|
+
return false;
|
|
193
|
+
} else {
|
|
194
|
+
console.warn(`Unsupported operator: ${operator}`);
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return records.filter(record => applyFilter(record, where));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function applyOrderBy(records, order_by) {
|
|
209
|
+
const keys = Object.keys(order_by);
|
|
210
|
+
if (keys.length > 0) {
|
|
211
|
+
const field = keys[0];
|
|
212
|
+
const direction = order_by[field] === "asc" ? "asc" : "desc";
|
|
213
|
+
return orderBy(records, [field], [direction]);
|
|
214
|
+
}
|
|
215
|
+
return records;
|
|
216
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getFieldPathToField } from "./getFieldPathToField";
|
|
2
|
+
|
|
3
|
+
export const formatPasteData = ({ schema, newVal, path }) => {
|
|
4
|
+
const pathToField = getFieldPathToField(schema);
|
|
5
|
+
const column = pathToField[path];
|
|
6
|
+
if (column.type === "genericSelect") {
|
|
7
|
+
if (newVal?.__genSelCol === path) {
|
|
8
|
+
newVal = newVal.__strVal;
|
|
9
|
+
} else {
|
|
10
|
+
newVal = undefined;
|
|
11
|
+
}
|
|
12
|
+
} else {
|
|
13
|
+
newVal = Object.hasOwn(newVal, "__strVal") ? newVal.__strVal : newVal;
|
|
14
|
+
}
|
|
15
|
+
return newVal;
|
|
16
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const getAllRows = e => {
|
|
2
|
+
const el = e.target.querySelector(".data-table-container")
|
|
3
|
+
? e.target.querySelector(".data-table-container")
|
|
4
|
+
: e.target.closest(".data-table-container");
|
|
5
|
+
|
|
6
|
+
const allRowEls = el.querySelectorAll(".rt-tr");
|
|
7
|
+
if (!allRowEls || !allRowEls.length) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
return allRowEls;
|
|
11
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const getCellCopyText = cellWrapper => {
|
|
2
|
+
const text = cellWrapper && cellWrapper.getAttribute("data-copy-text");
|
|
3
|
+
const jsonText = cellWrapper && cellWrapper.getAttribute("data-copy-json");
|
|
4
|
+
|
|
5
|
+
const textContent = text || cellWrapper.textContent || "";
|
|
6
|
+
return [textContent, jsonText];
|
|
7
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getIdOrCodeOrIndex } from "./getIdOrCodeOrIndex";
|
|
2
|
+
|
|
3
|
+
export const getCellInfo = ({
|
|
4
|
+
columnIndex,
|
|
5
|
+
columnPath,
|
|
6
|
+
rowId,
|
|
7
|
+
schema,
|
|
8
|
+
entities,
|
|
9
|
+
rowIndex,
|
|
10
|
+
isEntityDisabled,
|
|
11
|
+
entity
|
|
12
|
+
}) => {
|
|
13
|
+
const leftpath = schema.fields[columnIndex - 1]?.path;
|
|
14
|
+
const rightpath = schema.fields[columnIndex + 1]?.path;
|
|
15
|
+
const cellIdToLeft = leftpath && `${rowId}:${leftpath}`;
|
|
16
|
+
const cellIdToRight = rightpath && `${rowId}:${rightpath}`;
|
|
17
|
+
const rowAboveId =
|
|
18
|
+
entities[rowIndex - 1] &&
|
|
19
|
+
getIdOrCodeOrIndex(entities[rowIndex - 1], rowIndex - 1);
|
|
20
|
+
const rowBelowId =
|
|
21
|
+
entities[rowIndex + 1] &&
|
|
22
|
+
getIdOrCodeOrIndex(entities[rowIndex + 1], rowIndex + 1);
|
|
23
|
+
const cellIdAbove = rowAboveId && `${rowAboveId}:${columnPath}`;
|
|
24
|
+
const cellIdBelow = rowBelowId && `${rowBelowId}:${columnPath}`;
|
|
25
|
+
|
|
26
|
+
const cellId = `${rowId}:${columnPath}`;
|
|
27
|
+
const rowDisabled = isEntityDisabled(entity);
|
|
28
|
+
return {
|
|
29
|
+
cellId,
|
|
30
|
+
cellIdAbove,
|
|
31
|
+
cellIdToRight,
|
|
32
|
+
cellIdBelow,
|
|
33
|
+
cellIdToLeft,
|
|
34
|
+
rowDisabled
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { get } from "lodash-es";
|
|
2
|
+
import { isString } from "lodash-es";
|
|
3
|
+
import { isTruthy } from "./isTruthy";
|
|
4
|
+
|
|
5
|
+
export const getCellVal = (ent, path, col) => {
|
|
6
|
+
const isBool = col?.type === "boolean";
|
|
7
|
+
let selectedCellVal = get(ent, path, "");
|
|
8
|
+
if (isBool) {
|
|
9
|
+
if (isString(selectedCellVal)) {
|
|
10
|
+
selectedCellVal = selectedCellVal.toLowerCase();
|
|
11
|
+
}
|
|
12
|
+
selectedCellVal =
|
|
13
|
+
selectedCellVal === "true" ||
|
|
14
|
+
selectedCellVal === true ||
|
|
15
|
+
selectedCellVal === 1 ||
|
|
16
|
+
selectedCellVal === "yes";
|
|
17
|
+
selectedCellVal = isTruthy(selectedCellVal);
|
|
18
|
+
}
|
|
19
|
+
return selectedCellVal;
|
|
20
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import LocalizedFormat from "dayjs/plugin/localizedFormat";
|
|
3
|
+
import localeData from "dayjs/plugin/localeData";
|
|
4
|
+
|
|
5
|
+
dayjs.extend(localeData);
|
|
6
|
+
dayjs.extend(LocalizedFormat);
|
|
7
|
+
const userLocale = Intl.DateTimeFormat().resolvedOptions().locale;
|
|
8
|
+
|
|
9
|
+
if (userLocale) {
|
|
10
|
+
const requireLocale = (newLocale, skipCall) => {
|
|
11
|
+
if (dayjs.locale() !== newLocale) {
|
|
12
|
+
try {
|
|
13
|
+
require(`dayjs/locale/${newLocale}.js`);
|
|
14
|
+
dayjs.locale(newLocale);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
// error
|
|
17
|
+
if (!skipCall && newLocale.includes("-")) {
|
|
18
|
+
requireLocale(newLocale.split("-")[0], true);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const localeToUse = userLocale.toLowerCase();
|
|
24
|
+
requireLocale(localeToUse);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default function getDayjsFormatter(format) {
|
|
28
|
+
return {
|
|
29
|
+
formatDate: date => dayjs(date).format(format),
|
|
30
|
+
parseDate: str => dayjs(str, format).toDate(),
|
|
31
|
+
placeholder: format?.toLowerCase().includes("l")
|
|
32
|
+
? dayjs.Ls[dayjs.locale()]?.formats[format.toUpperCase()]
|
|
33
|
+
: format
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const getLastSelectedEntity = idMap => {
|
|
2
|
+
let lastSelectedEnt;
|
|
3
|
+
let latestTime;
|
|
4
|
+
Object.values(idMap).forEach(({ time, entity }) => {
|
|
5
|
+
if (!latestTime || time > latestTime) {
|
|
6
|
+
lastSelectedEnt = entity;
|
|
7
|
+
latestTime = time;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
return lastSelectedEnt;
|
|
11
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const getNewEntToSelect = ({
|
|
2
|
+
type,
|
|
3
|
+
lastSelectedIndex,
|
|
4
|
+
entities,
|
|
5
|
+
isEntityDisabled
|
|
6
|
+
}) => {
|
|
7
|
+
let newIndexToSelect;
|
|
8
|
+
if (type === "up") {
|
|
9
|
+
newIndexToSelect = lastSelectedIndex - 1;
|
|
10
|
+
} else {
|
|
11
|
+
newIndexToSelect = lastSelectedIndex + 1;
|
|
12
|
+
}
|
|
13
|
+
const newEntToSelect = entities[newIndexToSelect];
|
|
14
|
+
if (!newEntToSelect) return;
|
|
15
|
+
if (isEntityDisabled && isEntityDisabled(newEntToSelect)) {
|
|
16
|
+
return getNewEntToSelect({
|
|
17
|
+
type,
|
|
18
|
+
lastSelectedIndex: newIndexToSelect,
|
|
19
|
+
entities,
|
|
20
|
+
isEntityDisabled
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
return newEntToSelect;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export function getNewName(list, targetName) {
|
|
2
|
+
const usedNumbers = [];
|
|
3
|
+
|
|
4
|
+
for (let i = 0; i < list.length; i++) {
|
|
5
|
+
const currentName = list[i].name;
|
|
6
|
+
const baseName = currentName.replace(/\(\d+\)\.csv$/, ".csv");
|
|
7
|
+
|
|
8
|
+
if (baseName === targetName) {
|
|
9
|
+
const match = currentName.match(/\((\d+)\)\.csv$/);
|
|
10
|
+
if (match) {
|
|
11
|
+
usedNumbers[parseInt(match[1])] = true;
|
|
12
|
+
} else {
|
|
13
|
+
usedNumbers[0] = true;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let newName = targetName;
|
|
19
|
+
for (let i = 0; i <= usedNumbers.length; i++) {
|
|
20
|
+
if (!usedNumbers[i]) {
|
|
21
|
+
if (i === 0) {
|
|
22
|
+
newName = targetName;
|
|
23
|
+
} else {
|
|
24
|
+
newName = targetName.replace(".csv", `(${i}).csv`);
|
|
25
|
+
}
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return newName;
|
|
31
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { getCellCopyText } from "./getCellCopyText";
|
|
2
|
+
import { flatMap } from "lodash-es";
|
|
3
|
+
|
|
4
|
+
export const getRowCopyText = (rowEl, { specificColumn } = {}) => {
|
|
5
|
+
//takes in a row element
|
|
6
|
+
if (!rowEl) return [];
|
|
7
|
+
const textContent = [];
|
|
8
|
+
const jsonText = [];
|
|
9
|
+
|
|
10
|
+
for (const cellEl of rowEl.children) {
|
|
11
|
+
const cellChild = cellEl.querySelector(`[data-copy-text]`);
|
|
12
|
+
if (!cellChild) {
|
|
13
|
+
if (specificColumn) continue; //strip it
|
|
14
|
+
continue; //just leave it blank
|
|
15
|
+
}
|
|
16
|
+
if (
|
|
17
|
+
specificColumn &&
|
|
18
|
+
cellChild.getAttribute("data-test") !== specificColumn
|
|
19
|
+
) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const [t, j] = getCellCopyText(cellChild);
|
|
23
|
+
textContent.push(t);
|
|
24
|
+
jsonText.push(j);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return [flatMap(textContent).join("\t"), jsonText];
|
|
28
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
export default function getTextFromEl(el, options = {}) {
|
|
4
|
+
const { lowerCase } = options;
|
|
5
|
+
if (React.isValidElement(el)) {
|
|
6
|
+
return el && el.props && el.props.children
|
|
7
|
+
? (el.props.children.reduce
|
|
8
|
+
? el.props.children
|
|
9
|
+
: [el.props.children]
|
|
10
|
+
).reduce((acc, child) => {
|
|
11
|
+
if (child && child.props && child.props.children) {
|
|
12
|
+
acc += getTextFromEl(child);
|
|
13
|
+
} else if (typeof child === "string") {
|
|
14
|
+
if (lowerCase) {
|
|
15
|
+
acc += child.toLowerCase();
|
|
16
|
+
} else {
|
|
17
|
+
acc += child;
|
|
18
|
+
}
|
|
19
|
+
} else if (typeof child === "number") {
|
|
20
|
+
acc += child + "";
|
|
21
|
+
}
|
|
22
|
+
return acc;
|
|
23
|
+
}, "")
|
|
24
|
+
: "";
|
|
25
|
+
} else {
|
|
26
|
+
return el;
|
|
27
|
+
}
|
|
28
|
+
}
|
package/src/getVals.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getAllRows } from "./getAllRows";
|
|
2
|
+
import { getIdOrCodeOrIndex } from "./getIdOrCodeOrIndex";
|
|
3
|
+
import { handleCopyRows } from "./handleCopyRows";
|
|
4
|
+
|
|
5
|
+
export const handleCopyColumn = (e, cellWrapper, selectedRecords) => {
|
|
6
|
+
const specificColumn = cellWrapper.getAttribute("data-test");
|
|
7
|
+
let rowElsToCopy = getAllRows(e);
|
|
8
|
+
if (!rowElsToCopy) return;
|
|
9
|
+
if (selectedRecords) {
|
|
10
|
+
const ids = selectedRecords.map(e => getIdOrCodeOrIndex(e)?.toString());
|
|
11
|
+
rowElsToCopy = Array.from(rowElsToCopy).filter(rowEl => {
|
|
12
|
+
const id = rowEl.closest(".rt-tr-group")?.getAttribute("data-test-id");
|
|
13
|
+
return id !== undefined && ids.includes(id);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (!rowElsToCopy) return;
|
|
17
|
+
handleCopyRows(rowElsToCopy, {
|
|
18
|
+
specificColumn,
|
|
19
|
+
onFinishMsg: "Column Copied"
|
|
20
|
+
});
|
|
21
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import copy from "copy-to-clipboard";
|
|
2
|
+
|
|
3
|
+
export const handleCopyHelper = (stringToCopy, jsonToCopy, message) => {
|
|
4
|
+
!window.Cypress &&
|
|
5
|
+
copy(stringToCopy, {
|
|
6
|
+
onCopy: clipboardData => {
|
|
7
|
+
clipboardData.setData("application/json", JSON.stringify(jsonToCopy));
|
|
8
|
+
},
|
|
9
|
+
// keep this so that pasting into spreadsheets works.
|
|
10
|
+
format: "text/plain"
|
|
11
|
+
});
|
|
12
|
+
if (message) {
|
|
13
|
+
window.toastr.success(message);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import download from "downloadjs";
|
|
2
|
+
import { getRowCopyText } from "./getRowCopyText";
|
|
3
|
+
import { handleCopyHelper } from "./handleCopyHelper";
|
|
4
|
+
|
|
5
|
+
export const handleCopyRows = (
|
|
6
|
+
rowElsToCopy,
|
|
7
|
+
{ specificColumn, onFinishMsg, isDownload } = {}
|
|
8
|
+
) => {
|
|
9
|
+
let textToCopy = [];
|
|
10
|
+
const jsonToCopy = [];
|
|
11
|
+
rowElsToCopy.forEach(rowEl => {
|
|
12
|
+
const [t, j] = getRowCopyText(rowEl, { specificColumn });
|
|
13
|
+
textToCopy.push(t);
|
|
14
|
+
jsonToCopy.push(j);
|
|
15
|
+
});
|
|
16
|
+
textToCopy = textToCopy.filter(text => text).join("\n");
|
|
17
|
+
if (!textToCopy) return window.toastr.warning("No text to copy");
|
|
18
|
+
if (isDownload) {
|
|
19
|
+
download(textToCopy.replaceAll("\t", ","), "tableData.csv", "text/csv");
|
|
20
|
+
} else {
|
|
21
|
+
handleCopyHelper(textToCopy, jsonToCopy, onFinishMsg || "Row Copied");
|
|
22
|
+
}
|
|
23
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getAllRows } from "./getAllRows";
|
|
2
|
+
import { handleCopyRows } from "./handleCopyRows";
|
|
3
|
+
|
|
4
|
+
export const handleCopyTable = (e, opts) => {
|
|
5
|
+
try {
|
|
6
|
+
const allRowEls = getAllRows(e);
|
|
7
|
+
if (!allRowEls) return;
|
|
8
|
+
handleCopyRows(allRowEls, {
|
|
9
|
+
...opts,
|
|
10
|
+
onFinishMsg: "Table Copied"
|
|
11
|
+
});
|
|
12
|
+
} catch (error) {
|
|
13
|
+
console.error(`error:`, error);
|
|
14
|
+
window.toastr.error("Error copying rows.");
|
|
15
|
+
}
|
|
16
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const onEnterHelper = callback => ({
|
|
2
|
+
onKeyDown: event => {
|
|
3
|
+
if (event.key === "Enter") {
|
|
4
|
+
callback(event);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export const onBlurHelper = callback => ({
|
|
10
|
+
onBlur: event => {
|
|
11
|
+
callback(event);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const onEnterOrBlurHelper = callback => ({
|
|
16
|
+
onKeyDown: function (event) {
|
|
17
|
+
if (event.key === "Enter") {
|
|
18
|
+
callback(event);
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
onBlur: function (event) {
|
|
22
|
+
callback(event);
|
|
23
|
+
}
|
|
24
|
+
});
|