swoop-common 2.2.186 → 2.2.188

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.
@@ -2,6 +2,8 @@ import type { ComponentBatchRequest } from '../models/ComponentBatchRequest';
2
2
  import type { ComponentBatchResponse } from '../models/ComponentBatchResponse';
3
3
  import type { ComponentId } from '../models/ComponentId';
4
4
  import type { ComponentState } from '../models/ComponentState';
5
+ import type { CreditEntry } from '../models/CreditEntry';
6
+ import type { CreditEntryId } from '../models/CreditEntryId';
5
7
  import type { Destination } from '../models/Destination';
6
8
  import type { DTOComponentCreate } from '../models/DTOComponentCreate';
7
9
  import type { DTOComponentRead } from '../models/DTOComponentRead';
@@ -101,4 +103,22 @@ export declare class ComponentService {
101
103
  * @throws ApiError
102
104
  */
103
105
  static componentStateUpdate(componentId: ComponentId, state: ComponentState): CancelablePromise<DTOComponentRead>;
106
+ /**
107
+ * Add Credit Entry
108
+ * Add a credit, gesture, or compensation entry to a component and push a row to the Google Sheet
109
+ * @param componentId Id of a component
110
+ * @param requestBody
111
+ * @returns CreditEntry Credit entry created successfully
112
+ * @throws ApiError
113
+ */
114
+ static componentCreditEntryAdd(componentId: ComponentId, requestBody: CreditEntry): CancelablePromise<CreditEntry>;
115
+ /**
116
+ * Delete Credit Entry
117
+ * Soft-delete a credit entry and mark the corresponding Google Sheet row as DELETED
118
+ * @param componentId Id of a component
119
+ * @param entryId The ID of the credit entry to delete
120
+ * @returns void
121
+ * @throws ApiError
122
+ */
123
+ static componentCreditEntryDelete(componentId: ComponentId, entryId: CreditEntryId): CancelablePromise<void>;
104
124
  }
@@ -232,4 +232,52 @@ export class ComponentService {
232
232
  },
233
233
  });
234
234
  }
235
+ /**
236
+ * Add Credit Entry
237
+ * Add a credit, gesture, or compensation entry to a component and push a row to the Google Sheet
238
+ * @param componentId Id of a component
239
+ * @param requestBody
240
+ * @returns CreditEntry Credit entry created successfully
241
+ * @throws ApiError
242
+ */
243
+ static componentCreditEntryAdd(componentId, requestBody) {
244
+ return __request(OpenAPI, {
245
+ method: 'POST',
246
+ url: '/component/{componentId}/credit-entries',
247
+ path: {
248
+ 'componentId': componentId,
249
+ },
250
+ body: requestBody,
251
+ mediaType: 'application/json',
252
+ errors: {
253
+ 400: `If the payload is malformed or the component has no enquiry ID`,
254
+ 401: `Unauthorized - Missing or invalid Authorization header`,
255
+ 404: `If the component does not exist`,
256
+ 500: `Internal Server Error`,
257
+ },
258
+ });
259
+ }
260
+ /**
261
+ * Delete Credit Entry
262
+ * Soft-delete a credit entry and mark the corresponding Google Sheet row as DELETED
263
+ * @param componentId Id of a component
264
+ * @param entryId The ID of the credit entry to delete
265
+ * @returns void
266
+ * @throws ApiError
267
+ */
268
+ static componentCreditEntryDelete(componentId, entryId) {
269
+ return __request(OpenAPI, {
270
+ method: 'DELETE',
271
+ url: '/component/{componentId}/credit-entries/{entryId}',
272
+ path: {
273
+ 'componentId': componentId,
274
+ 'entryId': entryId,
275
+ },
276
+ errors: {
277
+ 401: `Unauthorized - Missing or invalid Authorization header`,
278
+ 404: `If the component or credit entry does not exist`,
279
+ 500: `Internal Server Error`,
280
+ },
281
+ });
282
+ }
235
283
  }
@@ -4,6 +4,8 @@ import type { ComponentBatchRequest } from '../models/ComponentBatchRequest';
4
4
  import type { ComponentBatchResponse } from '../models/ComponentBatchResponse';
5
5
  import type { ComponentId } from '../models/ComponentId';
