Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
52 changes: 51 additions & 1 deletion src/panels/config/script/ha-script-editor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import "@material/mwc-fab";
import { mdiCheck, mdiContentSave, mdiDelete, mdiDotsVertical } from "@mdi/js";
import {
mdiCheck,
mdiContentSave,
mdiDelete,
mdiDotsVertical,
mdiContentDuplicate,
} from "@mdi/js";
import "@polymer/app-layout/app-header/app-header";
import "@polymer/app-layout/app-toolbar/app-toolbar";
import "@polymer/paper-dropdown-menu/paper-dropdown-menu-light";
Expand Down Expand Up @@ -36,6 +42,7 @@ import {
MODES,
MODES_MAX,
ScriptConfig,
showScriptEditor,
triggerScript,
} from "../../../data/script";
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
Expand Down Expand Up @@ -132,6 +139,22 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {

<li divider role="separator"></li>

<mwc-list-item
.disabled=${!this.scriptEntityId}
.label=${this.hass.localize(
"ui.panel.config.script.picker.duplicate_script"
)}
graphic="icon"
>
${this.hass.localize(
"ui.panel.config.script.picker.duplicate_script"
)}
<ha-svg-icon
slot="graphic"
.path=${mdiContentDuplicate}
></ha-svg-icon>
</mwc-list-item>

<mwc-list-item
.disabled=${!this.scriptEntityId}
aria-label=${this.hass.localize(
Expand Down Expand Up @@ -550,6 +573,30 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
}
}

private async _duplicate() {
if (this._dirty) {
if (
!(await showConfirmationDialog(this, {
text: this.hass!.localize(
"ui.panel.config.common.editor.confirm_unsaved"
),
confirmText: this.hass!.localize("ui.common.yes"),
dismissText: this.hass!.localize("ui.common.no"),
}))
) {
return;
}
// Wait for dialog to complate closing
await new Promise((resolve) => setTimeout(resolve, 0));
}
showScriptEditor(this, {
...this._config,
alias: `${this._config?.alias} (${this.hass.localize(
"ui.panel.config.script.picker.duplicate"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should share this variable with the automation editor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean share the alias?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use: [%key:ui::panel::config::automation::picker::duplicate%] in en.json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. done.

)})`,
});
}

private async _deleteConfirm() {
showConfirmationDialog(this, {
text: this.hass.localize("ui.panel.config.script.editor.delete_confirm"),
Expand All @@ -573,6 +620,9 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
this._mode = "yaml";
break;
case 2:
this._duplicate();
break;
case 3:
this._deleteConfirm();
break;
}
Expand Down
4 changes: 3 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,9 @@
"edit_script": "Edit script",
"headers": {
"name": "Name"
}
},
"duplicate_script": "Duplicate script",
"duplicate": "[%key:ui::panel::config::automation::picker::duplicate%]"
},
"editor": {
"alias": "Name",
Expand Down