Skip to content

Commit

Permalink
move workspace modal registration to each implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
nielslyngsoe authored and iOvergaard committed May 29, 2024
1 parent 726aeef commit 657c7c1
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type { UmbBlockDataType } from '../../block/index.js';
import { UMB_BLOCK_CATALOGUE_MODAL, UmbBlockEntriesContext } from '../../block/index.js';
import { UMB_BLOCK_GRID_ENTRY_CONTEXT, type UmbBlockGridWorkspaceData } from '../index.js';
import {
UMB_BLOCK_GRID_ENTRY_CONTEXT,
UMB_BLOCK_GRID_WORKSPACE_MODAL,
type UmbBlockGridWorkspaceData,
} from '../index.js';
import type { UmbBlockGridLayoutModel, UmbBlockGridTypeAreaType, UmbBlockGridTypeModel } from '../types.js';
import { UMB_BLOCK_GRID_MANAGER_CONTEXT } from './block-grid-manager.context-token.js';
import type { UmbBlockGridScalableContainerContext } from './block-grid-scale-manager/block-grid-scale-manager.controller.js';
Expand All @@ -21,6 +25,7 @@ export class UmbBlockGridEntriesContext
{
//
#catalogueModal: UmbModalRouteRegistrationController<typeof UMB_BLOCK_CATALOGUE_MODAL.DATA, undefined>;
#workspaceModal: UmbModalRouteRegistrationController;

#parentEntry?: typeof UMB_BLOCK_GRID_ENTRY_CONTEXT.TYPE;

Expand Down Expand Up @@ -66,13 +71,13 @@ export class UmbBlockGridEntriesContext
setParentUnique(contentUdi: string | null) {
this.#parentUnique = contentUdi;
// Notice pathFolderName can be removed when we have switched to use a proper GUID/ID/KEY. [NL]
this._workspaceModal.setUniquePathValue('parentUnique', pathFolderName(contentUdi ?? 'null'));
this.#workspaceModal.setUniquePathValue('parentUnique', pathFolderName(contentUdi ?? 'null'));
this.#catalogueModal.setUniquePathValue('parentUnique', pathFolderName(contentUdi ?? 'null'));
}

setAreaKey(areaKey: string | null) {
this.#areaKey = areaKey;
this._workspaceModal.setUniquePathValue('areaKey', areaKey ?? 'null');
this.#workspaceModal.setUniquePathValue('areaKey', areaKey ?? 'null');
this.#catalogueModal.setUniquePathValue('areaKey', areaKey ?? 'null');
this.#gotAreaKey();
}
Expand All @@ -93,8 +98,6 @@ export class UmbBlockGridEntriesContext
constructor(host: UmbControllerHost) {
super(host, UMB_BLOCK_GRID_MANAGER_CONTEXT);

this._workspaceModal.addUniquePaths(['parentUnique', 'areaKey']);

this.consumeContext(UMB_BLOCK_GRID_ENTRY_CONTEXT, (blockGridEntry) => {
this.#parentEntry = blockGridEntry;
this.#gotBlockParentEntry(); // is not used at this point. [NL]
Expand All @@ -119,6 +122,24 @@ export class UmbBlockGridEntriesContext
// TODO: Does it make any sense that this is a state? Check usage and confirm. [NL]
this._catalogueRouteBuilderState.setValue(routeBuilder);
});

this.#workspaceModal = new UmbModalRouteRegistrationController(this, UMB_BLOCK_GRID_WORKSPACE_MODAL)
.addUniquePaths(['propertyAlias', 'variantId', 'parentUnique', 'areaKey'])
.addAdditionalPath('block')
.onSetup(() => {
return {
data: {
entityType: 'block',
preset: {},
originData: { areaKey: this.#areaKey, parentUnique: this.#parentUnique },
},
modal: { size: 'medium' },
};
})
.observeRouteBuilder((routeBuilder) => {
const newPath = routeBuilder({});
this._workspacePath.setValue(newPath);
});
}

protected _gotBlockManager() {
Expand All @@ -131,16 +152,17 @@ export class UmbBlockGridEntriesContext
this._manager.propertyAlias,
(alias) => {
this.#catalogueModal.setUniquePathValue('propertyAlias', alias ?? 'null');
this.#workspaceModal.setUniquePathValue('propertyAlias', alias ?? 'null');
},
'observePropertyAlias',
);

this.observe(
this._manager.variantId,
(variantId) => {
if (variantId) {
this.#catalogueModal.setUniquePathValue('variantId', variantId.toString());
}
// TODO: This might not be the property variant ID, but the content variant ID. Check up on what makes most sense?
this.#catalogueModal.setUniquePathValue('variantId', variantId?.toString());
this.#workspaceModal.setUniquePathValue('variantId', variantId?.toString());
},
'observePropertyAlias',
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { UmbBlockDataType } from '../../block/index.js';
import { UMB_BLOCK_CATALOGUE_MODAL, UmbBlockEntriesContext } from '../../block/index.js';
import type { UmbBlockListWorkspaceData } from '../index.js';
import { UMB_BLOCK_LIST_WORKSPACE_MODAL, type UmbBlockListWorkspaceData } from '../index.js';
import type { UmbBlockListLayoutModel, UmbBlockListTypeModel } from '../types.js';
import { UMB_BLOCK_LIST_MANAGER_CONTEXT } from './block-list-manager.context-token.js';
import { UmbBooleanState } from '@umbraco-cms/backoffice/observable-api';
Expand All @@ -15,6 +15,7 @@ export class UmbBlockListEntriesContext extends UmbBlockEntriesContext<
> {
//
#catalogueModal: UmbModalRouteRegistrationController<typeof UMB_BLOCK_CATALOGUE_MODAL.DATA, undefined>;
#workspaceModal: UmbModalRouteRegistrationController;

// We will just say its always allowed for list for now: [NL]
public readonly canCreate = new UmbBooleanState(true).asObservable();
Expand All @@ -40,6 +41,17 @@ export class UmbBlockListEntriesContext extends UmbBlockEntriesContext<
.observeRouteBuilder((routeBuilder) => {
this._catalogueRouteBuilderState.setValue(routeBuilder);
});

this.#workspaceModal = new UmbModalRouteRegistrationController(this, UMB_BLOCK_LIST_WORKSPACE_MODAL)
.addUniquePaths(['propertyAlias', 'variantId'])
.addAdditionalPath('block')
.onSetup(() => {
return { data: { entityType: 'block', preset: {} }, modal: { size: 'medium' } };
})
.observeRouteBuilder((routeBuilder) => {
const newPath = routeBuilder({});
this._workspacePath.setValue(newPath);
});
}

protected _gotBlockManager() {
Expand All @@ -64,16 +76,17 @@ export class UmbBlockListEntriesContext extends UmbBlockEntriesContext<
this._manager.propertyAlias,
(alias) => {
this.#catalogueModal.setUniquePathValue('propertyAlias', alias ?? 'null');
this.#workspaceModal.setUniquePathValue('propertyAlias', alias ?? 'null');
},
'observePropertyAlias',
);

this.observe(
this._manager.variantId,
(variantId) => {
if (variantId) {
this.#catalogueModal.setUniquePathValue('variantId', variantId.toString());
}
// TODO: This might not be the property variant ID, but the content variant ID. Check up on what makes most sense?
this.#catalogueModal.setUniquePathValue('variantId', variantId?.toString());
this.#workspaceModal.setUniquePathValue('variantId', variantId?.toString());
},
'observePropertyAlias',
);
Expand Down
24 changes: 20 additions & 4 deletions src/packages/block/block-rte/context/block-rte-entries.context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import type { UmbBlockDataType } from '../../block/index.js';
import { UMB_BLOCK_CATALOGUE_MODAL, UmbBlockEntriesContext } from '../../block/index.js';
import type { UmbBlockRteWorkspaceData } from '../index.js';
import type { UmbBlockRteLayoutModel, UmbBlockRteTypeModel } from '../types.js';
import {
UMB_BLOCK_RTE_WORKSPACE_MODAL,
type UmbBlockRteWorkspaceData,
} from '../workspace/block-rte-workspace.modal-token.js';
import { UMB_BLOCK_RTE_MANAGER_CONTEXT } from './block-rte-manager.context-token.js';
import { UmbBooleanState } from '@umbraco-cms/backoffice/observable-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
Expand All @@ -15,6 +18,7 @@ export class UmbBlockRteEntriesContext extends UmbBlockEntriesContext<
> {
//
#catalogueModal: UmbModalRouteRegistrationController<typeof UMB_BLOCK_CATALOGUE_MODAL.DATA, undefined>;
#workspaceModal: UmbModalRouteRegistrationController;

// We will just say its always allowed for RTE for now: [NL]
public readonly canCreate = new UmbBooleanState(true).asObservable();
Expand All @@ -38,6 +42,17 @@ export class UmbBlockRteEntriesContext extends UmbBlockEntriesContext<
.observeRouteBuilder((routeBuilder) => {
this._catalogueRouteBuilderState.setValue(routeBuilder);
});

this.#workspaceModal = new UmbModalRouteRegistrationController(this, UMB_BLOCK_RTE_WORKSPACE_MODAL)
.addUniquePaths(['propertyAlias', 'variantId'])
.addAdditionalPath('block')
.onSetup(() => {
return { data: { entityType: 'block', preset: {} }, modal: { size: 'medium' } };
})
.observeRouteBuilder((routeBuilder) => {
const newPath = routeBuilder({});
this._workspacePath.setValue(newPath);
});
}

protected _gotBlockManager() {
Expand All @@ -62,16 +77,17 @@ export class UmbBlockRteEntriesContext extends UmbBlockEntriesContext<
this._manager.propertyAlias,
(alias) => {
this.#catalogueModal.setUniquePathValue('propertyAlias', alias ?? 'null');
this.#workspaceModal.setUniquePathValue('propertyAlias', alias ?? 'null');
},
'observePropertyAlias',
);

this.observe(
this._manager.variantId,
(variantId) => {
if (variantId) {
this.#catalogueModal.setUniquePathValue('variantId', variantId.toString());
}
// TODO: This might not be the property variant ID, but the content variant ID. Check up on what makes most sense?
this.#catalogueModal.setUniquePathValue('variantId', variantId?.toString());
this.#workspaceModal.setUniquePathValue('variantId', variantId?.toString());
},
'observePropertyAlias',
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import type {
UmbBlockLayoutBaseModel,
UmbBlockViewPropsType,
UmbBlockWorkspaceData,
} from '@umbraco-cms/backoffice/block';
import type { UmbWorkspaceModalData } from '@umbraco-cms/backoffice/modal';
import type { UmbBlockWorkspaceData } from '@umbraco-cms/backoffice/block';
import type { UmbWorkspaceModalData, UmbWorkspaceModalValue } from '@umbraco-cms/backoffice/modal';
import { UmbModalToken } from '@umbraco-cms/backoffice/modal';

export interface UmbBlockRteWorkspaceData extends UmbBlockWorkspaceData<object> {}

export type UmbBlockRteWorkspaceValue = Array<UmbBlockViewPropsType<UmbBlockLayoutBaseModel>>;

export const UMB_BLOCK_RTE_WORKSPACE_MODAL = new UmbModalToken<UmbBlockRteWorkspaceData, UmbBlockRteWorkspaceValue>(
export const UMB_BLOCK_RTE_WORKSPACE_MODAL = new UmbModalToken<UmbBlockRteWorkspaceData, UmbWorkspaceModalValue>(
'Umb.Modal.Workspace',
{
modal: {
Expand All @@ -20,4 +14,4 @@ export const UMB_BLOCK_RTE_WORKSPACE_MODAL = new UmbModalToken<UmbBlockRteWorksp
data: { entityType: 'block', preset: {}, originData: {} },
// Recast the type, so the entityType data prop is not required:
},
) as UmbModalToken<Omit<UmbWorkspaceModalData, 'entityType'>, UmbBlockRteWorkspaceValue>;
) as UmbModalToken<Omit<UmbWorkspaceModalData, 'entityType'>, UmbWorkspaceModalValue>;
47 changes: 9 additions & 38 deletions src/packages/block/block/context/block-entries.context.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { UmbBlockDataType, UmbBlockLayoutBaseModel } from '../types.js';
import { UMB_BLOCK_WORKSPACE_MODAL } from '../workspace/block-workspace.modal-token.js';
import type { UmbBlockDataObjectModel, UmbBlockManagerContext } from './block-manager.context.js';
import type { UmbBlockWorkspaceData } from '../workspace/block-workspace.modal-token.js';
import { UMB_BLOCK_ENTRIES_CONTEXT } from './block-entries.context-token.js';
import type { UmbBlockDataObjectModel, UmbBlockManagerContext } from './block-manager.context.js';
import { type Observable, UmbArrayState, UmbBasicState, UmbStringState } from '@umbraco-cms/backoffice/observable-api';
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbBlockTypeBaseModel } from '@umbraco-cms/backoffice/block-type';
import type { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { type Observable, UmbArrayState, UmbBasicState, UmbStringState } from '@umbraco-cms/backoffice/observable-api';
import { type UmbModalRouteBuilder, UmbModalRouteRegistrationController } from '@umbraco-cms/backoffice/router';
import type { UmbModalRouteBuilder } from '@umbraco-cms/backoffice/router';

export abstract class UmbBlockEntriesContext<
BlockManagerContextTokenType extends UmbContextToken<BlockManagerContextType, BlockManagerContextType>,
Expand All @@ -21,13 +21,11 @@ export abstract class UmbBlockEntriesContext<
_manager?: BlockManagerContextType;
_retrieveManager;

_workspaceModal: UmbModalRouteRegistrationController;

protected _catalogueRouteBuilderState = new UmbBasicState<UmbModalRouteBuilder | undefined>(undefined);
readonly catalogueRouteBuilder = this._catalogueRouteBuilderState.asObservable();

#workspacePath = new UmbStringState(undefined);
workspacePath = this.#workspacePath.asObservable();
protected _workspacePath = new UmbStringState(undefined);
workspacePath = this._workspacePath.asObservable();

public abstract readonly canCreate: Observable<boolean>;

Expand All @@ -42,34 +40,7 @@ export abstract class UmbBlockEntriesContext<
this._retrieveManager = this.consumeContext(blockManagerContextToken, (blockGridManager) => {
this._manager = blockGridManager;
this._gotBlockManager();

this.observe(
this._manager.propertyAlias,
(alias) => {
this._workspaceModal.setUniquePathValue('propertyAlias', alias);
},
'observePropertyAlias',
);
this.observe(
this._manager.variantId,
(variantId) => {
// TODO: This might not be the property variant ID, but the content variant ID. Check up on what makes most sense?
this._workspaceModal.setUniquePathValue('variantId', variantId?.toString());
},
'observePropertyVariantId',
);
}).asPromise();

this._workspaceModal = new UmbModalRouteRegistrationController(this, UMB_BLOCK_WORKSPACE_MODAL)
.addUniquePaths(['propertyAlias', 'variantId'])
.addAdditionalPath('block')
.onSetup(() => {
return { data: { entityType: 'block', preset: {} }, modal: { size: 'medium' } };
})
.observeRouteBuilder((routeBuilder) => {
const newPath = routeBuilder({});
this.#workspacePath.setValue(newPath);
});
}

async getManager() {
Expand Down Expand Up @@ -100,14 +71,14 @@ export abstract class UmbBlockEntriesContext<
public abstract create(
contentElementTypeKey: string,
layoutEntry?: Omit<BlockLayoutType, 'contentUdi'>,
modalData?: typeof UMB_BLOCK_WORKSPACE_MODAL.DATA,
modalData?: UmbBlockWorkspaceData,
): Promise<UmbBlockDataObjectModel<BlockLayoutType> | undefined>;

abstract insert(
layoutEntry: BlockLayoutType,
content: UmbBlockDataType,
settings: UmbBlockDataType | undefined,
modalData: typeof UMB_BLOCK_WORKSPACE_MODAL.DATA,
modalData: UmbBlockWorkspaceData,
): Promise<boolean>;
//edit?
//editSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export class UmbBlockWorkspaceContext<LayoutDataType extends UmbBlockLayoutBaseM
} else {
// Update data:

this.#blockManager.setOneLayout(layoutData, this.#modalContext?.data as UmbBlockWorkspaceData);
this.#blockManager.setOneLayout(layoutData, this.#modalContext.data as UmbBlockWorkspaceData);
if (contentData) {
this.#blockManager.setOneContent(contentData);
}
Expand Down

0 comments on commit 657c7c1

Please sign in to comment.