Skip to content

Commit

Permalink
chore: prevent multiple handler bindings, teak push
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Nov 11, 2024
1 parent 87afab8 commit 27b6a42
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
11 changes: 9 additions & 2 deletions static/scripts/config-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,19 @@ export class ConfigParser {
repoPlugins.push(newPlugin);
}
});

this.newConfigYml = YAML.stringify({ plugins: repoPlugins });
} else if (option === "remove") {
// remove only this plugin, keep all others
repoPlugins = repoPlugins.filter((p) => !newPluginNames.includes(p.uses[0].plugin));
newPlugins.forEach((newPlugin) => {
const existingPlugin = repoPlugins.find((p) => p.uses[0].plugin === newPlugin.uses[0].plugin);
if (existingPlugin) {
repoPlugins = repoPlugins.filter((p) => p.uses[0].plugin !== newPlugin.uses[0].plugin);
}
});
this.newConfigYml = YAML.stringify({ plugins: newPlugins });
}

this.newConfigYml = YAML.stringify({ plugins: repoPlugins });
this.saveConfig();
return this.createOrUpdateFileContents(org, repo, path, env, octokit);
}
Expand Down
14 changes: 7 additions & 7 deletions static/scripts/render-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export class ManifestRenderer {
configSelect.appendChild(option);
});

configSelect.removeEventListener("change", this._handleConfigSelection.bind(this));
configSelect.addEventListener("change", this._handleConfigSelection.bind(this));
pickerCell.appendChild(configSelect);
pickerRow.appendChild(pickerCell);
Expand Down Expand Up @@ -309,6 +310,8 @@ export class ManifestRenderer {
this._manifestGui?.classList.add("rendered");
}

private _boundConfigAdd = this._writeNewConfig.bind(this, "add");
private _boundConfigRemove = this._writeNewConfig.bind(this, "remove");
private _renderConfigEditor(manifestStr: string): void {
this._currentStep = "configEditor";
this._backButton.style.display = "block";
Expand All @@ -320,15 +323,12 @@ export class ManifestRenderer {
this._processProperties(configProps);

const add = document.getElementById("add");
if (!add) {
throw new Error("Add button not found");
}
add.addEventListener("click", this._writeNewConfig.bind(this, "add"));
const remove = document.getElementById("remove");
if (!remove) {
throw new Error("Remove button not found");
if (!add || !remove) {
throw new Error("Add or remove button not found");
}
remove.addEventListener("click", this._writeNewConfig.bind(this, "remove"));
add.addEventListener("click", this._boundConfigAdd);
remove.addEventListener("click", this._boundConfigRemove);

this._updateGuiTitle(`Editing Configuration for ${pluginManifest.name}`);
this._manifestGui?.classList.add("plugin-editor");
Expand Down

0 comments on commit 27b6a42

Please sign in to comment.