-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkp/pkp-lib#6528 Initial UI for bulk delete of incomplete submissions…
… for admins and authors
- Loading branch information
1 parent
14c7d53
commit 8168537
Showing
8 changed files
with
308 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<template> | ||
<TableCell> | ||
<input | ||
type="checkbox" | ||
:checked="props.checked" | ||
:aria-describedby="describedBy" | ||
@change="emit('change', $event.target.checked)" | ||
/> | ||
</TableCell> | ||
</template> | ||
|
||
<script setup> | ||
import TableCell from './TableCell.vue'; | ||
const props = defineProps({ | ||
checked: {type: Boolean, required: true}, | ||
describedBy: {type: String, required: true}, | ||
}); | ||
const emit = defineEmits(['change']); | ||
</script> |
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
27 changes: 27 additions & 0 deletions
27
src/pages/dashboard/components/DashboardBulkDeleteButton.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,27 @@ | ||
<template> | ||
<PkpButton | ||
v-if="store.bulkDeleteDisplayDeleteButton" | ||
:is-disabled="store.bulkDeleteSubmissionIdsCanBeDeleted.length === 0" | ||
:is-active=" | ||
store.bulkDeleteEnabled && store.bulkDeleteSelectedItems.length === 0 | ||
" | ||
:is-warnable="!!store.bulkDeleteSelectedItems.length" | ||
@click=" | ||
() => | ||
store.bulkDeleteSelectedItems.length | ||
? store.bulkDeleteActionDelete() | ||
: store.bulkDeleteToggleEnabled() | ||
" | ||
> | ||
{{ t('admin.submissions.incomplete.bulkDelete.button') }} | ||
</PkpButton> | ||
</template> | ||
|
||
<script setup> | ||
import PkpButton from '@/components/Button/Button.vue'; | ||
import {useLocalize} from '@/composables/useLocalize'; | ||
import {useDashboardPageStore} from '../dashboardPageStore'; | ||
const store = useDashboardPageStore(); | ||
const {t} = useLocalize(); | ||
</script> |
40 changes: 40 additions & 0 deletions
40
src/pages/dashboard/components/DashboardTable/CellBulkDelete.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,40 @@ | ||
<template> | ||
<!--<TableCellSelect :value="isChecked" @change="toggle"></TableCellSelect>--> | ||
|
||
<TableCellSelect | ||
v-if="canBeDeleted" | ||
:checked="isChecked" | ||
:described-by="'submission-title-' + item.id" | ||
@change="change" | ||
/> | ||
<TableCell v-else></TableCell> | ||
</template> | ||
|
||
<script setup> | ||
import {computed} from 'vue'; | ||
import TableCellSelect from '@/components/Table/TableCellSelect.vue'; | ||
import TableCell from '@/components/Table/TableCell.vue'; | ||
import {useDashboardPageStore} from '@/pages/dashboard/dashboardPageStore'; | ||
const props = defineProps({item: {type: Object, required: true}}); | ||
const dashboardStore = useDashboardPageStore(); | ||
const isChecked = computed(() => { | ||
return dashboardStore.bulkDeleteSelectedItems.includes(props.item.id); | ||
}); | ||
const canBeDeleted = computed(() => { | ||
return dashboardStore.bulkDeleteSubmissionIdsCanBeDeleted.includes( | ||
props.item.id, | ||
); | ||
}); | ||
function change(checked) { | ||
if (checked) { | ||
dashboardStore.bulkDeleteSelectItem(props.item.id); | ||
} else { | ||
dashboardStore.bulkDeleteDeselectItem(props.item.id); | ||
} | ||
} | ||
</script> |
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
140 changes: 140 additions & 0 deletions
140
src/pages/dashboard/composables/useDashboardBulkDelete.js
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,140 @@ | ||
import {ref, computed} from 'vue'; | ||
|
||
import {useCurrentUser} from '@/composables/useCurrentUser'; | ||
import {useFetch} from '@/composables/useFetch'; | ||
import {useUrl} from '@/composables/useUrl'; | ||
import {useModal} from '@/composables/useModal'; | ||
import {useLocalize} from '@/composables/useLocalize'; | ||
import {DashboardPageTypes} from '../dashboardPageStore'; | ||
|
||
export function useDashboardBulkDelete({ | ||
submissions, | ||
dashboardPage, | ||
onSubmissionDeleteCallback, | ||
}) { | ||
const {t} = useLocalize(); | ||
|
||
// Display only for admins on editorial dashboard and for author dashboard, where user can delete own submissions | ||
const bulkDeleteDisplayDeleteButton = computed(() => { | ||
if ( | ||
dashboardPage === DashboardPageTypes.EDITORIAL_DASHBOARD && | ||
hasCurrentUserAtLeastOneRole([pkp.const.ROLE_ID_SITE_ADMIN]) | ||
) { | ||
return true; | ||
} else if (dashboardPage === DashboardPageTypes.MY_SUBMISSIONS) { | ||
return true; | ||
} | ||
|
||
return false; | ||
}); | ||
|
||
const bulkDeleteEnabled = ref(false); | ||
const bulkDeleteSelectedItems = ref([]); | ||
function bulkDeleteSelectItem(submissionId) { | ||
if (!bulkDeleteSelectedItems.value.includes(submissionId)) { | ||
bulkDeleteSelectedItems.value.push(submissionId); | ||
} | ||
} | ||
|
||
function bulkDeleteDeselectItem(submissionId) { | ||
bulkDeleteSelectedItems.value = bulkDeleteSelectedItems.value.filter( | ||
(id) => id !== submissionId, | ||
); | ||
} | ||
|
||
function bulkDeleteToggleEnabled() { | ||
bulkDeleteEnabled.value = !bulkDeleteEnabled.value; | ||
} | ||
|
||
const { | ||
hasCurrentUserAtLeastOneAssignedRoleInAnyStage, | ||
hasCurrentUserAtLeastOneRole, | ||
} = useCurrentUser(); | ||
|
||
function canBeDeleted(submission) { | ||
// incomplete submission can be deleted by author of the submission or admin | ||
if (submission.submissionProgress) | ||
if ( | ||
hasCurrentUserAtLeastOneRole([pkp.const.ROLE_ID_SITE_ADMIN]) || | ||
hasCurrentUserAtLeastOneAssignedRoleInAnyStage(submission, [ | ||
pkp.const.ROLE_ID_AUTHOR, | ||
]) | ||
) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
const bulkDeleteSubmissionIdsCanBeDeleted = computed(() => { | ||
const submissionIds = []; | ||
if (submissions.value && submissions.value?.length) { | ||
submissions.value.forEach((submission) => { | ||
if (canBeDeleted(submission)) { | ||
submissionIds.push(submission.id); | ||
} | ||
}); | ||
} | ||
|
||
return submissionIds; | ||
}); | ||
|
||
async function apiCall() { | ||
const {apiUrl} = useUrl(`_submissions`); | ||
const {fetch} = useFetch(apiUrl, { | ||
query: {ids: bulkDeleteSelectedItems.value}, | ||
method: 'DELETE', | ||
}); | ||
|
||
await fetch(); | ||
|
||
bulkDeleteResetSelection(); | ||
onSubmissionDeleteCallback(); | ||
} | ||
|
||
function bulkDeleteResetSelection() { | ||
bulkDeleteSelectedItems.value = []; | ||
bulkDeleteEnabled.value = false; | ||
} | ||
|
||
function bulkDeleteActionDelete() { | ||
const {openDialog} = useModal(); | ||
openDialog({ | ||
title: t('admin.submissions.incomplete.bulkDelete.confirm'), | ||
message: t('admin.submissions.incomplete.bulkDelete.body'), | ||
actions: [ | ||
{ | ||
label: t('common.confirm'), | ||
isPrimary: true, | ||
callback: async (close) => { | ||
await apiCall(); | ||
close(); | ||
}, | ||
}, | ||
{ | ||
label: t('common.cancel'), | ||
isWarnable: true, | ||
callback: (close) => { | ||
close(); | ||
}, | ||
}, | ||
], | ||
modalStyle: 'negative', | ||
close: () => {}, | ||
}); | ||
} | ||
|
||
return { | ||
bulkDeleteDisplayDeleteButton, | ||
bulkDeleteEnabled, | ||
bulkDeleteToggleEnabled, | ||
|
||
bulkDeleteSelectedItems, | ||
bulkDeleteSelectItem, | ||
bulkDeleteDeselectItem, | ||
bulkDeleteResetSelection, | ||
bulkDeleteActionDelete, | ||
|
||
bulkDeleteSubmissionIdsCanBeDeleted, | ||
}; | ||
} |
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