@teselagen/ui 0.9.7 → 0.10.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/DataTable/index.d.ts +3 -3
- package/index.cjs.js +21025 -21144
- package/index.es.js +21028 -21147
- package/package.json +2 -1
- package/src/DataTable/PagingTool.js +2 -2
- package/src/DataTable/RenderCell.js +8 -4
- package/src/DataTable/index.js +1210 -224
- package/src/DataTable/utils/useTableEntities.js +3 -2
- package/src/DataTable/utils/withTableParams.js +8 -7
- package/src/UploadCsvWizard.js +7 -5
- package/src/utils/hooks/useDeepEqualMemo.js +2 -2
- package/src/utils/isEqualIgnoreFunctions.js +23 -0
- package/src/utils/pureNoFunc.js +4 -20
- package/utils/isEqualIgnoreFunctions.d.ts +1 -0
- package/DataTable/EditabelCell.d.ts +0 -7
- package/DataTable/ReactTable.d.ts +0 -78
- package/DataTable/defaultProps.d.ts +0 -43
- package/DataTable/utils/computePresets.d.ts +0 -1
- package/DataTable/utils/types/Entity.d.ts +0 -9
- package/DataTable/utils/types/Field.d.ts +0 -4
- package/DataTable/utils/types/OrderBy.d.ts +0 -11
- package/DataTable/utils/types/Schema.d.ts +0 -4
- package/DataTable/utils/useDeepEqualMemo.d.ts +0 -1
- package/DataTable/utils/useHotKeysWrapper.d.ts +0 -29
- package/DataTable/utils/useTableParams.d.ts +0 -49
- package/src/DataTable/Columns.jsx +0 -945
- package/src/DataTable/EditabelCell.js +0 -44
- package/src/DataTable/EditabelCell.jsx +0 -44
- package/src/DataTable/ReactTable.js +0 -738
- package/src/DataTable/RenderCell.jsx +0 -191
- package/src/DataTable/defaultProps.js +0 -45
- package/src/DataTable/utils/computePresets.js +0 -42
- package/src/DataTable/utils/convertSchema.ts +0 -79
- package/src/DataTable/utils/formatPasteData.ts +0 -34
- package/src/DataTable/utils/getAllRows.ts +0 -11
- package/src/DataTable/utils/getCellCopyText.ts +0 -7
- package/src/DataTable/utils/getCellInfo.ts +0 -46
- package/src/DataTable/utils/getFieldPathToField.ts +0 -10
- package/src/DataTable/utils/getIdOrCodeOrIndex.ts +0 -14
- package/src/DataTable/utils/getLastSelectedEntity.ts +0 -15
- package/src/DataTable/utils/getNewEntToSelect.ts +0 -32
- package/src/DataTable/utils/initializeHasuraWhereAndFilter.ts +0 -35
- package/src/DataTable/utils/isBottomRightCornerOfRectangle.ts +0 -27
- package/src/DataTable/utils/isEntityClean.ts +0 -15
- package/src/DataTable/utils/primarySelectedValue.ts +0 -1
- package/src/DataTable/utils/removeCleanRows.ts +0 -26
- package/src/DataTable/utils/selection.ts +0 -11
- package/src/DataTable/utils/types/Entity.ts +0 -13
- package/src/DataTable/utils/types/Field.ts +0 -4
- package/src/DataTable/utils/types/OrderBy.ts +0 -15
- package/src/DataTable/utils/types/Schema.ts +0 -5
- package/src/DataTable/utils/useDeepEqualMemo.js +0 -10
- package/src/DataTable/utils/useHotKeysWrapper.js +0 -395
- package/src/DataTable/utils/useTableEntities.ts +0 -60
- package/src/DataTable/utils/useTableParams.js +0 -361
- package/src/DataTable/utils/utils.ts +0 -39
- package/src/Timeline/TimelineEvent.tsx +0 -36
- package/src/Timeline/index.tsx +0 -21
- package/src/utils/browserUtils.ts +0 -3
- package/src/utils/determineBlackOrWhiteTextColor.ts +0 -11
- package/src/utils/getTextFromEl.ts +0 -45
- package/src/utils/handlerHelpers.ts +0 -32
- package/src/utils/hooks/index.ts +0 -1
- package/src/utils/hooks/useDeepEqualMemo.ts +0 -10
- package/src/utils/hooks/useStableReference.ts +0 -9
- package/src/utils/hotkeyUtils.tsx +0 -155
- package/src/utils/isBeingCalledExcessively.ts +0 -37
- package/style.css +0 -10537
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { useSelector } from "react-redux";
|
|
3
|
-
import { Checkbox, Icon } from "@blueprintjs/core";
|
|
4
|
-
import {
|
|
5
|
-
getIdOrCodeOrIndex,
|
|
6
|
-
isBottomRightCornerOfRectangle,
|
|
7
|
-
PRIMARY_SELECTED_VAL
|
|
8
|
-
} from "./utils";
|
|
9
|
-
import { DropdownCell } from "./DropdownCell";
|
|
10
|
-
import { EditableCell } from "./EditabelCell";
|
|
11
|
-
import { getVals } from "./getVals";
|
|
12
|
-
import { CellDragHandle } from "./CellDragHandle";
|
|
13
|
-
|
|
14
|
-
export const RenderCell = ({
|
|
15
|
-
oldFunc,
|
|
16
|
-
getCopyTextForCell,
|
|
17
|
-
column,
|
|
18
|
-
isCellEditable,
|
|
19
|
-
isEntityDisabled,
|
|
20
|
-
finishCellEdit,
|
|
21
|
-
formName,
|
|
22
|
-
noEllipsis,
|
|
23
|
-
cancelCellEdit,
|
|
24
|
-
getCellHoverText,
|
|
25
|
-
selectedCells,
|
|
26
|
-
isSelectionARectangle,
|
|
27
|
-
startCellEdit,
|
|
28
|
-
tableRef,
|
|
29
|
-
onDragEnd,
|
|
30
|
-
args
|
|
31
|
-
}) => {
|
|
32
|
-
const editingCell = useSelector(
|
|
33
|
-
state => state.form?.[formName]?.values?.reduxFormEditingCell
|
|
34
|
-
);
|
|
35
|
-
const initialValue = useSelector(
|
|
36
|
-
state => state.form?.[formName]?.values?.reduxFormInitialValue
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
const [row] = args;
|
|
40
|
-
const rowId = getIdOrCodeOrIndex(row.original, row.index);
|
|
41
|
-
const cellId = `${rowId}:${row.column.path}`;
|
|
42
|
-
const isEditingCell = editingCell === cellId;
|
|
43
|
-
let val = oldFunc(...args);
|
|
44
|
-
const oldVal = val;
|
|
45
|
-
const text = getCopyTextForCell(val, row, column);
|
|
46
|
-
const dataTest = {
|
|
47
|
-
"data-test": "tgCell_" + column.path
|
|
48
|
-
};
|
|
49
|
-
const fullValue = row.original?.[row.column.path];
|
|
50
|
-
|
|
51
|
-
if (isEditingCell) {
|
|
52
|
-
if (column.type === "genericSelect") {
|
|
53
|
-
const GenericSelectComp = column.GenericSelectComp;
|
|
54
|
-
|
|
55
|
-
return (
|
|
56
|
-
<GenericSelectComp
|
|
57
|
-
rowId={rowId}
|
|
58
|
-
fullValue={fullValue}
|
|
59
|
-
initialValue={text}
|
|
60
|
-
{...dataTest}
|
|
61
|
-
finishEdit={(newVal, doNotStopEditing) => {
|
|
62
|
-
finishCellEdit(cellId, newVal, doNotStopEditing);
|
|
63
|
-
}}
|
|
64
|
-
dataTest={dataTest}
|
|
65
|
-
cancelEdit={cancelCellEdit}
|
|
66
|
-
/>
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
if (column.type === "dropdown" || column.type === "dropdownMulti") {
|
|
70
|
-
return (
|
|
71
|
-
<DropdownCell
|
|
72
|
-
isMulti={dataTest.isMulti || column.type === "dropdownMulti"}
|
|
73
|
-
initialValue={dataTest.initialValue || text}
|
|
74
|
-
options={getVals(column.values)}
|
|
75
|
-
finishEdit={(newVal, doNotStopEditing) => {
|
|
76
|
-
finishCellEdit(cellId, newVal, doNotStopEditing);
|
|
77
|
-
}}
|
|
78
|
-
dataTest={dataTest}
|
|
79
|
-
cancelEdit={cancelCellEdit}
|
|
80
|
-
/>
|
|
81
|
-
);
|
|
82
|
-
} else {
|
|
83
|
-
return (
|
|
84
|
-
<EditableCell
|
|
85
|
-
dataTest={dataTest}
|
|
86
|
-
cancelEdit={cancelCellEdit}
|
|
87
|
-
isNumeric={column.type === "number"}
|
|
88
|
-
initialValue={initialValue || text}
|
|
89
|
-
finishEdit={newVal => {
|
|
90
|
-
finishCellEdit(cellId, newVal);
|
|
91
|
-
}}
|
|
92
|
-
/>
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const isBool = column.type === "boolean";
|
|
98
|
-
if (isCellEditable && isBool) {
|
|
99
|
-
val = (
|
|
100
|
-
<Checkbox
|
|
101
|
-
disabled={isEntityDisabled(row.original)}
|
|
102
|
-
className="tg-cell-edit-boolean-checkbox"
|
|
103
|
-
checked={oldVal === "True"}
|
|
104
|
-
onChange={e => {
|
|
105
|
-
const checked = e.target.checked;
|
|
106
|
-
finishCellEdit(cellId, checked);
|
|
107
|
-
}}
|
|
108
|
-
/>
|
|
109
|
-
);
|
|
110
|
-
noEllipsis = true;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
//wrap the original tableColumn.Cell function in another div in order to add a title attribute
|
|
114
|
-
let title = text;
|
|
115
|
-
if (getCellHoverText) title = getCellHoverText(...args);
|
|
116
|
-
else if (column.getTitleAttr) title = column.getTitleAttr(...args);
|
|
117
|
-
const isSelectedCell = selectedCells?.[cellId];
|
|
118
|
-
const {
|
|
119
|
-
isRect,
|
|
120
|
-
selectionGrid,
|
|
121
|
-
lastRowIndex,
|
|
122
|
-
lastCellIndex,
|
|
123
|
-
entityMap,
|
|
124
|
-
pathToIndex
|
|
125
|
-
} = isSelectionARectangle();
|
|
126
|
-
|
|
127
|
-
return (
|
|
128
|
-
<>
|
|
129
|
-
<div
|
|
130
|
-
style={{
|
|
131
|
-
...(!noEllipsis && {
|
|
132
|
-
textOverflow: "ellipsis",
|
|
133
|
-
overflow: "hidden"
|
|
134
|
-
})
|
|
135
|
-
}}
|
|
136
|
-
{...dataTest}
|
|
137
|
-
className="tg-cell-wrapper"
|
|
138
|
-
data-copy-text={text}
|
|
139
|
-
data-copy-json={JSON.stringify(
|
|
140
|
-
//tnw: eventually we'll parse these back out and use either the fullValue (for the generic selects) or the regular text vals for everything else
|
|
141
|
-
column.type === "genericSelect"
|
|
142
|
-
? {
|
|
143
|
-
__strVal: fullValue,
|
|
144
|
-
__genSelCol: column.path
|
|
145
|
-
}
|
|
146
|
-
: { __strVal: text }
|
|
147
|
-
)}
|
|
148
|
-
title={title || undefined}
|
|
149
|
-
>
|
|
150
|
-
{val}
|
|
151
|
-
</div>
|
|
152
|
-
{isCellEditable &&
|
|
153
|
-
(column.type === "dropdown" ||
|
|
154
|
-
column.type === "dropdownMulti" ||
|
|
155
|
-
column.type === "genericSelect") && (
|
|
156
|
-
<Icon
|
|
157
|
-
icon="caret-down"
|
|
158
|
-
style={{
|
|
159
|
-
position: "absolute",
|
|
160
|
-
right: 5,
|
|
161
|
-
opacity: 0.3
|
|
162
|
-
}}
|
|
163
|
-
className="cell-edit-dropdown"
|
|
164
|
-
onClick={() => {
|
|
165
|
-
startCellEdit(cellId);
|
|
166
|
-
}}
|
|
167
|
-
/>
|
|
168
|
-
)}
|
|
169
|
-
|
|
170
|
-
{isSelectedCell &&
|
|
171
|
-
(isRect
|
|
172
|
-
? isBottomRightCornerOfRectangle({
|
|
173
|
-
cellId,
|
|
174
|
-
selectionGrid,
|
|
175
|
-
lastRowIndex,
|
|
176
|
-
lastCellIndex,
|
|
177
|
-
entityMap,
|
|
178
|
-
pathToIndex
|
|
179
|
-
})
|
|
180
|
-
: isSelectedCell === PRIMARY_SELECTED_VAL) && (
|
|
181
|
-
<CellDragHandle
|
|
182
|
-
key={cellId}
|
|
183
|
-
thisTable={tableRef.current.tableRef}
|
|
184
|
-
cellId={cellId}
|
|
185
|
-
isSelectionARectangle={isSelectionARectangle}
|
|
186
|
-
onDragEnd={onDragEnd}
|
|
187
|
-
/>
|
|
188
|
-
)}
|
|
189
|
-
</>
|
|
190
|
-
);
|
|
191
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { noop } from "lodash-es";
|
|
2
|
-
|
|
3
|
-
// eslint-disable-next-line import/no-anonymous-default-export
|
|
4
|
-
export default {
|
|
5
|
-
//NOTE: DO NOT SET DEFAULTS HERE FOR PROPS THAT GET COMPUTED AS PART OF PRESET GROUPS IN computePresets
|
|
6
|
-
addFilters: noop,
|
|
7
|
-
className: "",
|
|
8
|
-
clearFilters: noop,
|
|
9
|
-
contextMenu: noop,
|
|
10
|
-
disabled: false,
|
|
11
|
-
entities: [],
|
|
12
|
-
extraClasses: "",
|
|
13
|
-
filters: [],
|
|
14
|
-
isCopyable: true,
|
|
15
|
-
isEntityDisabled: noop,
|
|
16
|
-
isLoading: false,
|
|
17
|
-
isSimple: false,
|
|
18
|
-
isSingleSelect: false,
|
|
19
|
-
maxHeight: 600,
|
|
20
|
-
noHeader: false,
|
|
21
|
-
noSelect: false,
|
|
22
|
-
noUserSelect: false,
|
|
23
|
-
onDeselect: noop,
|
|
24
|
-
onMultiRowSelect: noop,
|
|
25
|
-
onRowClick: noop,
|
|
26
|
-
onRowSelect: noop,
|
|
27
|
-
onSingleRowSelect: noop,
|
|
28
|
-
page: 1,
|
|
29
|
-
pageSize: 10,
|
|
30
|
-
reduxFormExpandedEntityIdMap: {},
|
|
31
|
-
reduxFormSearchInput: "",
|
|
32
|
-
reduxFormSelectedEntityIdMap: {},
|
|
33
|
-
removeSingleFilter: noop,
|
|
34
|
-
resized: [],
|
|
35
|
-
resizePersist: noop,
|
|
36
|
-
setFilter: noop,
|
|
37
|
-
setOrder: noop,
|
|
38
|
-
setPage: noop,
|
|
39
|
-
setPageSize: noop,
|
|
40
|
-
setSearchTerm: noop,
|
|
41
|
-
showCount: false,
|
|
42
|
-
style: {},
|
|
43
|
-
withCheckboxes: false,
|
|
44
|
-
withSort: true
|
|
45
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { omitBy, isNil } from "lodash-es";
|
|
2
|
-
//we use this to make adding preset prop groups simpler
|
|
3
|
-
export default function computePresets(props = {}) {
|
|
4
|
-
const { isSimple } = props;
|
|
5
|
-
let toReturn = omitBy(props, isNil);
|
|
6
|
-
toReturn.pageSize = toReturn.controlled_pageSize || toReturn.pageSize;
|
|
7
|
-
if (isSimple) {
|
|
8
|
-
//isSimplePreset
|
|
9
|
-
toReturn = {
|
|
10
|
-
noHeader: true,
|
|
11
|
-
noFooter: !props.withPaging,
|
|
12
|
-
noPadding: true,
|
|
13
|
-
noFullscreenButton: true,
|
|
14
|
-
hidePageSizeWhenPossible: !props.withPaging,
|
|
15
|
-
isInfinite: !props.withPaging,
|
|
16
|
-
hideSelectedCount: true,
|
|
17
|
-
withTitle: false,
|
|
18
|
-
withSearch: false,
|
|
19
|
-
compact: true,
|
|
20
|
-
withPaging: false,
|
|
21
|
-
withFilter: false,
|
|
22
|
-
...toReturn
|
|
23
|
-
};
|
|
24
|
-
} else {
|
|
25
|
-
toReturn = {
|
|
26
|
-
// the usual defaults:
|
|
27
|
-
noFooter: false,
|
|
28
|
-
noPadding: false,
|
|
29
|
-
compact: true,
|
|
30
|
-
noFullscreenButton: false,
|
|
31
|
-
hidePageSizeWhenPossible: false,
|
|
32
|
-
isInfinite: false,
|
|
33
|
-
hideSelectedCount: false,
|
|
34
|
-
withTitle: true,
|
|
35
|
-
withSearch: true,
|
|
36
|
-
withPaging: true,
|
|
37
|
-
withFilter: true,
|
|
38
|
-
...toReturn
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
return toReturn || {};
|
|
42
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { camelCase } from "lodash-es";
|
|
2
|
-
import { startCase, keyBy, map } from "lodash-es";
|
|
3
|
-
|
|
4
|
-
type Field = {
|
|
5
|
-
type?: string;
|
|
6
|
-
displayName?: string;
|
|
7
|
-
path?: string;
|
|
8
|
-
filterDisabled?: boolean;
|
|
9
|
-
sortDisabled?: boolean;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
type Schema = { fields: (Field | string)[] };
|
|
13
|
-
|
|
14
|
-
type CompleteField = Field & {
|
|
15
|
-
type: string;
|
|
16
|
-
displayName: string;
|
|
17
|
-
path: string;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
type CompleteSchema = {
|
|
21
|
-
fields: CompleteField[];
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const convertSchema = (schema: Schema): CompleteSchema => {
|
|
25
|
-
let schemaToUse = schema;
|
|
26
|
-
if (!schemaToUse.fields && Array.isArray(schema)) {
|
|
27
|
-
schemaToUse = {
|
|
28
|
-
fields: schema
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
schemaToUse = {
|
|
32
|
-
...schemaToUse
|
|
33
|
-
};
|
|
34
|
-
schemaToUse.fields = schemaToUse.fields.map((field, i) => {
|
|
35
|
-
if (typeof field === "string") {
|
|
36
|
-
return {
|
|
37
|
-
displayName: startCase(camelCase(field)),
|
|
38
|
-
path: field,
|
|
39
|
-
type: "string"
|
|
40
|
-
};
|
|
41
|
-
} else {
|
|
42
|
-
const fieldToUse = { ...(field as Field) };
|
|
43
|
-
fieldToUse.type = fieldToUse.type || "string";
|
|
44
|
-
fieldToUse.displayName =
|
|
45
|
-
fieldToUse.displayName || startCase(camelCase(fieldToUse.path || ""));
|
|
46
|
-
// paths are needed for column resizing
|
|
47
|
-
if (!fieldToUse.path) {
|
|
48
|
-
fieldToUse.filterDisabled = true;
|
|
49
|
-
fieldToUse.sortDisabled = true;
|
|
50
|
-
fieldToUse.path = "fake-path" + i;
|
|
51
|
-
}
|
|
52
|
-
return fieldToUse as CompleteField;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
return schemaToUse as CompleteSchema;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export function mergeSchemas(_originalSchema: Schema, _overrideSchema: Schema) {
|
|
59
|
-
const originalSchema = convertSchema(_originalSchema);
|
|
60
|
-
const overrideSchema = convertSchema(_overrideSchema);
|
|
61
|
-
|
|
62
|
-
const overridesByKey = keyBy(overrideSchema.fields, "path");
|
|
63
|
-
return {
|
|
64
|
-
...originalSchema,
|
|
65
|
-
...overrideSchema,
|
|
66
|
-
fields: originalSchema.fields
|
|
67
|
-
.map(f => {
|
|
68
|
-
const override = overridesByKey[f.path];
|
|
69
|
-
if (override) {
|
|
70
|
-
delete overridesByKey[f.path];
|
|
71
|
-
return override;
|
|
72
|
-
}
|
|
73
|
-
return f;
|
|
74
|
-
})
|
|
75
|
-
.concat(map(overridesByKey))
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export default convertSchema;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { getFieldPathToField } from "./getFieldPathToField";
|
|
2
|
-
import type { Schema } from "./types/Schema";
|
|
3
|
-
|
|
4
|
-
type GenericSelectValue = {
|
|
5
|
-
__strVal: string;
|
|
6
|
-
__genSelCol: string;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const formatPasteData = ({
|
|
10
|
-
schema,
|
|
11
|
-
newVal,
|
|
12
|
-
path
|
|
13
|
-
}: {
|
|
14
|
-
schema: Schema;
|
|
15
|
-
newVal: GenericSelectValue | string | number | boolean | null | undefined;
|
|
16
|
-
path: string;
|
|
17
|
-
}) => {
|
|
18
|
-
const pathToField = getFieldPathToField(schema);
|
|
19
|
-
const column = pathToField[path];
|
|
20
|
-
if (column.type === "genericSelect") {
|
|
21
|
-
const value = newVal as GenericSelectValue;
|
|
22
|
-
if (value.__genSelCol === path) {
|
|
23
|
-
newVal = value.__strVal;
|
|
24
|
-
} else {
|
|
25
|
-
newVal = undefined;
|
|
26
|
-
}
|
|
27
|
-
} else {
|
|
28
|
-
newVal =
|
|
29
|
-
typeof newVal === "object" && newVal !== null && "__strVal" in newVal
|
|
30
|
-
? newVal.__strVal
|
|
31
|
-
: newVal;
|
|
32
|
-
}
|
|
33
|
-
return newVal;
|
|
34
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { RefObject } from "react";
|
|
2
|
-
|
|
3
|
-
export const getAllRows = (
|
|
4
|
-
tableRef: RefObject<{ tableRef: HTMLDivElement }>
|
|
5
|
-
) => {
|
|
6
|
-
const allRowEls = tableRef.current?.tableRef?.querySelectorAll(".rt-tr");
|
|
7
|
-
if (!allRowEls || !allRowEls.length) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
return allRowEls;
|
|
11
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export const getCellCopyText = (cellWrapper: HTMLElement | null) => {
|
|
2
|
-
const text = cellWrapper?.getAttribute("data-copy-text");
|
|
3
|
-
const jsonText = cellWrapper?.getAttribute("data-copy-json");
|
|
4
|
-
|
|
5
|
-
const textContent = text || cellWrapper?.textContent || "";
|
|
6
|
-
return [textContent, jsonText];
|
|
7
|
-
};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { getIdOrCodeOrIndex } from "./getIdOrCodeOrIndex";
|
|
2
|
-
import { Entity } from "./types/Entity";
|
|
3
|
-
|
|
4
|
-
export const getCellInfo = <T extends Entity>({
|
|
5
|
-
columnIndex,
|
|
6
|
-
columnPath,
|
|
7
|
-
rowId,
|
|
8
|
-
schema,
|
|
9
|
-
entities,
|
|
10
|
-
rowIndex,
|
|
11
|
-
isEntityDisabled,
|
|
12
|
-
entity
|
|
13
|
-
}: {
|
|
14
|
-
columnIndex: number;
|
|
15
|
-
columnPath: string;
|
|
16
|
-
rowId: string | number;
|
|
17
|
-
schema: { fields: { path: string }[] };
|
|
18
|
-
entities: T[];
|
|
19
|
-
rowIndex: number;
|
|
20
|
-
isEntityDisabled: (entity: T) => boolean;
|
|
21
|
-
entity: T;
|
|
22
|
-
}) => {
|
|
23
|
-
const leftpath = schema.fields[columnIndex - 1]?.path;
|
|
24
|
-
const rightpath = schema.fields[columnIndex + 1]?.path;
|
|
25
|
-
const cellIdToLeft = leftpath && `${rowId}:${leftpath}`;
|
|
26
|
-
const cellIdToRight = rightpath && `${rowId}:${rightpath}`;
|
|
27
|
-
const rowAboveId =
|
|
28
|
-
entities[rowIndex - 1] &&
|
|
29
|
-
getIdOrCodeOrIndex(entities[rowIndex - 1], rowIndex - 1);
|
|
30
|
-
const rowBelowId =
|
|
31
|
-
entities[rowIndex + 1] &&
|
|
32
|
-
getIdOrCodeOrIndex(entities[rowIndex + 1], rowIndex + 1);
|
|
33
|
-
const cellIdAbove = rowAboveId && `${rowAboveId}:${columnPath}`;
|
|
34
|
-
const cellIdBelow = rowBelowId && `${rowBelowId}:${columnPath}`;
|
|
35
|
-
|
|
36
|
-
const cellId = `${rowId}:${columnPath}`;
|
|
37
|
-
const rowDisabled = isEntityDisabled(entity);
|
|
38
|
-
return {
|
|
39
|
-
cellId,
|
|
40
|
-
cellIdAbove,
|
|
41
|
-
cellIdToRight,
|
|
42
|
-
cellIdBelow,
|
|
43
|
-
cellIdToLeft,
|
|
44
|
-
rowDisabled
|
|
45
|
-
};
|
|
46
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Field } from "./types/Field";
|
|
2
|
-
import { Schema } from "./types/Schema";
|
|
3
|
-
|
|
4
|
-
export const getFieldPathToField = (schema: Schema) => {
|
|
5
|
-
const fieldPathToField: { [path: string]: Field } = {};
|
|
6
|
-
schema.fields.forEach(f => {
|
|
7
|
-
fieldPathToField[f.path] = f;
|
|
8
|
-
});
|
|
9
|
-
return fieldPathToField;
|
|
10
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Entity } from "./types/Entity";
|
|
2
|
-
|
|
3
|
-
export const getIdOrCodeOrIndex = (record: Entity, rowIndex?: number) => {
|
|
4
|
-
if ("id" in record && (record.id || record.id === 0)) {
|
|
5
|
-
return record.id;
|
|
6
|
-
} else if ("code" in record && record.code) {
|
|
7
|
-
return record.code;
|
|
8
|
-
} else {
|
|
9
|
-
if (rowIndex === undefined || rowIndex === null) {
|
|
10
|
-
throw new Error("id, code, or rowIndex must be provided");
|
|
11
|
-
}
|
|
12
|
-
return rowIndex;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Entity } from "./types/Entity";
|
|
2
|
-
|
|
3
|
-
export const getLastSelectedEntity = (idMap: {
|
|
4
|
-
[id: string]: { time: number; entity: Entity };
|
|
5
|
-
}) => {
|
|
6
|
-
let lastSelectedEnt;
|
|
7
|
-
let latestTime: number | null = null;
|
|
8
|
-
Object.values(idMap).forEach(({ time, entity }) => {
|
|
9
|
-
if (!latestTime || time > latestTime) {
|
|
10
|
-
lastSelectedEnt = entity;
|
|
11
|
-
latestTime = time;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
return lastSelectedEnt;
|
|
15
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Entity } from "./types/Entity";
|
|
2
|
-
|
|
3
|
-
export const getNewEntToSelect = ({
|
|
4
|
-
type,
|
|
5
|
-
lastSelectedIndex,
|
|
6
|
-
entities,
|
|
7
|
-
isEntityDisabled
|
|
8
|
-
}: {
|
|
9
|
-
type: "up" | "down";
|
|
10
|
-
lastSelectedIndex: number;
|
|
11
|
-
entities: Entity[];
|
|
12
|
-
isEntityDisabled?: (entity: Entity) => boolean;
|
|
13
|
-
}): Entity | undefined => {
|
|
14
|
-
let newIndexToSelect;
|
|
15
|
-
if (type === "up") {
|
|
16
|
-
newIndexToSelect = lastSelectedIndex - 1;
|
|
17
|
-
} else {
|
|
18
|
-
newIndexToSelect = lastSelectedIndex + 1;
|
|
19
|
-
}
|
|
20
|
-
const newEntToSelect = entities[newIndexToSelect];
|
|
21
|
-
if (!newEntToSelect) return;
|
|
22
|
-
if (isEntityDisabled && isEntityDisabled(newEntToSelect)) {
|
|
23
|
-
return getNewEntToSelect({
|
|
24
|
-
type,
|
|
25
|
-
lastSelectedIndex: newIndexToSelect,
|
|
26
|
-
entities,
|
|
27
|
-
isEntityDisabled
|
|
28
|
-
}) as Entity;
|
|
29
|
-
} else {
|
|
30
|
-
return newEntToSelect;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
type Filter = {
|
|
2
|
-
[key: string]:
|
|
3
|
-
| { _eq: string | number | boolean }
|
|
4
|
-
| { _in: (string | number | boolean)[] }
|
|
5
|
-
| { _gt: number }
|
|
6
|
-
| { _lt: number }
|
|
7
|
-
| { _gte: number }
|
|
8
|
-
| { _lte: number };
|
|
9
|
-
};
|
|
10
|
-
type Where = { _and?: Filter[]; _or?: Filter[] };
|
|
11
|
-
type CurrentParams = object;
|
|
12
|
-
|
|
13
|
-
export function initializeHasuraWhereAndFilter(
|
|
14
|
-
additionalFilter:
|
|
15
|
-
| ((where: Where, currentParams: CurrentParams) => Filter | void)
|
|
16
|
-
| Filter
|
|
17
|
-
| undefined
|
|
18
|
-
| null,
|
|
19
|
-
where: Where = {},
|
|
20
|
-
currentParams: CurrentParams
|
|
21
|
-
) {
|
|
22
|
-
where._and = where._and || [];
|
|
23
|
-
where._or = where._or || [];
|
|
24
|
-
if (typeof additionalFilter === "function") {
|
|
25
|
-
const newWhere = additionalFilter(where, currentParams);
|
|
26
|
-
if (newWhere) {
|
|
27
|
-
Object.assign(where, newWhere);
|
|
28
|
-
}
|
|
29
|
-
} else if (
|
|
30
|
-
typeof additionalFilter === "object" &&
|
|
31
|
-
additionalFilter !== null
|
|
32
|
-
) {
|
|
33
|
-
where._and.push(additionalFilter);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export const isBottomRightCornerOfRectangle = ({
|
|
2
|
-
cellId,
|
|
3
|
-
selectionGrid,
|
|
4
|
-
lastRowIndex,
|
|
5
|
-
lastCellIndex,
|
|
6
|
-
entityMap,
|
|
7
|
-
pathToIndex
|
|
8
|
-
}: {
|
|
9
|
-
cellId: string;
|
|
10
|
-
selectionGrid: (string | undefined)[][];
|
|
11
|
-
lastRowIndex: number;
|
|
12
|
-
lastCellIndex: number;
|
|
13
|
-
entityMap: Record<string, { i: number }>;
|
|
14
|
-
pathToIndex: Record<string, number>;
|
|
15
|
-
}) => {
|
|
16
|
-
selectionGrid.forEach(row => {
|
|
17
|
-
// remove undefineds from start of row
|
|
18
|
-
while (row[0] === undefined && row.length) row.shift();
|
|
19
|
-
});
|
|
20
|
-
const [rowId, cellPath] = cellId.split(":");
|
|
21
|
-
const ent = entityMap[rowId];
|
|
22
|
-
if (!ent) return;
|
|
23
|
-
const { i } = ent;
|
|
24
|
-
const cellIndex = pathToIndex[cellPath];
|
|
25
|
-
const isBottomRight = i === lastRowIndex && cellIndex === lastCellIndex;
|
|
26
|
-
return isBottomRight;
|
|
27
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export function isEntityClean(e: { [key: string]: unknown } | null): boolean {
|
|
2
|
-
if (typeof e !== "object" || e === null) {
|
|
3
|
-
return true; // or return false depending on what you want for non-object inputs
|
|
4
|
-
}
|
|
5
|
-
let isClean = true;
|
|
6
|
-
for (const [key, val] of Object.entries(e)) {
|
|
7
|
-
if (key === "id") continue;
|
|
8
|
-
if (key === "_isClean") continue;
|
|
9
|
-
if (val) {
|
|
10
|
-
isClean = false;
|
|
11
|
-
break;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return isClean;
|
|
15
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const PRIMARY_SELECTED_VAL = "main_cell";
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { isEntityClean } from "./isEntityClean";
|
|
2
|
-
import { getIdOrCodeOrIndex } from "./getIdOrCodeOrIndex";
|
|
3
|
-
import { Entity } from "./types/Entity";
|
|
4
|
-
|
|
5
|
-
export const removeCleanRows = (
|
|
6
|
-
entities: Entity[],
|
|
7
|
-
cellValidation: Record<string, unknown>
|
|
8
|
-
) => {
|
|
9
|
-
const toFilterOut: Record<string, boolean> = {};
|
|
10
|
-
const entsToUse = (entities || []).filter(e => {
|
|
11
|
-
if (!(e._isClean || isEntityClean(e))) return true;
|
|
12
|
-
else {
|
|
13
|
-
toFilterOut[getIdOrCodeOrIndex(e)] = true;
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
const validationToUse: Record<string, unknown> = {};
|
|
19
|
-
Object.entries(cellValidation || {}).forEach(([k, v]) => {
|
|
20
|
-
const [rowId] = k.split(":");
|
|
21
|
-
if (!toFilterOut[rowId]) {
|
|
22
|
-
validationToUse[k] = v;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
return { entsToUse, validationToUse };
|
|
26
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { getIdOrCodeOrIndex } from "./getIdOrCodeOrIndex";
|
|
2
|
-
|
|
3
|
-
export const getSelectedRowsFromEntities = (
|
|
4
|
-
entities: { [key: string]: unknown }[],
|
|
5
|
-
idMap: Record<string, boolean>
|
|
6
|
-
) => {
|
|
7
|
-
if (!idMap) return [];
|
|
8
|
-
return entities.reduce((acc: number[], entity, i) => {
|
|
9
|
-
return idMap[getIdOrCodeOrIndex(entity, i)] ? acc.concat([i]) : acc;
|
|
10
|
-
}, []);
|
|
11
|
-
};
|