Skip to content

Commit b50391e

Browse files
committed
publish with descendants require mandatory languages
1 parent 60c6366 commit b50391e

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/packages/documents/documents/modals/publish-with-descendants-modal/document-publish-with-descendants-modal.element.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { UmbDocumentVariantState, type UmbDocumentVariantOptionModel } from '../../types.js';
2+
import { isNotPublishedMandatory } from '../utils.js';
23
import type {
34
UmbDocumentPublishWithDescendantsModalData,
45
UmbDocumentPublishWithDescendantsModalValue,
@@ -21,6 +22,9 @@ export class UmbDocumentPublishWithDescendantsModalElement extends UmbModalBaseE
2122
@state()
2223
_options: Array<UmbDocumentVariantOptionModel> = [];
2324

25+
@state()
26+
_hasNotSelectedMandatory?: boolean;
27+
2428
override firstUpdated() {
2529
this.#configureSelectionManager();
2630
}
@@ -29,25 +33,40 @@ export class UmbDocumentPublishWithDescendantsModalElement extends UmbModalBaseE
2933
this.#selectionManager.setMultiple(true);
3034
this.#selectionManager.setSelectable(true);
3135

32-
// Only display variants that are relevant to pick from, i.e. variants that are draft or published with pending changes:
36+
// Only display variants that are relevant to pick from, i.e. variants that are draft, not-published-mandatory or published with pending changes:
3337
this._options =
3438
this.data?.options.filter(
35-
(option) => option.variant && option.variant.state !== UmbDocumentVariantState.NOT_CREATED,
39+
(option) => isNotPublishedMandatory(option) || option.variant?.state !== UmbDocumentVariantState.NOT_CREATED,
3640
) ?? [];
3741

3842
let selected = this.value?.selection ?? [];
3943

4044
// Filter selection based on options:
4145
selected = selected.filter((s) => this._options.some((o) => o.unique === s));
4246

43-
this.#selectionManager.setSelection(selected);
44-
4547
// Additionally select mandatory languages:
48+
// [NL]: I think for now lets make it an active choice to select the languages. If you just made them, they would be selected. So it just to underline the act of actually selecting these languages.
49+
/*
4650
this._options.forEach((variant) => {
4751
if (variant.language?.isMandatory) {
48-
this.#selectionManager.select(variant.unique);
52+
selected.push(variant.unique);
4953
}
5054
});
55+
*/
56+
57+
this.#selectionManager.setSelection(selected);
58+
59+
this.observe(
60+
this.#selectionManager.selection,
61+
(selection: Array<string>) => {
62+
if (!this._options && !selection) return;
63+
64+
//Getting not published mandatory options — the options that are mandatory and not currently published.
65+
const missingMandatoryOptions = this._options.filter(isNotPublishedMandatory);
66+
this._hasNotSelectedMandatory = missingMandatoryOptions.some((option) => !selection.includes(option.unique));
67+
},
68+
'observeSelection',
69+
);
5170
}
5271

5372
#submit() {
@@ -83,6 +102,7 @@ export class UmbDocumentPublishWithDescendantsModalElement extends UmbModalBaseE
83102
<umb-document-variant-language-picker
84103
.selectionManager=${this.#selectionManager}
85104
.variantLanguageOptions=${this._options}
105+
.requiredFilter=${isNotPublishedMandatory}
86106
.pickableFilter=${this.data?.pickableFilter}></umb-document-variant-language-picker>
87107
88108
<uui-form-layout-item>
@@ -99,6 +119,7 @@ export class UmbDocumentPublishWithDescendantsModalElement extends UmbModalBaseE
99119
label="${this.localize.term('buttons_publishDescendants')}"
100120
look="primary"
101121
color="positive"
122+
?disabled=${this._hasNotSelectedMandatory}
102123
@click=${this.#submit}></uui-button>
103124
</div>
104125
</umb-body-layout> `;

0 commit comments

Comments
 (0)