@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.
Files changed (114) hide show
  1. package/package.json +1 -1
  2. package/src/AdvancedOptions.js +33 -0
  3. package/src/AssignDefaultsModeContext.js +22 -0
  4. package/src/CellDragHandle.js +132 -0
  5. package/src/ColumnFilterMenu.js +62 -0
  6. package/src/Columns.js +979 -0
  7. package/src/DisabledLoadingComponent.js +15 -0
  8. package/src/DisplayOptions.js +199 -0
  9. package/src/DropdownButton.js +36 -0
  10. package/src/DropdownCell.js +61 -0
  11. package/src/EditableCell.js +44 -0
  12. package/src/FillWindow.css +6 -0
  13. package/src/FillWindow.js +69 -0
  14. package/src/FilterAndSortMenu.js +388 -0
  15. package/src/FormSeparator.js +9 -0
  16. package/src/LoadingDots.js +14 -0
  17. package/src/MatchHeaders.js +234 -0
  18. package/src/PagingTool.js +225 -0
  19. package/src/RenderCell.js +191 -0
  20. package/src/SearchBar.js +69 -0
  21. package/src/SimpleStepViz.js +22 -0
  22. package/src/SortableColumns.js +100 -0
  23. package/src/TableFormTrackerContext.js +10 -0
  24. package/src/Tag.js +112 -0
  25. package/src/ThComponent.js +44 -0
  26. package/src/TimelineEvent.js +31 -0
  27. package/src/UploadCsvWizard.css +4 -0
  28. package/src/UploadCsvWizard.js +719 -0
  29. package/src/Uploader.js +1278 -0
  30. package/src/adHoc.js +10 -0
  31. package/src/autoTooltip.js +201 -0
  32. package/src/basicHandleActionsWithFullState.js +14 -0
  33. package/src/browserUtils.js +3 -0
  34. package/src/combineReducersWithFullState.js +14 -0
  35. package/src/commandControls.js +82 -0
  36. package/src/commandUtils.js +112 -0
  37. package/src/constants.js +1 -0
  38. package/src/convertSchema.js +69 -0
  39. package/src/customIcons.js +361 -0
  40. package/src/dataTableEnhancer.js +41 -0
  41. package/src/defaultFormatters.js +32 -0
  42. package/src/defaultValidators.js +40 -0
  43. package/src/determineBlackOrWhiteTextColor.js +4 -0
  44. package/src/editCellHelper.js +44 -0
  45. package/src/filterLocalEntitiesToHasura.js +216 -0
  46. package/src/formatPasteData.js +16 -0
  47. package/src/getAllRows.js +11 -0
  48. package/src/getCellCopyText.js +7 -0
  49. package/src/getCellInfo.js +36 -0
  50. package/src/getCellVal.js +20 -0
  51. package/src/getDayjsFormatter.js +35 -0
  52. package/src/getFieldPathToField.js +7 -0
  53. package/src/getIdOrCodeOrIndex.js +9 -0
  54. package/src/getLastSelectedEntity.js +11 -0
  55. package/src/getNewEntToSelect.js +25 -0
  56. package/src/getNewName.js +31 -0
  57. package/src/getRowCopyText.js +28 -0
  58. package/src/getTableConfigFromStorage.js +5 -0
  59. package/src/getTextFromEl.js +28 -0
  60. package/src/getVals.js +8 -0
  61. package/src/handleCopyColumn.js +21 -0
  62. package/src/handleCopyHelper.js +15 -0
  63. package/src/handleCopyRows.js +23 -0
  64. package/src/handleCopyTable.js +16 -0
  65. package/src/handlerHelpers.js +24 -0
  66. package/src/hotkeyUtils.js +131 -0
  67. package/src/index.js +1 -0
  68. package/src/initializeHasuraWhereAndFilter.js +27 -0
  69. package/src/isBeingCalledExcessively.js +24 -0
  70. package/src/isBottomRightCornerOfRectangle.js +20 -0
  71. package/src/isEntityClean.js +15 -0
  72. package/src/isTruthy.js +12 -0
  73. package/src/isValueEmpty.js +3 -0
  74. package/src/itemUpload.js +84 -0
  75. package/src/menuUtils.js +433 -0
  76. package/src/popoverOverflowModifiers.js +11 -0
  77. package/src/primarySelectedValue.js +1 -0
  78. package/src/pureNoFunc.js +31 -0
  79. package/src/queryParams.js +336 -0
  80. package/src/removeCleanRows.js +22 -0
  81. package/src/renderOnDoc.js +32 -0
  82. package/src/rerenderOnWindowResize.js +26 -0
  83. package/src/rowClick.js +181 -0
  84. package/src/selection.js +8 -0
  85. package/src/showAppSpinner.js +12 -0
  86. package/src/showDialogOnDocBody.js +33 -0
  87. package/src/showProgressToast.js +22 -0
  88. package/src/simplifyHasuraWhere.js +80 -0
  89. package/src/sortify.js +73 -0
  90. package/src/style.css +29 -0
  91. package/src/tableQueryParamsToHasuraClauses.js +113 -0
  92. package/src/tagUtils.js +45 -0
  93. package/src/tgFormValues.js +35 -0
  94. package/src/tg_modalState.js +47 -0
  95. package/src/throwFormError.js +16 -0
  96. package/src/toastr.js +148 -0
  97. package/src/tryToMatchSchemas.js +264 -0
  98. package/src/typeToCommonType.js +6 -0
  99. package/src/useDeepEqualMemo.js +15 -0
  100. package/src/useDialog.js +63 -0
  101. package/src/useStableReference.js +9 -0
  102. package/src/useTableEntities.js +38 -0
  103. package/src/useTraceUpdate.js +19 -0
  104. package/src/utils.js +37 -0
  105. package/src/validateTableWideErrors.js +160 -0
  106. package/src/viewColumn.js +97 -0
  107. package/src/withField.js +20 -0
  108. package/src/withFields.js +11 -0
  109. package/src/withLocalStorage.js +11 -0
  110. package/src/withSelectTableRecords.js +43 -0
  111. package/src/withSelectedEntities.js +65 -0
  112. package/src/withStore.js +10 -0
  113. package/src/withTableParams.js +288 -0
  114. package/src/wrapDialog.js +116 -0
