-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implemented selectable rows * Implemented selectable rows * Hiding bulk action's div if selectable rows is false * Move fetching selectable rows props to the table structure fetch * On mount add parallel execution for table structure and data * Add trash icon in Delete Selected button
- Loading branch information
1 parent
3f423d0
commit bda6685
Showing
14 changed files
with
209 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
krait-ui/src/components/bulk-action-links/BulkActionLinksList.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<script setup lang="ts"> | ||
import {useConfirmation, useDispatcher, useTable} from '~/mixins'; | ||
import {DeleteRecord, FetchRecords} from '~/actions'; | ||
import {Trash} from "@components/icons"; | ||
const props = defineProps({ | ||
tableName: { | ||
type: String, | ||
required: true, | ||
}, | ||
}); | ||
const {isLoading, bulkActionLinks, selectedRows, isSelectableRows} = useTable( | ||
props.tableName, | ||
); | ||
const {dispatch} = useDispatcher(props.tableName); | ||
const {ask} = useConfirmation(); | ||
const bulkDelete = async () => { | ||
if (selectedRows.value.length <= 0) return; | ||
const isConfirmed = await ask( | ||
'Are you sure that you want to delete those record?', | ||
); | ||
if (isConfirmed && bulkActionLinks.value.delete) { | ||
await dispatch<DeleteRecord>(DeleteRecord, { | ||
url: bulkActionLinks.value.delete, | ||
body: {data: selectedRows.value}, | ||
}); | ||
await dispatch<FetchRecords>(FetchRecords, {}); | ||
} | ||
}; | ||
</script> | ||
|
||
<template> | ||
<div v-if="isSelectableRows"> | ||
<button | ||
v-if="bulkActionLinks?.delete" | ||
class="btn btn-danger d-flex gap-1" | ||
:disabled="selectedRows.length == 0 || isLoading" | ||
@click="bulkDelete" | ||
> | ||
<Trash width="18"/> | ||
Delete selected | ||
</button> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as BulkActionLinksList } from './BulkActionLinksList.vue'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
krait-ui/src/components/select-all-checkbox/SelectAllCheckbox.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<script setup lang="ts"> | ||
import { ref, watch } from 'vue'; | ||
import { useTable } from '~/mixins'; | ||
const props = defineProps({ | ||
tableName: { | ||
type: String, | ||
required: true, | ||
}, | ||
}); | ||
const { selectedRows, records } = useTable(props.tableName); | ||
const checkBoxInput = ref<HTMLInputElement | null>(null); | ||
const isAllSelected = ref(false); | ||
const isIndeterminate = ref(false); | ||
const toggleSelectAll = () => { | ||
if (isIndeterminate.value || !isAllSelected.value) { | ||
selectedRows.value = records.value.map((record) => record.uuid); | ||
} else { | ||
selectedRows.value = []; | ||
} | ||
}; | ||
watch( | ||
selectedRows, | ||
(newSelectedRows) => { | ||
if (checkBoxInput.value) { | ||
if (newSelectedRows.length === records.value.length) { | ||
isAllSelected.value = true; | ||
isIndeterminate.value = false; | ||
checkBoxInput.value.indeterminate = false; | ||
} else { | ||
isAllSelected.value = false; | ||
isIndeterminate.value = newSelectedRows.length > 0; | ||
checkBoxInput.value.indeterminate = isIndeterminate.value; | ||
} | ||
} | ||
}, | ||
{ | ||
deep: true, | ||
}, | ||
); | ||
</script> | ||
|
||
<template> | ||
<input | ||
type="checkbox" | ||
@click="toggleSelectAll" | ||
:checked="isAllSelected" | ||
ref="checkBoxInput" | ||
/> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as SelectAllCheckbox } from './SelectAllCheckbox.vue'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters