fix filesystem folder creation
This commit is contained in:
@@ -46,7 +46,6 @@ const detailHandlers: RestHandler<MockedRequest<DefaultBodyType>>[] = [
|
||||
|
||||
rest.put(umbracoPath('/script'), async (req, res, ctx) => {
|
||||
const requestBody = (await req.json()) as UpdateScriptRequestModel;
|
||||
debugger;
|
||||
if (!requestBody) return res(ctx.status(400, 'no body found'));
|
||||
umbScriptMockDb.file.update(requestBody);
|
||||
return res(ctx.status(200));
|
||||
@@ -56,7 +55,6 @@ const detailHandlers: RestHandler<MockedRequest<DefaultBodyType>>[] = [
|
||||
const itemHandlers: RestHandler<MockedRequest<DefaultBodyType>>[] = [
|
||||
rest.get(umbracoPath('/script/item'), (req, res, ctx) => {
|
||||
const paths = req.url.searchParams.getAll('paths');
|
||||
debugger;
|
||||
if (!paths) return res(ctx.status(400, 'no body found'));
|
||||
const response = umbScriptMockDb.getItems(paths);
|
||||
return res(ctx.status(200), ctx.json(response));
|
||||
|
||||
@@ -6,6 +6,7 @@ import { type UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbTreeItemModelBase, UmbTreeStore } from '@umbraco-cms/backoffice/tree';
|
||||
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
|
||||
import { UmbId } from '@umbraco-cms/backoffice/id';
|
||||
import { UMB_NOTIFICATION_CONTEXT_TOKEN, UmbNotificationContext } from '@umbraco-cms/backoffice/notification';
|
||||
|
||||
export type UmbFolderToTreeItemMapper<FolderTreeItemType extends UmbTreeItemModelBase> = (
|
||||
item: UmbFolderModel,
|
||||
@@ -19,6 +20,7 @@ export abstract class UmbFolderRepositoryBase<FolderTreeItemType extends UmbTree
|
||||
protected _treeStore?: UmbTreeStore<FolderTreeItemType>;
|
||||
#folderDataSource: UmbFolderDataSource;
|
||||
#folderToTreeItemMapper: UmbFolderToTreeItemMapper<FolderTreeItemType>;
|
||||
#notificationContext?: UmbNotificationContext;
|
||||
|
||||
constructor(
|
||||
host: UmbControllerHost,
|
||||
@@ -30,9 +32,15 @@ export abstract class UmbFolderRepositoryBase<FolderTreeItemType extends UmbTree
|
||||
this.#folderDataSource = new folderDataSource(this);
|
||||
this.#folderToTreeItemMapper = folderToTreeItemMapper;
|
||||
|
||||
this._init = this.consumeContext(treeStoreContextAlias, (instance) => {
|
||||
this._treeStore = instance;
|
||||
}).asPromise();
|
||||
this._init = Promise.all([
|
||||
this.consumeContext(treeStoreContextAlias, (instance) => {
|
||||
this._treeStore = instance;
|
||||
}).asPromise(),
|
||||
|
||||
this.consumeContext(UMB_NOTIFICATION_CONTEXT_TOKEN, (instance) => {
|
||||
this.#notificationContext = instance;
|
||||
}).asPromise(),
|
||||
]);
|
||||
}
|
||||
|
||||
async createScaffold(parentUnique: string | null) {
|
||||
@@ -63,12 +71,28 @@ export abstract class UmbFolderRepositoryBase<FolderTreeItemType extends UmbTree
|
||||
if (data) {
|
||||
const folderTreeItem = this.#folderToTreeItemMapper(data);
|
||||
this._treeStore!.append(folderTreeItem);
|
||||
|
||||
const notification = { data: { message: `Folder created` } };
|
||||
this.#notificationContext!.peek('positive', notification);
|
||||
|
||||
return { data };
|
||||
}
|
||||
|
||||
return { error };
|
||||
}
|
||||
|
||||
/**
|
||||
* Request a folder
|
||||
* @param {string} unique
|
||||
* @return {*}
|
||||
* @memberof UmbFolderRepositoryBase
|
||||
*/
|
||||
async request(unique: string) {
|
||||
if (!unique) throw new Error('Unique is missing');
|
||||
await this._init;
|
||||
return await this.#folderDataSource.read(unique);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a folder
|
||||
* @param {UmbUpdateFolderModel} args
|
||||
@@ -87,6 +111,9 @@ export abstract class UmbFolderRepositoryBase<FolderTreeItemType extends UmbTree
|
||||
// @ts-ignore
|
||||
// TODO: I don't know why typescript is complaining about the name prop
|
||||
this._treeStore!.updateItem(args.unique, { name: data.name });
|
||||
|
||||
const notification = { data: { message: `Folder updated` } };
|
||||
this.#notificationContext!.peek('positive', notification);
|
||||
}
|
||||
|
||||
return { data, error };
|
||||
@@ -106,20 +133,11 @@ export abstract class UmbFolderRepositoryBase<FolderTreeItemType extends UmbTree
|
||||
|
||||
if (!error) {
|
||||
this._treeStore!.removeItem(unique);
|
||||
|
||||
const notification = { data: { message: `Folder deleted` } };
|
||||
this.#notificationContext!.peek('positive', notification);
|
||||
}
|
||||
|
||||
return { error };
|
||||
}
|
||||
|
||||
/**
|
||||
* Request a folder
|
||||
* @param {string} unique
|
||||
* @return {*}
|
||||
* @memberof UmbFolderRepositoryBase
|
||||
*/
|
||||
async request(unique: string) {
|
||||
if (!unique) throw new Error('Unique is missing');
|
||||
await this._init;
|
||||
return await this.#folderDataSource.read(unique);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ export class UmbScriptFolderServerDataSource implements UmbFolderDataSource {
|
||||
if (data) {
|
||||
const mappedData = {
|
||||
unique: this.#serverPathUniqueSerializer.toUnique(data.path),
|
||||
parentUnique: this.#serverPathUniqueSerializer.toUnique(data.parentPath),
|
||||
parentUnique: this.#serverPathUniqueSerializer.toParentUnique(data.path),
|
||||
name: data.name,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user