@@ -0,0 +1,131 @@
1
+ import React, { useMemo } from "react";
2
+ import { useHotkeys } from "@blueprintjs/core";
3
+ import { startCase } from "lodash-es";
4
+
5
+ // This has been mostly superseded by blueprint's KeyCombo component, but may
6
+ // still be useful for cases where we need plain text
7
+ export function comboToLabel(def, useSymbols = true) {
8
+ const combo = typeof def === "string" ? def : def.combo;
9
+
10
+ if (useSymbols) {
11
+ let parts = combo.replace("++", "+plus").split("+");
12
+ parts = parts.map(p => symbols[p] || startCase(p) || p);
13
+ return parts.join("");
14
+ } else {
15
+ return combo
16
+ .split("+")
17
+ .map(p => startCase(p) || p)
18
+ .join(" + ")
19
+ .replace("Meta", isMac ? "Cmd" : "Ctrl")
20
+ .replace("Mod", isMac ? "Cmd" : "Ctrl")
21
+ .replace("Alt", isMac ? "Option" : "Alt");
22
+ }
23
+ }
24
+
25
+ // HOF to get hotkey combos by id
26
+ export const hotkeysById =
27
+ (hotkeys, mode = "raw") =>
28
+ id => {
29
+ const def = getHotkeyProps(hotkeys[id]);
30
+ return (
31
+ def &&
32
+ (mode === "raw" ? def.combo : comboToLabel(def.combo, mode === "symbols"))
33
+ );
34
+ };
35
+
36
+ // Translate shorthand array if needed
37
+ export const getHotkeyProps = (def, id) => {
38
+ let out;
39
+ if (typeof def === "string") {
40
+ out = { combo: def };
41
+ } else if (def instanceof Array) {
42
+ out = { combo: def[0], label: def[1], ...(def[2] || {}) };
43
+ } else {
44
+ out = def;
45
+ }
46
+ out.label = out.label || startCase(id);
47
+ return out;
48
+ };
49
+
50
+ /*
51
+ * HOC to add hotkey support to components. Use this instead of blueprint's one.
52
+ *
53
+ * Arguments:
54
+ * - hotkeySpec: either a named hotkey section previously registered, or an
55
+ * object mapping command ids to hotkey definitions, where each hotkey can
56
+ * be either:
57
+ * - a string consisting in the key combo (e.g. 'ctrl+shift+x')
58
+ * - an array holding the combo, label, and an object with any other props
59
+ * - an object holding all props
60
+ * - handlers: an object mapping command ids to handler functions
61
+ * - options: an object that may specify the follownig options:
62
+ * - functional: boolean indicating if the wrapped component will be a
63
+ * functional stateless component instead of a class-based one
64
+ *
65
+ * Returns a function that can be invoked with a component class, or a
66
+ * stateless component function (if specified in the options) and returns
67
+ * the decorated class. It may also be invoked without arguments to generate a
68
+ * dummy ad-hoc component with no output.
69
+ *
70
+ */
71
+ export const withHotkeys = (hotkeys, handlers) => {
72
+ return ({ children } = {}) => {
73
+ const memoedHotkeys = useMemo(
74
+ () =>
75
+ Object.keys(hotkeys).map(id => {
76
+ const { ...props } = getHotkeyProps(hotkeys[id], id);
77
+ return {
78
+ key: id,
79
+ global: props.global !== false,
80
+ onKeyDown: function (e) {
81
+ return handlers[id](e);
82
+ },
83
+ ...props
84
+ };
85
+ }),
86
+ []
87
+ );
88
+
89
+ const { handleKeyDown, handleKeyUp } = useHotkeys(memoedHotkeys);
90
+ const newProps = {
91
+ tabIndex: 0,
92
+ onKeyDown: handleKeyDown,
93
+ onKeyUp: handleKeyUp
94
+ };
95
+ return children ? ( //tnr: if children are passed, we'll clone them with the new props
96
+ React.cloneElement(children, newProps)
97
+ ) : (
98
+ //if not, then we'll return a div that can be used
99
+ <div className="hotkeyHandler" {...newProps}></div>
100
+ );
101
+ };
102
+ };
103
+
104
+ const isMac = navigator.userAgent.includes("Mac OS X");
105
+
106
+ // TODO maybe avoid using symbols by default when not on Mac?
107
+ // Anyway, alternative 'Key + Key' description is provided as well
108
+ const symbols = {
109
+ cmd: "⌘",
110
+ meta: "⌘",
111
+ ctrl: "⌃",
112
+ alt: "⌥",
113
+ shift: "⇧",
114
+ esc: "␛", //'⎋',
115
+ enter: "⏎",
116
+ backspace: "⌫",
117
+ plus: "+",
118
+ tab: "⇥",
119
+ space: "␣",
120
+ capslock: "⇪",
121
+ pageup: "⇞",
122
+ pagedown: "⇟",
123
+ home: "↖",
124
+ end: "↘",
125
+ left: "←",
126
+ right: "→",
127
+ up: "↑",
128
+ down: "↓"
129
+ };
130
+
131
+ symbols.mod = symbols[isMac ? "meta" : "ctrl"];
package/src/index.js ADDED
@@ -0,0 +1 @@
1
+ export { useDeepEqualMemo } from "./useDeepEqualMemo";
@@ -0,0 +1,27 @@
1
+ export function initializeHasuraWhereAndFilter(
2
+ additionalFilter,
3
+ where = {},
4
+ currentParams
5
+ ) {
6
+ where._and = where._and || [];
7
+ where._or = where._or || [];
8
+ if (typeof additionalFilter === "function") {
9
+ const newWhere = additionalFilter(where, currentParams);
10
+ if (newWhere) {
11
+ where = {
12
+ ...where,
13
+ ...newWhere
14
+ };
15
+ }
16
+ } else if (typeof additionalFilter === "object")
17
+ where._and.push(additionalFilter);
18
+ }
19
+
20
+ export const addCustomColumnFilters = (where, fields, currentParams) => {
21
+ fields.forEach(field => {
22
+ const { customColumnFilter, filterDisabled } = field;
23
+ if (filterDisabled || !customColumnFilter) return;
24
+ customColumnFilter(where, currentParams);
25
+ });
26
+ };
27
+
@@ -0,0 +1,24 @@
1
+ const keyCount = {};
2
+ export const isBeingCalledExcessively = ({ uniqName }) => {
3
+ if (process.env.NODE_ENV !== "development") {
4
+ return;
5
+ }
6
+ if (!uniqName) {
7
+ throw new Error("uniqName is required");
8
+ }
9
+ // if this function is hit more than 10 times in a row in 2 seconds with the same uniqName then throw an error
10
+ if (keyCount[uniqName + "_timeout"]) {
11
+ clearTimeout(keyCount[uniqName + "_timeout"]);
12
+ }
13
+ keyCount[uniqName] = keyCount[uniqName] || 0;
14
+ keyCount[uniqName]++;
15
+
16
+ keyCount[uniqName + "_timeout"] = setTimeout(() => {
17
+ keyCount[uniqName] = 0;
18
+ }, 2000);
19
+
20
+ if (keyCount[uniqName] > 20) {
21
+ keyCount[uniqName] = 0;
22
+ throw new Error(`isBeingCalledExcessively: ${uniqName}`);
23
+ }
24
+ };
@@ -0,0 +1,20 @@
1
+ export const isBottomRightCornerOfRectangle = ({
2
+ cellId,
3
+ selectionGrid,
4
+ lastRowIndex,
5
+ lastCellIndex,
6
+ entityMap,
7
+ pathToIndex
8
+ }) => {
9
+ selectionGrid.forEach(row => {
10
+ // remove undefineds from start of row
11
+ while (row[0] === undefined && row.length) row.shift();
12
+ });
13
+ const [rowId, cellPath] = cellId.split(":");
14
+ const ent = entityMap[rowId];
15
+ if (!ent) return;
16
+ const { i } = ent;
17
+ const cellIndex = pathToIndex[cellPath];
18
+ const isBottomRight = i === lastRowIndex && cellIndex === lastCellIndex;
19
+ return isBottomRight;
20
+ };
@@ -0,0 +1,15 @@
1
+ export function isEntityClean(e) {
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
+ }
@@ -0,0 +1,12 @@
1
+ export function isTruthy(v) {
2
+ if (!v) return false;
3
+ if (typeof v === "string") {
4
+ if (v.toLowerCase() === "false") {
5
+ return false;
6
+ }
7
+ if (v.toLowerCase() === "no") {
8
+ return false;
9
+ }
10
+ }
11
+ return true;
12
+ }
@@ -0,0 +1,3 @@
1
+ export function isValueEmpty(val) {
2
+ return val === undefined || val === null || val === "";
3
+ }
@@ -0,0 +1,84 @@
1
+ import React from "react";
2
+ import {
3
+ ProgressBar,
4
+ Intent,
5
+ Button,
6
+ Tooltip,
7
+ Position,
8
+ Icon
9
+ } from "@blueprintjs/core";
10
+
11
+ const itemUpload = props => {
12
+ const item = props.item;
13
+ const name = nameShortener(item.name);
14
+
15
+ return (
16
+ <div className="item-upload-container" key={item.id}>
17
+ <div className="item-upload">
18
+ <div>
19
+ {!props.saved ? (
20
+ <Tooltip
21
+ content={
22
+ <span>
23
+ {`Click to
24
+ ${props.active ? "abort this uploading" : "remove this file"}`}
25
+ </span>
26
+ }
27
+ position={Position.LEFT}
28
+ usePortal={true}
29
+ >
30
+ <Button
31
+ intent={Intent.DANGER}
32
+ minimal
33
+ icon="delete"
34
+ onClick={props.onCancel}
35
+ />
36
+ </Tooltip>
37
+ ) : null}
38
+ </div>
39
+ <div>
40
+ <span>{name}</span>
41
+ </div>
42
+ <div>
43
+ {props.active ? `${props.value}%` : null}
44
+ {props.error ? (
45
+ <Tooltip content={props.error} usePortal={true}>
46
+ <Icon icon="error" intent={Intent.DANGER} />
47
+ </Tooltip>
48
+ ) : null}
49
+ {props.saved ? (
50
+ <Tooltip content={"File Saved"} usePortal={true}>
51
+ <Icon icon="saved" intent={Intent.SUCCESS} />
52
+ </Tooltip>
53
+ ) : null}
54
+ </div>
55
+ </div>
56
+ {props.active ? (
57
+ <ProgressBar intent={Intent.PRIMARY} value={props.value / 100} />
58
+ ) : null}
59
+ </div>
60
+ );
61
+ };
62
+
63
+ /**
64
+ * Short file names length to display
65
+ * @param {*} itemName
66
+ */
67
+ const nameShortener = itemName => {
68
+ if (itemName.length > 40) {
69
+ let name = "";
70
+ const arr = itemName.split(".");
71
+ name += `${arr[0].substring(0, 20)}...`;
72
+ if (arr.length >= 2) {
73
+ name += `${arr[arr.length - 2].substring(
74
+ arr[arr.length - 2].length - 5,
75
+ arr[arr.length - 2].length
76
+ )}`;
77
+ name += `.${arr[arr.length - 1]}`;
78
+ }
79
+ return name;
80
+ }
81
+ return itemName;
82
+ };
83
+
84
+ export default itemUpload;