Skip to content

Commit 89db3e2

Browse files
committed
feat(ui): Add form inputs for reporter plugin options
Add form inputs to configure all reporter plugin options when triggering an ORT run, similar to how it was previously implemented for advisor plugins. This change makes the `deduplicateDependencyTree` option obsolete because it can now be configured directly in the plugins supporting it. It also makes the default values for the report output formats obsolete because they can now be configured with plugin config templates. Signed-off-by: Martin Nonnenmacher <[email protected]>
1 parent 9b729f7 commit 89db3e2

File tree

3 files changed

+33
-118
lines changed

3 files changed

+33
-118
lines changed

ui/src/routes/organizations/$orgId/products/$productId/repositories/$repoId/-components/reporter-fields.tsx

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,14 @@
1919

2020
import { UseFormReturn } from 'react-hook-form';
2121

22-
import { PreconfiguredPluginDescriptor } from '@/api/requests';
23-
import { MultiSelectField } from '@/components/form/multi-select-field';
22+
import { PreconfiguredPluginDescriptor, Secret } from '@/api/requests';
23+
import { PluginMultiSelectField } from '@/components/form/plugin-multi-select-field.tsx';
2424
import {
2525
AccordionContent,
2626
AccordionItem,
2727
AccordionTrigger,
2828
} from '@/components/ui/accordion';
29-
import {
30-
FormControl,
31-
FormDescription,
32-
FormField,
33-
FormItem,
34-
FormLabel,
35-
} from '@/components/ui/form';
29+
import { FormControl, FormField } from '@/components/ui/form';
3630
import { Switch } from '@/components/ui/switch';
3731
import { CreateRunFormValues } from '../_repo-layout/create-run/-create-run-utils';
3832

@@ -41,20 +35,16 @@ type ReporterFieldsProps = {
4135
value: string;
4236
onToggle: () => void;
4337
reporterPlugins: PreconfiguredPluginDescriptor[];
38+
secrets: Secret[];
4439
};
4540

4641
export const ReporterFields = ({
4742
form,
4843
value,
4944
onToggle,
5045
reporterPlugins,
46+
secrets,
5147
}: ReporterFieldsProps) => {
52-
const reporterOptions = reporterPlugins.map((plugin) => ({
53-
id: plugin.id,
54-
label: plugin.displayName,
55-
description: plugin.description,
56-
}));
57-
5848
return (
5949
<div className='flex flex-row align-middle'>
6050
<FormField
@@ -73,46 +63,17 @@ export const ReporterFields = ({
7363
<AccordionItem value={value} className='flex-1'>
7464
<AccordionTrigger onClick={onToggle}>Reporter</AccordionTrigger>
7565
<AccordionContent>
76-
<MultiSelectField
66+
<PluginMultiSelectField
7767
form={form}
7868
name='jobConfigs.reporter.formats'
69+
configName='jobConfigs.reporter.config'
7970
label='Report formats'
8071
description={
8172
<>Select the report formats to generate from the run.</>
8273
}
83-
options={reporterOptions}
74+
plugins={reporterPlugins}
75+
secrets={secrets}
8476
/>
85-
{form.getValues('jobConfigs.reporter.formats').includes('WebApp') && (
86-
<FormField
87-
control={form.control}
88-
name='jobConfigs.reporter.deduplicateDependencyTree'
89-
render={({ field }) => (
90-
<FormItem className='mb-4 flex flex-row items-center justify-between rounded-lg border p-4'>
91-
<div className='space-y-0.5'>
92-
<FormLabel>Deduplicate dependency tree</FormLabel>
93-
<FormDescription>
94-
A flag to control whether subtrees occurring multiple
95-
times in the dependency tree are stripped.
96-
</FormDescription>
97-
<FormDescription>
98-
This will significantly reduce memory consumption of the
99-
Reporter and might alleviate some out-of-memory issues.
100-
</FormDescription>
101-
<FormDescription>
102-
NOTE: This option is currently effective only for the
103-
WebApp report format.
104-
</FormDescription>
105-
</div>
106-
<FormControl>
107-
<Switch
108-
checked={field.value}
109-
onCheckedChange={field.onChange}
110-
/>
111-
</FormControl>
112-
</FormItem>
113-
)}
114-
/>
115-
)}
11677
</AccordionContent>
11778
</AccordionItem>
11879
</div>

ui/src/routes/organizations/$orgId/products/$productId/repositories/$repoId/_repo-layout/create-run/-create-run-utils.ts

Lines changed: 21 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import {
2727
PluginConfig,
2828
PluginOptionType,
2929
PreconfiguredPluginDescriptor,
30-
ReporterJobConfiguration,
3130
} from '@/api/requests';
3231
import { PackageManagerId, packageManagers } from '@/lib/types';
3332

@@ -106,14 +105,21 @@ const createPluginConfigSchema = (plugin: PreconfiguredPluginDescriptor) => {
106105
};
107106

108107
export const createRunFormSchema = (
109-
advisorPlugins: PreconfiguredPluginDescriptor[]
108+
advisorPlugins: PreconfiguredPluginDescriptor[],
109+
reporterPlugins: PreconfiguredPluginDescriptor[]
110110
) => {
111111
const advisorConfigSchema: Record<string, z.ZodTypeAny> = {};
112112

113113
advisorPlugins.forEach((plugin) => {
114114
advisorConfigSchema[plugin.id] = createPluginConfigSchema(plugin);
115115
});
116116

117+
const reporterConfigSchema: Record<string, z.ZodTypeAny> = {};
118+
119+
reporterPlugins.forEach((plugin) => {
120+
reporterConfigSchema[plugin.id] = createPluginConfigSchema(plugin);
121+
});
122+
117123
return z.object({
118124
revision: z.string(),
119125
path: z.string(),
@@ -178,7 +184,7 @@ export const createRunFormSchema = (
178184
reporter: z.object({
179185
enabled: z.boolean(),
180186
formats: z.array(z.string()),
181-
deduplicateDependencyTree: z.boolean().optional(),
187+
config: z.object(reporterConfigSchema).optional(),
182188
}),
183189
notifier: z.object({
184190
enabled: z.boolean(),
@@ -342,7 +348,8 @@ function getPluginDefaultValues(plugins: PreconfiguredPluginDescriptor[]) {
342348
*/
343349
export function defaultValues(
344350
ortRun: OrtRun | null,
345-
advisorPlugins: PreconfiguredPluginDescriptor[]
351+
advisorPlugins: PreconfiguredPluginDescriptor[],
352+
reporterPlugins: PreconfiguredPluginDescriptor[]
346353
): z.infer<ReturnType<typeof createRunFormSchema>> {
347354
/**
348355
* Constructs the default options for a package manager, either as a blank set of options
@@ -380,17 +387,8 @@ export function defaultValues(
380387
};
381388
};
382389

383-
// Find out if any of the reporters had their options.deduplicateDependencyTree set to true in the previous run.
384-
// This is used to set the default value for the deduplicateDependencyTree toggle in the UI.
385-
const deduplicateDependencyTreeEnabled = ortRun
386-
? ortRun.jobConfigs.reporter?.config &&
387-
Object.keys(ortRun.jobConfigs.reporter.config ?? {}).some((key) => {
388-
const config = ortRun.jobConfigs.reporter?.config?.[key];
389-
return config?.options?.deduplicateDependencyTree === 'true';
390-
})
391-
: false;
392-
393390
const advisorPluginDefaultValues = getPluginDefaultValues(advisorPlugins);
391+
const reporterPluginDefaultValues = getPluginDefaultValues(reporterPlugins);
394392

395393
// Default values for the form: edit only these, not the defaultValues object.
396394
const baseDefaults = {
@@ -452,6 +450,7 @@ export function defaultValues(
452450
enabled: true,
453451
formats: ['CycloneDX', 'SpdxDocument', 'WebApp'],
454452
deduplicateDependencyTree: false,
453+
config: reporterPluginDefaultValues,
455454
},
456455
notifier: {
457456
enabled: false,
@@ -530,8 +529,10 @@ export function defaultValues(
530529
ortRun.jobConfigs.reporter?.formats?.map((format) =>
531530
format === 'CycloneDx' ? 'CycloneDX' : format
532531
) || baseDefaults.jobConfigs.reporter.formats,
533-
deduplicateDependencyTree:
534-
deduplicateDependencyTreeEnabled || undefined,
532+
config: mergePluginConfigs(
533+
ortRun?.jobConfigs?.reporter?.config,
534+
reporterPluginDefaultValues
535+
),
535536
},
536537
notifier: {
537538
enabled:
@@ -752,61 +753,13 @@ export function formValuesToPayload(
752753
// Reporter configuration
753754
//
754755

755-
// Check if CycloneDX, SPDX, and/or NOTICE file reports are enabled in the form,
756-
// and configure them to use all output formats, accordingly.
757-
758-
const cycloneDxEnabled =
759-
values.jobConfigs.reporter.formats.includes('CycloneDX');
760-
const spdxDocumentEnabled =
761-
values.jobConfigs.reporter.formats.includes('SpdxDocument');
762-
const noticeFileEnabled =
763-
values.jobConfigs.reporter.formats.includes('PlainTextTemplate');
764-
765-
const config: ReporterJobConfiguration['config'] = {};
766-
767-
if (spdxDocumentEnabled) {
768-
config.SpdxDocument = {
769-
options: {
770-
outputFileFormats: 'YAML,JSON',
771-
},
772-
secrets: {},
773-
};
774-
}
775-
776-
if (cycloneDxEnabled) {
777-
config.CycloneDX = {
778-
options: {
779-
outputFileFormats: 'XML,JSON',
780-
},
781-
secrets: {},
782-
};
783-
}
784-
785-
if (noticeFileEnabled) {
786-
config.PlainTextTemplate = {
787-
options: {
788-
templateIds: 'NOTICE_DEFAULT,NOTICE_SUMMARY',
789-
},
790-
secrets: {},
791-
};
792-
}
793-
794-
// If WebApp and the deduplicateDependencyTree option are enabled, add the configuration.
795-
796-
const webAppEnabled = values.jobConfigs.reporter.formats.includes('WebApp');
797-
if (webAppEnabled && values.jobConfigs.reporter.deduplicateDependencyTree) {
798-
config.WebApp = {
799-
options: {
800-
deduplicateDependencyTree: 'true',
801-
},
802-
secrets: {},
803-
};
804-
}
805-
806756
const reporterConfig = values.jobConfigs.reporter.enabled
807757
? {
808758
formats: values.jobConfigs.reporter.formats,
809-
config: Object.keys(config).length > 0 ? config : undefined,
759+
config: createPluginPayload(
760+
values.jobConfigs.reporter.config,
761+
values.jobConfigs.reporter.formats
762+
),
810763
}
811764
: undefined;
812765

ui/src/routes/organizations/$orgId/products/$productId/repositories/$repoId/_repo-layout/create-run/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ const CreateRunPage = () => {
124124
},
125125
});
126126

127-
const formSchema = createRunFormSchema(advisorPlugins);
127+
const formSchema = createRunFormSchema(advisorPlugins, reporterPlugins);
128128

129129
const form = useForm<z.infer<typeof formSchema>>({
130130
resolver: zodResolver(formSchema),
131-
defaultValues: defaultValues(ortRun, advisorPlugins),
131+
defaultValues: defaultValues(ortRun, advisorPlugins, reporterPlugins),
132132
});
133133

134134
const {
@@ -440,6 +440,7 @@ const CreateRunPage = () => {
440440
value='reporter'
441441
onToggle={() => toggleAccordionOpen('reporter')}
442442
reporterPlugins={reporterPlugins}
443+
secrets={secrets}
443444
/>
444445
<NotifierFields
445446
form={form}

0 commit comments

Comments
 (0)