Skip to content

Commit

Permalink
Merge pull request #54 from justinlampley/FixFirmwareOptionsNotPopula…
Browse files Browse the repository at this point in the history
…tedAfterBuild

Fix issue that after clicking "Back" button from the firmware flashing screen firmware options are not present anymore
  • Loading branch information
jurgelenas authored Aug 25, 2021
2 parents 0cfa97d + 7a69cea commit ef5dc53
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/ui/components/FirmwareVersionForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const FirmwareVersionForm: FunctionComponent<FirmwareVersionCardProps> = (
queryGitPullRequests,
{
loading: gitPullRequestsLoading,
data: gitpullRequestsResponse,
data: gitPullRequestsResponse,
error: pullRequestsError,
},
] = useGetPullRequestsLazyQuery();
Expand All @@ -121,7 +121,7 @@ const FirmwareVersionForm: FunctionComponent<FirmwareVersionCardProps> = (
gitTagsLoading || gitBranchesLoading || gitPullRequestsLoading;
const gitTags = gitTagsResponse?.releases ?? [];
const gitBranches = gitBranchesResponse?.gitBranches ?? [];
const gitPullRequests = gitpullRequestsResponse?.pullRequests ?? [];
const gitPullRequests = gitPullRequestsResponse?.pullRequests;

const [currentGitTag, setCurrentGitTag] = useState<string>(
data?.gitTag || ''
Expand Down Expand Up @@ -175,29 +175,39 @@ const FirmwareVersionForm: FunctionComponent<FirmwareVersionCardProps> = (
const [
currentGitPullRequest,
setCurrentGitPullRequest,
] = useState<PullRequestInput | null>(
gitPullRequests.find(
(item) => item.number === data?.gitPullRequest?.number
) || null
);
] = useState<PullRequestInput | null>(data?.gitPullRequest || null);

/*
Make sure that a valid pull request is selected
*/
useEffect(() => {
if (gitPullRequestsResponse?.pullRequests && currentGitPullRequest) {
const pullRequest =
gitPullRequestsResponse.pullRequests.find(
(item) => item.number === currentGitPullRequest.number
) || null;
// if we have a list of pull requests and the current pull request is not
// part of that list, then set current pull request to null
if (!pullRequest) {
setCurrentGitPullRequest(null);
}
}
}, [gitPullRequestsResponse, currentGitPullRequest]);

const onGitPullRequest = (value: string | null) => {
if (value === null) {
setCurrentGitPullRequest(null);
return;
}
const pullRequest =
gitPullRequests.find((item) => item.number === parseInt(value, 10)) ||
null;
const iValue = parseInt(value, 10);
const pullRequest = gitPullRequests?.find((item) => item.number === iValue);
if (pullRequest) {
setCurrentGitPullRequest({
id: pullRequest.id,
number: pullRequest.number,
title: pullRequest.title,
headCommitHash: pullRequest.headCommitHash,
});
} else {
setCurrentGitPullRequest(null);
}
};

Expand Down

0 comments on commit ef5dc53

Please sign in to comment.