Skip to content

Commit

Permalink
Simplify dialog setup
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianallgeier committed Dec 5, 2024
1 parent 4e16f49 commit 3c84509
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions panel/src/panel/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,7 @@ 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();
}
},
dialog: null,

/**
* Removes all unpublished changes
Expand Down Expand Up @@ -158,7 +148,7 @@ export default (panel) => {
await panel.api.post(api + "/changes/publish", values);

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

// update the props for the current view
if (this.isCurrent(api)) {
Expand All @@ -182,8 +172,11 @@ export default (panel) => {
// easier to debug the issue
console.error(error);

// set the dialog instance
this.dialog = panel.dialog;

// show a dialog to the user to try again
panel.dialog.open({
this.dialog.open({
component: "k-text-dialog",
props: {
id: "content-retry-dialog",
Expand All @@ -195,13 +188,17 @@ export default (panel) => {
}
},
on: {
close: () => {
this.dialog = null;
},
submit: async () => {
panel.dialog.isLoading = true;
this.dialog.isLoading = true;

// try again with the latest state in the props
await this.save(panel.view.props.content, api);

panel.dialog.isLoading = false;
// make sure the dialog is closed if the request was successful
this.dialog?.close();

// give a more reassuring longer success notification
panel.notification.success(panel.t(`form.${method}.success`));
Expand Down Expand Up @@ -236,7 +233,7 @@ export default (panel) => {
this.isProcessing = false;

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

// update the lock timestamp
if (this.isCurrent(api) === true) {
Expand Down

0 comments on commit 3c84509

Please sign in to comment.