@teselagen/ui 0.8.6-beta.2 → 0.8.8

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 (40) hide show
  1. package/DataTable/EditabelCell.d.ts +10 -0
  2. package/DataTable/defaultProps.d.ts +43 -0
  3. package/DataTable/utils/computePresets.d.ts +1 -0
  4. package/DataTable/utils/getRowCopyText.d.ts +3 -1
  5. package/DataTable/utils/handleCopyRows.d.ts +5 -1
  6. package/DataTable/utils/index.d.ts +1 -0
  7. package/DataTable/utils/queryParams.d.ts +14 -7
  8. package/DataTable/utils/rowClick.d.ts +1 -1
  9. package/FormComponents/Uploader.d.ts +3 -1
  10. package/FormComponents/tryToMatchSchemas.d.ts +1 -1
  11. package/MenuBar/index.d.ts +3 -1
  12. package/ResizableDraggableDialog/index.d.ts +3 -1
  13. package/TagSelect/index.d.ts +1 -1
  14. package/index.cjs.js +34520 -37504
  15. package/index.d.ts +0 -1
  16. package/index.es.js +33521 -36505
  17. package/package.json +1 -1
  18. package/src/DataTable/Columns.js +1 -1
  19. package/src/DataTable/DisplayOptions.js +1 -1
  20. package/src/DataTable/EditabelCell.js +55 -0
  21. package/src/DataTable/FilterAndSortMenu.js +30 -27
  22. package/src/DataTable/defaultProps.js +45 -0
  23. package/src/DataTable/index.js +14 -3
  24. package/src/DataTable/style.css +1 -1
  25. package/src/DataTable/utils/computePresets.js +42 -0
  26. package/src/DataTable/utils/queryParams.js +772 -64
  27. package/src/DataTable/utils/withTableParams.js +16 -3
  28. package/src/ExcelCell.js +38 -0
  29. package/src/FormComponents/index.js +2 -2
  30. package/src/index.js +0 -1
  31. package/{ui.css → style.css} +1 -1
  32. package/utils/hotkeyUtils.d.ts +3 -1
  33. package/DataTable/utils/filterLocalEntitiesToHasura.d.ts +0 -5
  34. package/DataTable/utils/initializeHasuraWhereAndFilter.d.ts +0 -2
  35. package/DataTable/utils/tableQueryParamsToHasuraClauses.d.ts +0 -26
  36. package/src/DataTable/utils/filterLocalEntitiesToHasura.js +0 -236
  37. package/src/DataTable/utils/filterLocalEntitiesToHasura.test.js +0 -587
  38. package/src/DataTable/utils/initializeHasuraWhereAndFilter.js +0 -26
  39. package/src/DataTable/utils/tableQueryParamsToHasuraClauses.js +0 -260
  40. package/src/DataTable/utils/tableQueryParamsToHasuraClauses.test.js +0 -206
@@ -6,13 +6,13 @@ import {
6
6
  makeDataTableHandlers,
7
7
  getQueryParams,
8
8
  setCurrentParamsOnUrl,
9
- getCurrentParamsFromUrl
9
+ getCurrentParamsFromUrl,
10
+ getCCDisplayName
10
11
  } from "./queryParams";
11
12
  import { withRouter } from "react-router-dom";
12
13
  import getTableConfigFromStorage from "./getTableConfigFromStorage";
13
14
  import { useDeepEqualMemo } from "../../utils/hooks/useDeepEqualMemo";
14
15
  import { branch, compose } from "recompose";
15
- import { getCCDisplayName } from "./tableQueryParamsToHasuraClauses";
16
16
 
