Take filtered state into account for buttons text
When the user filters the repositories, the buttons should reflect that the results are filtered and that the user is not exporting or copying all the results. If the user has selected repositories, the buttons should still say that they are exporting selected results.
This commit is contained in:
@@ -16,6 +16,7 @@ export type VariantAnalysisActionsProps = {
|
||||
exportResultsDisabled?: boolean;
|
||||
|
||||
hasSelectedRepositories?: boolean;
|
||||
hasFilteredRepositories?: boolean;
|
||||
};
|
||||
|
||||
const Container = styled.div`
|
||||
@@ -28,6 +29,28 @@ const Button = styled(VSCodeButton)`
|
||||
white-space: nowrap;
|
||||
`;
|
||||
|
||||
const chooseText = ({
|
||||
hasSelectedRepositories,
|
||||
hasFilteredRepositories,
|
||||
normalText,
|
||||
selectedText,
|
||||
filteredText,
|
||||
}: {
|
||||
hasSelectedRepositories?: boolean;
|
||||
hasFilteredRepositories?: boolean;
|
||||
normalText: string;
|
||||
selectedText: string;
|
||||
filteredText: string;
|
||||
}) => {
|
||||
if (hasSelectedRepositories) {
|
||||
return selectedText;
|
||||
}
|
||||
if (hasFilteredRepositories) {
|
||||
return filteredText;
|
||||
}
|
||||
return normalText;
|
||||
};
|
||||
|
||||
export const VariantAnalysisActions = ({
|
||||
variantAnalysisStatus,
|
||||
onStopQueryClick,
|
||||
@@ -38,6 +61,7 @@ export const VariantAnalysisActions = ({
|
||||
copyRepositoryListDisabled,
|
||||
exportResultsDisabled,
|
||||
hasSelectedRepositories,
|
||||
hasFilteredRepositories,
|
||||
}: VariantAnalysisActionsProps) => {
|
||||
return (
|
||||
<Container>
|
||||
@@ -48,18 +72,26 @@ export const VariantAnalysisActions = ({
|
||||
onClick={onCopyRepositoryListClick}
|
||||
disabled={copyRepositoryListDisabled}
|
||||
>
|
||||
{hasSelectedRepositories
|
||||
? "Copy selected repositories as a list"
|
||||
: "Copy repository list"}
|
||||
{chooseText({
|
||||
hasSelectedRepositories,
|
||||
hasFilteredRepositories,
|
||||
normalText: "Copy repository list",
|
||||
selectedText: "Copy selected repositories as a list",
|
||||
filteredText: "Copy filtered repositories as a list",
|
||||
})}
|
||||
</Button>
|
||||
<Button
|
||||
appearance="primary"
|
||||
onClick={onExportResultsClick}
|
||||
disabled={exportResultsDisabled}
|
||||
>
|
||||
{hasSelectedRepositories
|
||||
? "Export selected results"
|
||||
: "Export results"}
|
||||
{chooseText({
|
||||
hasSelectedRepositories,
|
||||
hasFilteredRepositories,
|
||||
normalText: "Export results",
|
||||
selectedText: "Export selected results",
|
||||
filteredText: "Export filtered results",
|
||||
})}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -131,6 +131,10 @@ export const VariantAnalysisHeader = ({
|
||||
stopQueryDisabled={!variantAnalysis.actionsWorkflowRunId}
|
||||
exportResultsDisabled={!hasDownloadedRepos}
|
||||
copyRepositoryListDisabled={!hasReposWithResults}
|
||||
hasFilteredRepositories={
|
||||
variantAnalysis.scannedRepos?.length !==
|
||||
filteredRepositories?.length
|
||||
}
|
||||
hasSelectedRepositories={
|
||||
selectedRepositoryIds && selectedRepositoryIds.length > 0
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ describe(VariantAnalysisActions.name, () => {
|
||||
variantAnalysisStatus: VariantAnalysisStatus.Succeeded,
|
||||
showResultActions: true,
|
||||
hasSelectedRepositories: true,
|
||||
hasFilteredRepositories: true,
|
||||
});
|
||||
|
||||
expect(screen.getByText("Export selected results")).toBeInTheDocument();
|
||||
@@ -106,4 +107,18 @@ describe(VariantAnalysisActions.name, () => {
|
||||
screen.getByText("Copy selected repositories as a list"),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("changes the text on the buttons when repositories are filtered", async () => {
|
||||
render({
|
||||
variantAnalysisStatus: VariantAnalysisStatus.Succeeded,
|
||||
showResultActions: true,
|
||||
hasSelectedRepositories: false,
|
||||
hasFilteredRepositories: true,
|
||||
});
|
||||
|
||||
expect(screen.getByText("Export filtered results")).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText("Copy filtered repositories as a list"),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user