Implement context base for a few last contexts (#18865)

* do not destroy instance

* UmbDashboardHealthCheckElement

* correct last contexts to use context-base

* informing user that Umb.Condition.MenuAlias does not work

* parse host to Section Context
This commit is contained in:
Niels Lyngsø
2025-03-31 10:02:25 +02:00
committed by GitHub
parent 3359562e32
commit ae87f9ccd4
16 changed files with 70 additions and 67 deletions

View File

@@ -1,17 +1,19 @@
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbNumberState } from '@umbraco-cms/backoffice/observable-api';
// The Example Workspace Context Controller:
export class WorkspaceContextCounter extends UmbControllerBase {
export class WorkspaceContextCounterElement extends UmbContextBase<
WorkspaceContextCounterElement,
typeof EXAMPLE_COUNTER_CONTEXT
> {
// We always keep our states private, and expose the values as observables:
#counter = new UmbNumberState(0);
readonly counter = this.#counter.asObservable();
constructor(host: UmbControllerHost) {
super(host, EXAMPLE_COUNTER_CONTEXT.toString());
this.provideContext(EXAMPLE_COUNTER_CONTEXT, this);
super(host, EXAMPLE_COUNTER_CONTEXT);
}
// Lets expose methods to update the state:
@@ -21,10 +23,10 @@ export class WorkspaceContextCounter extends UmbControllerBase {
}
// Declare a api export, so Extension Registry can initialize this class:
export const api = WorkspaceContextCounter;
export const api = WorkspaceContextCounterElement;
// Declare a Context Token that other elements can use to request the WorkspaceContextCounter:
export const EXAMPLE_COUNTER_CONTEXT = new UmbContextToken<WorkspaceContextCounter>(
export const EXAMPLE_COUNTER_CONTEXT = new UmbContextToken<WorkspaceContextCounterElement>(
'UmbWorkspaceContext',
'example.workspaceContext.counter',
);