moving and renaming
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
import { DataTypeResponseModel } from '@umbraco-cms/backoffice/backend-api';
|
||||
|
||||
export interface UmbDataTypeModel extends Omit<DataTypeResponseModel, '$type'> {
|
||||
type: 'data-type' | 'data-type-folder' | 'data-type-root';
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
export type * from './data-type-model';
|
||||
|
||||
/** Tried to find a common base of our entities — used by Entity Workspace Context */
|
||||
export type UmbEntityBase = {
|
||||
id?: string;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { UmbItemRepository, UmbRepositorySelectionManager } from '@umbraco-cms/backoffice/repository';
|
||||
import { UmbItemRepository, UmbRepositoryItemsManager } from '@umbraco-cms/backoffice/repository';
|
||||
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
|
||||
import {
|
||||
UMB_CONFIRM_MODAL,
|
||||
@@ -23,7 +23,7 @@ export class UmbPickerInputContext<ItemType extends ItemResponseModelBaseModel>
|
||||
|
||||
#init: Promise<unknown>;
|
||||
|
||||
#selectionManager;
|
||||
#itemManager;
|
||||
|
||||
selection;
|
||||
selectedItems;
|
||||
@@ -43,13 +43,13 @@ export class UmbPickerInputContext<ItemType extends ItemResponseModelBaseModel>
|
||||
this.modalAlias = modalAlias;
|
||||
this.#getUnique = getUniqueMethod || ((entry) => entry.id || '');
|
||||
|
||||
this.#selectionManager = new UmbRepositorySelectionManager<ItemType>(host, repositoryAlias);
|
||||
this.#itemManager = new UmbRepositoryItemsManager<ItemType>(host, repositoryAlias, this.#getUnique);
|
||||
|
||||
this.selection = this.#selectionManager.selection;
|
||||
this.selectedItems = this.#selectionManager.selectedItems;
|
||||
this.selection = this.#itemManager.uniques;
|
||||
this.selectedItems = this.#itemManager.items;
|
||||
|
||||
this.#init = Promise.all([
|
||||
this.#selectionManager.init,
|
||||
this.#itemManager.init,
|
||||
new UmbContextConsumerController(this.host, UMB_MODAL_CONTEXT_TOKEN, (instance) => {
|
||||
this.modalContext = instance;
|
||||
}).asPromise(),
|
||||
@@ -57,11 +57,11 @@ export class UmbPickerInputContext<ItemType extends ItemResponseModelBaseModel>
|
||||
}
|
||||
|
||||
getSelection() {
|
||||
return this.#selectionManager.getSelection();
|
||||
return this.#itemManager.getUniques();
|
||||
}
|
||||
|
||||
setSelection(selection: string[]) {
|
||||
this.#selectionManager.setSelection(selection);
|
||||
this.#itemManager.setUniques(selection);
|
||||
}
|
||||
|
||||
// TODO: If modalAlias is a ModalToken, then via TS, we should get the correct type for pickerData. Otherwise fallback to unknown.
|
||||
@@ -87,7 +87,7 @@ export class UmbPickerInputContext<ItemType extends ItemResponseModelBaseModel>
|
||||
if (!this.repository) throw new Error('Repository is not initialized');
|
||||
|
||||
// TODO: id won't always be available on the model, so we need to get the unique property from somewhere. Maybe the repository?
|
||||
const item = this.#selectionManager.getSelectedItems().find((item) => this.#getUnique(item) === unique);
|
||||
const item = this.#itemManager.getItems().find((item) => this.#getUnique(item) === unique);
|
||||
if (!item) throw new Error('Could not find item with unique: ' + unique);
|
||||
|
||||
const modalHandler = this.modalContext?.open(UMB_CONFIRM_MODAL, {
|
||||
|
||||
@@ -6,4 +6,4 @@ export * from './collection-repository.interface';
|
||||
export * from './item-repository.interface';
|
||||
export * from './move-repository.interface';
|
||||
export * from './copy-repository.interface';
|
||||
export * from './repository-selection.manager';
|
||||
export * from './repository-items.manager';
|
||||
|
||||
@@ -5,24 +5,40 @@ import { createExtensionClass } from '@umbraco-cms/backoffice/extension-api';
|
||||
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';
|
||||
import { ItemResponseModelBaseModel } from '@umbraco-cms/backoffice/backend-api';
|
||||
|
||||
export class UmbRepositorySelectionManager<ItemType extends ItemResponseModelBaseModel> {
|
||||
/**
|
||||
*
|
||||
* !!!!!!!!!!!!!!!!!!!!!
|
||||
* !!!!!!!!!!!!!!!!!!!!!
|
||||
* NOTE FOR MY SELF:
|
||||
* !!!!!!!!!!!!!!!!!!!!!
|
||||
* !!!!!!!!!!!!!!!!!!!!!
|
||||
*
|
||||
* Maybe this should not be called something with selection, but rather something with items/consumption/usage/... so its not about a selection, but just a given set of ids/uniques. We most likely need the unique getter method anyway.
|
||||
*/
|
||||
export class UmbRepositoryItemsManager<ItemType extends ItemResponseModelBaseModel> {
|
||||
host: UmbControllerHostElement;
|
||||
repository?: UmbItemRepository<ItemType>;
|
||||
#getUnique: (entry: ItemType) => string | undefined;
|
||||
|
||||
init: Promise<void>;
|
||||
|
||||
#selection = new UmbArrayState<string>([]);
|
||||
selection = this.#selection.asObservable();
|
||||
#uniques = new UmbArrayState<string>([]);
|
||||
uniques = this.#uniques.asObservable();
|
||||
|
||||
#selectedItems = new UmbArrayState<ItemType>([]);
|
||||
selectedItems = this.#selectedItems.asObservable();
|
||||
#items = new UmbArrayState<ItemType>([]);
|
||||
items = this.#items.asObservable();
|
||||
|
||||
#selectedItemsObserver?: UmbObserverController<ItemType[]>;
|
||||
itemsObserver?: UmbObserverController<ItemType[]>;
|
||||
|
||||
/* TODO: find a better way to have a getUniqueMethod. If we want to support trees/items of different types,
|
||||
then it need to be bound to the type and can't be a generic method we pass in. */
|
||||
constructor(host: UmbControllerHostElement, repositoryAlias: string) {
|
||||
constructor(
|
||||
host: UmbControllerHostElement,
|
||||
repositoryAlias: string,
|
||||
getUniqueMethod?: (entry: ItemType) => string | undefined
|
||||
) {
|
||||
this.host = host;
|
||||
this.#getUnique = getUniqueMethod || ((entry) => entry.id || '');
|
||||
|
||||
//TODO: The promise can probably be done in a cleaner way.
|
||||
this.init = new Promise((resolve) => {
|
||||
@@ -46,34 +62,32 @@ export class UmbRepositorySelectionManager<ItemType extends ItemResponseModelBas
|
||||
});
|
||||
}
|
||||
|
||||
getSelection() {
|
||||
return this.#selection.value;
|
||||
getUniques() {
|
||||
return this.#uniques.value;
|
||||
}
|
||||
|
||||
setSelection(selection: string[]) {
|
||||
this.#selection.next(selection);
|
||||
setUniques(uniques: string[]) {
|
||||
this.#uniques.next(uniques);
|
||||
|
||||
//TODO: Check if it's safe to call requestItems here.
|
||||
this.#requestItems();
|
||||
}
|
||||
|
||||
getSelectedItems() {
|
||||
return this.#selectedItems.value;
|
||||
getItems() {
|
||||
return this.#items.value;
|
||||
}
|
||||
|
||||
async #requestItems() {
|
||||
await this.init;
|
||||
if (!this.repository) throw new Error('Repository is not initialized');
|
||||
if (this.#selectedItemsObserver) this.#selectedItemsObserver.destroy();
|
||||
if (this.itemsObserver) this.itemsObserver.destroy();
|
||||
|
||||
// TODO: Test if its just some items that is gone now, if so then just filter them out. (maybe use code from #removeItem)
|
||||
|
||||
const { asObservable } = await this.repository.requestItems(this.getSelection());
|
||||
const { asObservable } = await this.repository.requestItems(this.getUniques());
|
||||
|
||||
if (asObservable) {
|
||||
this.#selectedItemsObserver = new UmbObserverController(this.host, asObservable(), (data) =>
|
||||
this.#selectedItems.next(data)
|
||||
);
|
||||
this.itemsObserver = new UmbObserverController(this.host, asObservable(), (data) => this.#items.next(data));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user