Skip to content

Commit

Permalink
🐛 Don't auto select source labels when setting a target (#1485)
Browse files Browse the repository at this point in the history
- Only include explicitly selected source labels from a selected target

Signed-off-by: ibolton336 <[email protected]>
  • Loading branch information
ibolton336 authored Oct 20, 2023
1 parent 07a31c0 commit abafafa
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
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
5 changes: 3 additions & 2 deletions client/src/app/pages/applications/analysis-wizard/review.tsx
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

0 comments on commit abafafa

Please sign in to comment.