Feature: Adds the missing dictionary to search (#2419)
* Feature: Adds the missing dictionary to search * Tweaks import sorting --------- Co-authored-by: leekelleher <leekelleher@gmail.com>
This commit is contained in:
@@ -3,6 +3,7 @@ import { manifests as dashboardManifests } from './dashboard/manifests.js';
|
||||
import { manifests as entityActionManifests } from './entity-action/manifests.js';
|
||||
import { manifests as menuItemManifests } from './menu-item/manifests.js';
|
||||
import { manifests as repositoryManifests } from './repository/manifests.js';
|
||||
import { manifests as searchManifests } from './search/manifests.js';
|
||||
import { manifests as treeManifests } from './tree/manifests.js';
|
||||
import { manifests as workspaceManifests } from './workspace/manifests.js';
|
||||
|
||||
@@ -12,6 +13,7 @@ export const manifests: Array<UmbExtensionManifest> = [
|
||||
...entityActionManifests,
|
||||
...menuItemManifests,
|
||||
...repositoryManifests,
|
||||
...searchManifests,
|
||||
...treeManifests,
|
||||
...workspaceManifests,
|
||||
];
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export const UMB_DICTIONARY_SEARCH_PROVIDER_ALIAS = 'Umb.SearchProvider.Dictionary';
|
||||
@@ -0,0 +1,23 @@
|
||||
import { UmbDictionarySearchServerDataSource } from './dictionary-search.server.data-source.js';
|
||||
import type { UmbDictionarySearchItemModel } from './dictionary.search-provider.js';
|
||||
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
|
||||
import type { UmbApi } from '@umbraco-cms/backoffice/extension-api';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import type { UmbSearchRepository, UmbSearchRequestArgs } from '@umbraco-cms/backoffice/search';
|
||||
|
||||
export class UmbDictionarySearchRepository
|
||||
extends UmbControllerBase
|
||||
implements UmbSearchRepository<UmbDictionarySearchItemModel>, UmbApi
|
||||
{
|
||||
#dataSource: UmbDictionarySearchServerDataSource;
|
||||
|
||||
constructor(host: UmbControllerHost) {
|
||||
super(host);
|
||||
|
||||
this.#dataSource = new UmbDictionarySearchServerDataSource(this);
|
||||
}
|
||||
|
||||
search(args: UmbSearchRequestArgs) {
|
||||
return this.#dataSource.search(args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { UMB_DICTIONARY_ENTITY_TYPE } from '../entity.js';
|
||||
import type { UmbDictionarySearchItemModel } from './dictionary.search-provider.js';
|
||||
import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';
|
||||
import { DictionaryService } from '@umbraco-cms/backoffice/external/backend-api';
|
||||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import type { UmbSearchDataSource, UmbSearchRequestArgs } from '@umbraco-cms/backoffice/search';
|
||||
|
||||
/**
|
||||
* A data source for the Rollback that fetches data from the server
|
||||
* @class UmbDictionarySearchServerDataSource
|
||||
* @implements {RepositoryDetailDataSource}
|
||||
*/
|
||||
export class UmbDictionarySearchServerDataSource implements UmbSearchDataSource<UmbDictionarySearchItemModel> {
|
||||
#host: UmbControllerHost;
|
||||
|
||||
/**
|
||||
* Creates an instance of UmbDictionarySearchServerDataSource.
|
||||
* @param {UmbControllerHost} host - The controller host for this controller to be appended to
|
||||
* @memberof UmbDictionarySearchServerDataSource
|
||||
*/
|
||||
constructor(host: UmbControllerHost) {
|
||||
this.#host = host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of versions for a data
|
||||
* @param args
|
||||
* @returns {*}
|
||||
* @memberof UmbDictionarySearchServerDataSource
|
||||
*/
|
||||
async search(args: UmbSearchRequestArgs) {
|
||||
const { data, error } = await tryExecuteAndNotify(
|
||||
this.#host,
|
||||
DictionaryService.getDictionary({
|
||||
filter: args.query,
|
||||
}),
|
||||
);
|
||||
|
||||
if (data) {
|
||||
const mappedItems: Array<UmbDictionarySearchItemModel> = data.items.map((item) => {
|
||||
return {
|
||||
href: '/section/translation/workspace/dictionary/edit/' + item.id,
|
||||
entityType: UMB_DICTIONARY_ENTITY_TYPE,
|
||||
unique: item.id,
|
||||
name: item.name ?? '',
|
||||
};
|
||||
});
|
||||
|
||||
return { data: { items: mappedItems, total: data.total } };
|
||||
}
|
||||
|
||||
return { error };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { UmbDictionaryItemModel } from '../index.js';
|
||||
import { UmbDictionarySearchRepository } from './dictionary-search.repository.js';
|
||||
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
|
||||
import type { UmbSearchProvider, UmbSearchRequestArgs } from '@umbraco-cms/backoffice/search';
|
||||
|
||||
export interface UmbDictionarySearchItemModel extends UmbDictionaryItemModel {
|
||||
href: string;
|
||||
}
|
||||
|
||||
export class UmbDictionarySearchProvider
|
||||
extends UmbControllerBase
|
||||
implements UmbSearchProvider<UmbDictionarySearchItemModel>
|
||||
{
|
||||
#repository = new UmbDictionarySearchRepository(this);
|
||||
|
||||
async search(args: UmbSearchRequestArgs) {
|
||||
return this.#repository.search(args);
|
||||
}
|
||||
|
||||
override destroy(): void {
|
||||
this.#repository.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
export { UmbDictionarySearchProvider as api };
|
||||
@@ -0,0 +1 @@
|
||||
export * from './constants.js';
|
||||
@@ -0,0 +1,21 @@
|
||||
import { UMB_DICTIONARY_ENTITY_TYPE } from '../entity.js';
|
||||
import { UMB_DICTIONARY_SEARCH_PROVIDER_ALIAS } from './constants.js';
|
||||
|
||||
export const manifests: Array<UmbExtensionManifest> = [
|
||||
{
|
||||
name: 'Dictionary Search Provider',
|
||||
alias: UMB_DICTIONARY_SEARCH_PROVIDER_ALIAS,
|
||||
type: 'searchProvider',
|
||||
api: () => import('./dictionary.search-provider.js'),
|
||||
weight: 600,
|
||||
meta: {
|
||||
label: 'Dictionary',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Dictionary Search Result Item ',
|
||||
alias: 'Umb.SearchResultItem.Dictionary',
|
||||
type: 'searchResultItem',
|
||||
forEntityTypes: [UMB_DICTIONARY_ENTITY_TYPE],
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user