@vuu-ui/vuu-data-react 2.1.19-beta.2 → 2.1.19-beta.4

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 (119) hide show
  1. package/cjs/data-editing/EditForm.css.js +6 -0
  2. package/cjs/data-editing/EditForm.css.js.map +1 -0
  3. package/cjs/data-editing/EditForm.js +90 -0
  4. package/cjs/data-editing/EditForm.js.map +1 -0
  5. package/cjs/data-editing/UnsavedChangesReport.css.js +6 -0
  6. package/cjs/data-editing/UnsavedChangesReport.css.js.map +1 -0
  7. package/cjs/data-editing/UnsavedChangesReport.js +29 -0
  8. package/cjs/data-editing/UnsavedChangesReport.js.map +1 -0
  9. package/cjs/data-editing/edit-rule-validation-checker.js +41 -0
  10. package/cjs/data-editing/edit-rule-validation-checker.js.map +1 -0
  11. package/cjs/data-editing/edit-validation-rules.js +52 -0
  12. package/cjs/data-editing/edit-validation-rules.js.map +1 -0
  13. package/cjs/data-editing/form-edit-state.js +26 -0
  14. package/cjs/data-editing/form-edit-state.js.map +1 -0
  15. package/cjs/data-editing/get-data-item-edit-control.js +105 -0
  16. package/cjs/data-editing/get-data-item-edit-control.js.map +1 -0
  17. package/cjs/data-editing/useEditForm.js +258 -0
  18. package/cjs/data-editing/useEditForm.js.map +1 -0
  19. package/cjs/datasource-provider/VuuDataSourceProvider.js +34 -0
  20. package/cjs/datasource-provider/VuuDataSourceProvider.js.map +1 -0
  21. package/cjs/datasource-provider/useAutoLoginToVuuServer.js +52 -0
  22. package/cjs/datasource-provider/useAutoLoginToVuuServer.js.map +1 -0
  23. package/cjs/hooks/useLookupValues.js +100 -0
  24. package/cjs/hooks/useLookupValues.js.map +1 -0
  25. package/cjs/hooks/useSessionDataSource.js +58 -0
  26. package/cjs/hooks/useSessionDataSource.js.map +1 -0
  27. package/cjs/hooks/useTypeaheadSuggestions.js +57 -0
  28. package/cjs/hooks/useTypeaheadSuggestions.js.map +1 -0
  29. package/cjs/hooks/useVisualLinks.js +84 -0
  30. package/cjs/hooks/useVisualLinks.js.map +1 -0
  31. package/cjs/hooks/useVuuMenuActions.js +352 -0
  32. package/cjs/hooks/useVuuMenuActions.js.map +1 -0
  33. package/cjs/hooks/useVuuTables.js +38 -0
  34. package/cjs/hooks/useVuuTables.js.map +1 -0
  35. package/cjs/index.js +42 -0
  36. package/cjs/index.js.map +1 -0
  37. package/cjs/lost-connection-indicator/LostConnectionIndicator.css.js +6 -0
  38. package/cjs/lost-connection-indicator/LostConnectionIndicator.css.js.map +1 -0
  39. package/cjs/lost-connection-indicator/LostConnectionIndicator.js +24 -0
  40. package/cjs/lost-connection-indicator/LostConnectionIndicator.js.map +1 -0
  41. package/cjs/lost-connection-indicator/useLostConnection.js +34 -0
  42. package/cjs/lost-connection-indicator/useLostConnection.js.map +1 -0
  43. package/cjs/session-editing-form/SessionEditingForm.css.js +6 -0
  44. package/cjs/session-editing-form/SessionEditingForm.css.js.map +1 -0
  45. package/cjs/session-editing-form/SessionEditingForm.js +270 -0
  46. package/cjs/session-editing-form/SessionEditingForm.js.map +1 -0
  47. package/esm/data-editing/EditForm.css.js +4 -0
  48. package/esm/data-editing/EditForm.css.js.map +1 -0
  49. package/esm/data-editing/EditForm.js +88 -0
  50. package/esm/data-editing/EditForm.js.map +1 -0
  51. package/esm/data-editing/UnsavedChangesReport.css.js +4 -0
  52. package/esm/data-editing/UnsavedChangesReport.css.js.map +1 -0
  53. package/esm/data-editing/UnsavedChangesReport.js +27 -0
  54. package/esm/data-editing/UnsavedChangesReport.js.map +1 -0
  55. package/esm/data-editing/edit-rule-validation-checker.js +37 -0
  56. package/esm/data-editing/edit-rule-validation-checker.js.map +1 -0
  57. package/esm/data-editing/edit-validation-rules.js +50 -0
  58. package/esm/data-editing/edit-validation-rules.js.map +1 -0
  59. package/esm/data-editing/form-edit-state.js +23 -0
  60. package/esm/data-editing/form-edit-state.js.map +1 -0
  61. package/esm/data-editing/get-data-item-edit-control.js +103 -0
  62. package/esm/data-editing/get-data-item-edit-control.js.map +1 -0
  63. package/esm/data-editing/useEditForm.js +256 -0
  64. package/esm/data-editing/useEditForm.js.map +1 -0
  65. package/esm/datasource-provider/VuuDataSourceProvider.js +32 -0
  66. package/esm/datasource-provider/VuuDataSourceProvider.js.map +1 -0
  67. package/esm/datasource-provider/useAutoLoginToVuuServer.js +50 -0
  68. package/esm/datasource-provider/useAutoLoginToVuuServer.js.map +1 -0
  69. package/esm/hooks/useLookupValues.js +98 -0
  70. package/esm/hooks/useLookupValues.js.map +1 -0
  71. package/esm/hooks/useSessionDataSource.js +56 -0
  72. package/esm/hooks/useSessionDataSource.js.map +1 -0
  73. package/esm/hooks/useTypeaheadSuggestions.js +54 -0
  74. package/esm/hooks/useTypeaheadSuggestions.js.map +1 -0
  75. package/esm/hooks/useVisualLinks.js +82 -0
  76. package/esm/hooks/useVisualLinks.js.map +1 -0
  77. package/esm/hooks/useVuuMenuActions.js +348 -0
  78. package/esm/hooks/useVuuMenuActions.js.map +1 -0
  79. package/esm/hooks/useVuuTables.js +36 -0
  80. package/esm/hooks/useVuuTables.js.map +1 -0
  81. package/esm/index.js +16 -0
  82. package/esm/index.js.map +1 -0
  83. package/esm/lost-connection-indicator/LostConnectionIndicator.css.js +4 -0
  84. package/esm/lost-connection-indicator/LostConnectionIndicator.css.js.map +1 -0
  85. package/esm/lost-connection-indicator/LostConnectionIndicator.js +22 -0
  86. package/esm/lost-connection-indicator/LostConnectionIndicator.js.map +1 -0
  87. package/esm/lost-connection-indicator/useLostConnection.js +32 -0
  88. package/esm/lost-connection-indicator/useLostConnection.js.map +1 -0
  89. package/esm/session-editing-form/SessionEditingForm.css.js +4 -0
  90. package/esm/session-editing-form/SessionEditingForm.css.js.map +1 -0
  91. package/esm/session-editing-form/SessionEditingForm.js +268 -0
  92. package/esm/session-editing-form/SessionEditingForm.js.map +1 -0
  93. package/package.json +21 -18
  94. package/src/data-editing/EditForm.css.js +0 -53
  95. package/src/data-editing/EditForm.js +0 -82
  96. package/src/data-editing/UnsavedChangesReport.css.js +0 -27
  97. package/src/data-editing/UnsavedChangesReport.js +0 -41
  98. package/src/data-editing/edit-rule-validation-checker.js +0 -30
  99. package/src/data-editing/edit-validation-rules.js +0 -33
  100. package/src/data-editing/form-edit-state.js +0 -16
  101. package/src/data-editing/get-data-item-edit-control.js +0 -63
  102. package/src/data-editing/index.js +0 -6
  103. package/src/data-editing/useEditForm.js +0 -253
  104. package/src/datasource-provider/VuuDataSourceProvider.js +0 -20
  105. package/src/datasource-provider/index.js +0 -1
  106. package/src/datasource-provider/useAutoLoginToVuuServer.js +0 -42
  107. package/src/hooks/useLookupValues.js +0 -93
  108. package/src/hooks/useSessionDataSource.js +0 -37
  109. package/src/hooks/useTypeaheadSuggestions.js +0 -50
  110. package/src/hooks/useVisualLinks.js +0 -87
  111. package/src/hooks/useVuuMenuActions.js +0 -269
  112. package/src/hooks/useVuuTables.js +0 -32
  113. package/src/index.js +0 -10
  114. package/src/lost-connection-indicator/LostConnectionIndicator.css.js +0 -29
  115. package/src/lost-connection-indicator/LostConnectionIndicator.js +0 -30
  116. package/src/lost-connection-indicator/useLostConnection.js +0 -28
  117. package/src/session-editing-form/SessionEditingForm.css.js +0 -47
  118. package/src/session-editing-form/SessionEditingForm.js +0 -236
  119. package/src/session-editing-form/index.js +0 -1
