ensure selection fits with options

This commit is contained in:
Niels Lyngsø
2024-03-01 09:59:37 +01:00
parent b49ef90215
commit dc1a2789db
4 changed files with 10 additions and 4 deletions

View File

@@ -26,13 +26,14 @@ export class UmbPickDocumentVariantModalController extends UmbControllerBase {
};
if (modalData.options.length === 0) {
// TODO: What do to when there is no options?
// TODO: What do to when there is no options? [NL]
}
const modalContext = modalManagerContext.open(UMB_DOCUMENT_LANGUAGE_PICKER_MODAL, {
data: modalData,
// We need to turn the selected variant ids into strings for them to be serializable to the value state, in other words the value of a modal cannot hold class instances:
value: { selection: selected.map((x) => x.toString()) ?? [] },
// Make selection unique by filtering out duplicates:
value: { selection: selected.map((x) => x.toString()).filter((v, i, a) => a.indexOf(v) === i) ?? [] },
});
const result = await modalContext.onSubmit().catch(() => undefined);

View File

@@ -36,6 +36,9 @@ export class UmbDocumentVariantPickerModalElement extends UmbModalBaseElement<
async #setInitialSelection() {
let selected = this.value?.selection ?? [];
// Filter selection based on options:
selected = selected.filter((s) => this.data?.options.some((o) => o.unique === s));
if (selected.length === 0) {
const context = await this.getContext(UMB_APP_LANGUAGE_CONTEXT);
const appCulture = context.getAppCulture();

View File

@@ -353,7 +353,10 @@ export class UmbDocumentWorkspaceContext
const activeVariantIds = activeVariants.map((activeVariant) => UmbVariantId.Create(activeVariant));
// TODO: We need to filter the selected array, so it only contains one of each variantId. [NL]
const selected = activeVariantIds.concat(this.#calculateChangedVariants());
const changedVariantIds = this.#calculateChangedVariants();
const selected = activeVariantIds.concat(changedVariantIds);
// Selected can contain entries that are not part of the options, therefor the modal filters selection based on options.
const options = await firstValueFrom(this.variantOptions);
// If there is only one variant, we don't need to open the modal.

View File

@@ -253,7 +253,6 @@ export class UmbDocumentWorkspaceViewInfoElement extends UmbLitElement {
}
async #openTemplatePicker() {
console.log(this._allowedTemplates);
const modal = this.#modalManagerContext?.open(UMB_TEMPLATE_PICKER_MODAL, {
data: {
hideTreeRoot: true,