swoop-common 2.0.4 → 2.0.6

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.
@@ -7,6 +7,7 @@ export type { BookingItem } from './index';
7
7
  export type { BookingItemResponse } from './index';
8
8
  export type { BookingResponse } from './index';
9
9
  export type { Bundle } from './index';
10
+ export type { BundleDay } from './index';
10
11
  export type { BundleItem } from './index';
11
12
  export type { ComponentDetails } from './index';
12
13
  export type { componentId } from './index';
@@ -9,6 +9,7 @@ export type { BookingItem } from './models/BookingItem';
9
9
  export type { BookingItemResponse } from './models/BookingItemResponse';
10
10
  export type { BookingResponse } from './models/BookingResponse';
11
11
  export type { Bundle } from './models/Bundle';
12
+ export type { BundleDay } from './models/BundleDay';
12
13
  export type { BundleItem } from './models/BundleItem';
13
14
  export type { ComponentDetails } from './models/ComponentDetails';
14
15
  export type { componentId } from './models/componentId';
@@ -1,8 +1,8 @@
1
- import type { BundleItem } from './BundleItem';
1
+ import type { BundleDay } from './BundleDay';
2
2
  export type Bundle = {
3
- startDay: number;
4
- endDay: number;
5
- items: Array<BundleItem>;
3
+ days: Array<BundleDay>;
6
4
  title: string;
7
- summary: string;
5
+ description: string;
6
+ start: string;
7
+ end: string;
8
8
  };
@@ -0,0 +1,8 @@
1
+ import type { BundleItem } from './BundleItem';
2
+ export type BundleDay = {
3
+ title?: string;
4
+ description?: string;
5
+ items?: Array<BundleItem>;
6
+ startDay?: string;
7
+ endDay?: string;
8
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -9,6 +9,7 @@ export type { BookingItem } from './models/BookingItem';
9
9
  export type { BookingItemResponse } from './models/BookingItemResponse';
10
10
  export type { BookingResponse } from './models/BookingResponse';
11
11
  export type { Bundle } from './models/Bundle';
12
+ export type { BundleDay } from './models/BundleDay';
12
13
  export type { BundleItem } from './models/BundleItem';
13
14
  export type { ComponentDetails } from './models/ComponentDetails';
14
15
  export type { componentId } from './models/componentId';
@@ -1,8 +1,8 @@
1
- import type { BundleItem } from './BundleItem';
1
+ import type { BundleDay } from './BundleDay';
2
2
  export type Bundle = {
3
- startDay: number;
4
- endDay: number;
5
- items: Array<BundleItem>;
3
+ days: Array<BundleDay>;
6
4
  title: string;
7
- summary: string;
5
+ description: string;
6
+ start: string;
7
+ end: string;
8
8
  };
@@ -0,0 +1,8 @@
1
+ import type { BundleItem } from './BundleItem';
2
+ export type BundleDay = {
3
+ title?: string;
4
+ description?: string;
5
+ items?: Array<BundleItem>;
6
+ startDay?: string;
7
+ endDay?: string;
8
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -6,6 +6,7 @@ import "../../renderers/Example";
6
6
  import "../../renderers/Image/ImageForm";
7
7
  import "../../renderers/Image/ImagePresentation";
8
8
  import "../../renderers/StagedText";
9
+ import "../../renderers/Subset";
9
10
  import "../../renderers/TemplatePicker";
10
11
  import "../../renderers/textfield/MultilineForm";
11
12
  import "../../renderers/textfield/MultilinePresentation";
@@ -8,6 +8,7 @@ import "../../renderers/Example";
8
8
  import "../../renderers/Image/ImageForm";
9
9
  import "../../renderers/Image/ImagePresentation";
10
10
  import "../../renderers/StagedText";
11
+ import "../../renderers/Subset";
11
12
  import "../../renderers/TemplatePicker";
12
13
  import "../../renderers/textfield/MultilineForm";
13
14
  import "../../renderers/textfield/MultilinePresentation";
@@ -0,0 +1,20 @@
1
+ import { DTOComponentRead } from '../../api/generated/core/exports';
2
+ export declare const fetchComponents: () => Promise<{
3
+ data: {
4
+ revisions: DTOComponentRead[];
5
+ id: string;
6
+ templateId: string;
7
+ revisionGroupId: string;
8
+ revision: number;
9
+ metadata: import("../../api/generated/core").Metadata;
10
+ name: string;
11
+ componentFields: Array<import("../../api/generated/core").Field>;
12
+ partners: Array<string>;
13
+ bundle: Array<import("../../api/generated/core").Bundle>;
14
+ startDate?: string | null;
15
+ endDate?: string | null;
16
+ duration?: number | null;
17
+ details: import("../../api/generated/core").ComponentDetails;
18
+ state?: string | null;
19
+ }[];
20
+ }>;
@@ -0,0 +1,67 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import React, { useEffect, useMemo, useState } from 'react';
11
+ import { Paper, Typography, Box, TextField, Autocomplete } from '@mui/material';
12
+ import { useLocalErrors } from '../hooks/errors';
13
+ import { ComponentPool } from '../registry/types';
14
+ import { registerComponent } from '../registry/components';
15
+ import { CoreService } from '../../api/generated/core';
16
+ const FormComponentPicker = ({ components, selectedComponent, onChange, set, getError, label, enabled }) => {
17
+ const selected = components.find(c => c.id === selectedComponent) || null;
18
+ return (React.createElement(Paper, { component: "form", sx: { display: 'flex', flexDirection: 'column', gap: 1, p: 2, mb: 1 }, noValidate: true, autoComplete: "off" },
19
+ React.createElement(Typography, { variant: 'h6' }, label),
20
+ React.createElement(Autocomplete, { options: components, getOptionLabel: (option) => option.name, getOptionKey: o => o.id, value: selected, onChange: (_, newValue) => onChange(newValue ? newValue.id : null), renderInput: (params) => (React.createElement(TextField, Object.assign({}, params, { variant: "outlined", placeholder: "Search and select a component", disabled: !enabled }))), renderOption: (props, option) => (React.createElement("li", Object.assign({}, props),
21
+ React.createElement(Box, null,
22
+ React.createElement(Typography, { variant: "body1" }, option.name),
23
+ React.createElement(Typography, { variant: "caption", color: "text.secondary" },
24
+ "Version: v",
25
+ option.revision)))), isOptionEqualToValue: (option, value) => option.id === value.id })));
26
+ };
27
+ const FormRendererComponentPicker = ({ data, handleChange, path, label, enabled, schema }) => {
28
+ const [components, setComponents] = useState([]);
29
+ const getError = useLocalErrors(path);
30
+ const set = useMemo(() =>
31
+ // @ts-ignore
32
+ schema['x-set'] || [], [schema]);
33
+ useEffect(() => {
34
+ const load = () => __awaiter(void 0, void 0, void 0, function* () {
35
+ try {
36
+ const fetched = yield fetchComponents();
37
+ let filtered = fetched.data;
38
+ if (set.length > 0) {
39
+ filtered = filtered.filter(c => set.includes(c.templateId));
40
+ }
41
+ setComponents(filtered);
42
+ }
43
+ catch (err) {
44
+ console.error('Error loading components:', err);
45
+ }
46
+ });
47
+ load();
48
+ }, [set]);
49
+ return (React.createElement(FormComponentPicker, { components: components, selectedComponent: data || null, onChange: (id) => handleChange(path, id), set: set, getError: getError, label: label, enabled: enabled }));
50
+ };
51
+ registerComponent("TEMP DONT USE", FormRendererComponentPicker, ComponentPool.FORM);
52
+ export const fetchComponents = () => __awaiter(void 0, void 0, void 0, function* () {
53
+ const componentsByGroup = new Map();
54
+ const data = yield (new CoreService).componentList(1, 1000);
55
+ (data.data || []).forEach((component) => {
56
+ const groupId = component.revisionGroupId;
57
+ if (!componentsByGroup.has(groupId)) {
58
+ componentsByGroup.set(groupId, []);
59
+ }
60
+ componentsByGroup.get(groupId).push(component);
61
+ });
62
+ const latestComponents = Array.from(componentsByGroup.values()).map((components) => {
63
+ const sortedComponents = components.sort((a, b) => b.revision - a.revision);
64
+ return Object.assign(Object.assign({}, sortedComponents[0]), { revisions: sortedComponents });
65
+ });
66
+ return { data: latestComponents };
67
+ });
@@ -9,7 +9,7 @@ export const generateJsonSchema = (formSchema, stage, onlyEditableFields) => {
9
9
  properties: {},
10
10
  required: [],
11
11
  };
12
- formSchema.forEach((s) => {
12
+ formSchema.forEach(s => {
13
13
  if (stage < s.existsFrom)
14
14
  return;
15
15
  if (onlyEditableFields && !s.editableIn.includes(stage))
@@ -32,17 +32,12 @@ const defaultConverter = (field, stage, omitTitle, isChild) => {
32
32
  field.fieldType = (_a = field.fieldType) !== null && _a !== void 0 ? _a : "string";
33
33
  let schema = getType(field.fieldType);
34
34
  if (!schema)
35
- throw new Error("tried to generate schema from unknown type: " +
36
- field.fieldType +
37
- "\nFull object: " +
38
- JSON.stringify(field, null, 2));
35
+ throw new Error("tried to generate schema from unknown type: " + field.fieldType + "\nFull object: " + JSON.stringify(field, null, 2));
39
36
  const requiredFields = [];
40
37
  if (field.required)
41
38
  requiredFields.push(field.name);
42
39
  // Specific for array
43
- let arrayItems = field.fieldType === "array"
44
- ? defaultConverter((_b = field.arrayOptions) === null || _b === void 0 ? void 0 : _b.itemDefinition, stage, true, true)
45
- : undefined;
40
+ let arrayItems = field.fieldType === "array" ? defaultConverter((_b = field.arrayOptions) === null || _b === void 0 ? void 0 : _b.itemDefinition, stage, true, true) : undefined;
46
41
  // Obj childs
47
42
  const properties = {};
48
43
  for (const child of (_d = (_c = field.objectOptions) === null || _c === void 0 ? void 0 : _c.properties) !== null && _d !== void 0 ? _d : []) {
@@ -51,20 +46,16 @@ const defaultConverter = (field, stage, omitTitle, isChild) => {
51
46
  if (child.required)
52
47
  requiredFields.push(fieldId);
53
48
  }
54
- let enumOpts = field.fieldType === "enum" || "stagedEnum"
55
- ? (() => {
56
- var _a;
57
- let enumOptions = (((_a = field.enumOptions) === null || _a === void 0 ? void 0 : _a.enumValues) ||
58
- []);
59
- if (enumOptions.length === 0)
60
- enumOptions.push("");
61
- return enumOptions;
62
- })()
63
- : undefined;
49
+ // Enum fails if empty, fixes
50
+ let enumOpts = field.fieldType === "enum" ? (() => {
51
+ var _a;
52
+ let enumOptions = (((_a = field.enumOptions) === null || _a === void 0 ? void 0 : _a.enumValues) || []);
53
+ if (enumOptions.length === 0)
54
+ enumOptions.push("");
55
+ return enumOptions;
56
+ })() : undefined;
64
57
  // Component (probably should change this)
65
- let templates = field.fieldType === "componentPicker"
66
- ? { "x-templateIds": (_e = field.componentOptions) === null || _e === void 0 ? void 0 : _e.templateIds }
67
- : {};
58
+ let templates = field.fieldType === "componentPicker" ? { "x-templateIds": (_e = field.componentOptions) === null || _e === void 0 ? void 0 : _e.templateIds } : {};
68
59
  let title = omitTitle ? undefined : field.name;
69
- return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (!isChild && !field.editableIn.includes(stage) && { readOnly: true })), { title, type: schema.schema.type, "x-type": schema.schema["x-type"] }), templates), (schema.schema.type === "object" && { properties })), { required: requiredFields }), (enumOpts && { enum: enumOpts })), (arrayItems && { items: arrayItems })), (field.fieldType === "object" && { properties }));
60
+ return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, ((!isChild && !field.editableIn.includes(stage)) && { readOnly: true })), { title, type: schema.schema.type, "x-type": schema.schema["x-type"] }), templates), (schema.schema.type === "object" && { properties })), { required: requiredFields }), (enumOpts && { enum: enumOpts })), (arrayItems && { items: arrayItems })), (field.fieldType === "object" && { properties }));
70
61
  };
