Skip to content

Commit

Permalink
storage: Allow all actions in a dialog to be specified via "Variants"
Browse files Browse the repository at this point in the history
This makes it easier to work with different sets of actions, and
allows the primary action to have a tag as well.
  • Loading branch information
mvollmer committed Jan 9, 2024
1 parent 92ab4f8 commit db69adc
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions pkg/storaged/dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -408,29 +408,32 @@ export const dialog_open = (def) => {
}

const footer_props = (running_title, running_promise) => {
let actions = [];
const actions = [];

function add_action(variant) {
actions.push({
caption: variant.Title,
style: actions.length == 0 ? "primary" : "secondary",
danger: def.Action.Danger || def.Action.DangerButton,
disabled: running_promise != null || (def.Action.disable_on_error &&
errors && errors.toString() != "[object Object]"),
clicked: progress_callback => run_action(progress_callback, variant.tag),
});
}

if (def.Action) {
actions = [
{
caption: def.Action.Title,
style: "primary",
danger: def.Action.Danger || def.Action.DangerButton,
disabled: running_promise != null || (def.Action.disable_on_error &&
errors && errors.toString() != "[object Object]"),
clicked: progress_callback => run_action(progress_callback, null),
}
];
if (def.Action.Title) {
add_action({
Title: def.Action.Title,
tag: null,
});
}

if (def.Action.Variants)
if (def.Action.Variants) {
for (const v of def.Action.Variants) {
actions.push({
caption: v.Title,
style: "secondary",
danger: def.Action.Danger || def.Action.DangerButton,
disabled: running_promise != null,
clicked: progress_callback => run_action(progress_callback, v.tag),
});
add_action(v);
}
}
}

const extra = (
Expand Down

0 comments on commit db69adc

Please sign in to comment.