Skip to content

Commit

Permalink
Merge pull request #198 from bcgov/feature/confirm-toggle-public
Browse files Browse the repository at this point in the history
Display confirmation dialog and toasts on toggling file to public
  • Loading branch information
TimCsaky authored May 16, 2024
2 parents 9b0f424 + f6485a5 commit 39dbec7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
1 change: 1 addition & 0 deletions frontend/src/components/object/ObjectPermission.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ onBeforeMount(() => {
class="ml-4"
:bucket-id="object.bucketId"
:object-id="object.id"
:object-name="object.name"
:object-public="object.public"
:user-id="getUserId"
/>
Expand Down
35 changes: 32 additions & 3 deletions frontend/src/components/object/ObjectPublicToggle.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { ref, watch } from 'vue';
import { InputSwitch } from '@/lib/primevue';
import { InputSwitch, useConfirm, useToast } from '@/lib/primevue';
import { useObjectStore, usePermissionStore } from '@/store';
import { Permissions } from '@/utils/constants';
Expand All @@ -11,6 +11,7 @@ import type { Ref } from 'vue';
type Props = {
bucketId: string;
objectId: string;
objectName: string;
objectPublic: boolean;
userId: string;
};
Expand All @@ -25,8 +26,36 @@ const permissionStore = usePermissionStore();
const isPublic: Ref<boolean> = ref(props.objectPublic);
// Actions
const togglePublic = async (isPublic: boolean) => {
await objectStore.togglePublic(props.objectId, isPublic);
const toast = useToast();
const confirm = useConfirm();
const togglePublic = async (setPublicValue: boolean) => {
if (setPublicValue) {
confirm.require({
message:
'Please confirm that you want to set the file(s) to public. ' +
'This allows the share link to be accessible by anyone, even without credentials.',
header: 'Confirm set to public',
acceptLabel: 'Confirm',
rejectLabel: 'Cancel',
accept: () => {
objectStore
.togglePublic(props.objectId, true)
.then(() => {
toast.success(`"${props.objectName}" set to public`);
})
.catch((e) => toast.error(e));
},
reject: () => (isPublic.value = false),
onHide: () => (isPublic.value = false)
});
} else
objectStore
.togglePublic(props.objectId, false)
.then(() => {
toast.success(`"${props.objectName}" is no longer public`);
})
.catch((e) => toast.error(e));
};
watch(props, () => {
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/components/object/ObjectTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,7 @@ const selectedFilters = (payload: any) => {
>
<template #body="{ data }">
<div>
<router-link
:to="{ name: RouteNames.DETAIL_OBJECTS, query: { objectId: data.id } }"
>
<router-link :to="{ name: RouteNames.DETAIL_OBJECTS, query: { objectId: data.id } }">
<span v-tooltip.bottom="'View file details'">
{{ data.name }}
</span>
Expand Down Expand Up @@ -307,6 +305,7 @@ const selectedFilters = (payload: any) => {
v-if="props.bucketId && getUserId"
:bucket-id="props.bucketId"
:object-id="data.id"
:object-name="data.name"
:object-public="data.public"
:user-id="getUserId"
/>
Expand Down

0 comments on commit 39dbec7

Please sign in to comment.