From fe25bf19acf5f973ccd86bafb1ecc8d8ce754d33 Mon Sep 17 00:00:00 2001 From: Simeon Widdis Date: Mon, 10 Jun 2024 10:50:09 -0700 Subject: [PATCH] Add applicable_data_sources field to workflows definition (#1868) * Add applicable_data_sources field to workflows definition Signed-off-by: Simeon Widdis * Add workflow filtering by applicable data sources Signed-off-by: Simeon Widdis * Add tests for new functionality Signed-off-by: Simeon Widdis * Only use applicable workflows in index-based install Signed-off-by: Simeon Widdis * Rename flint dashboards workflow since there's no collision Signed-off-by: Simeon Widdis --------- Signed-off-by: Simeon Widdis --- .../setup_integration_inputs.test.tsx.snap | 157 ++++++++++++++++++ .../setup_integration_inputs.test.tsx | 37 ++++- .../components/setup_integration.tsx | 9 + .../components/setup_integration_inputs.tsx | 52 +++--- .../amazon_vpc_flow-1.1.0.json | 10 +- server/adaptors/integrations/types.ts | 1 + server/adaptors/integrations/validators.ts | 9 + 7 files changed, 250 insertions(+), 25 deletions(-) diff --git a/public/components/integrations/components/__tests__/__snapshots__/setup_integration_inputs.test.tsx.snap b/public/components/integrations/components/__tests__/__snapshots__/setup_integration_inputs.test.tsx.snap index 2b74ba8818..253e068f95 100644 --- a/public/components/integrations/components/__tests__/__snapshots__/setup_integration_inputs.test.tsx.snap +++ b/public/components/integrations/components/__tests__/__snapshots__/setup_integration_inputs.test.tsx.snap @@ -203,6 +203,17 @@ exports[`Integration Setup Inputs Renders the S3 connector form as expected 1`] + +
+ Must select at least one workflow. +
+
+ + + +
+`; + +exports[`Integration Setup Inputs Renders the workflows inputs with conditional workflows 1`] = ` + + +
+
+ { it('Renders the workflows inputs', async () => { const wrapper = mount( - {}} integration={TEST_INTEGRATION_CONFIG} /> + {}} + integration={TEST_INTEGRATION_CONFIG} + /> + ); + + await waitFor(() => { + expect(wrapper).toMatchSnapshot(); + }); + }); + + it('Renders the workflows inputs with conditional workflows', async () => { + const wrapper = mount( + {}} + integration={{ + ...TEST_INTEGRATION_CONFIG, + workflows: [ + { + name: 'workflow1', + label: 'Workflow 1', + description: 'This is a test workflow.', + enabled_by_default: true, + }, + { + name: 'workflow2', + label: 'Workflow 2', + description: 'This should not render.', + enabled_by_default: true, + applicable_data_sources: ['index'], + }, + ], + }} + /> ); await waitFor(() => { diff --git a/public/components/integrations/components/setup_integration.tsx b/public/components/integrations/components/setup_integration.tsx index 490759146f..c53ed29b8d 100644 --- a/public/components/integrations/components/setup_integration.tsx +++ b/public/components/integrations/components/setup_integration.tsx @@ -144,6 +144,14 @@ const addIntegration = async ({ let sessionId: string | null = null; if (config.connectionType === 'index') { + let enabledWorkflows: string[] | undefined; + if (integration.workflows) { + enabledWorkflows = integration.workflows + .filter((w) => + w.applicable_data_sources ? w.applicable_data_sources.includes('index') : true + ) + .map((w) => w.name); + } const res = await addIntegrationRequest({ addSample: false, templateName: integration.name, @@ -152,6 +160,7 @@ const addIntegration = async ({ name: config.displayName, indexPattern: config.connectionDataSource, skipRedirect: setIsInstalling ? true : false, + workflows: enabledWorkflows, }); if (setIsInstalling) { setIsInstalling(false, res); diff --git a/public/components/integrations/components/setup_integration_inputs.tsx b/public/components/integrations/components/setup_integration_inputs.tsx index 8978b825c8..4ab4bc70f7 100644 --- a/public/components/integrations/components/setup_integration_inputs.tsx +++ b/public/components/integrations/components/setup_integration_inputs.tsx @@ -99,8 +99,8 @@ const suggestDataSources = async ( }>; const filterCondition = type === 's3' - ? (item: any) => item.connector === 'S3GLUE' - : (item: any) => item.connector === 'SECURITYLAKE'; + ? (item: { connector: string }) => item.connector === 'S3GLUE' + : (item: { connector: string }) => item.connector === 'SECURITYLAKE'; return ( result?.filter(filterCondition).map((item) => { @@ -121,33 +121,41 @@ export function SetupWorkflowSelector({ integrationWorkflows, useWorkflows, toggleWorkflow, + config, }: { integrationWorkflows?: IntegrationWorkflow[]; useWorkflows: Map; toggleWorkflow: (name: string) => void; + config: IntegrationSetupInputs; }) { if (!integrationWorkflows) { return null; } - const cards = integrationWorkflows.map((workflow) => { - return ( - <> - toggleWorkflow(workflow.name)} - > - {workflow.description} - - - - ); - }); + const cards = integrationWorkflows + .filter((workflow) => + workflow.applicable_data_sources + ? workflow.applicable_data_sources.includes(config.connectionType) + : true + ) + .map((workflow) => { + return ( + <> + toggleWorkflow(workflow.name)} + > + {workflow.description} + + + + ); + }); return <>{cards}; } @@ -343,9 +351,11 @@ export function IntegrationQueryInputs({ } export function IntegrationWorkflowsInputs({ + config, updateConfig, workflows, }: { + config: IntegrationSetupInputs; updateConfig: (updates: Partial) => void; workflows?: IntegrationWorkflow[]; }) { @@ -378,6 +388,7 @@ export function IntegrationWorkflowsInputs({ error={['Must select at least one workflow.']} > diff --git a/server/adaptors/integrations/__data__/repository/amazon_vpc_flow/amazon_vpc_flow-1.1.0.json b/server/adaptors/integrations/__data__/repository/amazon_vpc_flow/amazon_vpc_flow-1.1.0.json index 868b7e17bc..cd0358e0f5 100644 --- a/server/adaptors/integrations/__data__/repository/amazon_vpc_flow/amazon_vpc_flow-1.1.0.json +++ b/server/adaptors/integrations/__data__/repository/amazon_vpc_flow/amazon_vpc_flow-1.1.0.json @@ -19,13 +19,15 @@ "name": "dashboards", "label": "Dashboards & Visualizations", "description": "Dashboards and indices that enable you to easily visualize important metrics.", - "enabled_by_default": false + "enabled_by_default": false, + "applicable_data_sources": ["index"] }, { "name": "flint-live-dashboards", - "label": "Dashboards & Visualizations For Flint Integrations using live queries", - "description": "Dashboards and visualizations aligned with Flint S3 datasource ", - "enabled_by_default": false + "label": "Dashboards & Visualizations", + "description": "Dashboards and indices that enable you to easily visualize important metrics.", + "enabled_by_default": false, + "applicable_data_sources": ["s3"] } ], "statics": { diff --git a/server/adaptors/integrations/types.ts b/server/adaptors/integrations/types.ts index aff0ddac48..95a7895041 100644 --- a/server/adaptors/integrations/types.ts +++ b/server/adaptors/integrations/types.ts @@ -66,6 +66,7 @@ interface IntegrationWorkflow { label: string; description: string; enabled_by_default: boolean; + applicable_data_sources?: string[]; } type ParsedIntegrationAsset = diff --git a/server/adaptors/integrations/validators.ts b/server/adaptors/integrations/validators.ts index 497e380d10..2ae70cf539 100644 --- a/server/adaptors/integrations/validators.ts +++ b/server/adaptors/integrations/validators.ts @@ -40,6 +40,13 @@ const templateSchema: JSONSchemaType = { label: { type: 'string' }, description: { type: 'string' }, enabled_by_default: { type: 'boolean' }, + applicable_data_sources: { + type: 'array', + items: { + type: 'string', + }, + nullable: true, + }, }, required: ['name', 'label', 'description', 'enabled_by_default'], }, @@ -110,6 +117,7 @@ const instanceSchema: JSONSchemaType = { templateName: { type: 'string' }, dataSource: { type: 'string' }, creationDate: { type: 'string' }, + status: { type: 'string', nullable: true }, assets: { type: 'array', items: { @@ -119,6 +127,7 @@ const instanceSchema: JSONSchemaType = { assetId: { type: 'string' }, isDefaultAsset: { type: 'boolean' }, description: { type: 'string' }, + status: { type: 'string', nullable: true }, }, required: ['assetType', 'assetId', 'isDefaultAsset', 'description'], },