Skip to content

Commit

Permalink
feat: add building utilities for extra
Browse files Browse the repository at this point in the history
  • Loading branch information
spaenleh committed Mar 7, 2023
1 parent 36e18fc commit 0c1a7ee
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions src/utils/extra.ts
Original file line number Diff line number Diff line change
@@ -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<LocalFileItemExtra>,
Expand Down Expand Up @@ -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 {};
};

0 comments on commit 0c1a7ee

Please sign in to comment.