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

Retry failed save and publish requests #6833

Merged
merged 7 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,12 @@
"form.discard.confirm": "Do you really want to <strong>discard all your changes</strong>?",
"form.locked": "This content is disabled for you as it is currently edited by another user",
"form.unsaved": "The current changes have not yet been saved",
"form.save.error": "Your changes could not be saved.",
"form.save.success": "Your changes have been saved",
"form.preview": "Preview changes",
"form.preview.draft": "Preview draft",
"form.publish.error": "Your changes could not be published.",
"form.publish.success": "Your changes have been published",

"hide": "Hide",
"hour": "Hour",
Expand Down
2 changes: 1 addition & 1 deletion panel/src/components/Dialogs/Dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
$vnode.data.staticClass,
$attrs.class
]"
:data-has-footer="cancelButton || submitButton"
:data-has-footer="Boolean(cancelButton || submitButton)"
:data-size="size"
method="dialog"
@click.stop
Expand Down
59 changes: 58 additions & 1 deletion panel/src/panel/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ export default (panel) => {
return changes;
},

/**
* Closes the retry dialog if it is still open
*/
closeRetryDialog() {
if (
panel.dialog.isOpen &&
panel.dialog.props.id === "content-retry-dialog"
) {
panel.dialog.close();
}
},
bastianallgeier marked this conversation as resolved.
Show resolved Hide resolved

/**
* Removes all unpublished changes
*/
Expand Down Expand Up @@ -145,17 +157,59 @@ export default (panel) => {
try {
await panel.api.post(api + "/changes/publish", values);

// close the retry dialog if it is still open
this.closeRetryDialog();

// update the props for the current view
if (this.isCurrent(api)) {
panel.view.props.originals = panel.view.props.content;
}

panel.events.emit("content.publish", { values, api });
} catch (error) {
this.retry("publish", error, panel.view.props.content, api);
} finally {
this.isProcessing = false;
}
},

/**
* Opens a dialog with the error message
* to retry the given method.
*/
retry(method, error, values, api) {
// log the error to the console to make it
// easier to debug the issue
console.error(error);

// show a dialog to the user to try again
panel.dialog.open({
component: "k-text-dialog",
props: {
id: "content-retry-dialog",
text: panel.t(`form.${method}.error`),
cancelButton: panel.t("close"),
submitButton: {
icon: "refresh",
text: panel.t("retry")
}
},
on: {
submit: async () => {
panel.dialog.isLoading = true;

// try again with the latest state in the props
await this.save(panel.view.props.content, api);
bastianallgeier marked this conversation as resolved.
Show resolved Hide resolved

panel.dialog.isLoading = true;
bastianallgeier marked this conversation as resolved.
Show resolved Hide resolved

// give a more reassuring longer success notification
panel.notification.success(panel.t(`form.${method}.success`));
}
}
});
},

/**
* Saves any changes
*/
Expand All @@ -181,6 +235,9 @@ export default (panel) => {

this.isProcessing = false;

// close the retry dialog if it is still open
this.closeRetryDialog();

// update the lock timestamp
if (this.isCurrent(api) === true) {
panel.view.props.lock.modified = new Date();
Expand All @@ -191,7 +248,7 @@ export default (panel) => {
// silent aborted requests, but throw all other errors
if (error.name !== "AbortError") {
this.isProcessing = false;
throw error;
this.retry("save", error, panel.view.props.content, api);
distantnative marked this conversation as resolved.
Show resolved Hide resolved
}
}
},
Expand Down