Skip to content

Commit

Permalink
Refactored CountSelect.
Browse files Browse the repository at this point in the history
  • Loading branch information
Utar94 committed Apr 18, 2024
1 parent 3cafaf8 commit 65dbde7
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 15 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/departments/DepartmentList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ watch(payload, (payload) => refresh(payload), { deep: true, immediate: true });
<div class="row">
<SearchInput class="col-lg-4" v-model="search" />
<SortSelect class="col-lg-4" :descending="isDescending" :options="sortOptions" v-model="sort" @descending="isDescending = $event" />
<CountSelect class="col-lg-4" :model-value="count.toString()" @update:model-value="count = $event ?? 0" />
<CountSelect class="col-lg-4" :model-value="count" @update:model-value="count = $event ?? 0" />
</div>
<template v-if="departments.length">
<table class="table table-striped">
Expand Down
39 changes: 31 additions & 8 deletions frontend/src/components/shared/CountSelect.vue
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
<script setup lang="ts">
import { TarSelect, parsingUtils, type SelectOptions } from "logitar-vue3-ui";
import { TarSelect, parsingUtils, type SelectOption, type SelectSize } from "logitar-vue3-ui";
import { useI18n } from "vue-i18n";
const { parseNumber } = parsingUtils;
const { t } = useI18n();
const props = withDefaults(defineProps<SelectOptions>(), {
floating: true,
id: "count",
label: "count",
options: () => [{ text: "10" }, { text: "25" }, { text: "50" }, { text: "100" }],
});
const props = withDefaults(
defineProps<{
ariaLabel?: string;
describedBy?: string;
disabled?: boolean | string;
floating?: boolean | string;
id?: string;
label?: string;
modelValue?: number;
multiple?: boolean | string;
name?: string;
options?: SelectOption[];
placeholder?: string;
required?: boolean | string;
size?: SelectSize;
}>(),
{
floating: true,
id: "count",
label: "count",
options: () => [{ text: "10" }, { text: "25" }, { text: "50" }, { text: "100" }],
},
);
defineEmits<{
(e: "update:model-value", value?: number): void;
}>();
</script>

<template>
<TarSelect v-bind="props" :label="t(label)" :options="options" @update:model-value="$emit('update:model-value', parseNumber($event))" />
<TarSelect
v-bind="props"
:aria-label="ariaLabel ? t(ariaLabel) : undefined"
:label="t(label)"
:placeholder="placeholder ? t(placeholder) : undefined"
@update:model-value="$emit('update:model-value', parseNumber($event))"
/>
</template>
2 changes: 1 addition & 1 deletion frontend/src/views/articles/ArticleList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ watch(
@descending="setQuery('isDescending', $event.toString())"
@update:model-value="setQuery('sort', $event ?? '')"
/>
<CountSelect class="col-lg-4" :model-value="count.toString()" @update:model-value="setQuery('count', ($event ?? 10).toString())" />
<CountSelect class="col-lg-4" :model-value="count" @update:model-value="setQuery('count', ($event ?? 10).toString())" />
</div>
<template v-if="articles.length">
<table class="table table-striped">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/banners/BannerList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ watch(
@descending="setQuery('isDescending', $event.toString())"
@update:model-value="setQuery('sort', $event ?? '')"
/>
<CountSelect class="col-lg-4" :model-value="count.toString()" @update:model-value="setQuery('count', ($event ?? 10).toString())" />
<CountSelect class="col-lg-4" :model-value="count" @update:model-value="setQuery('count', ($event ?? 10).toString())" />
</div>
<template v-if="banners.length">
<table class="table table-striped">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/products/ProductList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ watch(
@descending="setQuery('isDescending', $event.toString())"
@update:model-value="setQuery('sort', $event ?? '')"
/>
<CountSelect class="col-lg-4" :model-value="count.toString()" @update:model-value="setQuery('count', ($event ?? 10).toString())" />
<CountSelect class="col-lg-4" :model-value="count" @update:model-value="setQuery('count', ($event ?? 10).toString())" />
</div>
<template v-if="products.length">
<table class="table table-striped">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/receipts/ReceiptListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ watch(
@descending="setQuery('isDescending', $event.toString())"
@update:model-value="setQuery('sort', $event ?? '')"
/>
<CountSelect class="col-lg-4" :model-value="count.toString()" @update:model-value="setQuery('count', ($event ?? 10).toString())" />
<CountSelect class="col-lg-4" :model-value="count" @update:model-value="setQuery('count', ($event ?? 10).toString())" />
</div>
<template v-if="receipts.length">
<ReceiptList :receipts="receipts" />
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/stores/StoreList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ watch(
@descending="setQuery('isDescending', $event.toString())"
@update:model-value="setQuery('sort', $event ?? '')"
/>
<CountSelect class="col-lg-3" :model-value="count.toString()" @update:model-value="setQuery('count', ($event ?? 10).toString())" />
<CountSelect class="col-lg-3" :model-value="count" @update:model-value="setQuery('count', ($event ?? 10).toString())" />
</div>
<template v-if="stores.length">
<table class="table table-striped">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/taxes/TaxList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ watch(
@descending="setQuery('isDescending', $event.toString())"
@update:model-value="setQuery('sort', $event ?? '')"
/>
<CountSelect class="col-lg-3" :model-value="count.toString()" @update:model-value="setQuery('count', ($event ?? 10).toString())" />
<CountSelect class="col-lg-3" :model-value="count" @update:model-value="setQuery('count', ($event ?? 10).toString())" />
</div>
<template v-if="taxes.length">
<table class="table table-striped">
Expand Down

0 comments on commit 65dbde7

Please sign in to comment.