Skip to content

Commit

Permalink
add default branch to query params
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnDuprey committed Feb 11, 2025
1 parent 4905c8b commit 9653cc5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion 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
15 changes: 9 additions & 6 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 @@ -110,10 +110,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 +169,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 Down

0 comments on commit 9653cc5

Please sign in to comment.