17
17
  /**
18
18
  * Note all these options can be passed at Design Time or at Runtime (like reduxForm())
@@ -32,6 +32,7 @@ import { getCCDisplayName } from "./tableQueryParamsToHasuraClauses";
32
32
  export const useTableParams = props => {
33
33
  const {
34
34
  additionalFilter,
35
+ additionalOrFilter,
35
36
  controlled_pageSize,
36
37
  defaults: _defaults,
37
38
  doNotCoercePageSize,
@@ -165,6 +166,16 @@ export const useTableParams = props => {
165
166
  );
166
167
 
167
168
  const queryParams = useMemo(() => {
169
+ const additionalFilterToUse =
170
+ typeof additionalFilter === "function"
171
+ ? additionalFilter
172
+ : () => additionalFilter;
173
+
174
+ const additionalOrFilterToUse =
175
+ typeof additionalOrFilter === "function"
176
+ ? additionalOrFilter
177
+ : () => additionalOrFilter;
178
+
168
179
  return getQueryParams({
169
180
  doNotCoercePageSize,
170
181
  currentParams,
@@ -174,7 +185,8 @@ export const useTableParams = props => {
174
185
  schema: convertedSchema,
175
186
  isInfinite: isInfinite || (isSimple && !withPaging),
176
187
  isLocalCall,
177
- additionalFilter,
188
+ additionalFilter: additionalFilterToUse,
189
+ additionalOrFilter: additionalOrFilterToUse,
178
190
  noOrderError,
179
191
  isCodeModel,
180
192
  ownProps: passingProps
@@ -182,6 +194,7 @@ export const useTableParams = props => {
182
194
  }, [
183
195
  additionalFilter,
184
196
  passingProps,
197
+ additionalOrFilter,
185
198
  doNotCoercePageSize,
186
199
  currentParams,
187
200
  entities,
@@ -0,0 +1,38 @@
1
+ /* eslint react/jsx-no-bind: 0 */
2
+ import { Popover } from "@blueprintjs/core";
3
+ import React, { useState } from "react";
4
+
5
+ export default function ExcelCell() {
6
+ const [v, setV] = useState("");
7
+ const [isPopoverOpen, setIsPopoverOpen] = useState(false);
8
+ return (
9
+ <Popover
10
+ onClose={() => {
11
+ setIsPopoverOpen(false);
12
+ }}
13
+ isOpen={isPopoverOpen}
14
+ content={<div>Sum</div>}
15
+ >
16
+ <div
17
+ style={{
18
+ border: "1px solid #ccc",
19
+ padding: 5,
20
+ width: 100,
21
+ height: 30
22
+ }}
23
+ contentEditable
24
+ onInput={e => {
25
+ const text = e.currentTarget.textContent;
26
+
27
+ if (text === "=") {
28
+ // open a popover
29
+ setIsPopoverOpen(true);
30
+ }
31
+ setV(text);
32
+ }}
33
+ >
34
+ {v}
35
+ </div>
36
+ </Popover>
37
+ );
38
+ }
@@ -114,14 +114,14 @@ function removeUnwantedProps(props) {
114
114
 
115
115
  const LabelWithTooltipInfo = ({ label, tooltipInfo, labelStyle }) =>
116
116
  tooltipInfo ? (
117
- <span style={{ display: "flex", alignItems: "center", ...labelStyle }}>
117
+ <div style={{ display: "flex", alignItems: "center", ...labelStyle }}>
118
118
  {label}{" "}
119
119
  <InfoHelper
120
120
  style={{ marginLeft: "5px", marginTop: "-6px" }}
121
121
  size={12}
122
122
  content={tooltipInfo}
123
123
  />
124
- </span>
124
+ </div>
125
125
  ) : (
126
126
  label || null
127
127
  );
package/src/index.js CHANGED
@@ -85,4 +85,3 @@ const noop = () => undefined;
85
85
  export { noop };
86
86
  export { default as showDialogOnDocBody } from "./showDialogOnDocBody";
87
87
  export { default as TableFormTrackerContext } from "./DataTable/TableFormTrackerContext";
88
- export { initializeHasuraWhereAndFilter } from "./DataTable/utils/initializeHasuraWhereAndFilter";
@@ -9676,7 +9676,7 @@ body:not(.drag-active)
9676
9676
  display: flex;
9677
9677
  flex-wrap: wrap;
9678
9678
  align-items: center;
9679
- margin-top: 10px;
9679
+ margin-top: 20px;
9680
9680
  }
9681
9681
 
