Skip to content

Commit 63002e4

Browse files
Copilotnielslyngsoe
andcommitted
Refactor routeSetup to use args object for better flexibility
Co-authored-by: nielslyngsoe <[email protected]>
1 parent ee314fe commit 63002e4

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed

src/Umbraco.Web.UI.Client/src/packages/core/router/modal-registration/modal-route-registration.controller.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { IRouterSlot, Params } from '../router-slot/index.js';
22
import { UMB_ROUTE_PATH_ADDENDUM_CONTEXT } from '../contexts/route-path-addendum.context-token.js';
33
import { UMB_ROUTE_CONTEXT } from '../route/route.context-token.js';
44
import { encodeFolderName } from '../encode-folder-name.function.js';
5-
import type { UmbModalRouteRegistration } from './modal-route-registration.interface.js';
5+
import type { UmbModalRouteRegistration, UmbModalRouteSetupArgs } from './modal-route-registration.interface.js';
66
import type {
77
UmbModalConfig,
88
UmbModalContext,
@@ -329,28 +329,22 @@ export class UmbModalRouteRegistrationController<
329329
this.#modalContext = undefined;
330330
};
331331

332-
async routeSetup(
333-
router: IRouterSlot,
334-
modalManagerContext: UmbModalManagerContext,
335-
params: Params,
336-
routeHandler: UmbModalRouteHandler,
337-
routeContextToken: UmbContextToken<any>,
338-
) {
332+
async routeSetup(args: UmbModalRouteSetupArgs) {
339333
// If already open, don't do anything:
340334
if (this.active) return;
341335

342-
const modalData = this.#onSetupCallback ? await this.#onSetupCallback(params) : undefined;
336+
const modalData = this.#onSetupCallback ? await this.#onSetupCallback(args.params) : undefined;
343337
if (modalData !== false) {
344-
const args = {
338+
const modalArgs = {
345339
modal: {},
346340
...modalData,
347-
router,
348-
routeHandler,
349-
routeContextToken,
341+
router: args.router,
342+
routeHandler: args.routeHandler,
343+
routeContextToken: args.routeContextToken,
350344
} as UmbModalContextClassArgs<UmbModalToken<UmbModalTokenData, UmbModalTokenValue>>;
351-
args.modal!.key = this.#key;
345+
modalArgs.modal!.key = this.#key;
352346

353-
this.#modalContext = modalManagerContext.open(this, this.#modalAlias, args);
347+
this.#modalContext = args.modalManagerContext.open(this, this.#modalAlias, modalArgs);
354348
this.#modalContext.onSubmit().then(this.#onSubmit, this.#onReject);
355349
return this.#modalContext;
356350
}

src/Umbraco.Web.UI.Client/src/packages/core/router/modal-registration/modal-route-registration.interface.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import type {
88
} from '@umbraco-cms/backoffice/modal';
99
import type { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
1010

11+
export type UmbModalRouteSetupArgs = {
12+
router: IRouterSlot;
13+
modalManagerContext: UmbModalManagerContext;
14+
params: Params;
15+
routeHandler: UmbModalRouteHandler;
16+
routeContextToken: UmbContextToken<any>;
17+
};
18+
1119
export interface UmbModalRouteRegistration<
1220
UmbModalTokenData extends { [key: string]: any } = { [key: string]: any },
1321
UmbModalTokenValue = any,
@@ -21,11 +29,7 @@ export interface UmbModalRouteRegistration<
2129
open(params: { [key: string]: string | number }, prepend?: string): void;
2230

2331
routeSetup(
24-
router: IRouterSlot,
25-
modalManagerContext: UmbModalManagerContext,
26-
params: Params,
27-
routeHandler: UmbModalRouteHandler,
28-
routeContextToken: UmbContextToken<any>,
32+
args: UmbModalRouteSetupArgs,
2933
): Promise<undefined | UmbModalContext<UmbModalTokenData, UmbModalTokenValue>>;
3034

3135
// eslint-disable-next-line @typescript-eslint/naming-convention

src/Umbraco.Web.UI.Client/src/packages/core/router/route/route.context.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ export class UmbRouteContext extends UmbContextBase {
6969
component: EmptyDiv,
7070
setup: async (component, info) => {
7171
if (!this.#modalContext) return;
72-
const modalContext = await modalRegistration.routeSetup(
73-
this.#modalRouter,
74-
this.#modalContext,
75-
info.match.params,
76-
this.#routeHandler,
77-
UMB_ROUTE_CONTEXT,
78-
);
72+
const modalContext = await modalRegistration.routeSetup({
73+
router: this.#modalRouter,
74+
modalManagerContext: this.#modalContext,
75+
params: info.match.params,
76+
routeHandler: this.#routeHandler,
77+
routeContextToken: UMB_ROUTE_CONTEXT,
78+
});
7979
if (modalContext) {
8080
modalContext._internal_setCurrentModalPath(info.match.fragments.consumed);
8181
}

0 commit comments

Comments
 (0)