From 5b96f217518fdbdb74fa545390ed2318502a9c7e Mon Sep 17 00:00:00 2001
From: Bharat Pasupula <123897612+bhapas@users.noreply.github.com>
Date: Thu, 13 Feb 2025 17:02:03 +0100
Subject: [PATCH 1/4] [Automatic Import] Fix generated name for integration
title (#210916)
## Summary
A bug was introduced with #210770 and this PR fixes that. The Package
name generated is validated.
(cherry picked from commit cf0f338d8749c90024b2409fbb7b036469bfab6e)
# Conflicts:
# x-pack/platform/plugins/shared/integration_assistant/public/components/create_integration/create_integration_assistant/steps/data_stream_step/data_stream_step.tsx
---
.../data_stream_step.test.tsx | 55 ++++++++++++++++++-
.../data_stream_step/data_stream_step.tsx | 4 +-
2 files changed, 56 insertions(+), 3 deletions(-)
diff --git a/x-pack/platform/plugins/shared/integration_assistant/public/components/create_integration/create_integration_assistant/steps/data_stream_step/data_stream_step.test.tsx b/x-pack/platform/plugins/shared/integration_assistant/public/components/create_integration/create_integration_assistant/steps/data_stream_step/data_stream_step.test.tsx
index a0d95d4bb77b0..2bcee43dc8326 100644
--- a/x-pack/platform/plugins/shared/integration_assistant/public/components/create_integration/create_integration_assistant/steps/data_stream_step/data_stream_step.test.tsx
+++ b/x-pack/platform/plugins/shared/integration_assistant/public/components/create_integration/create_integration_assistant/steps/data_stream_step/data_stream_step.test.tsx
@@ -8,7 +8,7 @@
import React from 'react';
import { render, act, type RenderResult, fireEvent } from '@testing-library/react';
import { TestProvider } from '../../../../../mocks/test_provider';
-import { DataStreamStep } from './data_stream_step';
+import { DataStreamStep, getNameFromTitle } from './data_stream_step';
import { ActionsProvider } from '../../state';
import { mockActions, mockState } from '../../mocks/state';
@@ -243,4 +243,57 @@ describe('DataStreamStep', () => {
expect(result.queryByTestId('generationModal')).toBeInTheDocument();
});
});
+
+ describe('when integrationSettings has an invalid generated name from title', () => {
+ describe.each(['123 abc', '1a'])('should render error for %s', (invalidTitle) => {
+ let result: RenderResult;
+ beforeEach(() => {
+ jest.clearAllMocks();
+ result = render(
+ ,
+ { wrapper }
+ );
+ });
+
+ it('should set empty name for invalid title', () => {
+ const input = result.getByTestId('nameInput');
+ expect(input).toHaveValue(''); // name is not set
+ });
+ });
+ });
+
+ describe('when integrationSettings has an valid generated name from title', () => {
+ describe.each(['abc 123', '$abc123', 'abc 123 abc', 'abc_123', 'abc_123_abc'])(
+ 'should render error for %s',
+ (validTitle) => {
+ let result: RenderResult;
+ beforeEach(() => {
+ jest.clearAllMocks();
+ result = render(
+ ,
+ { wrapper }
+ );
+ });
+
+ it('should auto-generate name from title', () => {
+ const input = result.getByTestId('nameInput');
+ expect(input).toHaveValue(getNameFromTitle(validTitle));
+ expect(mockActions.setIntegrationSettings).toHaveBeenCalledWith({
+ name: getNameFromTitle(validTitle),
+ title: validTitle,
+ });
+ });
+ }
+ );
+ });
});
diff --git a/x-pack/platform/plugins/shared/integration_assistant/public/components/create_integration/create_integration_assistant/steps/data_stream_step/data_stream_step.tsx b/x-pack/platform/plugins/shared/integration_assistant/public/components/create_integration/create_integration_assistant/steps/data_stream_step/data_stream_step.tsx
index fe9a61958445e..e6832610b4d1d 100644
--- a/x-pack/platform/plugins/shared/integration_assistant/public/components/create_integration/create_integration_assistant/steps/data_stream_step/data_stream_step.tsx
+++ b/x-pack/platform/plugins/shared/integration_assistant/public/components/create_integration/create_integration_assistant/steps/data_stream_step/data_stream_step.tsx
@@ -120,7 +120,7 @@ export const DataStreamStep = React.memo(
// Only executed once when the packageNames are loaded
if (packageNames != null && integrationSettings?.name == null && integrationSettings?.title) {
const generatedName = getNameFromTitle(integrationSettings.title);
- if (!packageNames.has(generatedName)) {
+ if (!packageNames.has(generatedName) && isValidName(generatedName)) {
setName(generatedName);
setIntegrationValues({ name: generatedName });
}
@@ -183,7 +183,7 @@ export const DataStreamStep = React.memo(
Date: Fri, 14 Feb 2025 09:12:07 +0100
Subject: [PATCH 2/4] remove celInputResult
---
.../steps/data_stream_step/data_stream_step.test.tsx | 2 --
1 file changed, 2 deletions(-)
diff --git a/x-pack/platform/plugins/shared/integration_assistant/public/components/create_integration/create_integration_assistant/steps/data_stream_step/data_stream_step.test.tsx b/x-pack/platform/plugins/shared/integration_assistant/public/components/create_integration/create_integration_assistant/steps/data_stream_step/data_stream_step.test.tsx
index 2bcee43dc8326..225f8fa4fb789 100644
--- a/x-pack/platform/plugins/shared/integration_assistant/public/components/create_integration/create_integration_assistant/steps/data_stream_step/data_stream_step.test.tsx
+++ b/x-pack/platform/plugins/shared/integration_assistant/public/components/create_integration/create_integration_assistant/steps/data_stream_step/data_stream_step.test.tsx
@@ -254,7 +254,6 @@ describe('DataStreamStep', () => {
integrationSettings={{ title: invalidTitle }}
connector={mockState.connector}
isGenerating={false}
- celInputResult={undefined}
/>,
{ wrapper }
);
@@ -279,7 +278,6 @@ describe('DataStreamStep', () => {
integrationSettings={{ title: validTitle }}
connector={mockState.connector}
isGenerating={false}
- celInputResult={undefined}
/>,
{ wrapper }
);
From 0afdf3540f94075d9e75c33fc107b91980fed686 Mon Sep 17 00:00:00 2001
From: Bharat Pasupula <123897612+bhapas@users.noreply.github.com>
Date: Fri, 14 Feb 2025 09:12:37 +0100
Subject: [PATCH 3/4] export const
---
.../steps/data_stream_step/data_stream_step.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/x-pack/platform/plugins/shared/integration_assistant/public/components/create_integration/create_integration_assistant/steps/data_stream_step/data_stream_step.tsx b/x-pack/platform/plugins/shared/integration_assistant/public/components/create_integration/create_integration_assistant/steps/data_stream_step/data_stream_step.tsx
index e6832610b4d1d..8578c2da7380d 100644
--- a/x-pack/platform/plugins/shared/integration_assistant/public/components/create_integration/create_integration_assistant/steps/data_stream_step/data_stream_step.tsx
+++ b/x-pack/platform/plugins/shared/integration_assistant/public/components/create_integration/create_integration_assistant/steps/data_stream_step/data_stream_step.tsx
@@ -45,7 +45,7 @@ export const InputTypeOptions: Array> = [
];
const isValidName = (name: string) => NAME_REGEX_PATTERN.test(name);
-const getNameFromTitle = (title: string) => title.toLowerCase().replaceAll(/[^a-z0-9]/g, '_');
+export const getNameFromTitle = (title: string) => title.toLowerCase().replaceAll(/[^a-z0-9]/g, '_');
interface DataStreamStepProps {
integrationSettings: State['integrationSettings'];
From ea0db349cb697b59de05684907adadd6a2a2bd6d Mon Sep 17 00:00:00 2001
From: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Date: Fri, 14 Feb 2025 08:36:09 +0000
Subject: [PATCH 4/4] [CI] Auto-commit changed files from 'node scripts/eslint
--no-cache --fix'
---
.../steps/data_stream_step/data_stream_step.tsx | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/x-pack/platform/plugins/shared/integration_assistant/public/components/create_integration/create_integration_assistant/steps/data_stream_step/data_stream_step.tsx b/x-pack/platform/plugins/shared/integration_assistant/public/components/create_integration/create_integration_assistant/steps/data_stream_step/data_stream_step.tsx
index 8578c2da7380d..46305750fccde 100644
--- a/x-pack/platform/plugins/shared/integration_assistant/public/components/create_integration/create_integration_assistant/steps/data_stream_step/data_stream_step.tsx
+++ b/x-pack/platform/plugins/shared/integration_assistant/public/components/create_integration/create_integration_assistant/steps/data_stream_step/data_stream_step.tsx
@@ -45,7 +45,8 @@ export const InputTypeOptions: Array> = [
];
const isValidName = (name: string) => NAME_REGEX_PATTERN.test(name);
-export const getNameFromTitle = (title: string) => title.toLowerCase().replaceAll(/[^a-z0-9]/g, '_');
+export const getNameFromTitle = (title: string) =>
+ title.toLowerCase().replaceAll(/[^a-z0-9]/g, '_');
interface DataStreamStepProps {
integrationSettings: State['integrationSettings'];