Skip to content

Commit

Permalink
Choose initially selected languages from available providers
Browse files Browse the repository at this point in the history
Resolves: #2009
Signed-off-by: Radoslaw Szwajkowski <[email protected]>
  • Loading branch information
rszwajko committed Aug 2, 2024
1 parent a342f27 commit 09e54c7
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions client/src/app/pages/applications/analysis-wizard/set-targets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Application, TagCategory, Target } from "@app/api/models";
import { useFetchTagCategories } from "@app/queries/tags";
import { SimpleSelectCheckbox } from "@app/components/SimpleSelectCheckbox";
import { getUpdatedFormLabels, updateSelectedTargets } from "./utils";
import { unique } from "radash";

interface SetTargetsProps {
applications: Application[];
Expand Down Expand Up @@ -48,22 +49,23 @@ export const SetTargets: React.FC<SetTargetsProps> = ({ applications }) => {
);
};

const initialProviders = Array.from(
new Set(
applications
.flatMap((app) => app.tags || [])
.map((tag) => {
return {
category: findCategoryForTag(tag.id),
tag,
};
})
.filter((tagWithCat) => tagWithCat?.category?.name === "Language")
.map((tagWithCat) => tagWithCat.tag.name)
)
).filter(Boolean);
const allProviders = targets.flatMap((target) => target.provider);
const languageOptions = Array.from(new Set(allProviders));

const [providers, setProviders] = useState(initialProviders);
const initialProviders = unique(
applications
.flatMap((app) => app.tags || [])
.map((tag) => {
return {
category: findCategoryForTag(tag.id),
tag,
};
})
.filter((tag) => tag?.category?.name === "Language")
.map((languageTag) => languageTag.tag.name)
).filter((language) => languageOptions.includes(language));

const [selectedProviders, setSelectedProviders] = useState(initialProviders);

const handleOnSelectedCardTargetChange = (selectedLabelName: string) => {
const otherSelectedLabels = formLabels?.filter((formLabel) => {
Expand Down Expand Up @@ -119,16 +121,13 @@ export const SetTargets: React.FC<SetTargetsProps> = ({ applications }) => {
setValue("selectedTargets", updatedSelectedTargets);
};

const allProviders = targets.flatMap((target) => target.provider);
const languageOptions = Array.from(new Set(allProviders));

const targetsToRender: Target[] = !targetOrderSetting.isSuccess
? []
: targetOrderSetting.data
.map((targetId) => targets.find((target) => target.id === targetId))
.filter(Boolean)
.filter((target) =>
providers.some((p) => target.provider?.includes(p) ?? false)
selectedProviders.some((p) => target.provider?.includes(p) ?? false)
);

return (
Expand All @@ -146,15 +145,15 @@ export const SetTargets: React.FC<SetTargetsProps> = ({ applications }) => {
<SimpleSelectCheckbox
placeholderText="Filter by language..."
width={300}
value={providers}
value={selectedProviders}
options={languageOptions?.map((language): SelectOptionProps => {
return {
children: <div>{language}</div>,
value: language,
};
})}
onChange={(selection) => {
setProviders(selection as string[]);
setSelectedProviders(selection as string[]);
}}
id="filter-by-language"
toggleId="action-select-toggle"
Expand Down

0 comments on commit 09e54c7

Please sign in to comment.