Skip to content

Commit

Permalink
chore: make multiRemove button disabled when nothing's selected #356
Browse files Browse the repository at this point in the history
  • Loading branch information
bsilkyn committed May 16, 2024
1 parent 48e913d commit 31985e8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
8 changes: 5 additions & 3 deletions frontend/src/components/admin/LazyDataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const props = defineProps<{
}>();
/* Emits */
const emit = defineEmits(['select'])
const emit = defineEmits(['select']);
/* Injections */
const { t } = useI18n();
Expand Down Expand Up @@ -62,19 +62,21 @@ const onSelectAllChange = (event: DataTableSelectAllChangeEvent): void => {
props.get().then(() => {
selectAll.value = true;
selected.value = props.entities;
emit('select', selected.value);
});
} else {
selectAll.value = false;
selected.value = [];
emit('select', selected.value);
}
};
const onRowSelect = (): void => {
selectAll.value = selected.value?.length === (props.pagination?.count ?? 0);
emit('select');
emit('select', selected.value);
};
const onRowUnselect = (): void => {
selectAll.value = false;
emit('select');
emit('select', selected.value);
};
defineExpose({ fetch });
Expand Down
32 changes: 21 additions & 11 deletions frontend/src/views/admin/DockerImagesView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import LazyDataTable from '@/components/admin/LazyDataTable.vue';
import { useDockerImages } from '@/composables/services/docker.service.ts';
import { useFilter } from '@/composables/filters/filter.ts';
import { useI18n } from 'vue-i18n';
import { computed, ref} from 'vue';
import { ref } from 'vue';
import { useRoute } from 'vue-router';
import { DockerImage } from '@/types/DockerImage.ts';
import { getDockerImageFilters } from '@/types/filter/Filter.ts';
Expand All @@ -23,8 +23,15 @@ import IconField from 'primevue/iconfield';
/* Injection */
const { t } = useI18n();
const { query } = useRoute();
const { pagination, dockerImages, getDockerImages, searchDockerImages, patchDockerImage, createDockerImage, deleteDockerImage } =
useDockerImages();
const {
pagination,
dockerImages,
getDockerImages,
searchDockerImages,
patchDockerImage,
createDockerImage,
deleteDockerImage,
} = useDockerImages();
const { filter, onFilter } = useFilter(getDockerImageFilters(query));
const dataTable = ref();
Expand All @@ -35,9 +42,7 @@ const addItem = ref<DockerImage>(DockerImage.blankDockerImage());
const selectOptions = ref(['admin.list', 'admin.add']);
const selected = ref<string>(t(selectOptions.value[0]));
const multiRemove = computed(() => {
})
const multiRemove = ref<boolean>(false);
const columns = ref([
{ field: 'id', header: 'admin.id' },
Expand All @@ -51,7 +56,7 @@ const columns = ref([
const showSafetyGuard = ref<boolean>(false);
const safetyGuardFunction = ref<() => Promise<void>>(async () => {});
const safetyGuardCleanup = async (): Promise<void> => {
const safetyGuardCleanup = async (): Promise<void> => {
showSafetyGuard.value = false;
await safetyGuardFunction.value();
await dataTable.value.fetch();
Expand All @@ -74,10 +79,14 @@ const toggleSafetyGuardRemove = (data: DockerImage): void => {
editItem.value = data;
safetyGuardFunction.value = removeItem;
showSafetyGuard.value = true;
}
};
const removeItem = async (): Promise<void> => {
await deleteDockerImage(editItem.value.id);
}
};
const onSelect = (selected: any[] | null): void => {
multiRemove.value = (selected?.length === undefined || selected?.length === 0) ?? false;
};
</script>

<template>
Expand All @@ -96,6 +105,7 @@ const removeItem = async (): Promise<void> => {
:filter="filter"
:on-filter="onFilter"
ref="dataTable"
@select="onSelect"
>
<template #header>
<div class="mb-3 gap-3">
Expand All @@ -106,7 +116,7 @@ const removeItem = async (): Promise<void> => {
<InputText v-model="filter['search']" :placeholder="t('admin.search.general')" />
</IconField>
</div>
<Button class="w-1 mb-3 gap-3" :disabled="">
<Button class="w-1 mb-3 gap-3" :disabled="multiRemove">
{{ t('admin.delete') }}
</Button>
</template>
Expand Down Expand Up @@ -143,7 +153,7 @@ const removeItem = async (): Promise<void> => {
/>
</template>
</Column>
<Column key="remove" :header-style="{ width: '11%'}" class="p-col">
<Column key="remove" :header-style="{ width: '11%' }" class="p-col">
<template #body="{ data }">
<Button @click="() => toggleSafetyGuardRemove(data)" class="justify-content-center">
{{ t('admin.delete') }}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/admin/UsersView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const saveItem = async (): Promise<void> => {
:field="column.field"
:header="t(column.header)"
:show-filter-menu="false"
:header-style="{ width: '23%'}"
:header-style="{ width: '23%' }"
class="p-col"
>
<template #filter>
Expand All @@ -183,7 +183,7 @@ const saveItem = async (): Promise<void> => {
{{ data.roles.map((role: Role) => t('admin.' + role)).join(', ') }}
</template>
</Column>
<Column :header-style="{ width: '8%'}" class="p-col">
<Column :header-style="{ width: '8%' }" class="p-col">
<template #body="{ data }">
<Button @click="() => showPopup(data)">{{ t('admin.edit') }}</Button>
</template>
Expand Down

0 comments on commit 31985e8

Please sign in to comment.