swoop-common 1.0.35 → 1.0.37
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.
- package/dist/api/additions/templateHierarchyResolver.d.ts +2 -0
- package/dist/api/additions/templateHierarchyResolver.js +102 -0
- package/dist/api/generated/itinerary/services/ItineraryService.d.ts +8 -1
- package/dist/api/generated/itinerary/services/ItineraryService.js +22 -0
- package/dist/api/init.d.ts +5 -0
- package/dist/api/init.js +6 -5
- package/dist/rendering/components/StyledFormView.d.ts +4 -2
- package/dist/rendering/components/StyledFormView.js +3 -3
- package/dist/rendering/renderers/ComponentPicker.js +2 -2
- package/dist/rendering/renderers/TemplatePicker.js +2 -2
- package/package.json +1 -1
- package/dist/rendering/util/lib.d.ts +0 -1
- package/dist/rendering/util/lib.js +0 -6
- /package/dist/api/{generated/itinerary/bundler.d.ts → bundler.d.ts} +0 -0
- /package/dist/api/{generated/itinerary/bundler.js → bundler.js} +0 -0
|
@@ -0,0 +1,102 @@
|
|
|
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 { services } from "../init";
|
|
11
|
+
const buildTemplateTree = (templates) => {
|
|
12
|
+
const revisionGroups = new Map();
|
|
13
|
+
// Step 1: Group templates by revisionGroupId
|
|
14
|
+
for (const template of templates) {
|
|
15
|
+
const groupId = template.revisionGroupId;
|
|
16
|
+
if (!revisionGroups.has(groupId)) {
|
|
17
|
+
revisionGroups.set(groupId, {
|
|
18
|
+
revisionGroupId: groupId,
|
|
19
|
+
versions: [],
|
|
20
|
+
children: [],
|
|
21
|
+
parentRevisionGroupId: null,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
revisionGroups.get(groupId).versions.push(template);
|
|
25
|
+
}
|
|
26
|
+
// Step 2: Assign parentRevisionGroupId from the latest template in each group
|
|
27
|
+
for (const group of revisionGroups.values()) {
|
|
28
|
+
const latest = group.versions.reduce((a, b) => a.revision > b.revision ? a : b);
|
|
29
|
+
group.parentRevisionGroupId = latest.parentRevisionGroupId || null;
|
|
30
|
+
}
|
|
31
|
+
// Step 3: Build hierarchy
|
|
32
|
+
const roots = [];
|
|
33
|
+
for (const group of revisionGroups.values()) {
|
|
34
|
+
const parentId = group.parentRevisionGroupId;
|
|
35
|
+
if (parentId && revisionGroups.has(parentId)) {
|
|
36
|
+
revisionGroups.get(parentId).children.push(group);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
roots.push(group);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return roots;
|
|
43
|
+
};
|
|
44
|
+
export const resolveTemplateHierarchy = (templateId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
// First fetch all templates
|
|
46
|
+
const allTemplates = yield services.CoreService.templateList(1);
|
|
47
|
+
console.log(JSON.stringify(allTemplates, null, 2));
|
|
48
|
+
// Find the initial template
|
|
49
|
+
const initialTemplate = allTemplates.data.find((t) => t.id === templateId);
|
|
50
|
+
if (!initialTemplate) {
|
|
51
|
+
throw new Error(`Template with ID ${templateId} not found`);
|
|
52
|
+
}
|
|
53
|
+
// Build the complete template tree
|
|
54
|
+
const templateTree = buildTemplateTree(allTemplates.data);
|
|
55
|
+
// Find the group containing our template
|
|
56
|
+
const findGroup = (groups) => {
|
|
57
|
+
for (const group of groups) {
|
|
58
|
+
if (group.versions.some((t) => t.id === templateId)) {
|
|
59
|
+
return group;
|
|
60
|
+
}
|
|
61
|
+
const found = findGroup(group.children);
|
|
62
|
+
if (found)
|
|
63
|
+
return found;
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
};
|
|
67
|
+
const targetGroup = findGroup(templateTree);
|
|
68
|
+
if (!targetGroup) {
|
|
69
|
+
throw new Error(`Could not find template group for template ${templateId}`);
|
|
70
|
+
}
|
|
71
|
+
// Build the hierarchy by following parent links
|
|
72
|
+
const hierarchy = [];
|
|
73
|
+
let currentGroup = targetGroup;
|
|
74
|
+
while (currentGroup) {
|
|
75
|
+
// Get the latest version of the current group
|
|
76
|
+
const latestTemplate = currentGroup.versions.reduce((a, b) => a.revision > b.revision ? a : b);
|
|
77
|
+
hierarchy.unshift(latestTemplate); // Add to beginning to get root -> leaf order
|
|
78
|
+
// Move up to parent group
|
|
79
|
+
if (currentGroup.parentRevisionGroupId) {
|
|
80
|
+
// Find the parent group in the tree
|
|
81
|
+
const findParentGroup = (groups) => {
|
|
82
|
+
for (const group of groups) {
|
|
83
|
+
if (group.revisionGroupId === currentGroup.parentRevisionGroupId) {
|
|
84
|
+
return group;
|
|
85
|
+
}
|
|
86
|
+
const found = findParentGroup(group.children);
|
|
87
|
+
if (found)
|
|
88
|
+
return found;
|
|
89
|
+
}
|
|
90
|
+
return undefined;
|
|
91
|
+
};
|
|
92
|
+
const parentGroup = findParentGroup(templateTree);
|
|
93
|
+
if (!parentGroup)
|
|
94
|
+
break;
|
|
95
|
+
currentGroup = parentGroup;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return hierarchy; // Already in root -> leaf order
|
|
102
|
+
});
|
|
@@ -4,7 +4,8 @@ import type { DTOItineraryUpdate } from '../models/DTOItineraryUpdate';
|
|
|
4
4
|
import type { DTORegionCreate } from '../models/DTORegionCreate';
|
|
5
5
|
import type { DTORegionRead } from '../models/DTORegionRead';
|
|
6
6
|
import type { Pagination } from '../models/Pagination';
|
|
7
|
-
import
|
|
7
|
+
import { CancelablePromise } from '../core/CancelablePromise';
|
|
8
|
+
import { DTOTemplateRead } from '../models/DTOTemplateRead';
|
|
8
9
|
export declare class ItineraryService {
|
|
9
10
|
/**
|
|
10
11
|
* List Itineraries
|
|
@@ -82,4 +83,10 @@ export declare class ItineraryService {
|
|
|
82
83
|
* @throws ApiError
|
|
83
84
|
*/
|
|
84
85
|
regionCreate(requestBody?: DTORegionCreate): CancelablePromise<DTORegionRead>;
|
|
86
|
+
/**
|
|
87
|
+
* Resolve template hierarchy
|
|
88
|
+
* @returns Array<DTOTemplateRead> OK
|
|
89
|
+
* @throws Error | ApiError
|
|
90
|
+
*/
|
|
91
|
+
templateResolveHierarchy(templateId: string): CancelablePromise<Array<DTOTemplateRead>>;
|
|
85
92
|
}
|
|
@@ -1,5 +1,16 @@
|
|
|
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 { CancelablePromise } from '../core/CancelablePromise';
|
|
1
11
|
import { OpenAPI } from '../core/OpenAPI';
|
|
2
12
|
import { request as __request } from '../core/request';
|
|
13
|
+
import { resolveTemplateHierarchy } from '../../../additions/templateHierarchyResolver';
|
|
3
14
|
export class ItineraryService {
|
|
4
15
|
/**
|
|
5
16
|
* List Itineraries
|
|
@@ -140,4 +151,15 @@ export class ItineraryService {
|
|
|
140
151
|
mediaType: 'application/json',
|
|
141
152
|
});
|
|
142
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Resolve template hierarchy
|
|
156
|
+
* @returns Array<DTOTemplateRead> OK
|
|
157
|
+
* @throws Error | ApiError
|
|
158
|
+
*/
|
|
159
|
+
templateResolveHierarchy(templateId) {
|
|
160
|
+
return new CancelablePromise((resolve, _reject, _onCancel) => __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
const out = yield resolveTemplateHierarchy(templateId);
|
|
162
|
+
resolve(out);
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
143
165
|
}
|
package/dist/api/init.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import * as Core from "./generated/core/index";
|
|
2
2
|
import * as Itinerary from "./generated/itinerary/index";
|
|
3
3
|
import * as Swoop from "./generated/swoop/index";
|
|
4
|
+
export declare const services: {
|
|
5
|
+
SwoopService: Swoop.SwoopService;
|
|
6
|
+
CoreService: Core.CoreService;
|
|
7
|
+
ItineraryService: Itinerary.ItineraryService;
|
|
8
|
+
};
|
|
4
9
|
export declare const init: (opts: {
|
|
5
10
|
itineraryServiceUrl: string;
|
|
6
11
|
coreServiceUrl: string;
|
package/dist/api/init.js
CHANGED
|
@@ -2,6 +2,11 @@ import * as Core from "./generated/core/index";
|
|
|
2
2
|
import * as Itinerary from "./generated/itinerary/index";
|
|
3
3
|
import * as Swoop from "./generated/swoop/index";
|
|
4
4
|
let initalised = false;
|
|
5
|
+
export const services = {
|
|
6
|
+
SwoopService: new Swoop.SwoopService(),
|
|
7
|
+
CoreService: new Core.CoreService(),
|
|
8
|
+
ItineraryService: new Itinerary.ItineraryService(),
|
|
9
|
+
};
|
|
5
10
|
export const init = (opts) => {
|
|
6
11
|
// Keeps it consitent
|
|
7
12
|
if (opts.coreServiceUrl.endsWith("/"))
|
|
@@ -15,11 +20,7 @@ export const init = (opts) => {
|
|
|
15
20
|
Itinerary.OpenAPI.BASE = opts.itineraryServiceUrl;
|
|
16
21
|
Swoop.OpenAPI.BASE = opts.swoopServiceForwardUrl;
|
|
17
22
|
initalised = true;
|
|
18
|
-
return
|
|
19
|
-
SwoopService: new Swoop.SwoopService(),
|
|
20
|
-
CoreService: new Core.CoreService(),
|
|
21
|
-
ItineraryService: new Itinerary.ItineraryService(),
|
|
22
|
-
};
|
|
23
|
+
return services;
|
|
23
24
|
};
|
|
24
25
|
export const initialisedCheck = () => {
|
|
25
26
|
if (initalised)
|
|
@@ -30,8 +30,10 @@ interface Props {
|
|
|
30
30
|
* The stage at which to render this template
|
|
31
31
|
*/
|
|
32
32
|
stage: Stage;
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Should readonly fields be hidden
|
|
35
|
+
*/
|
|
36
|
+
hideReadonlyFields?: boolean;
|
|
35
37
|
}
|
|
36
38
|
export declare const StyledFormView: React.FC<Props>;
|
|
37
39
|
export {};
|
|
@@ -5,9 +5,9 @@ import { getComponents } from '../registry/components';
|
|
|
5
5
|
import { generateJsonSchema } from '../schema/generate/jsonSchemaGenerate';
|
|
6
6
|
import { generateUiSchema } from '../schema/generate/uiSchemaGenerate';
|
|
7
7
|
import { initialisedCheck } from '../../api/init';
|
|
8
|
-
export const StyledFormView = ({ initialData, schema, onChange, stage, pool, readonly,
|
|
8
|
+
export const StyledFormView = ({ initialData, schema, onChange, stage, pool, readonly, hideReadonlyFields }) => {
|
|
9
9
|
useEffect(initialisedCheck, []);
|
|
10
|
-
const json =
|
|
11
|
-
const ui =
|
|
10
|
+
const json = generateJsonSchema(schema, stage, hideReadonlyFields);
|
|
11
|
+
const ui = generateUiSchema(schema, stage, hideReadonlyFields);
|
|
12
12
|
return (React.createElement(JsonForms, { onChange: onChange, data: initialData, schema: json, uischema: ui, renderers: [...materialRenderers, ...getComponents(pool)], readonly: readonly, cells: materialCells }));
|
|
13
13
|
};
|
|
@@ -12,7 +12,7 @@ import { Paper, Typography, Box, TextField, Autocomplete } from '@mui/material';
|
|
|
12
12
|
import { useLocalErrors } from '../hooks/errors';
|
|
13
13
|
import { ComponentPool } from '../registry/types';
|
|
14
14
|
import { registerComponent } from '../registry/components';
|
|
15
|
-
import {
|
|
15
|
+
import { services } from '../../api/init';
|
|
16
16
|
const FormComponentPicker = ({ components, selectedComponent, onChange, templateIds, getError, label, enabled }) => {
|
|
17
17
|
const selected = components.find(c => c.id === selectedComponent) || null;
|
|
18
18
|
return (React.createElement(Paper, { component: "form", sx: { display: 'flex', flexDirection: 'column', gap: 1, p: 2, mb: 1 }, noValidate: true, autoComplete: "off" },
|
|
@@ -51,7 +51,7 @@ const FormRendererComponentPicker = ({ data, handleChange, path, label, enabled,
|
|
|
51
51
|
registerComponent("component", FormRendererComponentPicker, ComponentPool.FORM);
|
|
52
52
|
export const fetchComponents = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
53
|
const componentsByGroup = new Map();
|
|
54
|
-
const data = yield CoreService.componentList(1, 1000);
|
|
54
|
+
const data = yield services.CoreService.componentList(1, 1000);
|
|
55
55
|
(data.data || []).forEach((component) => {
|
|
56
56
|
const groupId = component.revisionGroupId;
|
|
57
57
|
if (!componentsByGroup.has(groupId)) {
|
|
@@ -13,7 +13,7 @@ import { Paper, Typography, Box, TextField, Chip, Autocomplete } from '@mui/mate
|
|
|
13
13
|
import { useLocalErrors } from '../hooks/errors';
|
|
14
14
|
import { registerComponent } from '../registry/components';
|
|
15
15
|
import { ComponentPool } from '../registry/types';
|
|
16
|
-
import {
|
|
16
|
+
import { services } from '../../api/init';
|
|
17
17
|
const FormTemplatePicker = ({ templates, selectedTemplates, onChange, label, enabled }) => {
|
|
18
18
|
const selectedValues = templates.filter(t => selectedTemplates.includes(t.id));
|
|
19
19
|
return (React.createElement(Paper, { component: "form", sx: { display: 'flex', flexDirection: 'column', gap: 2, p: 2, mb: 1 }, noValidate: true, autoComplete: "off" },
|
|
@@ -33,7 +33,7 @@ const FormRendererTemplatePicker = ({ data, handleChange, path, label, enabled }
|
|
|
33
33
|
useEffect(() => {
|
|
34
34
|
const load = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
35
|
try {
|
|
36
|
-
const result = yield CoreService.templateList(1);
|
|
36
|
+
const result = yield services.CoreService.templateList(1);
|
|
37
37
|
setTemplates(result.data);
|
|
38
38
|
}
|
|
39
39
|
catch (err) {
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const SwoopService: import("../../api/generated/swoop").SwoopService, ItineraryService: import("../../api/generated/itinerary").ItineraryService, CoreService: import("../../api/generated/core").CoreService;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { init } from "../../api/init";
|
|
2
|
-
export const { SwoopService, ItineraryService, CoreService } = init({
|
|
3
|
-
coreServiceUrl: "https://data-api-dev.swoop-adventures.com/core-data-service/v1/",
|
|
4
|
-
itineraryServiceUrl: "https://data-api-dev.swoop-adventures.com/itinerary-builder-service/v1/",
|
|
5
|
-
swoopServiceForwardUrl: "https://data-api-dev.swoop-adventures.com/itinerary-builder-service/v1/forward"
|
|
6
|
-
});
|
|
File without changes
|
|
File without changes
|