add dictionary move entity action

This commit is contained in:
Mads Rasmussen
2024-04-11 13:21:39 +02:00
parent b58aeee48a
commit 336214b38e
7 changed files with 103 additions and 0 deletions

View File

@@ -0,0 +1 @@
export { UmbMoveDictionaryRepository, UMB_MOVE_DICTIONARY_REPOSITORY_ALIAS } from './repository/index.js';

View File

@@ -0,0 +1,23 @@
import { UMB_DICTIONARY_ENTITY_TYPE } from '../../entity.js';
import { UMB_DICTIONARY_PICKER_MODAL } from '../../modals/dictionary-picker-modal.token.js';
import { UMB_DICTIONARY_TREE_REPOSITORY_ALIAS } from '../../tree/index.js';
import { UMB_MOVE_DICTIONARY_REPOSITORY_ALIAS } from './repository/index.js';
import { manifests as repositoryManifests } from './repository/manifests.js';
import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
const entityActions: Array<ManifestTypes> = [
{
type: 'entityAction',
kind: 'moveTo',
alias: 'Umb.EntityAction.Dictionary.Move',
name: 'Move Dictionary Entity Action',
forEntityTypes: [UMB_DICTIONARY_ENTITY_TYPE],
meta: {
treeRepositoryAlias: UMB_DICTIONARY_TREE_REPOSITORY_ALIAS,
moveToRepositoryAlias: UMB_MOVE_DICTIONARY_REPOSITORY_ALIAS,
treePickerModal: UMB_DICTIONARY_PICKER_MODAL,
},
},
];
export const manifests = [...entityActions, ...repositoryManifests];

View File

@@ -0,0 +1 @@
export const UMB_MOVE_DICTIONARY_REPOSITORY_ALIAS = 'Umb.Repository.Dictionary.Move';

View File

@@ -0,0 +1,20 @@
import { UmbDictionaryMoveServerDataSource } from './dictionary-move.server.data-source.js';
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
import type { UmbMoveToRepository, UmbMoveToRequestArgs } from '@umbraco-cms/backoffice/repository';
import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';
export class UmbMoveDictionaryRepository extends UmbRepositoryBase implements UmbMoveToRepository {
#moveSource = new UmbDictionaryMoveServerDataSource(this);
async requestMove(args: UmbMoveToRequestArgs) {
const { error } = await this.#moveSource.move(args);
if (!error) {
const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT);
const notification = { data: { message: `Moved` } };
notificationContext.peek('positive', notification);
}
return { error };
}
}

View File

@@ -0,0 +1,44 @@
import { DictionaryService } from '@umbraco-cms/backoffice/external/backend-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';
import type { UmbMoveToDataSource, UmbMoveToRequestArgs } from '@umbraco-cms/backoffice/repository';
/**
* Move Dictionary Server Data Source
* @export
* @class UmbDictionaryMoveServerDataSource
*/
export class UmbDictionaryMoveServerDataSource implements UmbMoveToDataSource {
#host: UmbControllerHost;
/**
* Creates an instance of UmbDictionaryMoveServerDataSource.
* @param {UmbControllerHost} host
* @memberof UmbDictionaryMoveServerDataSource
*/
constructor(host: UmbControllerHost) {
this.#host = host;
}
/**
* Move an item for the given id to the target unique
* @param {string} unique
* @param {(string | null)} targetUnique
* @return {*}
* @memberof UmbDictionaryMoveServerDataSource
*/
async move(args: UmbMoveToRequestArgs) {
if (!args.unique) throw new Error('Unique is missing');
if (args.destination.unique === undefined) throw new Error('Destination unique is missing');
return tryExecuteAndNotify(
this.#host,
DictionaryService.putDictionaryByIdMove({
id: args.unique,
requestBody: {
target: args.destination.unique ? { id: args.destination.unique } : null,
},
}),
);
}
}

View File

@@ -0,0 +1,2 @@
export { UmbMoveDictionaryRepository } from './dictionary-move.repository.js';
export { UMB_MOVE_DICTIONARY_REPOSITORY_ALIAS } from './constants.js';

View File

@@ -0,0 +1,12 @@
import { UMB_MOVE_DICTIONARY_REPOSITORY_ALIAS } from './constants.js';
import { UmbMoveDictionaryRepository } from './dictionary-move.repository.js';
import type { ManifestRepository } from '@umbraco-cms/backoffice/extension-registry';
const moveRepository: ManifestRepository = {
type: 'repository',
alias: UMB_MOVE_DICTIONARY_REPOSITORY_ALIAS,
name: 'Move Dictionary Repository',
api: UmbMoveDictionaryRepository,
};
export const manifests = [moveRepository];