Handle vary by segment variant-entires (#20191)

* refactor code

* display language name for empty names

* ensure all culture variants when entering a segment-shared value, shared across cultures

* Revert parts of "ensure all culture variants when entering a segment-shared value, shared across cultures"

This reverts commit 0e64f7269574baaffa11c5688e236642c7561f15.
This commit is contained in:
Niels Lyngsø
2025-10-02 14:51:34 +02:00
committed by GitHub
parent 436be6ec3f
commit b35db9cb5b
4 changed files with 28 additions and 9 deletions

View File

@@ -89,6 +89,7 @@ export class UmbContentWorkspaceDataManager<
const currentData = this.getCurrent();
if (!currentData) throw new Error('Data is missing');
// If varies by segment:
if (!variantId.isSegmentInvariant()) {
// The server requires a segment name. It doesn't matter what it is as long as it is not empty. The server will overwrite it with the name of the default.
update = { ...update, name: 'Segment' } as ModelVariantType;

View File

@@ -83,10 +83,14 @@ export class UmbElementWorkspaceDataManager<ModelType extends UmbElementDetailMo
} else {
variantsToStore = [...selectedVariants, invariantVariantId];
}
const data = this.getCurrent();
if (!data) throw new Error('Current data is missing');
//if (!data.unique) throw new Error('Unique of current data is missing');
// If we vary by segment we need to save all segments for a selected culture.
// And all segments for the invariant culture.
if (this._variesBySegment === true) {
const dataSegments = this.getCurrent()!.values.map((x) => x.segment);
const dataSegments = data.values.map((x) => x.segment).filter((x) => x) as Array<string>;
variantsToStore = [
...variantsToStore,
...dataSegments.flatMap((segment) => variantsToStore.map((variant) => variant.toSegment(segment))),
@@ -98,12 +102,7 @@ export class UmbElementWorkspaceDataManager<ModelType extends UmbElementDetailMo
];
}
const data = this.getCurrent();
if (!data) throw new Error('Current data is missing');
//if (!data.unique) throw new Error('Unique of current data is missing');
const persistedData = this.getPersisted();
return await new UmbMergeContentVariantDataController(this).process(
persistedData,
data,

View File

@@ -672,8 +672,23 @@ export abstract class UmbContentDetailWorkspaceContextBase<
// TODO: fix type error
this._data.updateCurrent({ values });
// TODO: Ideally we should move this type of logic to the act of saving [NL]
this._data.ensureVariantData(variantId);
/**
* Handling of Not-Culture but Segment variant properties: [NL]
* We need to ensure variant-entries across all culture variants for the given segment variant, when er property is configured to vary by segment but not culture.
* This is the only different case, in all other cases its fine to just target the given variant.
*/
if (this.getVariesByCulture() && property.variesByCulture === false && property.variesBySegment === true) {
// get all culture options:
const cultureOptions = await firstValueFrom(this.variantOptions);
for (const cultureOption of cultureOptions) {
if (cultureOption.segment === variantId.segment) {
this._data.ensureVariantData(UmbVariantId.Create(cultureOption));
}
}
} else {
// otherwise we know the property variant-id will be matching with a variant:
this._data.ensureVariantData(variantId);
}
}
this.finishPropertyValueChange();
}

View File

@@ -497,7 +497,11 @@ export class UmbWorkspaceSplitViewVariantSelectorElement<
return variantOption?.segmentInfo?.name ?? this._labelDefault;
}
return variantOption.variant?.name ?? variantOption.language.name;
if (variantOption.variant?.name && variantOption.variant?.name.trim() !== '') {
return variantOption.variant?.name;
}
return variantOption.language.name;
}
#getVariantSpecInfo(variantOption: VariantOptionModelType | undefined) {