Skip to content

Commit

Permalink
chore: org config select
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Nov 29, 2024
1 parent b780a46 commit 4672fac
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
9 changes: 8 additions & 1 deletion static/scripts/config-parser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import YAML from "yaml";
import { Plugin, PluginConfig } from "../types/plugins";
import { Octokit } from "@octokit/rest";
import { RequestError } from "@octokit/request-error";
import { toastNotification } from "../utils/toaster";
import { CONFIG_FULL_PATH, CONFIG_ORG_REPO } from "@ubiquity-os/plugin-sdk/constants";

Expand Down Expand Up @@ -70,6 +69,10 @@ export class ConfigParser {
}

async fetchUserInstalledConfig(org: string, octokit: Octokit, repo = CONFIG_ORG_REPO, path = CONFIG_FULL_PATH) {
if (org === repo) {
repo = CONFIG_ORG_REPO;
}

if (repo === CONFIG_ORG_REPO) {
await this.configRepoExistenceCheck(org, repo, octokit);
}
Expand Down Expand Up @@ -119,6 +122,10 @@ export class ConfigParser {
}

async createOrUpdateFileContents(org: string, repo: string, path: string, octokit: Octokit) {
if (org === repo) {
repo = CONFIG_ORG_REPO;
}

const recentSha = await octokit.repos.getContent({
owner: org,
repo: repo,
Expand Down
43 changes: 37 additions & 6 deletions static/scripts/rendering/repo-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,47 @@ export function renderRepoPicker(renderer: ManifestRenderer, repos: Record<strin

localStorage.setItem("orgRepos", JSON.stringify(repos));

const selectedOrg = localStorage.getItem("selectedOrg");

if (!selectedOrg) {
throw new Error(`No selected org found in local storage`);
}

const topLevelRow = document.createElement("tr");
const topLevelCell = document.createElement("td");
topLevelCell.colSpan = 4;
topLevelCell.className = STRINGS.TDV_CENTERED;

const useOrgConfigButton = createElement("button", {
id: "use-org-config-button",
textContent: `Use ${selectedOrg} config`,
});

useOrgConfigButton.style.width = "100%";
useOrgConfigButton.style.textAlign = "left";

useOrgConfigButton.addEventListener("click", () => {
localStorage.setItem("selectedRepo", selectedOrg);
fetchOrgConfig(renderer, selectedOrg, selectedOrg)
.then(() => {
renderPluginSelector(renderer);
})
.catch((error) => {
console.error(error);
toastNotification("Error fetching org config", { type: "error" });
});
});

topLevelCell.appendChild(useOrgConfigButton);
topLevelRow.appendChild(topLevelCell);
renderer.manifestGuiBody.appendChild(topLevelRow);

const pickerRow = document.createElement("tr");
const pickerCell = document.createElement("td");
pickerCell.colSpan = 4;
pickerCell.className = STRINGS.TDV_CENTERED;

updateGuiTitle("Select a Repository");
const selectedOrg = localStorage.getItem("selectedOrg");

if (!selectedOrg) {
throw new Error(`No selected org found in local storage`);
}

const repoSelect = createElement("select", {
id: "repo-picker-select",
Expand All @@ -42,7 +72,7 @@ export function renderRepoPicker(renderer: ManifestRenderer, repos: Record<strin

const defaultOption = createElement("option", {
value: null,
textContent: "Select a repository...",
textContent: "Or select a repository...",
});
repoSelect.appendChild(defaultOption);

Expand All @@ -64,6 +94,7 @@ export function renderRepoPicker(renderer: ManifestRenderer, repos: Record<strin
pickerCell.appendChild(repoSelect);
pickerRow.appendChild(pickerCell);
renderer.manifestGuiBody.appendChild(pickerRow);

renderer.manifestGui?.classList.add("rendered");
}

Expand Down

0 comments on commit 4672fac

Please sign in to comment.