Skip to content

Commit

Permalink
Reload repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Jan 16, 2025
1 parent 479d7c8 commit f9d3c32
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
6 changes: 6 additions & 0 deletions web/src/api/software.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ const fetchRepositories = (): Promise<Repository[]> => get("/api/software/reposi
*/
const updateConfig = (config: SoftwareConfig) => put("/api/software/config", config);

/**
* Updates the software configuration
*/
const probe = () => post("/api/software/probe");

/**
* Request registration of selected product with given key
*/
Expand All @@ -81,5 +86,6 @@ export {
fetchRegistration,
fetchRepositories,
updateConfig,
probe,
register,
};
26 changes: 22 additions & 4 deletions web/src/components/software/SoftwarePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import React from "react";
import {
Alert,
Button,
DescriptionList,
DescriptionListDescription,
DescriptionListGroup,
Expand All @@ -33,7 +35,13 @@ import {
import { Link, IssuesHint, Page } from "~/components/core";
import UsedSize from "./UsedSize";
import { useIssues } from "~/queries/issues";
import { usePatterns, useProposal, useProposalChanges, useRepositories } from "~/queries/software";
import {
usePatterns,
useProposal,
useProposalChanges,
useRepositories,
useRepositoryMutation,
} from "~/queries/software";
import { Pattern, SelectedBy } from "~/types/software";
import { _ } from "~/i18n";
import { SOFTWARE as PATHS } from "~/routes/paths";
Expand Down Expand Up @@ -86,9 +94,6 @@ const NoPatterns = (): React.ReactNode => (
</Page.Section>
);

// TODO: implement a real button, reprobe after clicking
const ReloadSection = (): React.ReactNode => <p>{_("Reload")}</p>;

/**
* Software page component
*/
Expand All @@ -97,13 +102,26 @@ function SoftwarePage(): React.ReactNode {
const proposal = useProposal();
const patterns = usePatterns();
const repos = useRepositories();
const { mutate: probe } = useRepositoryMutation();

useProposalChanges();

// Selected patterns section should fill the full width in big screen too when
// there is no information for rendering the Proposal Size section.
const selectedPatternsXlSize = proposal.size ? 6 : 12;

const ReloadSection = (): React.ReactNode => (
<Alert variant="warning" isInline title={_("Repository load failed")}>
{_(
"Some installation repositories failed to load. The system cannot be installed without them.",
)}{" "}
{/* TODO: add some loading indicator */}
<Button variant="link" isInline onClick={probe}>
{_("Try again")}
</Button>
</Alert>
);

const reload = repos.some((r) => !r.loaded) ? <ReloadSection /> : null;

return (
Expand Down
17 changes: 17 additions & 0 deletions web/src/queries/software.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
fetchProposal,
fetchRegistration,
fetchRepositories,
probe,
register,
updateConfig,
} from "~/api/software";
Expand Down Expand Up @@ -151,6 +152,21 @@ const useRegisterMutation = () => {
return useMutation(query);
};

/**
* Hook that builds a mutation for reloading repositories
*/
const useRepositoryMutation = () => {
const queryClient = useQueryClient();

const query = {
mutationFn: probe,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["software/repositories"] });
},
};
return useMutation(query);
};

/**
* Returns available products and selected one, if any
*/
Expand Down Expand Up @@ -285,4 +301,5 @@ export {
useRegistration,
useRegisterMutation,
useRepositories,
useRepositoryMutation,
};

0 comments on commit f9d3c32

Please sign in to comment.