update partial view snippets to support new snippet id

This commit is contained in:
Mads Rasmussen
2024-01-16 12:31:46 +01:00
parent c88a4ea0bb
commit ab1baf6e9f
6 changed files with 38 additions and 22 deletions

View File

@@ -26,15 +26,15 @@ class UmbPartialViewMockDB extends UmbFileSystemMockDbBase<UmbMockPartialViewMod
return { items: snippetItems, total };
}
getSnippet(fileName: string): PartialViewSnippetResponseModel | undefined {
return snippets.find((item) => item.fileName === fileName);
getSnippet(id: string): PartialViewSnippetResponseModel | undefined {
return snippets.find((item) => item.id === id);
}
}
const createSnippetItem = (item: PartialViewSnippetResponseModel): PartialViewSnippetItemResponseModel => {
return {
name: item.name,
fileName: item.fileName,
id: item.id,
};
};

View File

@@ -33,7 +33,7 @@ export class UmbDataTypeMoveServerDataSource implements UmbMoveDataSource {
return tryExecuteAndNotify(
this.#host,
DataTypeResource.postDataTypeByIdMove({
DataTypeResource.putDataTypeByIdMove({
id: unique,
requestBody: {
targetId: targetUnique,

View File

@@ -76,7 +76,7 @@ export class UmbPartialViewCreateOptionsModalElement extends UmbModalBaseElement
<uui-box>
<!-- TODO: construct url -->
<uui-menu-item
href=${`section/settings/workspace/partial-view/create/${this.data?.parentUnique || 'null'}/Empty`}
href=${`section/settings/workspace/partial-view/create/${this.data?.parentUnique || 'null'}`}
label="New empty partial view"
@click=${this.#onNavigate}>
<uui-icon slot="icon" name="icon-article"></uui-icon>}

View File

@@ -25,8 +25,8 @@ export class UmbPartialViewCreateFromSnippetModalElement extends UmbModalBaseEle
this._snippets = data.items.map((snippet) => {
return {
name: snippet.name,
path: `section/settings/workspace/partial-view/create/${this.data?.parentUnique || 'null'}/${
snippet.fileName
path: `section/settings/workspace/partial-view/create/${this.data?.parentUnique || 'null'}/snippet/${
snippet.id
}`,
};
});

View File

@@ -69,9 +69,13 @@ export class UmbPartialViewWorkspaceContext
}
}
async create(parentUnique: string | null, snippetName = 'Empty') {
const { data: snippet } = await this.#getSnippet(snippetName);
const snippetContent = snippet?.content ?? '';
async create(parentUnique: string | null, snippetId?: string) {
let snippetContent = '';
if (snippetId) {
const { data: snippet } = await this.#getSnippet(snippetId);
snippetContent = snippet?.content || '';
}
const { data } = await this.repository.createScaffold(parentUnique, { content: snippetContent });
@@ -104,11 +108,11 @@ export class UmbPartialViewWorkspaceContext
this.#data.destroy();
}
#getSnippet(snippetFileName: string) {
#getSnippet(snippetId: string) {
return tryExecuteAndNotify(
this,
PartialViewResource.getPartialViewSnippetByFileName({
fileName: snippetFileName,
PartialViewResource.getPartialViewSnippetById({
id: snippetId,
}),
);
}

View File

@@ -17,18 +17,20 @@ export class UmbPartialViewWorkspaceElement extends UmbLitElement {
@state()
_routes: UmbRoute[] = [
{
path: 'create/:parentUnique/:snippetName',
path: 'create/:parentUnique/snippet/:snippetId',
component: this.#createElement,
setup: async (component: PageComponent, info: IRoutingInfo) => {
const parentUnique = info.match.params.parentUnique === 'null' ? null : info.match.params.parentUnique;
const snippetName = info.match.params.snippetName;
await this.#workspaceContext.create(parentUnique, snippetName);
new UmbWorkspaceIsNewRedirectController(
this,
this.#workspaceContext,
this.shadowRoot!.querySelector('umb-router-slot')!,
);
const snippetId = info.match.params.snippetId;
await this.#onCreate(parentUnique, snippetId);
},
},
{
path: 'create/:parentUnique',
component: this.#createElement,
setup: async (component: PageComponent, info: IRoutingInfo) => {
const parentUnique = info.match.params.parentUnique === 'null' ? null : info.match.params.parentUnique;
await this.#onCreate(parentUnique);
},
},
{
@@ -41,6 +43,16 @@ export class UmbPartialViewWorkspaceElement extends UmbLitElement {
},
];
#onCreate = async (parentUnique: string | null, snippetId: string | undefined) => {
await this.#workspaceContext.create(parentUnique, snippetId);
new UmbWorkspaceIsNewRedirectController(
this,
this.#workspaceContext,
this.shadowRoot!.querySelector('umb-router-slot')!,
);
};
render() {
return html`<umb-router-slot .routes=${this._routes}></umb-router-slot>`;
}