@@ -1,236 +0,0 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import { VuuDataSource } from "@vuu-ui/vuu-data-remote";
3
- import { Range, buildColumnMap, getTypedValue, queryClosest, shallowEquals } from "@vuu-ui/vuu-utils";
4
- import { Button, FormField, FormFieldHelperText, FormFieldLabel, Input, useIdMemo } from "@salt-ds/core";
5
- import { useComponentCssInjection } from "@salt-ds/styles";
6
- import { useWindow } from "@salt-ds/window";
7
- import clsx from "clsx";
8
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
9
- import SessionEditingForm from "./SessionEditingForm.css";
10
- const classBase = "vuuSessionEditingForm";
11
- const getField = (fields, name)=>{
12
- const field = fields.find((f)=>f.name === name);
13
- if (field) return field;
14
- throw Error(`SessionEditingForm, no field '${name}' found`);
15
- };
16
- const getFieldNameAndValue = ({ target })=>{
17
- const formField = queryClosest(target, ".saltFormField");
18
- if (formField) {
19
- const { dataset: { field } } = formField;
20
- if (void 0 === field) throw Error("SessionEditingForm, form field has no field data attribute");
21
- return [
22
- field,
23
- target.value
24
- ];
25
- }
26
- throw Error("Form control is not enclosed in FormField");
27
- };
28
- const Status = {
29
- uninitialised: 0,
30
- unchanged: 1,
31
- changed: 2,
32
- invalid: 3
33
- };
34
- const getDataSource = (dataSource, schema)=>{
35
- if (dataSource) return dataSource;
36
- if (schema) return new VuuDataSource({
37
- bufferSize: 0,
38
- table: schema.table,
39
- columns: schema.columns.map((col)=>col.name)
40
- });
41
- throw Error("SessionEditingForm: either a DataSource or a TableSchema must be provided");
42
- };
43
- const SessionEditingForm_SessionEditingForm = ({ className, config: { fields, key: keyField }, dataSource: dataSourceProp, id: idProp, onClose, schema, ...htmlAttributes })=>{
44
- const targetWindow = useWindow();
45
- useComponentCssInjection({
46
- testId: "vuu-session-editing-form",
47
- css: SessionEditingForm,
48
- window: targetWindow
49
- });
50
- const [fieldStatusValues, setFieldStatusValues] = useState({});
51
- const [values, setValues] = useState();
52
- const [errorMessage, setErrorMessage] = useState("");
53
- const formContentRef = useRef(null);
54
- const initialDataRef = useRef(void 0);
55
- const dataStatusRef = useRef(Status.uninitialised);
56
- const dataSource = useMemo(()=>{
57
- const ds = getDataSource(dataSourceProp, schema);
58
- const { columns } = ds;
59
- const columnMap = buildColumnMap(ds.columns);
60
- const applyServerData = (data)=>{
61
- if (columnMap) {
62
- const values = {};
63
- for (const column of columns)values[column] = data[columnMap[column]];
64
- if (dataStatusRef.current === Status.uninitialised) {
65
- dataStatusRef.current = Status.unchanged;
66
- initialDataRef.current = values;
67
- }
68
- setValues(values);
69
- }
70
- };
71
- ds.subscribe({
72
- range: Range(0, 5)
73
- }, (message)=>{
74
- if ("viewport-update" === message.type && message.rows) if (dataStatusRef.current === Status.uninitialised) applyServerData(message.rows[0]);
75
- else console.log("what do we do with server updates");
76
- });
77
- return ds;
78
- }, [
79
- dataSourceProp,
80
- schema
81
- ]);
82
- const id = useIdMemo(idProp);
83
- const handleChange = useCallback((evt)=>{
84
- const [field, value] = getFieldNameAndValue(evt);
85
- const { type } = getField(fields, field);
86
- const typedValue = getTypedValue(value, type);
87
- setValues((values = {})=>{
88
- const newValues = {
89
- ...values,
90
- [field]: typedValue
91
- };
92
- const notUpdated = shallowEquals(newValues, initialDataRef.current);
93
- dataStatusRef.current = notUpdated ? Status.unchanged : void 0 !== typedValue ? Status.changed : Status.invalid;
94
- return newValues;
95
- });
96
- }, [
97
- fields
98
- ]);
99
- const handleBlur = useCallback(async (evt)=>{
100
- const [column, value] = getFieldNameAndValue(evt);
101
- const key = values?.[keyField];
102
- const { type } = getField(fields, column);
103
- const data = getTypedValue(value, type, true);
104
- if ("string" == typeof key) {
105
- const response = await dataSource.rpcRequest?.({
106
- params: {
107
- key,
108
- column,
109
- data
110
- },
111
- rpcName: "editCell",
112
- type: "RPC_REQUEST"
113
- });
114
- if (response?.type === "SUCCESS_RESULT") setFieldStatusValues((map)=>({
115
- ...map,
116
- [column]: void 0
117
- }));
118
- else if (response?.type === "ERROR_RESULT") {
119
- console.log(`edit rejected ${response.errorMessage}`);
120
- setFieldStatusValues((map)=>({
121
- ...map,
122
- [column]: response.errorMessage
123
- }));
124
- }
125
- }
126
- }, [
127
- dataSource,
128
- fields,
129
- keyField,
130
- values
131
- ]);
132
- const handleSubmit = useCallback(async ()=>{
133
- const response = await dataSource.rpcRequest?.({
134
- params: {
135
- comment: ""
136
- },
137
- rpcName: "submitForm",
138
- type: "RPC_REQUEST"
139
- });
140
- if (response?.type === "SUCCESS_RESULT") onClose?.();
141
- else if (response?.type === "ERROR_RESULT") setErrorMessage(response.errorMessage);
142
- }, [
143
- dataSource,
144
- onClose
145
- ]);
146
- const handleKeyDown = useCallback((evt)=>{
147
- if ("Enter" === evt.key && dataStatusRef.current === Status.changed) handleSubmit();
148
- }, [
149
- handleSubmit
150
- ]);
151
- const handleCancel = useCallback(()=>{
152
- onClose?.();
153
- }, [
154
- onClose
155
- ]);
156
- const getFormControl = (field)=>{
157
- const value = String(values?.[field.name] ?? "");
158
- if (field.readonly || field.name === keyField) return /*#__PURE__*/ jsx("div", {
159
- className: `${classBase}-fieldValue vuuReadOnly`,
160
- children: value
161
- });
162
- return /*#__PURE__*/ jsx(Input, {
163
- className: `${classBase}-fieldValue`,
164
- onBlur: handleBlur,
165
- onChange: handleChange,
166
- value: value,
167
- id: `${id}-input-${field.name}`
168
- });
169
- };
170
- useEffect(()=>{
171
- if (formContentRef.current) {
172
- const firstInput = formContentRef.current.querySelector("input");
173
- if (firstInput) setTimeout(()=>{
174
- firstInput.focus();
175
- firstInput.select();
176
- }, 100);
177
- }
178
- }, []);
179
- useEffect(()=>()=>{
180
- if (dataSource) dataSource.unsubscribe();
181
- }, [
182
- dataSource
183
- ]);
184
- const isDirty = dataStatusRef.current === Status.changed;
185
- return /*#__PURE__*/ jsxs("div", {
186
- ...htmlAttributes,
187
- className: clsx(classBase, className),
188
- children: [
189
- errorMessage ? /*#__PURE__*/ jsx("div", {
190
- className: `${classBase}-errorBanner`,
191
- "data-icon": "error",
192
- title: errorMessage,
193
- children: "Error, edit(s) not saved"
194
- }) : void 0,
195
- /*#__PURE__*/ jsx("div", {
196
- className: `${classBase}-content`,
197
- ref: formContentRef,
198
- onKeyDown: handleKeyDown,
199
- children: fields.map((field)=>/*#__PURE__*/ jsxs(FormField, {
200
- className: `${classBase}-field`,
201
- "data-field": field.name,
202
- necessity: field.required ? "required" : "optional",
203
- readOnly: field.readonly,
204
- validationStatus: fieldStatusValues[field.name] ? "error" : void 0,
205
- children: [
206
- /*#__PURE__*/ jsx(FormFieldLabel, {
207
- children: field?.label ?? field.description
208
- }),
209
- getFormControl(field),
210
- /*#__PURE__*/ jsx(FormFieldHelperText, {
211
- children: fieldStatusValues[field.name] ?? ""
212
- })
213
- ]
214
- }, field.name))
215
- }),
216
- /*#__PURE__*/ jsxs("div", {
217
- className: `${classBase}-buttonbar salt-theme salt-density-high`,
218
- children: [
219
- /*#__PURE__*/ jsx(Button, {
220
- type: "submit",
221
- variant: "cta",
222
- disabled: !isDirty,
223
- onClick: handleSubmit,
224
- children: "Submit"
225
- }),
226
- /*#__PURE__*/ jsx(Button, {
227
- variant: "secondary",
228
- onClick: handleCancel,
229
- children: "Cancel"
230
- })
231
- ]
232
- })
233
- ]
234
- });
235
- };
236
- export { SessionEditingForm_SessionEditingForm as SessionEditingForm };
@@ -1 +0,0 @@
1
- export * from "./SessionEditingForm.js";