6
6
  import type { ComponentState } from '../models/ComponentState';
7
+ import type { CreditEntry } from '../models/CreditEntry';
8
+ import type { CreditEntryId } from '../models/CreditEntryId';
7
9
  import type { Destination } from '../models/Destination';
8
10
  import type { DTOBranchRead } from '../models/DTOBranchRead';
9
11
  import type { DTOComponentCreate } from '../models/DTOComponentCreate';
@@ -356,6 +358,24 @@ export declare class CoreService {
356
358
  * @throws ApiError
357
359
  */
358
360
  componentStateUpdate(componentId: ComponentId, state: ComponentState): CancelablePromise<DTOComponentRead>;
361
+ /**
362
+ * Add Credit Entry
363
+ * Add a credit, gesture, or compensation entry to a component and push a row to the Google Sheet
364
+ * @param componentId Id of a component
365
+ * @param requestBody
366
+ * @returns CreditEntry Credit entry created successfully
367
+ * @throws ApiError
368
+ */
369
+ componentCreditEntryAdd(componentId: ComponentId, requestBody: CreditEntry): CancelablePromise<CreditEntry>;
370
+ /**
371
+ * Delete Credit Entry
372
+ * Soft-delete a credit entry and mark the corresponding Google Sheet row as DELETED
373
+ * @param componentId Id of a component
374
+ * @param entryId The ID of the credit entry to delete
375
+ * @returns void
376
+ * @throws ApiError
377
+ */
378
+ componentCreditEntryDelete(componentId: ComponentId, entryId: CreditEntryId): CancelablePromise<void>;
359
379
  /**
360
380
  * List Trip Comparisons by Enquiry ID
361
381
  * Retrieves all trip comparison items for a specific enquiryId.
@@ -810,6 +810,54 @@ export class CoreService {
810
810
  },
811
811
  });
812
812
  }
813
+ /**
814
+ * Add Credit Entry
815
+ * Add a credit, gesture, or compensation entry to a component and push a row to the Google Sheet
816
+ * @param componentId Id of a component
817
+ * @param requestBody
818
+ * @returns CreditEntry Credit entry created successfully
819
+ * @throws ApiError
820
+ */
821
+ componentCreditEntryAdd(componentId, requestBody) {
822
+ return __request(OpenAPI, {
823
+ method: 'POST',
824
+ url: '/component/{componentId}/credit-entries',
825
+ path: {
826
+ 'componentId': componentId,
827
+ },
828
+ body: requestBody,
829
+ mediaType: 'application/json',
830
+ errors: {
831
+ 400: `If the payload is malformed or the component has no enquiry ID`,
832
+ 401: `Unauthorized - Missing or invalid Authorization header`,
833
+ 404: `If the component does not exist`,
834
+ 500: `Internal Server Error`,
835
+ },
836
+ });
837
+ }
838
+ /**
839
+ * Delete Credit Entry
840
+ * Soft-delete a credit entry and mark the corresponding Google Sheet row as DELETED
841
+ * @param componentId Id of a component
842
+ * @param entryId The ID of the credit entry to delete
843
+ * @returns void
844
+ * @throws ApiError
845
+ */
846
+ componentCreditEntryDelete(componentId, entryId) {
847
+ return __request(OpenAPI, {
848
+ method: 'DELETE',
849
+ url: '/component/{componentId}/credit-entries/{entryId}',
850
+ path: {
851
+ 'componentId': componentId,
852
+ 'entryId': entryId,
853
+ },
854
+ errors: {
855
+ 401: `Unauthorized - Missing or invalid Authorization header`,
856
+ 404: `If the component or credit entry does not exist`,
857
+ 500: `Internal Server Error`,
858
+ },
859
+ });
860
+ }
813
861
  /**
814
862
  * List Trip Comparisons by Enquiry ID
815
863
  * Retrieves all trip comparison items for a specific enquiryId.
@@ -7,11 +7,44 @@ import { generateJsonSchema } from "../schema/generate/jsonSchemaGenerate";
7
7
  import { generateUiSchema } from "../schema/generate/uiSchemaGenerate";
8
8
  import { initialisedCheck } from "../../api/init";
9
9
  import ComponentContext from "../contexts/ComponentContext";
10
+ function normalizeFormData(data, schema) {
11
+ if (!schema || typeof schema !== "object" || !data || typeof data !== "object") {
12
+ return data;
13
+ }
14
+ const normalized = Array.isArray(data) ? [...data] : Object.assign({}, data);
15
+ if (schema.type === "object" && schema.properties) {
16
+ for (const [key, propSchema] of Object.entries(schema.properties)) {
17
+ const val = data[key];
18
+ if (val !== undefined && propSchema && typeof propSchema === "object") {
19
+ const type = propSchema.type;
20
+ if (type === "array") {
21
+ const itemsSchema = propSchema.items;
22
+ const valAsArray = Array.isArray(val)
23
+ ? val
24
+ : (val === null || val === undefined ? [] : [val]);
25
+ if (itemsSchema && typeof itemsSchema === "object") {
26
+ normalized[key] = valAsArray.map((item) => normalizeFormData(item, itemsSchema));
27
+ }
28
+ else {
29
+ normalized[key] = valAsArray;
30
+ }
31
+ }
32
+ else if (type === "object") {
33
+ normalized[key] = normalizeFormData(val, propSchema);
34
+ }
35
+ }
36
+ }
37
+ }
38
+ return normalized;
39
+ }
10
40
  export const StyledFormView = ({ initialData, schema, onChange, stage, pool, readonly, hideReadonlyFields, hintComponentId, overrideJsonSchema, overrideUiSchema, }) => {
11
41
  useEffect(initialisedCheck, []);
12
42
  const wrapperRef = React.useRef(null);
13
43
  const json = overrideJsonSchema || generateJsonSchema(schema, stage, hideReadonlyFields);
14
44
  const ui = overrideUiSchema || generateUiSchema(schema, stage, hideReadonlyFields);
45
+ const normalizedData = React.useMemo(() => {
46
+ return normalizeFormData(initialData, json);
47
+ }, [initialData, json]);
15
48
  useEffect(() => {
16
49
  const root = wrapperRef.current;
17
50
  if (!root)
@@ -105,7 +138,7 @@ export const StyledFormView = ({ initialData, schema, onChange, stage, pool, rea
105
138
  },
106
139
  } }),
107
140
  React.createElement("div", { className: "json-forms-wrapper", ref: wrapperRef },
108
- React.createElement(JsonForms, { onChange: onChange, data: initialData, schema: json, uischema: ui, renderers: [
141
+ React.createElement(JsonForms, { onChange: onChange, data: normalizedData, schema: json, uischema: ui, renderers: [
109
142
  ...materialRenderers,
110
143
  ...((pool && getComponents(pool)) || []),
111
144
  ], readonly: readonly, cells: materialCells }))));
@@ -6,6 +6,7 @@ import "../../renderers/Debug";
6
6
  import "../../renderers/Example";
7
7
  import "../../renderers/Image/ImageForm";
8
8
  import "../../renderers/Image/ImagePresentation";
9
+ import "../../renderers/MultiEnum";
9
10
  import "../../renderers/NestedObjectArray";
10
11
  import "../../renderers/StagedText";
11
12
  import "../../renderers/Subset";
@@ -8,6 +8,7 @@ import "../../renderers/Debug";
8
8
  import "../../renderers/Example";
9
9
  import "../../renderers/Image/ImageForm";
10
10
  import "../../renderers/Image/ImagePresentation";
11
+ import "../../renderers/MultiEnum";
11
12
  import "../../renderers/NestedObjectArray";
12
13
  import "../../renderers/StagedText";
13
14
  import "../../renderers/Subset";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ import { resolveSchema } from "@jsonforms/core";
2
+ import React from "react";
3
+ import { Autocomplete, TextField } from "@mui/material";
4
+ import { ComponentPool } from "../registry/types";
5
+ import { registerComponent } from "../registry/components";
6
+ const MultiEnumRenderer = ({ data, handleChange, path, schema, label, enabled, required }) => {
7
+ const resolvedItems = schema.items;
8
+ const options = Array.isArray(resolvedItems === null || resolvedItems === void 0 ? void 0 : resolvedItems.enum) ? resolvedItems.enum : [];
9
+ const value = Array.isArray(data) ? data : [];
10
+ const handleSelectChange = (_event, newValue) => {
11
+ handleChange(path, newValue);
12
+ };
13
+ return (React.createElement(Autocomplete, { multiple: true, options: options, value: value, onChange: handleSelectChange, disabled: !enabled, renderInput: (params) => (React.createElement(TextField, Object.assign({}, params, { label: label, required: required, variant: "outlined", fullWidth: true }))), fullWidth: true, sx: { mt: 1.5, mb: 1.5 } }));
14
+ };
15
+ const multiEnumTester = (uischema, schema) => {
16
+ const ui = uischema;
17
+ if (!ui || !ui.scope)
18
+ return -1;
19
+ const resolved = resolveSchema(schema, ui.scope, schema);
20
+ if (!resolved)
21
+ return -1;
22
+ if (resolved.type === "array" &&
23
+ resolved.multiSelect === true &&
24
+ resolved.items &&
25
+ typeof resolved.items === "object") {
26
+ const items = resolved.items;
27
+ if (items.type === "string" && Array.isArray(items.enum)) {
28
+ return 10;
29
+ }
30
+ }
31
+ return -1;
32
+ };
33
+ registerComponent("multi-enum-select", MultiEnumRenderer, ComponentPool.FORM, multiEnumTester);
@@ -67,7 +67,7 @@ const NestedObjectArrayRenderer = ({ data, handleChange, path, schema, label, en
67
67
  gap: 1
68
68
  } },
69
69
  React.createElement(Typography, { sx: { flex: 1 } }, getItemLabel(item, index)),
70
- enabled && (React.createElement(IconButton, { size: "small", color: "error", onClick: (e) => removeItem(e, index), "aria-label": "Remove item" },
70
+ enabled && (React.createElement(IconButton, { component: "span", size: "small", color: "error", onClick: (e) => removeItem(e, index), "aria-label": "Remove item" },
71
71
  React.createElement(DeleteIcon, { fontSize: "small" }))))),
72
72
  React.createElement(AccordionDetails, null,
73
73
  React.createElement(JsonForms, { schema: itemSchema, data: item, onChange: ({ data: newData }) => handleItemChange(index, newData), renderers: renderers, cells: materialCells, readonly: !enabled }))))),
@@ -29,7 +29,7 @@ export const generateJsonSchema = (formSchema, stage, onlyEditableFields) => {
29
29
  }
30
30
  };
31
31
  const defaultConverter = (field, stage, omitTitle, isChild) => {
32
- var _a, _b, _c, _d;
32
+ var _a, _b, _c, _d, _e;
33
33
  field.fieldType = (_a = field.fieldType) !== null && _a !== void 0 ? _a : "string";
34
34
  let schema = getType(field.fieldType);
35
35
  if (!schema)
@@ -94,5 +94,11 @@ const defaultConverter = (field, stage, omitTitle, isChild) => {
94
94
  : {};
95
95
  let title = omitTitle ? undefined : field.name;
96
96
  let isReadonly = !isChild && !field.editableIn.map(Number).includes(stage);
97
+ if (field.fieldType === "enum" && ((_e = field.enumOptions) === null || _e === void 0 ? void 0 : _e.multiSelect)) {
98
+ return Object.assign(Object.assign(Object.assign({}, (isReadonly && { readOnly: true })), { title, type: "array", "x-type": schema.schema["x-type"], items: {
99
+ type: "string",
100
+ enum: enumOpts || [],
101
+ }, uniqueItems: true }), directOptions);
102
+ }
97
103
  return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (isReadonly && { readOnly: true })), { title, type: schema.schema.type, "x-type": schema.schema["x-type"] }), templates), (schema.schema.type === "object" && { properties })), (field.fieldType === "object" && { required: requiredFields })), (enumOpts && { enum: enumOpts })), (radioOpts && { enum: radioOpts })), (stagedEnumOpts && { items: { enum: stagedEnumOpts, type: "string" } })), (arrayItems && { items: arrayItems })), (field.fieldType === "object" && { properties })), directOptions);
98
104
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swoop-common",
3
- "version": "2.2.186",
3
+ "version": "2.2.188",
4
4
  "main": "dist/api/index.js",
5
5
  "types": "dist/api/index.d.ts",
6
6
  "exports": {