Skip to content

Commit

Permalink
Merge pull request #18203 from ahmedhamidawan/fix_content_item_on_error
Browse files Browse the repository at this point in the history
[24.0] Add `GenericItem` error handling
  • Loading branch information
dannon authored May 23, 2024
2 parents 37aeadd + cef091b commit 2ddea78
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions client/src/components/History/Content/GenericItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@

<script>
import LoadingSpan from "components/LoadingSpan";
import { Toast } from "composables/toast";
import { mapActions } from "pinia";
import { deleteContent, updateContentFields } from "@/components/History/model/queries";
import { DatasetCollectionProvider, DatasetProvider } from "@/components/providers";
import { DatasetCollectionElementProvider } from "@/components/providers/storeProviders";
import { useHistoryStore } from "@/stores/historyStore";
import { errorMessageAsString } from "@/utils/simple-error";
import ContentItem from "./ContentItem";
import GenericElement from "./GenericElement";
Expand Down Expand Up @@ -76,17 +78,37 @@ export default {
},
methods: {
...mapActions(useHistoryStore, ["applyFilters"]),
onDelete(item, recursive = false) {
deleteContent(item, { recursive: recursive });
async onDelete(item, recursive = false) {
try {
await deleteContent(item, { recursive: recursive });
} catch (error) {
this.onError(error, "Failed to delete item");
}
},
onUndelete(item) {
updateContentFields(item, { deleted: false });
onError(e, title = "Error") {
const error = errorMessageAsString(e, "Dataset operation failed.");
Toast.error(error, title);
},
onHide(item) {
updateContentFields(item, { visible: false });
async onUndelete(item) {
try {
await updateContentFields(item, { deleted: false });
} catch (error) {
this.onError(error, "Failed to undelete item");
}
},
onUnhide(item) {
updateContentFields(item, { visible: true });
async onHide(item) {
try {
await updateContentFields(item, { visible: false });
} catch (error) {
this.onError(error, "Failed to hide item");
}
},
async onUnhide(item) {
try {
await updateContentFields(item, { visible: true });
} catch (error) {
this.onError(error, "Failed to unhide item");
}
},
async onHighlight(item) {
const { history_id } = item;
Expand All @@ -98,7 +120,7 @@ export default {
try {
await this.applyFilters(history_id, filters);
} catch (error) {
this.onError(error);
this.onError(error, "Failed to highlight related items");
}
},
},
Expand Down

0 comments on commit 2ddea78

Please sign in to comment.