Skip to content
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

Make Multiselect conditionally rendered #17269

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/src/components/History/Content/ContentItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
:elements-datatypes="item.elements_datatypes" />
<StatelessTags
v-if="!tagsDisabled || hasTags"
class="px-2"
:value="tags"
:disabled="tagsDisabled"
:clickable="filterable"
Expand Down
16 changes: 8 additions & 8 deletions client/src/components/TagsMultiselect/StatelessTags.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { computed } from "vue";
import StatelessTags from "./StatelessTags";

const autocompleteTags = ["#named_user_tag", "abc", "my_tag"];
const toggleButton = ".toggle-button";

const localVue = getLocalVue();

Expand Down Expand Up @@ -65,11 +66,12 @@ describe("StatelessTags", () => {
disabled: false,
});

wrapper.find(toggleButton).trigger("click");
await wrapper.vm.$nextTick();

const multiselect = wrapper.find(".multiselect");

multiselect.find("button").trigger("click");
await wrapper.vm.$nextTick();

const options = multiselect.findAll(".multiselect-option");
const visibleOptions = options.filter((option) => option.isVisible());

Expand All @@ -85,10 +87,9 @@ describe("StatelessTags", () => {
disabled: false,
});

const multiselect = wrapper.find(".multiselect");

multiselect.find("button").trigger("click");
wrapper.find(toggleButton).trigger("click");
await wrapper.vm.$nextTick();
const multiselect = wrapper.find(".multiselect");
await multiselect.find("input").setValue("new_tag");
await wrapper.vm.$nextTick();
multiselect.find(".multiselect-option").trigger("click");
Expand All @@ -103,10 +104,9 @@ describe("StatelessTags", () => {
disabled: false,
});

const multiselect = wrapper.find(".multiselect");

multiselect.find("button").trigger("click");
wrapper.find(toggleButton).trigger("click");
await wrapper.vm.$nextTick();
const multiselect = wrapper.find(".multiselect");
await multiselect.find("input").setValue(":illegal_tag");
await wrapper.vm.$nextTick();

Expand Down
179 changes: 93 additions & 86 deletions client/src/components/TagsMultiselect/StatelessTags.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import { library } from "@fortawesome/fontawesome-svg-core";
import { faCheck, faPlus, faTags, faTimes } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { BButton } from "bootstrap-vue";
import type { Ref } from "vue";
import { computed, ref } from "vue";
import { computed, nextTick, ref } from "vue";
import Multiselect from "vue-multiselect";

import { useToast } from "@/composables/toast";
Expand All @@ -20,7 +21,6 @@ interface StatelessTagsProps {
useToggleLink?: boolean;
maxVisibleTags?: number;
placeholder?: string;
noPadding?: boolean;
}