@@ -37,7 +37,17 @@ registerType("enum", "Dropdown", { type: "string" }, {
37
37
  title: "Dropdown Values",
38
38
  type: "array",
39
39
  items: { type: "string" },
40
- },
40
+ }
41
+ }
42
+ }, true);
43
+ registerType("array", "List", { type: "array" }, {
44
+ type: "object",
45
+ title: "List Options",
46
+ properties: {
47
+ minItems: { type: "integer", minimum: 0 },
48
+ maxItems: { type: "integer", minimum: 1 },
49
+ uniqueItems: { type: "boolean", default: false },
50
+ itemDefinition: { $ref: "#/$defs/arrayItemDefinition" },
41
51
  },
42
52
  }, true);
43
53
  registerType("stagedEnum", "Staged Dropdown", {
@@ -54,16 +64,6 @@ registerType("stagedEnum", "Staged Dropdown", {
54
64
  },
55
65
  },
56
66
  }, true);
57
- registerType("array", "List", { type: "array" }, {
58
- type: "object",
59
- title: "List Options",
60
- properties: {
61
- minItems: { type: "integer", minimum: 0 },
62
- maxItems: { type: "integer", minimum: 1 },
63
- uniqueItems: { type: "boolean", default: false },
64
- itemDefinition: { $ref: "#/$defs/arrayItemDefinition" },
65
- },
66
- }, true);
67
67
  registerType("object", "Group", { type: "object" }, {
68
68
  type: "object",
69
69
  title: "Group",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swoop-common",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "main": "dist/api/index.js",
5
5
  "types": "dist/api/index.d.ts",
6
6
  "exports": {