add mocked stylesheet data + mocked db
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import { UmbEntityData } from './entity.data';
|
||||
import { createFileSystemTreeItem } from './utils';
|
||||
import {
|
||||
FileSystemTreeItemPresentationModel,
|
||||
PagedFileSystemTreeItemPresentationModel,
|
||||
} from '@umbraco-cms/backoffice/backend-api';
|
||||
|
||||
type StylesheetDBItem = FileSystemTreeItemPresentationModel & {
|
||||
content: string;
|
||||
};
|
||||
|
||||
export const data: Array<StylesheetDBItem> = [
|
||||
{
|
||||
path: 'Stylesheet File 1.css',
|
||||
isFolder: false,
|
||||
name: 'Stylesheet File 1.css',
|
||||
type: 'stylesheet',
|
||||
icon: 'icon-brackets',
|
||||
hasChildren: false,
|
||||
content: `Stylesheet content 1`,
|
||||
},
|
||||
{
|
||||
path: 'Stylesheet File 2.css',
|
||||
isFolder: false,
|
||||
name: 'Stylesheet File 2.css',
|
||||
type: 'stylesheet',
|
||||
icon: 'icon-brackets',
|
||||
hasChildren: false,
|
||||
content: `Stylesheet content 2`,
|
||||
},
|
||||
{
|
||||
path: 'Folder 1',
|
||||
isFolder: true,
|
||||
name: 'Folder 1',
|
||||
type: 'stylesheet',
|
||||
icon: 'icon-folder',
|
||||
hasChildren: false,
|
||||
content: `Stylesheet content 3`,
|
||||
},
|
||||
{
|
||||
path: 'Folder 1/Stylesheet File 3.css',
|
||||
isFolder: false,
|
||||
name: 'Stylesheet File 3.css',
|
||||
type: 'stylesheet',
|
||||
icon: 'icon-brackets',
|
||||
hasChildren: false,
|
||||
content: `Stylesheet content 3`,
|
||||
},
|
||||
];
|
||||
|
||||
// Temp mocked database
|
||||
// TODO: all properties are optional in the server schema. I don't think this is correct.
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
class UmbStylesheetData extends UmbEntityData<StylesheetDBItem> {
|
||||
constructor() {
|
||||
super(data);
|
||||
}
|
||||
|
||||
getTreeRoot(): PagedFileSystemTreeItemPresentationModel {
|
||||
const items = this.data.filter((item) => item.path === item.name);
|
||||
const treeItems = items.map((item) => createFileSystemTreeItem(item));
|
||||
const total = items.length;
|
||||
return { items: treeItems, total };
|
||||
}
|
||||
|
||||
getTreeItemChildren(parentPath: string): PagedFileSystemTreeItemPresentationModel {
|
||||
const items = this.data.filter((item) => item.path?.startsWith(parentPath));
|
||||
const treeItems = items.map((item) => createFileSystemTreeItem(item));
|
||||
const total = items.length;
|
||||
return { items: treeItems, total };
|
||||
}
|
||||
|
||||
getTreeItem(paths: Array<string>): Array<FileSystemTreeItemPresentationModel> {
|
||||
const items = this.data.filter((item) => paths.includes(item.path ?? ''));
|
||||
return items.map((item) => createFileSystemTreeItem(item));
|
||||
}
|
||||
}
|
||||
|
||||
export const umbStylesheetData = new UmbStylesheetData();
|
||||
@@ -6,6 +6,7 @@ import type {
|
||||
FolderTreeItemResponseModel,
|
||||
DocumentTypeResponseModel,
|
||||
DocumentResponseModel,
|
||||
FileSystemTreeItemPresentationModel,
|
||||
} from '@umbraco-cms/backoffice/backend-api';
|
||||
|
||||
export const createEntityTreeItem = (item: any): EntityTreeItemResponseModel => {
|
||||
@@ -38,7 +39,9 @@ export const createContentTreeItem = (item: any): ContentTreeItemResponseModel &
|
||||
};
|
||||
|
||||
// TODO: remove isTrashed type extension when we have found a solution to trashed items
|
||||
export const createDocumentTreeItem = (item: DocumentResponseModel): DocumentTreeItemResponseModel & { isTrashed: boolean } => {
|
||||
export const createDocumentTreeItem = (
|
||||
item: DocumentResponseModel
|
||||
): DocumentTreeItemResponseModel & { isTrashed: boolean } => {
|
||||
return {
|
||||
...createContentTreeItem(item),
|
||||
/*
|
||||
@@ -57,3 +60,10 @@ export const createDocumentTypeTreeItem = (item: DocumentTypeResponseModel): Doc
|
||||
isElement: item.isElement,
|
||||
};
|
||||
};
|
||||
|
||||
export const createFileSystemTreeItem = (item: any): FileSystemTreeItemPresentationModel => {
|
||||
return {
|
||||
...createFolderTreeItem(item),
|
||||
path: item.path,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user