Skip to content

Commit

Permalink
Merge pull request #89 from KelvinTegelaar/dev
Browse files Browse the repository at this point in the history
[pull] dev from KelvinTegelaar:dev
  • Loading branch information
pull[bot] authored Feb 11, 2025
2 parents ef17d84 + 456973a commit 8dbef6f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
15 changes: 7 additions & 8 deletions src/pages/tools/community-repos/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Page = () => {
const actions = [
{
label: "View Templates",
link: "/tools/community-repos/repo?name=[FullName]",
link: "/tools/community-repos/repo?name=[FullName]&branch=[DefaultBranch]",
icon: <OpenInNew />,
},
{
Expand Down Expand Up @@ -82,13 +82,12 @@ const Page = () => {
searchMutation.mutate({
url: "/api/ExecGitHubAction",
data: {
Search: {
Repository: repo ? repo : "",
User: user ? user : "",
Org: org ? org : "",
SearchTerm: searchTerms,
Type: "repositories",
},
Action: "Search",
Repository: repo ? repo : "",
User: user ? user : "",
Org: org ? org : "",
SearchTerm: searchTerms,
Type: "repositories",
},
});
};
Expand Down
23 changes: 14 additions & 9 deletions src/pages/tools/community-repos/repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import React from "react";

const Page = () => {
const router = useRouter();
const { name } = router.query;
const { name, branch } = router.query;
const [openJsonDialog, setOpenJsonDialog] = useState(false);
const [fileResults, setFileResults] = useState([]);
const [jsonContent, setJsonContent] = useState({});
const [branches, setBranches] = useState([]);
const [selectedBranch, setSelectedBranch] = useState("");
const [selectedBranch, setSelectedBranch] = useState(branch);
const [selectedRepo, setSelectedRepo] = useState(name);

const searchMutation = ApiPostCall({
Expand Down Expand Up @@ -87,12 +87,14 @@ const Page = () => {
}
};

const handleJsonView = (url) => {
const handleJsonView = (path) => {
fileQuery.mutate({
url: "/api/ExecGitHubAction",
data: {
Action: "GetFileContents",
Url: url,
FullName: selectedRepo,
Path: path,
Branch: branch,
},
});
setOpenJsonDialog(true);
Expand All @@ -110,10 +112,10 @@ const Page = () => {
}
}, [selectedBranch]);

const updateQueryParams = (newRepo) => {
const updateQueryParams = (prop, newValue) => {
const query = { ...router.query };
if (query.name !== newRepo) {
query.name = newRepo;
if (query[prop] !== newValue) {
query[prop] = newValue;
router.replace(
{
pathname: router.pathname,
Expand Down Expand Up @@ -169,7 +171,10 @@ const Page = () => {
? { label: selectedBranch, value: selectedBranch }
: { label: "Loading branches", value: "" }
}
onChange={(event, newValue) => setSelectedBranch(newValue.value)}
onChange={(event, newValue) => {
setSelectedBranch(newValue.value);
updateQueryParams("branch", newValue.value);
}}
options={branches.map((branch) => ({ label: branch.name, value: branch.name }))}
multiple={false}
label="Select Branch"
Expand All @@ -187,7 +192,7 @@ const Page = () => {
actions={[
{
label: "View Template",
customFunction: (row) => handleJsonView(row.url),
customFunction: (row) => handleJsonView(row.path),
noConfirm: true,
icon: <EyeIcon />,
hideBulk: true,
Expand Down
14 changes: 13 additions & 1 deletion src/pages/tools/templatelib/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useEffect } from "react";
import { Grid, Divider, Typography, CircularProgress, Alert, Chip, Link } from "@mui/material";
import { useForm, useWatch } from "react-hook-form";
import { Layout as DashboardLayout } from "/src/layouts/index.js";
Expand Down Expand Up @@ -48,6 +48,15 @@ const TemplateLibrary = () => {
};
};

useEffect(() => {
if (templateRepo?.value) {
formControl.setValue("templateRepoBranch", {
label: templateRepo.addedFields.branch,
value: templateRepo.addedFields.branch,
});
}
}, [templateRepo?.value]);

return (
<CippFormPage
formControl={formControl}
Expand Down Expand Up @@ -121,6 +130,9 @@ const TemplateLibrary = () => {
dataKey: "Results",
valueField: "FullName",
labelField: (option) => `${option.Name} (${option.URL})`,
addedField: {
branch: "DefaultBranch",
},
}}
formControl={formControl}
multiple={false}
Expand Down

0 comments on commit 8dbef6f

Please sign in to comment.