Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delete submission button and overflow menu #1446

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions web/src/views/SubmissionPortal/Components/SubmissionList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ const headers: DataTableHeader[] = [
{
text: '',
value: 'action',
sortable: false,
},
{
text: '',
value: 'menu',
align: 'end',
sortable: false,
},
Expand All @@ -62,6 +67,9 @@ export default defineComponent({
multiSort: false,
mustSort: false,
});
const deleteDialog = ref(false);
const deleteConfirmation = ref(false);
const dialogUpdated = ref(false);

function getStatus(item: api.MetadataSubmissionRecord) {
const color = item.status === submissionStatus.Complete ? 'success' : 'default';
Expand All @@ -80,6 +88,47 @@ export default defineComponent({
router?.push({ name: 'Submission Context', params: { id: item.id } });
}

function waitForDialogUpdate(): Promise<void> {
return new Promise<void>((resolve) => {
const intervalId = setInterval(() => {
if (dialogUpdated.value === true) {
clearInterval(intervalId);
resolve();
}
}, 600);
});
}

async function deleteSubmission(item: api.MetadataSubmissionRecord) {
deleteDialog.value = true;
await waitForDialogUpdate();
if (deleteConfirmation) {
//do the deletion
//for now we just resume as a confirmation that the logic worked
resume(item);
}

deleteDialog.value = false;
deleteConfirmation.value = false;
dialogUpdated.value = false;
return item;
}

function deleteDialogUpdate(confirmation: boolean) {
deleteConfirmation.value = confirmation;
dialogUpdated.value = true;
}

async function handleOverflowMenu(item: api.MetadataSubmissionRecord, title: String) {
switch (title) {
case 'Delete':
deleteSubmission(item);
break;
default:
break;
}
}

const submission = usePaginatedResults(ref([]), api.listRecords, ref([]), itemsPerPage);
watch(options, () => {
submission.setPage(options.value.page);
Expand All @@ -89,17 +138,28 @@ export default defineComponent({

return {
HARMONIZER_TEMPLATES,
deleteDialog,
deleteConfirmation,
dialogUpdated,
IconBar,
IntroBlurb,
TitleBanner,
createNewSubmission,
getStatus,
resume,
handleOverflowMenu,
deleteDialogUpdate,
headers,
options,
submission,
};
},
data: () => ({
OverFlowMenuItems: [
{ title: 'Delete' },
{ title: 'Future button' },
],
}),
});
</script>

Expand Down Expand Up @@ -203,8 +263,57 @@ export default defineComponent({
</v-icon>
</v-btn>
</template>
<template #[`item.menu`]="{ item }">
<v-menu
offset-x
>
<template #activator="{ on }">
<v-btn
class="ml-1"
icon="mdi-dots-vertical"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you aren't done yet, but just wanted to point out that the icon prop is a boolean and doesn't take a string. It indicates a type of button, in this case round and 'text' (transparent). Therefore using the icon prop makes the text prop redundant.
Admittedly icon is not an intuitive name for this behavior.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes a lot of sense why it was behaving unexpectedly. Thanks for pointing it out. I think that format is from vuetify 1 since I formatted it after those docs. I’m planning to go through and update all those kinds of things after looking at the vuetify2 docs some more.

text
v-on="on"
>
<v-icon>
mdi-dots-vertical
</v-icon>
</v-btn>
</template>
<v-list>
<v-list-item
v-for="(entry, i) in OverFlowMenuItems"
:key="i"
@click="() => handleOverflowMenu(item,entry.title)"
>
<v-list-item-title>{{ entry.title }}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</template>
</v-data-table>
</v-card>
</v-card>
<v-row justify="center">
<v-dialog
v-model="deleteDialog"
class="ma-5"
>
<v-card>
<v-card-title class="text-h5">
Are you sure you want to delete this submission in progress?
</v-card-title>
<v-btn
@click="deleteDialogUpdate(true)"
>
Delete
</v-btn>
<v-btn
@click="deleteDialogUpdate(false)"
>
Cancel
</v-btn>
</v-card>
</v-dialog>
</v-row>
</div>
</template>