Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Don't auto select source labels when setting a target #1485

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { useAsyncYupValidation } from "@app/hooks/useAsyncYupValidation";
import { CustomRules } from "./custom-rules";
import { useFetchIdentities } from "@app/queries/identities";
import { useTaskGroup } from "./components/TaskGroupContext";
import { getParsedLabel } from "@app/utils/rules-utils";

interface IAnalysisWizard {
applications: Application[];
Expand Down Expand Up @@ -164,6 +165,7 @@ export const AnalysisWizard: React.FC<IAnalysisWizard> = ({
mode: "binary",
formLabels: [],
selectedTargets: [],
selectedSourceLabels: [],
withKnownLibs: "app",
includedPackages: [],
excludedPackages: [],
Expand Down Expand Up @@ -251,7 +253,16 @@ export const AnalysisWizard: React.FC<IAnalysisWizard> = ({
labels: {
included: Array.from(
new Set<string>([
...fieldValues.formLabels.map((label) => label.label),
...fieldValues.formLabels
.filter(
(label) =>
getParsedLabel(label.label).labelType !== "source"
)
.map((label) => label.label)
.filter(Boolean),
...fieldValues.selectedSourceLabels
.map((label) => label.label)
.filter(Boolean),
])
),
excluded: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const Review: React.FC<IReview> = ({ applications, mode }) => {
const { watch } = useFormContext<AnalysisWizardFormValues>();
const {
formLabels,
selectedSourceLabels,
withKnownLibs,
includedPackages,
hasExcludedPackages,
Expand Down Expand Up @@ -101,13 +102,13 @@ export const Review: React.FC<IReview> = ({ applications, mode }) => {
</DescriptionListGroup>
<DescriptionListGroup>
<DescriptionListTerm>
{formLabels.length > 1
{selectedSourceLabels.length > 1
? t("wizard.terms.sources")
: t("wizard.terms.source")}
</DescriptionListTerm>
<DescriptionListDescription id="sources">
<List isPlain>
{formLabels.map((label, index) => {
{selectedSourceLabels.map((label, index) => {
const parsedLabel = getParsedLabel(label?.label);
if (parsedLabel.labelType === "source") {
return (
Expand Down
7 changes: 7 additions & 0 deletions client/src/app/pages/applications/analysis-wizard/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export interface OptionsStepValues {
diva: boolean;
excludedRulesTags: string[];
autoTaggingEnabled: boolean;
selectedSourceLabels: TargetLabel[];
}

const useOptionsStepSchema = (): yup.SchemaOf<OptionsStepValues> => {
Expand All @@ -166,6 +167,12 @@ const useOptionsStepSchema = (): yup.SchemaOf<OptionsStepValues> => {
diva: yup.bool().defined(),
excludedRulesTags: yup.array().of(yup.string().defined()),
autoTaggingEnabled: yup.bool().defined(),
selectedSourceLabels: yup.array().of(
yup.object().shape({
name: yup.string().defined(),
label: yup.string().defined(),
})
),
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ export const SetOptions: React.FC = () => {
/>
<HookFormPFGroupController
control={control}
name="formLabels"
name="selectedSourceLabels"
label={t("wizard.terms.sources")}
fieldId="sources"
renderInput={({
field: { onChange, onBlur, value },
fieldState: { isDirty, error, isTouched },
}) => {
const sourceSelections = formLabels
const sourceSelections = value
.map((formLabel) => {
const parsedLabel = getParsedLabel(formLabel?.label);
if (parsedLabel.labelType === "source") {
Expand All @@ -190,17 +190,17 @@ export const SetOptions: React.FC = () => {
(label) => label.label === selectionWithLabelSelector
) || "";

const formLabelLabels = formLabels.map(
const formLabelLabels = value.map(
(formLabel) => formLabel.label
);
if (
matchingLabel &&
!formLabelLabels.includes(matchingLabel.label)
) {
onChange([...formLabels, matchingLabel]);
onChange([...value, matchingLabel]);
} else {
onChange(
formLabels.filter(
value.filter(
(formLabel) =>
formLabel.label !== selectionWithLabelSelector
)
Expand Down