9682
9682
  .ReactTable {
@@ -1,4 +1,6 @@
1
1
  export function comboToLabel(def: any, useSymbols?: boolean): any;
2
2
  export function hotkeysById(hotkeys: any, mode?: string): (id: any) => any;
3
3
  export function getHotkeyProps(def: any, id: any): any;
4
- export function withHotkeys(hotkeys: any, handlers: any): ({ children }?: {}) => import("react/jsx-runtime").JSX.Element;
4
+ export function withHotkeys(hotkeys: any, handlers: any): ({ children }?: {
5
+ children: any;
6
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -1,5 +0,0 @@
1
- export function filterLocalEntitiesToHasura(records: any, { where, order_by, limit, offset, isInfinite }?: {}): {
2
- entities: any[];
3
- entitiesAcrossPages: any[];
4
- entityCount: number;
5
- };
@@ -1,2 +0,0 @@
1
- export function initializeHasuraWhereAndFilter(additionalFilter: any, where: {} | undefined, currentParams: any): void;
2
- export function addCustomColumnFilters(where: any, fields: any, currentParams: any): void;
@@ -1,26 +0,0 @@
1
- export function tableQueryParamsToHasuraClauses({ page, pageSize, searchTerm, filters, order, schema, additionalFilter }: {
2
- page: any;
3
- pageSize: any;
4
- searchTerm: any;
5
- filters: any;
6
- order: any;
7
- schema: any;
8
- additionalFilter: any;
9
- }): {
10
- where: {};
11
- order_by: {};
12
- limit: any;
13
- offset: number;
14
- };
15
- /**
16
- * Takes a schema and returns an object with the fields mapped by their camelCased display name.
17
- * If the displayName is not set or is a jsx element, the path is used instead.
18
- * The same conversion must be done when using the result of this method
19
- */
20
- export function getFieldsMappedByCCDisplayName(schema: any): any;
21
- /**
22
- *
23
- * @param {object} field
24
- * @returns the camelCase display name of the field, to be used for filters, sorting, etc
25
- */
26
- export function getCCDisplayName(field: object): string;
@@ -1,236 +0,0 @@
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 (isEmpty(filter[key])) {
60
- continue;
61
- }
62
- if (!every(filter[key], subFilter => applyFilter(record, subFilter))) {
63
- return false;
64
- }
65
- } else if (key === "_or") {
66
- if (isEmpty(filter[key])) {
67
- continue;
68
- }
69
- if (!some(filter[key], subFilter => applyFilter(record, subFilter))) {
70
- return false;
71
- }
72
- } else if (key === "_not") {
73
- if (applyFilter(record, filter[key])) {
74
- return false;
75
- }
76
- } else {
77
- const value = record[key];
78
- const conditions = filter[key];
79
-
80
- // Handle nested object properties
81
- if (
82
- isObject(value) &&
83
- isObject(conditions) &&
84
- !hasOperator(conditions)
85
- ) {
86
- return applyFilter(value, conditions);
87
- }
88
-
89
- for (const operator in conditions) {
90
- const conditionValue = conditions[operator];
91
-
92
- // Handle range conditions (_gt/_lt or _gte/_lte combinations)
93
- if (operator === "_gt" && conditions._lt) {
94
- if (!(value > conditionValue && value < conditions._lt))
95
- return false;
96
- continue;
97
- }
98
- if (operator === "_gte" && conditions._lte) {
99
- if (!(value >= conditionValue && value <= conditions._lte))
100
- return false;
101
- continue;
102
- }
103
-
104
- switch (operator) {
105
- case "_eq":
106
- if (!isEqual(value, conditionValue)) return false;
107
- break;
108
- case "_neq":
109
- if (isEqual(value, conditionValue)) return false;
110
- break;
111
- case "_gt":
112
- if (!(value > conditionValue)) return false;
113
- break;
114
- case "_gte":
115
- if (!(value >= conditionValue)) return false;
116
- break;
117
- case "_lt":
118
- if (!(value < conditionValue)) return false;
119
- break;
120
- case "_lte":
121
- if (!(value <= conditionValue)) return false;
122
- break;
123
- case "_like":
124
- if (
125
- !isString(value) ||
126
- !new RegExp(conditionValue.replace(/%/g, ".*")).test(value)
127
- )
128
- return false;
129
- break;
130
- case "_ilike":
131
- if (
132
- !isString(value) ||
133
- !new RegExp(conditionValue.replace(/%/g, ".*"), "i").test(value)
134
- )
135
- return false;
136
- break;
137
- case "_nlike":
138
- if (
139
- !isString(value) ||
140
- new RegExp(conditionValue.replace(/%/g, ".*")).test(value)
141
- )
142
- return false;
143
- break;
144
- case "_nilike":
145
- if (
146
- !isString(value) ||
147
- new RegExp(conditionValue.replace(/%/g, ".*"), "i").test(value)
148
- )
149
- return false;
150
- break;
151
- case "_starts_with":
152
- if (!isString(value) || !value.startsWith(conditionValue))
153
- return false;
154
- break;
155
- case "_ends_with":
156
- if (!isString(value) || !value.endsWith(conditionValue))
157
- return false;
158
- break;
159
- case "_is_null":
160
- if (
161
- (conditionValue && !isNull(value)) ||
162
- (!conditionValue && isNull(value))
163
- )
164
- return false;
165
- break;
166
- case "_contains":
167
- if (
168
- !isArray(value) ||
169
- !every(conditionValue, item => includes(value, item))
170
- )
171
- return false;
172
- break;
173
- case "_contained_in":
174
- if (
175
- !isArray(value) ||
176
- !every(value, item => includes(conditionValue, item))
177
- )
178
- return false;
179
- break;
180
- case "_has_key":
181
- if (!isObject(value) || !has(value, conditionValue)) return false;
182
- break;
183
- case "_has_keys_any":
184
- if (
185
- !isObject(value) ||
186
- !some(conditionValue, item => has(value, item))
187
- )
188
- return false;
189
- break;
190
- case "_has_keys_all":
191
- if (
192
- !isObject(value) ||
193
- !every(conditionValue, item => has(value, item))
194
- )
195
- return false;
196
- break;
197
- case "_similar":
198
- if (
199
- !isString(value) ||
200
- !new RegExp(conditionValue.replace(/%/g, ".*")).test(value)
201
- )
202
- return false;
203
- break;
204
- default:
205
- if (operator.startsWith("_")) {
206
- console.warn(`Unsupported operator: ${operator}`);
207
- return false;
208
- } else {
209
- console.warn(`Unsupported operator: ${operator}`);
210
- return false;
211
- }
212
- }
213
- }
214
- }
215
- }
216
-
217
- return true;
218
- }
219
-
220
- // Helper to check if an object contains any Hasura operators
221
- function hasOperator(obj) {
222
- return Object.keys(obj).some(key => key.startsWith("_"));
223
- }
224
-
225
- return records.filter(record => applyFilter(record, where));
226
- }
227
-
228
- function applyOrderBy(records, order_by) {
229
- const keys = Object.keys(order_by);
230
- if (keys.length > 0) {
231
- const field = keys[0];
232
- const direction = order_by[field] === "asc" ? "asc" : "desc";
233
- return orderBy(records, [field], [direction]);
234
- }
235
- return records;
236
- }