Skip to content

Commit

Permalink
Merge pull request #393 from intuitem/hotfix/create-evidence-in-globa…
Browse files Browse the repository at this point in the history
…l-applied-control

#392_Fix creation of objects when parent is in root folder
  • Loading branch information
ab-smith authored May 7, 2024
2 parents 8480447 + b2dc15f commit 701f2e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion frontend/src/lib/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const MONTH_LIST = [
'December'
];

const UUID_REGEX = '([0-9a-f]{8}\\-[0-9a-f]{4}\\-[0-9a-f]{4}\\-[0-9a-f]{4}\\-[0-9a-f]{12})';
export const UUID_REGEX = '([0-9a-f]{8}\\-[0-9a-f]{4}\\-[0-9a-f]{4}\\-[0-9a-f]{4}\\-[0-9a-f]{12})';
export const UUID_LIST_REGEX = new RegExp(`^${UUID_REGEX}(,${UUID_REGEX})*$`);

export const URN_REGEX =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BASE_API_URL } from '$lib/utils/constants';
import { BASE_API_URL, UUID_REGEX } from '$lib/utils/constants';
import { URL_MODEL_MAP, getModelInfo, type ModelMapEntry } from '$lib/utils/crud';
import { tableSourceMapper, type TableSource } from '@skeletonlabs/skeleton';

Expand Down Expand Up @@ -67,7 +67,16 @@ export const load: LayoutServerLoad = async ({ fetch, params }) => {
const deleteForm = await superValidate(zod(z.object({ id: z.string().uuid() })));
const createSchema = modelSchema(e.urlModel);
initialData[e.field] = data.id;
if (data.folder) initialData['folder'] = data.folder.id ?? data.folder;
if (data.folder) {
if (!new RegExp(UUID_REGEX).test(data.folder)) {
const objectEndpoint = `${endpoint}object/`;
const objectResponse = await fetch(objectEndpoint);
const objectData = await objectResponse.json();
initialData['folder'] = objectData.folder;
} else {
initialData['folder'] = data.folder.id ?? data.folder;
}
}
const createForm = await superValidate(initialData, zod(createSchema), { errors: false });

const foreignKeys: Record<string, any> = {};
Expand Down

0 comments on commit 701f2e7

Please sign in to comment.