-
-
Notifications
You must be signed in to change notification settings - Fork 304
Migrate CategoryOptions dropdown to KMultiSelect #6092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
abea701
a461724
11094ae
dcaabe2
1f96708
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,39 @@ | ||
| <template> | ||
|
|
||
| <div> | ||
| <DropdownWrapper> | ||
| <KMultiSelect | ||
| v-if="!expanded" | ||
| :value="autocompleteValues" | ||
| :options="categoriesList" | ||
| itemValue="value" | ||
| itemText="text" | ||
| :label="translateMetadataString('category')" | ||
| :autoPromoteParent="false" | ||
| clearable | ||
| :noResultsText="$tr('noCategoryFoundText')" | ||
| :messages="messages" | ||
| @input="onKMultiSelectInput" | ||
| > | ||
| <template #chip="{ option, remove: removeChip }"> | ||
| <span :ref="'category-chip-' + option.value"> | ||
| <KChip | ||
| :text="option.text" | ||
| :removeLabel="$tr('removeCategory', { label: tooltipText(option.value) })" | ||
| close | ||
| @close="removeChip" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ Resolved — addressed in the current code. suggestion: KDS's default chip slot puts
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| @mousedown.native.prevent | ||
| /> | ||
| </span> | ||
| <KTooltip | ||
| :reference="'category-chip-' + option.value" | ||
| :refs="$refs" | ||
| placement="top" | ||
| :text="tooltipText(option.value)" | ||
| /> | ||
| </template> | ||
| </KMultiSelect> | ||
|
|
||
| <DropdownWrapper v-if="expanded"> | ||
| <template #default="{ attach, menuProps }"> | ||
| <VAutocomplete | ||
| :value="autocompleteValues" | ||
|
|
@@ -18,8 +50,8 @@ | |
| :menu-props="{ | ||
| ...menuProps, | ||
| zIndex: 4, | ||
| height: expanded ? 0 : 'auto', | ||
| maxHeight: expanded ? 0 : 300, | ||
| height: 0, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ Resolved — addressed in the current code. suggestion: With the VAutocomplete now behind
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done,removed |
||
| maxHeight: 0, | ||
| }" | ||
| :attach="attach" | ||
| @click:clear="$nextTick(() => removeAll())" | ||
|
|
@@ -44,34 +76,6 @@ | |
| </div> | ||
| </VTooltip> | ||
| </template> | ||
|
|
||
| <template #no-data> | ||
| <VListTile v-if="categoryText && categoryText.trim()"> | ||
| <VListTileContent> | ||
| <VListTileTitle> | ||
| {{ $tr('noCategoryFoundText', { text: categoryText.trim() }) }} | ||
| </VListTileTitle> | ||
| </VListTileContent> | ||
| </VListTile> | ||
| </template> | ||
|
|
||
| <template #item="{ item }"> | ||
| <VListTile | ||
| :value="isSelected(item.value)" | ||
| :class="{ parentOption: !item.value.includes('.') }" | ||
| @mousedown.prevent | ||
| @click="onChange(item.value)" | ||
| > | ||
| <KCheckbox | ||
| :checked="isSelected(item.value)" | ||
| :label="item.text" | ||
| :value="item.value" | ||
| style="margin-top: 10px" | ||
| :style="treeItemStyle(item)" | ||
| :ripple="false" | ||
| /> | ||
| </VListTile> | ||
| </template> | ||
| </VAutocomplete> | ||
| </template> | ||
| </DropdownWrapper> | ||
|
|
@@ -104,13 +108,17 @@ | |
| <script> | ||
|
|
||
| import camelCase from 'lodash/camelCase'; | ||
| import KMultiSelect from 'kolibri-design-system/lib/candidate/multiselect/KMultiSelect'; | ||
| import KChip from 'kolibri-design-system/lib/candidate/multiselect/KChip'; | ||
| import { getSortedCategories } from 'shared/utils/helpers'; | ||
| import { commonStrings } from 'shared/strings/commonStrings'; | ||
| import { communityChannelsStrings } from 'shared/strings/communityChannelsStrings'; | ||
| import DropdownWrapper from 'shared/views/form/DropdownWrapper'; | ||
| import { constantsTranslationMixin, metadataTranslationMixin } from 'shared/mixins'; | ||
|
|
||
| export default { | ||
| name: 'CategoryOptions', | ||
| components: { DropdownWrapper }, | ||
| components: { KMultiSelect, KChip, DropdownWrapper }, | ||
| mixins: [constantsTranslationMixin, metadataTranslationMixin], | ||
| props: { | ||
| /** | ||
|
|
@@ -177,6 +185,34 @@ | |
| option.text.toLowerCase().includes(searchQuery), | ||
| ); | ||
| }, | ||
| messages() { | ||
| const { | ||
| openMenuAction$, | ||
| closeMenuAction$, | ||
| optionsClickableLabel$, | ||
| allOptionsSelectedLabel$, | ||
| allOptionsDeselectedLabel$, | ||
| optionDeselectedLabel$, | ||
| partiallySelectedLabel$, | ||
| optionSelectedLabel$, | ||
| optionRemovedLabel$, | ||
| } = commonStrings; | ||
| const { clearAllAction$ } = communityChannelsStrings; | ||
| return { | ||
| clearText: clearAllAction$, | ||
| open: openMenuAction$, | ||
| close: closeMenuAction$, | ||
| clickable: optionsClickableLabel$, | ||
| allOptionsSelected: allOptionsSelectedLabel$, | ||
| allOptionsDeselected: allOptionsDeselectedLabel$, | ||
| optionDeselected: optionDeselectedLabel$, | ||
| partiallySelected: partiallySelectedLabel$, | ||
| itemsSelected: ({ count }) => this.$tr('itemsSelected', { count }), | ||
| selected: optionSelectedLabel$, | ||
| removed: optionRemovedLabel$, | ||
| cleared: () => this.$tr('allCategoriesCleared'), | ||
| }; | ||
| }, | ||
| }, | ||
| methods: { | ||
| treeItemStyle(item) { | ||
|
|
@@ -201,6 +237,11 @@ | |
| removeAll() { | ||
| this.selected = {}; | ||
| }, | ||
| // Dropdown mode is only rendered when a single node is edited, so every | ||
| // selected category simply applies to all of nodeIds. | ||
| onKMultiSelectInput(newValues) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ Resolved — addressed in the current code. suggestion: The Suggest reducing to the reachable case and reinstating the carryover with the expanded-mode migration that actually needs it: this.selected = Object.fromEntries(newValues.map(value => [value, this.nodeIds]));
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| this.selected = Object.fromEntries(newValues.map(value => [value, this.nodeIds])); | ||
| }, | ||
| tooltipText(optionId) { | ||
| const option = this.categoriesList.find(option => option.value === optionId); | ||
| if (!option) { | ||
|
|
@@ -275,6 +316,9 @@ | |
| }, | ||
| $trs: { | ||
| noCategoryFoundText: 'Category not found', | ||
| itemsSelected: '{count, plural, one {# category selected} other {# categories selected}}', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ Resolved — addressed in the current code. praise: Count kept inside the ICU plural rather than composed alongside the translated string — pluralisation and digit formatting stay under translator control. |
||
| allCategoriesCleared: 'All categories cleared', | ||
| removeCategory: 'Remove {label}', | ||
| }, | ||
| }; | ||
|
|
||
|
|
@@ -283,10 +327,6 @@ | |
|
|
||
| <style lang="scss" scoped> | ||
|
|
||
| .parentOption:not(:first-child) { | ||
| border-top: 1px solid rgba(0, 0, 0, 0.12); | ||
| } | ||
|
|
||
| .checkbox-list-wrapper { | ||
| height: 250px; | ||
| overflow-y: auto; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Resolved — addressed in the current code.
blocking:
KChipgets:textandclosebut noremoveLabel, so its close button falls back to KDS's hard-coded English (KChip/index.vue:107—`Remove ${this.text}`). Every category chip's ✕ is announced asRemove Dancein every locale, andcategoryOptions.spec.js:98asserts that literal, pinning it in place.Fix is one binding plus one new string. Since the
KTooltipistrigger="hover", the full path is mouse-only today — passing it here covers keyboard and screen reader users too::removeLabel="removeCategoryAction$({ label: tooltipText(option.value) })"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed