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 { 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 @@
mode: "binary",
formLabels: [],
selectedTargets: [],
selectedSourceLabels: [],
withKnownLibs: "app",
includedPackages: [],
excludedPackages: [],
Expand Down Expand Up @@ -251,7 +253,16 @@
labels: {
included: Array.from(
new Set<string>([
...fieldValues.formLabels.map((label) => label.label),
...fieldValues.formLabels
.filter(
(label) =>
getParsedLabel(label.label).labelType !== "source"

Check warning on line 259 in client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx

View check run for this annotation

Codecov / codecov/patch

client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx#L259

Added line #L259 was not covered by tests
)
.map((label) => label.label)

Check warning on line 261 in client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx

View check run for this annotation

Codecov / codecov/patch

client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx#L261

Added line #L261 was not covered by tests
.filter(Boolean),
...fieldValues.selectedSourceLabels
.map((label) => label.label)

Check warning on line 264 in client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx

View check run for this annotation

Codecov / codecov/patch

client/src/app/pages/applications/analysis-wizard/analysis-wizard.tsx#L264

Added line #L264 was not covered by tests
.filter(Boolean),
])
),
excluded: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
const { watch } = useFormContext<AnalysisWizardFormValues>();
const {
formLabels,
selectedSourceLabels,
withKnownLibs,
includedPackages,
hasExcludedPackages,
Expand Down Expand Up @@ -101,13 +102,13 @@
</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) => {

Check warning on line 111 in client/src/app/pages/applications/analysis-wizard/review.tsx

View check run for this annotation

Codecov / codecov/patch

client/src/app/pages/applications/analysis-wizard/review.tsx#L111

Added line #L111 was not covered by tests
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 @@
/>
<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

Check warning on line 168 in client/src/app/pages/applications/analysis-wizard/set-options.tsx

View check run for this annotation

Codecov / codecov/patch

client/src/app/pages/applications/analysis-wizard/set-options.tsx#L168

Added line #L168 was not covered by tests
.map((formLabel) => {
const parsedLabel = getParsedLabel(formLabel?.label);
if (parsedLabel.labelType === "source") {
Expand All @@ -190,17 +190,17 @@
(label) => label.label === selectionWithLabelSelector
) || "";

const formLabelLabels = formLabels.map(
const formLabelLabels = value.map(

Check warning on line 193 in client/src/app/pages/applications/analysis-wizard/set-options.tsx

View check run for this annotation

Codecov / codecov/patch

client/src/app/pages/applications/analysis-wizard/set-options.tsx#L193

Added line #L193 was not covered by tests
(formLabel) => formLabel.label
);
if (
matchingLabel &&
!formLabelLabels.includes(matchingLabel.label)
) {
onChange([...formLabels, matchingLabel]);
onChange([...value, matchingLabel]);

Check warning on line 200 in client/src/app/pages/applications/analysis-wizard/set-options.tsx

View check run for this annotation

Codecov / codecov/patch

client/src/app/pages/applications/analysis-wizard/set-options.tsx#L200

Added line #L200 was not covered by tests
} else {
onChange(
formLabels.filter(
value.filter(
(formLabel) =>
formLabel.label !== selectionWithLabelSelector
)
Expand Down
Loading