const props = withDefaults(defineProps<StatelessTagsProps>(), {
Expand Down Expand Up @@ -68,8 +68,9 @@ const { editing, ariaExpanded, onOpen, onClose } = useMultiselect();

const multiselectElement: Ref<Multiselect | null> = ref(null);

function openMultiselect() {
//@ts-ignore bad library types
async function openMultiselect() {
editing.value = true;
await nextTick();
multiselectElement.value?.activate();
}

Expand Down Expand Up @@ -110,67 +111,82 @@ function onTagClicked(tag: string) {
</script>

<template>
<div class="stateless-tags" :class="{ 'px-1': !props.noPadding }">
<Multiselect
v-if="!disabled"
ref="multiselectElement"
open-direction="bottom"
:placeholder="props.placeholder"
:value="tags"
:options="userTags"
:multiple="true"
:taggable="true"
:close-on-select="false"
:aria-expanded="ariaExpanded"
@tag="onAddTag"
@input="onInput"
@open="onOpen"
@close="onClose">
<template v-slot:tag="{ option, search }">
<Tag
:option="option"
:search="search"
:editable="true"
:clickable="props.clickable"
@deleted="onDelete"
@click="onTagClicked"></Tag>
</template>

<template v-slot:noOptions>
<span class="multiselect-option">Type to add new tag</span>
</template>

<template v-slot:caret>
<b-button v-if="!editing" class="toggle-button" variant="link" tabindex="-1" @click="openMultiselect">
<div class="stateless-tags">
<div v-if="!disabled">
<div v-if="!editing" class="tags-edit">
<div class="interactive-tags">
<Tag
v-for="tag in tags"
:key="tag"
:option="tag"
:editable="true"
:clickable="props.clickable"
@deleted="onDelete"
@click="onTagClicked"></Tag>
</div>
<button class="toggle-button" tabindex="-1" @click="openMultiselect">
{{ props.placeholder }}
<FontAwesomeIcon icon="fa-tags" />
</b-button>
</template>

<template v-slot:option="{ option }">
<span class="multiselect-option" :class="{ invalid: !isValid(option) }">
<span>{{ option.label ?? option }}</span>
<span v-if="tags.includes(option)" class="float-right">
<span class="info">
<FontAwesomeIcon class="check-icon" icon="fa-check" fixed-width />
</span>

<span class="info highlighted">
<FontAwesomeIcon class="times-icon" icon="fa-times" fixed-width />
<span class="sr-only">remove tag</span>
</button>
</div>
<Multiselect
v-else
ref="multiselectElement"
open-direction="bottom"
:placeholder="props.placeholder"
:value="tags"
:options="userTags"
:multiple="true"
:taggable="true"
:close-on-select="false"
:aria-expanded="ariaExpanded"
@tag="onAddTag"
@input="onInput"
@open="onOpen"
@close="onClose">
<template v-slot:tag="{ option, search }">
<Tag
:option="option"
:search="search"
:editable="true"
:clickable="props.clickable"
@deleted="onDelete"
@click="onTagClicked"></Tag>
</template>

<template v-slot:noOptions>
<span class="multiselect-option">Type to add new tag</span>
</template>

<template v-slot:caret>
<!-- render nothing -->
</template>

<template v-slot:option="{ option }">
<span class="multiselect-option" :class="{ invalid: !isValid(option) }">
<span>{{ option.label ?? option }}</span>
<span v-if="tags.includes(option)" class="float-right">
<span class="info">
<FontAwesomeIcon class="check-icon" icon="fa-check" fixed-width />
</span>

<span class="info highlighted">
<FontAwesomeIcon class="times-icon" icon="fa-times" fixed-width />
<span class="sr-only">remove tag</span>
</span>
</span>
</span>
<span v-else class="float-right">
<span class="info highlighted">
<FontAwesomeIcon class="plus-icon" icon="fa-plus" fixed-width />
<span class="sr-only">add tag</span>
<span v-else class="float-right">
<span class="info highlighted">
<FontAwesomeIcon class="plus-icon" icon="fa-plus" fixed-width />
<span class="sr-only">add tag</span>
</span>
</span>
</span>
</span>
</template>
</Multiselect>
</template>
</Multiselect>
</div>

<div v-else :class="{ 'pl-1': !props.noPadding, 'pb-2': !props.noPadding }">
<div v-else>
<div class="d-inline">
<Tag
v-for="tag in trimmedTags"
Expand All @@ -179,14 +195,14 @@ function onTagClicked(tag: string) {
:editable="false"
:clickable="props.clickable"
@click="onTagClicked"></Tag>
<b-button
<BButton
v-if="slicedTags.length > 0 && !toggledOpen"
:id="toggleButtonId"
variant="link"
class="toggle-link"
@click="() => (toggledOpen = true)">
{{ slicedTags.length }} more...
</b-button>
</BButton>

<b-tooltip
v-if="slicedTags.length > 0 && !toggledOpen"
Expand Down Expand Up @@ -226,6 +242,20 @@ function onTagClicked(tag: string) {
}
}

&:deep(.multiselect) .multiselect__input,
.toggle-button {
font-size: $font-size-base;
color: $text-color;
text-decoration: none;
padding: 0 0.25rem;
background: none;
cursor: text;
text-align: left;
margin: 0;
border: none;
width: 100%;
}

&:deep(.multiselect) {
min-height: unset;
display: flex;
Expand All @@ -234,7 +264,7 @@ function onTagClicked(tag: string) {
.multiselect__select {
top: unset;
bottom: 0;
padding: 0 0.25rem;
padding: 0;
z-index: 1;
height: $font-size-base * 2;

Expand All @@ -252,7 +282,7 @@ function onTagClicked(tag: string) {
}

.multiselect__tags {
padding: 0 0.25rem;
padding: 0;
background: none;
font-size: $font-size-base;
border: none;
Expand All @@ -263,36 +293,13 @@ function onTagClicked(tag: string) {
top: 100%;
z-index: 800;
width: calc(100% - 4px);
left: 2px;

box-shadow: 0 0 6px 0 rgba(3, 0, 34, 0.048), 0 0 4px 0 rgba(3, 0, 34, 0.185);
}

&.multiselect--above .multiselect__content-wrapper {
top: unset;
}

.multiselect__input,
.toggle-button {
font-size: $font-size-base;
color: $text-color;
text-decoration: none;
padding: 0;
background: none;
cursor: text;
text-align: left;
margin: 0;
border: none;
}

.multiselect__input {
padding-left: 0.25rem;
}

.toggle-button {
padding-left: 0.5rem;
}

// built in option class
.multiselect__option {
min-height: unset;
Expand Down
6 changes: 3 additions & 3 deletions client/src/utils/navigation/navigation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ history_panel:
tag_editor:
selectors:
_: '${scope} .details .stateless-tags'
toggle: '${_} .toggle-link'
toggle: '${_} .toggle-button'
display: '${_} .tag span'
input: '${_} input'
tag_area: '${_} .multiselect__tags'
Expand Down Expand Up @@ -262,7 +262,7 @@ history_panel:
title_input: '.dataset-collection-panel .controls .title input'
subtitle: '.dataset-collection-panel .controls .title .subtitle'
elements_warning: '.dataset-collection-panel .controls .elements-warning'
tag_area_button: '.details .stateless-tags .multiselect button'
tag_area_button: '.details .stateless-tags .toggle-button'
tag_area_input: '.details .stateless-tags .multiselect input'
list_items: '.dataset-collection-panel .listing .content-item'
back_to_history: svg[data-description="back to history"]
Expand All @@ -279,7 +279,7 @@ history_panel:
empty_message: '.empty-message'
size: '.history-size'
tag_area: '.details .stateless-tags'
tag_area_button: '.details .stateless-tags .multiselect button'
tag_area_button: '.details .stateless-tags .toggle-button'
tag_area_input: '.details .stateless-tags .multiselect input'
tag_close_btn: '.tags-display .tag-delete-button'
tags: '.tag span'
Expand Down
Loading