wip loading segment data

This commit is contained in:
Mads Rasmussen
2025-03-25 21:42:29 +01:00
parent 21a23b8057
commit 45ff3c3a6f
21 changed files with 152 additions and 1 deletions

View File

@@ -88,6 +88,7 @@
"./script": "./dist-cms/packages/templating/scripts/index.js",
"./search": "./dist-cms/packages/search/index.js",
"./section": "./dist-cms/packages/core/section/index.js",
"./segment": "./dist-cms/packages/core/segment/index.js",
"./server-file-system": "./dist-cms/packages/core/server-file-system/index.js",
"./settings": "./dist-cms/packages/settings/index.js",
"./sorter": "./dist-cms/packages/core/sorter/index.js",

View File

@@ -5,6 +5,7 @@ import type { UmbContentVariantPickerData, UmbContentVariantPickerValue } from '
import type { UmbContentPropertyDatasetContext } from '../property-dataset-context/index.js';
import type { UmbContentValidationRepository } from '../repository/content-validation-repository.interface.js';
import type { UmbContentWorkspaceContext } from './content-workspace-context.interface.js';
import { UmbContentDetailValidationPathTranslator } from './content-detail-validation-path-translator.js';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import type { UmbDetailRepository, UmbDetailRepositoryConstructor } from '@umbraco-cms/backoffice/repository';
import {
@@ -51,7 +52,7 @@ import {
type UmbPropertyTypePresetModel,
type UmbPropertyTypePresetModelTypeModel,
} from '@umbraco-cms/backoffice/property';
import { UmbContentDetailValidationPathTranslator } from './content-detail-validation-path-translator.js';
import { UmbSegmentCollectionRepository, type UmbSegmentCollectionItemModel } from '@umbraco-cms/backoffice/segment';
export interface UmbContentDetailWorkspaceContextArgs<
DetailModelType extends UmbContentDetailModel<VariantModelType>,
@@ -140,6 +141,9 @@ export abstract class UmbContentDetailWorkspaceContextBase<
*/
public readonly languages = this.#languages.asObservable();
#segmentRepository = new UmbSegmentCollectionRepository(this);
#segments = new UmbArrayState<UmbSegmentCollectionItemModel>([], (x) => x.unique);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// TODO: fix type error

View File

@@ -82,6 +82,7 @@ export class UmbWorkspaceSplitViewVariantSelectorElement<
workspaceContext.variantOptions,
(variantOptions) => {
this._variantOptions = (variantOptions as Array<VariantOptionModelType>).sort(this._variantSorter);
debugger;
this.#setReadOnlyCultures();
},
'_observeVariantOptions',

View File

@@ -0,0 +1 @@
export * from './repository/constants.js';

View File

@@ -0,0 +1 @@
export { UmbSegmentCollectionRepository } from './repository/index.js';

View File

@@ -0,0 +1,3 @@
import { manifests as collectionRepositoryManifests } from './repository/manifests.js';
export const manifests: Array<UmbExtensionManifest> = [...collectionRepositoryManifests];

View File

@@ -0,0 +1 @@
export const UMB_SEGMENT_COLLECTION_REPOSITORY_ALIAS = 'Umb.Repository.SegmentCollection';

View File

@@ -0,0 +1,2 @@
export { UMB_SEGMENT_COLLECTION_REPOSITORY_ALIAS } from './constants.js';
export { UmbSegmentCollectionRepository } from './segment-collection.repository.js';

View File

@@ -0,0 +1,10 @@
import { UMB_SEGMENT_COLLECTION_REPOSITORY_ALIAS } from './constants.js';
export const manifests: Array<UmbExtensionManifest> = [
{
type: 'repository',
alias: UMB_SEGMENT_COLLECTION_REPOSITORY_ALIAS,
name: 'Segment Collection Repository',
api: () => import('./segment-collection.repository.js'),
},
];

View File

@@ -0,0 +1,21 @@
import type { UmbSegmentCollectionFilterModel } from '../types.js';
import { UmbSegmentCollectionServerDataSource } from './segment-collection.server.data-source.js';
import type { UmbSegmentCollectionDataSource } from './types.js';
import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';
import type { UmbCollectionRepository } from '@umbraco-cms/backoffice/collection';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
export class UmbSegmentCollectionRepository extends UmbRepositoryBase implements UmbCollectionRepository {
#collectionSource: UmbSegmentCollectionDataSource;
constructor(host: UmbControllerHost) {
super(host);
this.#collectionSource = new UmbSegmentCollectionServerDataSource(host);
}
async requestCollection(filter: UmbSegmentCollectionFilterModel) {
return this.#collectionSource.getCollection(filter);
}
}
export default UmbSegmentCollectionRepository;

View File

@@ -0,0 +1,43 @@
import type { UmbSegmentCollectionFilterModel } from '../types.js';
import { UMB_SEGMENT_ENTITY_TYPE } from '../../entity.js';
import type { UmbSegmentCollectionItemModel } from './types.js';
import type { UmbCollectionDataSource } from '@umbraco-cms/backoffice/collection';
import { SegmentService } from '@umbraco-cms/backoffice/external/backend-api';
import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
/**
* A data source that fetches the language collection data from the server.
* @class UmbLanguageCollectionServerDataSource
* @implements {UmbCollectionDataSource}
*/
export class UmbSegmentCollectionServerDataSource
extends UmbControllerBase
implements UmbCollectionDataSource<UmbSegmentCollectionItemModel>
{
/**
* Gets the language collection filtered by the given filter.
* @param {UmbSegmentCollectionFilterModel} filter
* @returns {*}
* @memberof UmbLanguageCollectionServerDataSource
*/
async getCollection(filter: UmbSegmentCollectionFilterModel) {
const { data, error } = await tryExecuteAndNotify(this, SegmentService.getSegment(filter));
if (data) {
const items = data.items.map((item) => {
const model: UmbSegmentCollectionItemModel = {
entityType: UMB_SEGMENT_ENTITY_TYPE,
unique: item.alias,
alias: item.alias,
};
return model;
});
return { data: { items, total: data.total } };
}
return { error };
}
}

View File

@@ -0,0 +1,13 @@
import type { UmbSegmentCollectionFilterModel } from '../types.js';
import type { UmbCollectionDataSource } from '@umbraco-cms/backoffice/collection';
export type UmbSegmentCollectionDataSource = UmbCollectionDataSource<
UmbSegmentCollectionItemModel,
UmbSegmentCollectionFilterModel
>;
export interface UmbSegmentCollectionItemModel {
entityType: string;
unique: string;
alias: string;
}

View File

@@ -0,0 +1,4 @@
export interface UmbSegmentCollectionFilterModel {
skip?: number;
take?: number;
}

View File

@@ -0,0 +1,5 @@
export * from './repository/constants.js';
export { UMB_SEGMENT_ENTITY_TYPE as UMB_LANGUAGE_ENTITY_TYPE, UMB_LANGUAGE_ROOT_ENTITY_TYPE } from './entity.js';
export { UMB_APP_LANGUAGE_CONTEXT } from './global-contexts/app-language.context-token.js';
export { UMB_LANGUAGE_ACCESS_WORKSPACE_CONTEXT } from './permissions/language-access.workspace.context-token.js';

View File

@@ -0,0 +1,2 @@
export const UMB_SEGMENT_ENTITY_TYPE = 'segment';
export type UmbSegmentEntityType = typeof UMB_SEGMENT_ENTITY_TYPE;

View File

@@ -0,0 +1,4 @@
export * from './constants.js';
export * from './repository/index.js';
export type * from './types.js';

View File

@@ -0,0 +1,3 @@
import { manifests as repositoryManifests } from './repository/manifests.js';
export const manifests: Array<UmbExtensionManifest> = [...repositoryManifests];

View File

@@ -0,0 +1,10 @@
import type { UmbSegmentEntityType } from './entity.js';
export type { UmbSegmentEntityType } from './entity.js';
export type * from './repository/types.js';
export interface UmbSegmentDetailModel {
entityType: UmbSegmentEntityType;
unique: string;
alias: string;
}

View File

@@ -0,0 +1,9 @@
export const name = 'Umbraco.Core.Segment';
export const extensions = [
{
name: 'Segment Bundle',
alias: 'Umb.Bundle.Segment',
type: 'bundle',
js: () => import('./manifests.js'),
},
];

View File

@@ -0,0 +1,12 @@
import { defineConfig } from 'vite';
import { rmSync } from 'fs';
import { getDefaultConfig } from '../../vite-config-base';
const dist = '../../../dist-cms/packages/segment';
// delete the unbundled dist folder
rmSync(dist, { recursive: true, force: true });
export default defineConfig({
...getDefaultConfig({ dist }),
});

View File

@@ -117,6 +117,7 @@ DON'T EDIT THIS FILE DIRECTLY. It is generated by /devops/tsconfig/index.js
"@umbraco-cms/backoffice/script": ["./src/packages/templating/scripts/index.ts"],
"@umbraco-cms/backoffice/search": ["./src/packages/search/index.ts"],
"@umbraco-cms/backoffice/section": ["./src/packages/core/section/index.ts"],
"@umbraco-cms/backoffice/segment": ["./src/packages/core/segment/index.ts"],
"@umbraco-cms/backoffice/server-file-system": ["./src/packages/core/server-file-system/index.ts"],
"@umbraco-cms/backoffice/settings": ["./src/packages/settings/index.ts"],
"@umbraco-cms/backoffice/sorter": ["./src/packages/core/sorter/index.ts"],