feat: add error handling and append slot to VnMultiCheck component
This commit is contained in:
parent
5b4ff55a1d
commit
2fb7947278
|
@ -43,5 +43,6 @@ const checkboxModel = computed({
|
||||||
{{ info }}
|
{{ info }}
|
||||||
</QTooltip>
|
</QTooltip>
|
||||||
</QIcon>
|
</QIcon>
|
||||||
|
<slot name="append"></slot>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -15,7 +15,6 @@ const props = defineProps({
|
||||||
},
|
},
|
||||||
url: {
|
url: {
|
||||||
type: String,
|
type: String,
|
||||||
default: null,
|
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
searchUrl: {
|
searchUrl: {
|
||||||
|
@ -24,6 +23,8 @@ const props = defineProps({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const value = ref(false);
|
const value = ref(false);
|
||||||
|
const menuRef = ref(null);
|
||||||
|
const errorMessage = ref(null);
|
||||||
const rows = ref(0);
|
const rows = ref(0);
|
||||||
const onClick = () => {
|
const onClick = () => {
|
||||||
if (value.value) {
|
if (value.value) {
|
||||||
|
@ -37,7 +38,11 @@ const onClick = () => {
|
||||||
.then(({ data }) => {
|
.then(({ data }) => {
|
||||||
rows.value = data;
|
rows.value = data;
|
||||||
})
|
})
|
||||||
.catch(console.error);
|
.catch(({ response }) => {
|
||||||
|
if (response.data.error.name === 'UserError') {
|
||||||
|
errorMessage.value = t('tooManyResults');
|
||||||
|
} else errorMessage.value = response.data.error.message;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
defineEmits(['update:selected', 'select:all']);
|
defineEmits(['update:selected', 'select:all']);
|
||||||
|
@ -45,36 +50,63 @@ defineEmits(['update:selected', 'select:all']);
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div style="display: flex">
|
<div style="display: flex">
|
||||||
<VnCheckbox v-model="value" @click="$emit('update:selected', value)" />
|
<VnCheckbox v-model="value" @click="$emit('update:selected', value)">
|
||||||
<QBtn
|
<template #append>
|
||||||
|
<QIcon
|
||||||
|
data-cy="btnMultiCheck"
|
||||||
v-if="value && $props.expand"
|
v-if="value && $props.expand"
|
||||||
flat
|
name="expand_more"
|
||||||
dense
|
|
||||||
icon="expand_more"
|
|
||||||
@click="onClick"
|
@click="onClick"
|
||||||
|
class="cursor-pointer"
|
||||||
>
|
>
|
||||||
<QMenu anchor="bottom right" self="top right">
|
<QMenu
|
||||||
<QList>
|
fit
|
||||||
<QItem v-ripple clickable @click="$emit('select:all', toRaw(rows))">
|
anchor="bottom start"
|
||||||
{{ t('Select all', { rows: rows.length }) }}
|
self="top left"
|
||||||
|
ref="menuRef"
|
||||||
|
data-cy="menuMultiCheck"
|
||||||
|
>
|
||||||
|
<QList separator>
|
||||||
|
<QItem
|
||||||
|
data-cy="selectAll"
|
||||||
|
v-ripple
|
||||||
|
clickable
|
||||||
|
@click="
|
||||||
|
$refs.menuRef.hide();
|
||||||
|
$emit('select:all', toRaw(rows));
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<QItemSection>
|
||||||
|
<QItemLabel>
|
||||||
|
<span v-text="t('Select all')" />
|
||||||
|
</QItemLabel>
|
||||||
|
<QItemLabel overline caption>
|
||||||
|
<span
|
||||||
|
v-if="errorMessage"
|
||||||
|
class="text-negative"
|
||||||
|
v-text="errorMessage"
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
v-else
|
||||||
|
v-text="t('records', { rows: rows.length })"
|
||||||
|
/>
|
||||||
|
</QItemLabel>
|
||||||
|
</QItemSection>
|
||||||
</QItem>
|
</QItem>
|
||||||
<slot name="more-options"></slot>
|
<slot name="more-options"></slot>
|
||||||
</QList>
|
</QList>
|
||||||
</QMenu>
|
</QMenu>
|
||||||
</QBtn>
|
</QIcon>
|
||||||
|
</template>
|
||||||
|
</VnCheckbox>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<i18n lang="yml">
|
<i18n lang="yml">
|
||||||
en:
|
en:
|
||||||
Select all: 'Select all ({rows})'
|
tooManyResults: Too many results. Please narrow down your search.
|
||||||
fr:
|
records: '{rows} records'
|
||||||
Select all: 'Sélectionner tout ({rows})'
|
|
||||||
es:
|
es:
|
||||||
Select all: 'Seleccionar todo ({rows})'
|
Select all: Seleccionar todo
|
||||||
de:
|
tooManyResults: Demasiados registros. Restringe la búsqueda.
|
||||||
Select all: 'Alle auswählen ({rows})'
|
records: '{rows} registros'
|
||||||
it:
|
|
||||||
Select all: 'Seleziona tutto ({rows})'
|
|
||||||
pt:
|
|
||||||
Select all: 'Selecionar tudo ({rows})'
|
|
||||||
</i18n>
|
</i18n>
|
||||||
|
|
Loading…
Reference in New Issue