Update rename-server-file-repository-base.ts
This commit is contained in:
@@ -1,16 +1,24 @@
|
||||
import type { UmbRenameServerFileDataSource, UmbRenameServerFileDataSourceConstructor } from './types.js';
|
||||
import type { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
|
||||
import type { UmbDetailStore } from '@umbraco-cms/backoffice/store';
|
||||
import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';
|
||||
|
||||
export abstract class UmbRenameServerFileRepositoryBase<
|
||||
DetailModelType extends { unique: string },
|
||||
> extends UmbRepositoryBase {
|
||||
#renameSource: UmbRenameServerFileDataSource<DetailModelType>;
|
||||
#detailStoreContextAlias: string | UmbContextToken<UmbDetailStore<DetailModelType>>;
|
||||
|
||||
constructor(host: UmbControllerHost, detailSource: UmbRenameServerFileDataSourceConstructor<DetailModelType>) {
|
||||
constructor(
|
||||
host: UmbControllerHost,
|
||||
detailSource: UmbRenameServerFileDataSourceConstructor<DetailModelType>,
|
||||
detailStoreContextAlias: string | UmbContextToken<UmbDetailStore<DetailModelType>>,
|
||||
) {
|
||||
super(host);
|
||||
this.#renameSource = new detailSource(host);
|
||||
this.#detailStoreContextAlias = detailStoreContextAlias;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,6 +35,13 @@ export abstract class UmbRenameServerFileRepositoryBase<
|
||||
const { data, error } = await this.#renameSource.rename(unique, name);
|
||||
|
||||
if (data) {
|
||||
const detailStore = await this.getContext(this.#detailStoreContextAlias);
|
||||
|
||||
/* When renaming a file the unique changed because it is based on the path/name
|
||||
We need to remove the old item and append the new item */
|
||||
detailStore.removeItem(unique);
|
||||
detailStore.append(data);
|
||||
|
||||
const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT);
|
||||
const notification = { data: { message: `Renamed` } };
|
||||
notificationContext.peek('positive', notification);
|
||||
|
||||
Reference in New Issue
Block a user