Skip to content

Commit

Permalink
Chnage promise chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
TimCsaky committed Oct 19, 2023
1 parent ebf8a7e commit ff51c62
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 30 deletions.
16 changes: 8 additions & 8 deletions frontend/src/components/object/DeleteObjectButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ const confirmDelete = () => {
acceptLabel: 'Confirm',
rejectLabel: 'Cancel',
accept: async () => {
try {
props.ids?.forEach(async (ele) => {
const res = await objectStore.deleteObjects([ele], props.versionId);
if (res) emit('on-deleted-success', props.versionId);
});
} catch (error: any) {
toast.error(`Error deleting one or more ${item}s`);
emit('on-deleted-error');
for( const id of props.ids){
try {
await objectStore.deleteObjects([id], props.versionId);
emit('on-deleted-success', props.versionId);
}
catch{
// intentionally left blank
}
}
}
});
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/components/object/ObjectFileDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
ObjectVersion
} from '@/components/object';
import { ShareObjectButton } from '@/components/object/share';
import { Button, Dialog, Divider, useToast } from '@/lib/primevue';
import { Button, Dialog, Divider } from '@/lib/primevue';
import {
useAuthStore,
useMetadataStore,
Expand Down Expand Up @@ -60,7 +60,6 @@ const version: Ref<Version | undefined> = ref(undefined);
// Actions
const router = useRouter();
const toast = useToast();
const showPermissions = async (objectId: string) => {
permissionsVisible.value = true;
Expand All @@ -69,8 +68,6 @@ const showPermissions = async (objectId: string) => {
};
async function onDeletedSuccess(versionId: string) {
toast.success('File deleted');
await Promise.all([
objectStore.fetchObjects({objectId: props.objectId, userId: getUserId.value, bucketPerms: true}),
versionStore.fetchVersions({ objectId: props.objectId })
Expand Down
10 changes: 1 addition & 9 deletions frontend/src/components/object/ObjectList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ObjectTable,
ObjectUpload
} from '@/components/object';
import { Button, useToast } from '@/lib/primevue';
import { Button } from '@/lib/primevue';
import {
useAuthStore,
useBucketStore,
Expand Down Expand Up @@ -47,9 +47,6 @@ const selectedObjectIds = computed(() => {
return getSelectedObjects.value.map((o) => o.id);
});
// Actions
const toast = useToast();
const showObjectInfo = async (objectId: string | undefined) => {
objectInfoId.value = objectId;
};
Expand All @@ -75,10 +72,6 @@ const closeUpload = () => {
// }
// };
function onDeletedSuccess() {
toast.success('File deleted');
}
onMounted(async () => {
// Removed for now
// updateBreadcrumb();
Expand Down Expand Up @@ -122,7 +115,6 @@ onMounted(async () => {
:disabled="displayUpload"
:ids="selectedObjectIds"
:mode="ButtonMode.BUTTON"
@on-deleted-success="onDeletedSuccess"
/>
</div>

Expand Down
4 changes: 1 addition & 3 deletions frontend/src/components/object/ObjectVersion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
DeleteObjectButton,
DownloadObjectButton
} from '@/components/object';
import { Button, Column, DataTable, useToast } from '@/lib/primevue';
import { Button, Column, DataTable } from '@/lib/primevue';
import { useAppStore, useAuthStore, usePermissionStore, useUserStore, useVersionStore } from '@/store';
import { Permissions, RouteNames } from '@/utils/constants';
import { ButtonMode } from '@/utils/enums';
Expand Down Expand Up @@ -42,13 +42,11 @@ const tableData: Ref<Array<VersionDataSource>> = ref([]);
// Actions
const router = useRouter();
const toast = useToast();
// Highlight row for currently selected version
const rowClass = (data: any) => [{ 'selected-row': data.id === props.versionId }];
async function onDeletedSuccess(versionId: string) {
toast.success('File deleted');
await versionStore.fetchVersions({ objectId: props.objectId });
// Navigate to new latest version if deleting active version
Expand Down
10 changes: 4 additions & 6 deletions frontend/src/store/objectStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,12 @@ export const useObjectStore = defineStore('object', () => {

try {
appStore.beginIndeterminateLoading();
return await Promise.all(
objectIds.map(async (id) => {
await objectService.deleteObject(id, versionId);
})
);
await objectService.deleteObject(objectIds[0], versionId);
toast.success('Object deleted');
}
catch (error: any) {
toast.error('Deleting object', error);
toast.error('deleting object.');
throw error;
}
finally {
fetchObjects({ bucketId: bucketId, userId: getUserId.value, bucketPerms: true });
Expand Down

0 comments on commit ff51c62

Please sign in to comment.