-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
V15: Add abstraction for named entity detail workspaces (#17959)
* chore: add validation to mocked endpoints * feat: create new base context `UmbEntityNamedDetailWorkspaceContextBase` to use for named entities * feat: extend from `UmbEntityNamedDetailWorkspaceContextBase` to be able to save some code * feat: allow to pass on the generic parameters * feat: add type-safety property * chore: remove duplicate code by extending from correct interface * chore: fix type casting * feat: make class abstract and add explanatory comment
- Loading branch information
1 parent
b5e4806
commit c3134cb
Showing
17 changed files
with
134 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/Umbraco.Web.UI.Client/src/mocks/handlers/partial-view/rename.handlers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 4 additions & 6 deletions
10
.../packages/core/workspace/contexts/tokens/invariant-dataset-workspace-context.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...UI.Client/src/packages/core/workspace/entity-detail/entity-named-detail-workspace-base.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { UmbNamableWorkspaceContext } from '../types.js'; | ||
import { UmbEntityDetailWorkspaceContextBase } from './entity-detail-workspace-base.js'; | ||
import type { UmbEntityDetailWorkspaceContextCreateArgs } from './types.js'; | ||
import type { UmbNamedEntityModel } from '@umbraco-cms/backoffice/entity'; | ||
import type { UmbDetailRepository } from '@umbraco-cms/backoffice/repository'; | ||
|
||
export abstract class UmbEntityNamedDetailWorkspaceContextBase< | ||
NamedDetailModelType extends UmbNamedEntityModel = UmbNamedEntityModel, | ||
NamedDetailRepositoryType extends | ||
UmbDetailRepository<NamedDetailModelType> = UmbDetailRepository<NamedDetailModelType>, | ||
CreateArgsType extends | ||
UmbEntityDetailWorkspaceContextCreateArgs<NamedDetailModelType> = UmbEntityDetailWorkspaceContextCreateArgs<NamedDetailModelType>, | ||
> | ||
extends UmbEntityDetailWorkspaceContextBase<NamedDetailModelType, NamedDetailRepositoryType, CreateArgsType> | ||
implements UmbNamableWorkspaceContext | ||
{ | ||
// Just for context token safety: | ||
public readonly IS_ENTITY_NAMED_DETAIL_WORKSPACE_CONTEXT = true; | ||
|
||
readonly name = this._data.createObservablePartOfCurrent((data) => data?.name); | ||
|
||
getName() { | ||
return this._data.getCurrent()?.name; | ||
} | ||
|
||
setName(name: string | undefined) { | ||
// We have to cast to Partial because TypeScript doesn't understand that the model has a name property due to generic sub-types | ||
this._data.updateCurrent({ name } as Partial<NamedDetailModelType>); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
.../src/packages/core/workspace/entity-detail/entity-named-detail-workspace.context-token.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { UmbWorkspaceContext } from '../workspace-context.interface.js'; | ||
import type { UmbEntityNamedDetailWorkspaceContextBase } from './entity-named-detail-workspace-base.js'; | ||
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api'; | ||
|
||
export const UMB_ENTITY_NAMED_DETAIL_WORKSPACE_CONTEXT = new UmbContextToken< | ||
UmbWorkspaceContext, | ||
UmbEntityNamedDetailWorkspaceContextBase | ||
>( | ||
'UmbWorkspaceContext', | ||
undefined, | ||
(context): context is UmbEntityNamedDetailWorkspaceContextBase => | ||
(context as UmbEntityNamedDetailWorkspaceContextBase).IS_ENTITY_NAMED_DETAIL_WORKSPACE_CONTEXT, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/Umbraco.Web.UI.Client/src/packages/core/workspace/namable/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export type * from './namable-workspace-context.interface.js'; | ||
export * from './namable-workspace.context-token.js'; |
1 change: 1 addition & 0 deletions
1
src/Umbraco.Web.UI.Client/src/packages/core/workspace/namable/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type * from './namable-workspace-context.interface.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters