diff --git a/src/pages/tools/community-repos/index.js b/src/pages/tools/community-repos/index.js
index f862ba2aa028..044fe1c8e035 100644
--- a/src/pages/tools/community-repos/index.js
+++ b/src/pages/tools/community-repos/index.js
@@ -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: ,
},
{
@@ -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",
},
});
};
diff --git a/src/pages/tools/community-repos/repo.js b/src/pages/tools/community-repos/repo.js
index 060915cb2cf5..433b534e683b 100644
--- a/src/pages/tools/community-repos/repo.js
+++ b/src/pages/tools/community-repos/repo.js
@@ -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({
@@ -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);
@@ -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,
@@ -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"
@@ -187,7 +192,7 @@ const Page = () => {
actions={[
{
label: "View Template",
- customFunction: (row) => handleJsonView(row.url),
+ customFunction: (row) => handleJsonView(row.path),
noConfirm: true,
icon: ,
hideBulk: true,
diff --git a/src/pages/tools/templatelib/index.jsx b/src/pages/tools/templatelib/index.jsx
index a58adc3e0453..e05689adf61f 100644
--- a/src/pages/tools/templatelib/index.jsx
+++ b/src/pages/tools/templatelib/index.jsx
@@ -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";
@@ -48,6 +48,15 @@ const TemplateLibrary = () => {
};
};
+ useEffect(() => {
+ if (templateRepo?.value) {
+ formControl.setValue("templateRepoBranch", {
+ label: templateRepo.addedFields.branch,
+ value: templateRepo.addedFields.branch,
+ });
+ }
+ }, [templateRepo?.value]);
+
return (
{
dataKey: "Results",
valueField: "FullName",
labelField: (option) => `${option.Name} (${option.URL})`,
+ addedField: {
+ branch: "DefaultBranch",
+ },
}}
formControl={formControl}
multiple={false}