From 0c1a7ee4a51e51a57c8225acb197c829d8d8c9bb Mon Sep 17 00:00:00 2001 From: spaenleh Date: Fri, 3 Mar 2023 09:25:26 +0100 Subject: [PATCH 1/3] feat: add building utilities for extra --- src/utils/extra.ts | 49 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/src/utils/extra.ts b/src/utils/extra.ts index 14766b50..d17bc306 100644 --- a/src/utils/extra.ts +++ b/src/utils/extra.ts @@ -1,18 +1,21 @@ -import { ItemType } from '../constants'; +import { ItemLoginSchema, ItemType } from '../constants'; import { DocumentItemExtra, + DocumentItemExtraProperties, EmbeddedLinkItemExtra, + EmbeddedLinkItemExtraProperties, FolderItemExtra, ShortcutItemExtra, } from '../interfaces'; import { AppItemExtra, EtherpadItemExtra, + FileItemProperties, H5PItemExtra, LocalFileItemExtra, S3FileItemExtra, } from '../services'; -import { ImmutableCast } from '@/frontend/types'; +import { ImmutableCast, ItemLogin } from '@/frontend/types'; export const getFileExtra = < U extends LocalFileItemExtra | ImmutableCast, @@ -67,3 +70,45 @@ export const getH5PExtra = < >( extra?: U, ): U[ItemType.H5P] | undefined => extra?.[ItemType.H5P]; + +export const buildDocumentExtra = ( + text: DocumentItemExtraProperties, +): DocumentItemExtra => ({ + [ItemType.DOCUMENT]: text, +}); + +export const buildFileExtra = ( + file: FileItemProperties, +): LocalFileItemExtra => ({ + [ItemType.LOCAL_FILE]: file, +}); + +export const buildS3FileExtra = ( + s3File: FileItemProperties, +): S3FileItemExtra => ({ + [ItemType.S3_FILE]: s3File, +}); + +export const buildEmbeddedLinkExtra = ( + embeddedLink: EmbeddedLinkItemExtraProperties, +): EmbeddedLinkItemExtra => ({ + [ItemType.LINK]: embeddedLink, +}); + +export const buildShortcutExtra = (target: string): ShortcutItemExtra => ({ + [ItemType.SHORTCUT]: { target }, +}); + +// todo: improve extra typing +export const buildItemLoginSchemaExtra = ( + schema?: ItemLoginSchema, +): { itemLogin?: ItemLogin } => { + if (schema) { + return { + itemLogin: { loginSchema: schema }, + }; + } + + // remove setting + return {}; +}; From 8a6408ddeb055b2cc48fd4c1de49a53e85eb7e3d Mon Sep 17 00:00:00 2001 From: Basile Spaenlehauer Date: Wed, 8 Mar 2023 13:54:13 +0100 Subject: [PATCH 2/3] fix: rename buildDocumentExtra argument Co-authored-by: Alexandre Chau --- src/utils/extra.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/extra.ts b/src/utils/extra.ts index d17bc306..8af898fa 100644 --- a/src/utils/extra.ts +++ b/src/utils/extra.ts @@ -72,9 +72,9 @@ export const getH5PExtra = < ): U[ItemType.H5P] | undefined => extra?.[ItemType.H5P]; export const buildDocumentExtra = ( - text: DocumentItemExtraProperties, + document: DocumentItemExtraProperties, ): DocumentItemExtra => ({ - [ItemType.DOCUMENT]: text, + [ItemType.DOCUMENT]: document, }); export const buildFileExtra = ( From 6c89027a2256516763756f52d378bc62c2567cd0 Mon Sep 17 00:00:00 2001 From: Basile Spaenlehauer Date: Wed, 8 Mar 2023 13:55:39 +0100 Subject: [PATCH 3/3] fix: simplify buildItemLoginSchemaExtra Co-authored-by: Alexandre Chau --- src/utils/extra.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/utils/extra.ts b/src/utils/extra.ts index 8af898fa..54e846f2 100644 --- a/src/utils/extra.ts +++ b/src/utils/extra.ts @@ -102,13 +102,4 @@ export const buildShortcutExtra = (target: string): ShortcutItemExtra => ({ // todo: improve extra typing export const buildItemLoginSchemaExtra = ( schema?: ItemLoginSchema, -): { itemLogin?: ItemLogin } => { - if (schema) { - return { - itemLogin: { loginSchema: schema }, - }; - } - - // remove setting - return {}; -}; +): { itemLogin?: ItemLogin } => schema ? ({ itemLogin: { loginSchema: schema }, }) : ({});