Merge branch 'bugfix/input-section' into feature/Section-User-Permission

This commit is contained in:
Mads Rasmussen
2024-03-12 09:10:49 +01:00
committed by GitHub
11 changed files with 68 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
export * from './components/index.js';
export * from './content-type-container-structure-helper.class.js';
export * from './content-type-property-structure-helper.class.js';
export * from './content-type-structure-manager.class.js';
export * from './repository/index.js';
export * from './types.js';
export * from './components/index.js';
export * from './structure/index.js';

View File

@@ -0,0 +1,46 @@
import { expect } from '@open-wc/testing';
import { createRoutePathBuilder } from './generate-route-path-builder.function.js';
describe('createRoutePathBuilder', () => {
it('should return a function that builds a route path without parameters', () => {
const buildPath = createRoutePathBuilder('test/path');
expect(buildPath(null)).to.eq('/test/path/');
});
it('should return a function that builds a route path with parameters', () => {
const buildPath = createRoutePathBuilder(':param0/test/:param1/path/:param2');
expect(buildPath({ param0: 'value0', param1: 'value1', param2: 'value2' })).to.eq(
'/value0/test/value1/path/value2/',
);
});
it('should convert number parameters to strings', () => {
const buildPath = createRoutePathBuilder('test/:param1/path/:param2');
expect(buildPath({ param1: 123, param2: 456 })).to.eq('/test/123/path/456/');
});
it('should not consider route segments that resembles parameters as parameters', () => {
const buildPath = createRoutePathBuilder('test/uc:store/path');
expect(buildPath({ someOtherParam: 'test' })).to.eq('/test/uc:store/path/');
});
it('should support multiple parameters with the same name', () => {
const buildPath = createRoutePathBuilder('test/:param1/path/:param1');
expect(buildPath({ param1: 'value1' })).to.eq('/test/value1/path/value1/');
});
it('should not consider parameters that are not in the params object', () => {
const buildPath = createRoutePathBuilder('test/:param1/path/:param2');
expect(buildPath({ param1: 'value1' })).to.eq('/test/value1/path/:param2/');
});
it('should support complex objects as parameters with a custom toString method', () => {
const buildPath = createRoutePathBuilder('test/:param1/path/:param2');
const obj = {
toString() {
return 'value1';
},
};
expect(buildPath({ param1: obj, param2: 'value2' })).to.eq('/test/value1/path/value2/');
});
});

View File

@@ -1,17 +1,18 @@
/* eslint-disable */
import { stripSlash } from '@umbraco-cms/backoffice/external/router-slot'; // This must only include the util to avoid side effects of registering the route element.
const PARAM_IDENTIFIER = /:([^\\/]+)/g;
const PARAM_IDENTIFIER = /:([^\/]+)/g;
export function createRoutePathBuilder(path: string) {
return (params: { [key: string]: string | number } | null) => {
return (params: { [key: string]: string | number | { toString: () => string } } | null) => {
return (
'/' +
stripSlash(
params
? path.replace(PARAM_IDENTIFIER, (substring: string, ...args: string[]) => {
return params[args[0]].toString();
})
? path.replace(PARAM_IDENTIFIER, (_substring: string, ...args: string[]) => {
// Replace the parameter with the value from the params object or the parameter name if it doesn't exist (args[0] is the parameter name without the colon)
return typeof params[args[0]] !== 'undefined' ? params[args[0]].toString() : `:${args[0]}`;
})
: path,
) +
'/'

View File

@@ -149,7 +149,6 @@ export class UmbRouteContext extends UmbControllerBase {
: this.#routerActiveLocalPath + '/'
: '';
const localPath = routeBasePath + routeActiveLocalPath + modalRegistration.generateModalPath();
const urlBuilder = createRoutePathBuilder(localPath);
modalRegistration._internal_setRouteBuilder(urlBuilder);

View File

@@ -70,6 +70,10 @@ export class UmbRouterSlotElement extends UmbLitElement {
return this.#router.constructAbsolutePath('') || '';
}
protected _constructLocalRouterPath() {
return this.#router.match?.fragments.consumed ?? '';
}
connectedCallback() {
super.connectedCallback();
// Currently we have to set this every time as RouteSlot looks for its parent every-time it is connected. Aka it has not way to explicitly set the parent.
@@ -101,7 +105,7 @@ export class UmbRouterSlotElement extends UmbLitElement {
this.#routeContext._internal_routerGotBasePath(this._routerPath);
this.dispatchEvent(new UmbRouterSlotInitEvent());
const newActiveLocalPath = this.#router.match?.route.path;
const newActiveLocalPath = this._constructLocalRouterPath();
if (this._activeLocalPath !== newActiveLocalPath) {
this._activeLocalPath = newActiveLocalPath;
this.#routeContext._internal_routerGotActiveLocalPath(this._activeLocalPath);
@@ -112,11 +116,14 @@ export class UmbRouterSlotElement extends UmbLitElement {
private _onNavigationChanged = (event?: any) => {
if (event.detail.slot === this.#router) {
this._activeLocalPath = event.detail.match.route.path;
this.#routeContext._internal_routerGotActiveLocalPath(this._activeLocalPath);
this.dispatchEvent(new UmbRouterSlotChangeEvent());
const newActiveLocalPath = this._constructLocalRouterPath();
if (this._activeLocalPath !== newActiveLocalPath) {
this._activeLocalPath = newActiveLocalPath;
this.#routeContext._internal_routerGotActiveLocalPath(newActiveLocalPath);
this.dispatchEvent(new UmbRouterSlotChangeEvent());
}
} else if (event.detail.slot === this.#modalRouter) {
const newActiveModalLocalPath = event.detail.match.route.path;
const newActiveModalLocalPath = this.#modalRouter.match?.fragments.consumed ?? '';
this.#routeContext._internal_modalRouterChanged(newActiveModalLocalPath);
}
};

View File

@@ -1,8 +1,4 @@
import {
UMB_DATA_TYPE_ENTITY_TYPE,
UMB_DATA_TYPE_FOLDER_ENTITY_TYPE,
UMB_DATA_TYPE_ROOT_ENTITY_TYPE,
} from '../../entity.js';
import { UMB_DATA_TYPE_FOLDER_ENTITY_TYPE, UMB_DATA_TYPE_ROOT_ENTITY_TYPE } from '../../entity.js';
import type { ManifestTypes } from '@umbraco-cms/backoffice/extension-registry';
export const manifests: Array<ManifestTypes> = [
@@ -11,7 +7,7 @@ export const manifests: Array<ManifestTypes> = [
kind: 'reloadTreeItemChildren',
alias: 'Umb.EntityAction.DataType.Tree.ReloadChildrenOf',
name: 'Reload Data Type Tree Item Children Entity Action',
forEntityTypes: [UMB_DATA_TYPE_ENTITY_TYPE, UMB_DATA_TYPE_ROOT_ENTITY_TYPE, UMB_DATA_TYPE_FOLDER_ENTITY_TYPE],
forEntityTypes: [UMB_DATA_TYPE_ROOT_ENTITY_TYPE, UMB_DATA_TYPE_FOLDER_ENTITY_TYPE],
meta: {},
},
];