diff --git a/frontend/src/__mocks__/mockConnectionType.ts b/frontend/src/__mocks__/mockConnectionType.ts index e713e10fc7..d6b543b4f0 100644 --- a/frontend/src/__mocks__/mockConnectionType.ts +++ b/frontend/src/__mocks__/mockConnectionType.ts @@ -76,7 +76,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'short-text', name: 'Short text 1', description: 'Test short text', - envVar: 'short-text-1', + envVar: 'short_text_1', required: false, properties: {}, }, @@ -84,7 +84,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'short-text', name: 'Short text 2', description: 'Test short text with default value', - envVar: 'short-text-2', + envVar: 'short_text_2', required: true, properties: { defaultValue: 'This is the default value', @@ -95,7 +95,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'short-text', name: 'Short text 3', description: 'Test short text with default value and read only', - envVar: 'short-text-3', + envVar: 'short_text_3', required: false, properties: { defaultValue: 'This is the default value and is read only', @@ -106,7 +106,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'short-text', name: 'Short text 4', description: 'Test short text with no default value and read only', - envVar: 'short-text-4', + envVar: 'short_text_4', required: false, properties: { defaultReadOnly: true, @@ -122,7 +122,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'text', name: 'Text 1', description: 'Test text', - envVar: 'text-1', + envVar: 'text_1', required: false, properties: {}, }, @@ -130,7 +130,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'text', name: 'Text 2', description: 'Test text with default value', - envVar: 'text-2', + envVar: 'text_2', required: true, properties: { defaultValue: 'This is the default value\nOne\nTwo\nThree\nFour', @@ -141,7 +141,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'text', name: 'Text 3', description: 'Test text with default value and read only', - envVar: 'text-3', + envVar: 'text_3', required: false, properties: { defaultValue: 'This is the default value\nOne\nTwo\nThree\nFour', @@ -152,7 +152,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'text', name: 'Text 4', description: 'Test text with no default value and read only', - envVar: 'text-4', + envVar: 'text_4', required: false, properties: { defaultReadOnly: true, @@ -168,7 +168,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'hidden', name: 'Hidden 1', description: 'Test hidden', - envVar: 'hidden-1', + envVar: 'hidden_1', required: false, properties: {}, }, @@ -176,7 +176,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'hidden', name: 'Hidden 2', description: 'Test hidden with default value', - envVar: 'hidden-2', + envVar: 'hidden_2', required: true, properties: { defaultValue: 'This is the default value', @@ -187,7 +187,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'hidden', name: 'Hidden 3', description: 'Test hidden with default value and read only', - envVar: 'hidden-3', + envVar: 'hidden_3', required: false, properties: { defaultValue: 'This is the default value', @@ -198,7 +198,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'hidden', name: 'Hidden 4', description: 'Test hidden with no default value and read only', - envVar: 'hidden-4', + envVar: 'hidden_4', required: false, properties: { defaultReadOnly: true, @@ -214,7 +214,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'uri', name: 'URI 1', description: 'Test URI', - envVar: 'uri-1', + envVar: 'uri_1', required: false, properties: {}, }, @@ -222,7 +222,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'uri', name: 'URI 2', description: 'Test URI with default value', - envVar: 'uri-2', + envVar: 'uri_2', required: true, properties: { defaultValue: 'https://www.redhat.com', @@ -233,7 +233,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'uri', name: 'URI 3', description: 'Test URI with default value and read only', - envVar: 'uri-3', + envVar: 'uri_3', required: false, properties: { defaultValue: 'https://www.redhat.com', @@ -244,7 +244,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'uri', name: 'URI 4', description: 'Test URI with no default value and read only', - envVar: 'uri-4', + envVar: 'uri_4', required: false, properties: { defaultReadOnly: true, @@ -260,7 +260,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'file', name: 'File 1', description: 'Test file', - envVar: 'file-1', + envVar: 'file_1', required: false, properties: {}, }, @@ -268,7 +268,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'file', name: 'File 2', description: 'Test file with default value', - envVar: 'file-2', + envVar: 'file_2', required: true, properties: { defaultValue: 'This is the default value', @@ -279,7 +279,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'file', name: 'File 3', description: 'Test file with default value and read only', - envVar: 'file-3', + envVar: 'file_3', required: false, properties: { defaultValue: 'This is the default value', @@ -290,7 +290,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'file', name: 'File 4', description: 'Test file with no default value and read only', - envVar: 'file-4', + envVar: 'file_4', required: false, properties: { defaultReadOnly: true, @@ -306,7 +306,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'boolean', name: 'Boolean 1', description: 'Test boolean', - envVar: 'boolean-1', + envVar: 'boolean_1', required: false, properties: {}, }, @@ -314,7 +314,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'boolean', name: 'Boolean 2', description: 'Test boolean with default value', - envVar: 'boolean-2', + envVar: 'boolean_2', required: true, properties: { label: 'Input label', @@ -326,7 +326,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'boolean', name: 'Boolean 3', description: 'Test boolean with default value and read only', - envVar: 'boolean-3', + envVar: 'boolean_3', required: false, properties: { label: 'Input label', @@ -338,7 +338,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'boolean', name: 'Boolean 4', description: 'Test boolean with no default value and read only', - envVar: 'boolean-4', + envVar: 'boolean_4', required: false, properties: { label: 'Input label', @@ -355,7 +355,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'numeric', name: 'Numeric 1', description: 'Test numeric', - envVar: 'numeric-1', + envVar: 'numeric_1', required: false, properties: {}, }, @@ -363,7 +363,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'numeric', name: 'Numeric 2', description: 'Test numeric with default value', - envVar: 'numeric-2', + envVar: 'numeric_2', required: true, properties: { defaultValue: 2, @@ -374,7 +374,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'numeric', name: 'Numeric 3', description: 'Test numeric with default value and read only', - envVar: 'numeric-3', + envVar: 'numeric_3', required: false, properties: { defaultValue: 2, @@ -385,7 +385,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'numeric', name: 'Numeric 4', description: 'Test numeric with no default value and read only', - envVar: 'numeric-4', + envVar: 'numeric_4', required: false, properties: { defaultReadOnly: true, @@ -401,7 +401,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'dropdown', name: 'Dropdown single 1', description: 'Test dropdown single variant', - envVar: 'dropdown-single-1', + envVar: 'dropdown_single_1', required: false, properties: { variant: 'single', @@ -417,7 +417,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'dropdown', name: 'Dropdown single 2', description: 'Test dropdown single variant with default value', - envVar: 'dropdown-2', + envVar: 'dropdown_2', required: true, properties: { variant: 'single', @@ -435,7 +435,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'dropdown', name: 'Dropdown single 3', description: 'Test dropdown single variant with default value and read only', - envVar: 'dropdown-3', + envVar: 'dropdown_3', required: true, properties: { variant: 'single', @@ -453,7 +453,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'dropdown', name: 'Dropdown single 4', description: 'Test dropdown single variant with no default value and read only', - envVar: 'dropdown-4', + envVar: 'dropdown_4', required: true, properties: { variant: 'single', @@ -476,7 +476,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'dropdown', name: 'Dropdown multi 1', description: 'Test dropdown multi variant', - envVar: 'dropdown-multi-1', + envVar: 'dropdown_multi_1', required: false, properties: { variant: 'multi', @@ -492,7 +492,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'dropdown', name: 'Dropdown multi 2', description: 'Test dropdown multi variant with default values', - envVar: 'dropdown-multi-2', + envVar: 'dropdown_multi_2', required: false, properties: { variant: 'multi', @@ -510,7 +510,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'dropdown', name: 'Dropdown multi 3', description: 'Test dropdown multi variant with default values and read only', - envVar: 'dropdown-multi-3', + envVar: 'dropdown_multi_3', required: false, properties: { variant: 'multi', @@ -528,7 +528,7 @@ const mockFields: ConnectionTypeField[] = [ type: 'dropdown', name: 'Dropdown multi 4', description: 'Test dropdown multi variant with no default values and read only', - envVar: 'dropdown-multi-4', + envVar: 'dropdown_multi_4', required: false, properties: { variant: 'multi', diff --git a/frontend/src/__tests__/cypress/cypress/tests/mocked/connectionTypes/createConnectionType.cy.ts b/frontend/src/__tests__/cypress/cypress/tests/mocked/connectionTypes/createConnectionType.cy.ts index 8127cb383d..ba78974006 100644 --- a/frontend/src/__tests__/cypress/cypress/tests/mocked/connectionTypes/createConnectionType.cy.ts +++ b/frontend/src/__tests__/cypress/cypress/tests/mocked/connectionTypes/createConnectionType.cy.ts @@ -157,14 +157,14 @@ describe('edit', () => { { type: 'short-text', name: 'field1', - envVar: 'short-text-1', + envVar: 'short_text_1', required: false, properties: {}, }, { type: 'short-text', name: 'field2', - envVar: 'short-text-2', + envVar: 'short_text_2', required: true, properties: {}, }, @@ -216,7 +216,7 @@ describe('edit', () => { { type: 'short-text', name: 'field1', - envVar: 'short-text-1', + envVar: 'short_text_1', properties: {}, }, { @@ -226,7 +226,7 @@ describe('edit', () => { { type: 'short-text', name: 'field2', - envVar: 'short-text-2', + envVar: 'short_text_2', properties: {}, }, { @@ -236,7 +236,7 @@ describe('edit', () => { { type: 'short-text', name: 'field3', - envVar: 'short-text-3', + envVar: 'short_text_3', properties: {}, }, ], diff --git a/frontend/src/concepts/connectionTypes/__tests__/utils.spec.ts b/frontend/src/concepts/connectionTypes/__tests__/utils.spec.ts index 7be6062f76..e0c1bb0383 100644 --- a/frontend/src/concepts/connectionTypes/__tests__/utils.spec.ts +++ b/frontend/src/concepts/connectionTypes/__tests__/utils.spec.ts @@ -9,6 +9,7 @@ import { defaultValueToString, fieldNameToEnvVar, fieldTypeToString, + isValidEnvVar, toConnectionTypeConfigMap, toConnectionTypeConfigMapObj, } from '~/concepts/connectionTypes/utils'; @@ -238,7 +239,7 @@ describe('fieldNameToEnvVar', () => { expect(fieldNameToEnvVar('THREE_')).toBe('THREE_'); }); it('should remove invalid characters', () => { - expect(fieldNameToEnvVar('a!@#$%^&*()-=_+[]\\{}|;\':"`,./<>?1')).toBe('A-_.1'); + expect(fieldNameToEnvVar('a!@#$%^&*()-=_+[]\\{}|;\':"`,./<>?1')).toBe('A__1'); expect(fieldNameToEnvVar('=== tWo')).toBe('_TWO'); }); it('should remove numbers at the start', () => { @@ -246,3 +247,18 @@ describe('fieldNameToEnvVar', () => { expect(fieldNameToEnvVar('++123 TWO 456')).toBe('_TWO_456'); }); }); + +describe('isValidEnvVar', () => { + it('should be valid env var', () => { + expect(isValidEnvVar('NAME')).toBe(true); + expect(isValidEnvVar('UNDERSCORE_NAME')).toBe(true); + expect(isValidEnvVar('has_digits_1234')).toBe(true); + }); + + it('should be invalid env var', () => { + expect(isValidEnvVar('.dot')).toBe(false); + expect(isValidEnvVar('has-dash')).toBe(false); + expect(isValidEnvVar('1_digit_as_first_char')).toBe(false); + expect(isValidEnvVar('has space')).toBe(false); + }); +}); diff --git a/frontend/src/concepts/connectionTypes/fields/__tests__/BooleanFormField.spec.tsx b/frontend/src/concepts/connectionTypes/fields/__tests__/BooleanFormField.spec.tsx index ee6c6b95f7..c05daa52e7 100644 --- a/frontend/src/concepts/connectionTypes/fields/__tests__/BooleanFormField.spec.tsx +++ b/frontend/src/concepts/connectionTypes/fields/__tests__/BooleanFormField.spec.tsx @@ -11,7 +11,7 @@ describe('BooleanFormField', () => { const field: BooleanField = { type: 'boolean', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { label: 'test-label', defaultValue: false, @@ -35,7 +35,7 @@ describe('BooleanFormField', () => { const field: BooleanField = { type: 'boolean', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { label: 'test-label', defaultValue: true, @@ -61,7 +61,7 @@ describe('BooleanFormField', () => { const field: BooleanField = { type: 'boolean', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { label: 'test-label', defaultValue: true, diff --git a/frontend/src/concepts/connectionTypes/fields/__tests__/ConnectionTypeDataFormField.spec.tsx b/frontend/src/concepts/connectionTypes/fields/__tests__/ConnectionTypeDataFormField.spec.tsx index 9919206c8d..71e32e9723 100644 --- a/frontend/src/concepts/connectionTypes/fields/__tests__/ConnectionTypeDataFormField.spec.tsx +++ b/frontend/src/concepts/connectionTypes/fields/__tests__/ConnectionTypeDataFormField.spec.tsx @@ -14,7 +14,7 @@ describe('ConnectionTypeDataFormField', () => { const field = { type, name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: {}, } as ConnectionTypeDataField; expect( diff --git a/frontend/src/concepts/connectionTypes/fields/__tests__/ConnectionTypeFormFields.spec.tsx b/frontend/src/concepts/connectionTypes/fields/__tests__/ConnectionTypeFormFields.spec.tsx index b578f858da..8ffb2e406e 100644 --- a/frontend/src/concepts/connectionTypes/fields/__tests__/ConnectionTypeFormFields.spec.tsx +++ b/frontend/src/concepts/connectionTypes/fields/__tests__/ConnectionTypeFormFields.spec.tsx @@ -8,7 +8,7 @@ const testFields: ConnectionTypeField[] = [ { type: 'boolean', name: 'Boolean 1', - envVar: 'boolean-1', + envVar: 'boolean_1', properties: {}, }, { @@ -18,13 +18,13 @@ const testFields: ConnectionTypeField[] = [ { type: 'text', name: 'Text 1', - envVar: 'text-1', + envVar: 'text_1', properties: {}, }, { type: 'text', name: 'Text 2', - envVar: 'text-2', + envVar: 'text_2', properties: {}, }, { @@ -34,7 +34,7 @@ const testFields: ConnectionTypeField[] = [ { type: 'numeric', name: 'Numeric 1', - envVar: 'numeric-1', + envVar: 'numeric_1', properties: {}, }, ]; @@ -46,12 +46,12 @@ describe('ConnectionTypeFormFields', () => { const section2 = result.getByRole('group', { name: 'section-2' }); // test unground - within(result.container).getByTestId('field boolean boolean-1'); - expect(within(section1).queryByTestId('field boolean boolean-1')).toBe(null); - expect(within(section2).queryByTestId('field boolean boolean-1')).toBe(null); + within(result.container).getByTestId('field boolean boolean_1'); + expect(within(section1).queryByTestId('field boolean boolean_1')).toBe(null); + expect(within(section2).queryByTestId('field boolean boolean_1')).toBe(null); - within(section1).getByTestId('field text text-1'); - within(section1).getByTestId('field text text-2'); - within(section2).getByTestId('field numeric numeric-1'); + within(section1).getByTestId('field text text_1'); + within(section1).getByTestId('field text text_2'); + within(section2).getByTestId('field numeric numeric_1'); }); }); diff --git a/frontend/src/concepts/connectionTypes/fields/__tests__/DefaultValueTextRenderer.spec.tsx b/frontend/src/concepts/connectionTypes/fields/__tests__/DefaultValueTextRenderer.spec.tsx index 069da91f7b..5468bae8f0 100644 --- a/frontend/src/concepts/connectionTypes/fields/__tests__/DefaultValueTextRenderer.spec.tsx +++ b/frontend/src/concepts/connectionTypes/fields/__tests__/DefaultValueTextRenderer.spec.tsx @@ -9,7 +9,7 @@ describe('DefaultValueTextRenderer', () => { const field: TextField = { type: 'text', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { defaultValue: 'Test value', defaultReadOnly: true, diff --git a/frontend/src/concepts/connectionTypes/fields/__tests__/DropdownFormField.spec.tsx b/frontend/src/concepts/connectionTypes/fields/__tests__/DropdownFormField.spec.tsx index 3b6f792c61..ef6b017acc 100644 --- a/frontend/src/concepts/connectionTypes/fields/__tests__/DropdownFormField.spec.tsx +++ b/frontend/src/concepts/connectionTypes/fields/__tests__/DropdownFormField.spec.tsx @@ -12,7 +12,7 @@ describe('DropdownFormField', () => { const field: DropdownField = { type: 'dropdown', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { variant: 'single', items: [ @@ -45,7 +45,7 @@ describe('DropdownFormField', () => { const field: DropdownField = { type: 'dropdown', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { variant: 'single', items: [ @@ -91,7 +91,7 @@ describe('DropdownFormField', () => { const field: DropdownField = { type: 'dropdown', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { variant: 'single', items: [ @@ -124,7 +124,7 @@ describe('DropdownFormField', () => { const field: DropdownField = { type: 'dropdown', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { variant: 'multi', items: [ @@ -169,7 +169,7 @@ describe('DropdownFormField', () => { const field: DropdownField = { type: 'dropdown', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { variant: 'multi', items: [ @@ -214,7 +214,7 @@ describe('DropdownFormField', () => { const field: DropdownField = { type: 'dropdown', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { variant: 'multi', items: [ diff --git a/frontend/src/concepts/connectionTypes/fields/__tests__/FileFormField.spec.tsx b/frontend/src/concepts/connectionTypes/fields/__tests__/FileFormField.spec.tsx index eaf618d982..759365de91 100644 --- a/frontend/src/concepts/connectionTypes/fields/__tests__/FileFormField.spec.tsx +++ b/frontend/src/concepts/connectionTypes/fields/__tests__/FileFormField.spec.tsx @@ -11,7 +11,7 @@ describe('FileFormField', () => { const field: FileField = { type: 'file', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { defaultValue: 'default-value', extensions: ['.jpg', '.svg', '.png'], @@ -40,7 +40,7 @@ describe('FileFormField', () => { const field: FileField = { type: 'file', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { defaultValue: 'default-value', }, @@ -72,7 +72,7 @@ describe('FileFormField', () => { const field: FileField = { type: 'file', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { defaultValue: 'default-value', defaultReadOnly: true, diff --git a/frontend/src/concepts/connectionTypes/fields/__tests__/HiddenFormField.spec.tsx b/frontend/src/concepts/connectionTypes/fields/__tests__/HiddenFormField.spec.tsx index caf889e724..3295c03acb 100644 --- a/frontend/src/concepts/connectionTypes/fields/__tests__/HiddenFormField.spec.tsx +++ b/frontend/src/concepts/connectionTypes/fields/__tests__/HiddenFormField.spec.tsx @@ -11,7 +11,7 @@ describe('HiddenFormField', () => { const field: HiddenField = { type: 'hidden', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { defaultValue: 'default-value', }, @@ -36,7 +36,7 @@ describe('HiddenFormField', () => { const field: HiddenField = { type: 'hidden', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { defaultValue: 'default-value', }, @@ -67,7 +67,7 @@ describe('HiddenFormField', () => { const field: HiddenField = { type: 'hidden', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { defaultValue: 'default-value', defaultReadOnly: true, diff --git a/frontend/src/concepts/connectionTypes/fields/__tests__/NumericFormField.spec.tsx b/frontend/src/concepts/connectionTypes/fields/__tests__/NumericFormField.spec.tsx index ce6179dd7a..35a2033331 100644 --- a/frontend/src/concepts/connectionTypes/fields/__tests__/NumericFormField.spec.tsx +++ b/frontend/src/concepts/connectionTypes/fields/__tests__/NumericFormField.spec.tsx @@ -11,7 +11,7 @@ describe('NumericFormField', () => { const field: NumericField = { type: 'numeric', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { defaultValue: 2, }, @@ -33,7 +33,7 @@ describe('NumericFormField', () => { const field: NumericField = { type: 'numeric', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { defaultValue: 2, }, @@ -57,7 +57,7 @@ describe('NumericFormField', () => { const field: NumericField = { type: 'numeric', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { defaultValue: 2, defaultReadOnly: true, diff --git a/frontend/src/concepts/connectionTypes/fields/__tests__/ShortTextFormField.spec.tsx b/frontend/src/concepts/connectionTypes/fields/__tests__/ShortTextFormField.spec.tsx index c0e0017f01..59cda94e25 100644 --- a/frontend/src/concepts/connectionTypes/fields/__tests__/ShortTextFormField.spec.tsx +++ b/frontend/src/concepts/connectionTypes/fields/__tests__/ShortTextFormField.spec.tsx @@ -11,7 +11,7 @@ describe('ShortTextFormField', () => { const field: ShortTextField = { type: 'short-text', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { defaultValue: 'default-value', }, @@ -35,7 +35,7 @@ describe('ShortTextFormField', () => { const field: ShortTextField = { type: 'short-text', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { defaultValue: 'default-value', }, @@ -65,7 +65,7 @@ describe('ShortTextFormField', () => { const field: ShortTextField = { type: 'short-text', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { defaultValue: 'default-value', defaultReadOnly: true, diff --git a/frontend/src/concepts/connectionTypes/fields/__tests__/TextFormField.spec.tsx b/frontend/src/concepts/connectionTypes/fields/__tests__/TextFormField.spec.tsx index e4177e781d..59af7a18ea 100644 --- a/frontend/src/concepts/connectionTypes/fields/__tests__/TextFormField.spec.tsx +++ b/frontend/src/concepts/connectionTypes/fields/__tests__/TextFormField.spec.tsx @@ -11,7 +11,7 @@ describe('TextFormField', () => { const field: TextField = { type: 'text', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { defaultValue: 'default-value', }, @@ -33,7 +33,7 @@ describe('TextFormField', () => { const field: TextField = { type: 'text', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { defaultValue: 'default-value', }, @@ -63,7 +63,7 @@ describe('TextFormField', () => { const field: TextField = { type: 'text', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { defaultValue: 'default-value', defaultReadOnly: true, diff --git a/frontend/src/concepts/connectionTypes/fields/__tests__/UriFormField.spec.tsx b/frontend/src/concepts/connectionTypes/fields/__tests__/UriFormField.spec.tsx index 00695efc10..dfd8878cdf 100644 --- a/frontend/src/concepts/connectionTypes/fields/__tests__/UriFormField.spec.tsx +++ b/frontend/src/concepts/connectionTypes/fields/__tests__/UriFormField.spec.tsx @@ -10,7 +10,7 @@ describe('UriFormField', () => { const field: UriField = { type: 'uri', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { defaultValue: 'http://foo.com', }, @@ -32,7 +32,7 @@ describe('UriFormField', () => { const field: UriField = { type: 'uri', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { defaultValue: 'http://foo.com', }, @@ -62,7 +62,7 @@ describe('UriFormField', () => { const field: UriField = { type: 'uri', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { defaultValue: 'http://foo.com', defaultReadOnly: true, @@ -78,7 +78,7 @@ describe('UriFormField', () => { const field: UriField = { type: 'uri', name: 'test-name', - envVar: 'test-envVar', + envVar: 'test_envVar', properties: { defaultValue: 'http://foo.com', defaultReadOnly: false, diff --git a/frontend/src/concepts/connectionTypes/utils.ts b/frontend/src/concepts/connectionTypes/utils.ts index 00cea86d97..0f0896ed44 100644 --- a/frontend/src/concepts/connectionTypes/utils.ts +++ b/frontend/src/concepts/connectionTypes/utils.ts @@ -76,9 +76,12 @@ export const fieldTypeToString = (type: ConnectionTypeFieldTypeUnion): string => }; export const fieldNameToEnvVar = (name: string): string => { - const spacesAsUnderscores = name.replace(/ /g, '_'); - const removeInvalid = spacesAsUnderscores.replace(/[^\w\-.]/g, ''); + const spacesAsUnderscores = name.replace(/(\s|-)/g, '_'); + const removeInvalid = spacesAsUnderscores.replace(/[^\w]/g, ''); const removeNumbersAtStart = removeInvalid.replace(/^[0-9]+/g, ''); const allUppercase = removeNumbersAtStart.toUpperCase(); return allUppercase; }; + +const ENV_VAR_NAME_REGEX = new RegExp('^[_a-zA-Z][_a-zA-Z0-9]*$'); +export const isValidEnvVar = (name: string): boolean => ENV_VAR_NAME_REGEX.test(name); diff --git a/frontend/src/pages/connectionTypes/manage/ConnectionTypeDataFieldModal.tsx b/frontend/src/pages/connectionTypes/manage/ConnectionTypeDataFieldModal.tsx index b68a543ac0..806bc8978e 100644 --- a/frontend/src/pages/connectionTypes/manage/ConnectionTypeDataFieldModal.tsx +++ b/frontend/src/pages/connectionTypes/manage/ConnectionTypeDataFieldModal.tsx @@ -28,14 +28,16 @@ import { ConnectionTypeFieldType, isConnectionTypeDataField, } from '~/concepts/connectionTypes/types'; -import { fieldNameToEnvVar, fieldTypeToString } from '~/concepts/connectionTypes/utils'; +import { + fieldNameToEnvVar, + fieldTypeToString, + isValidEnvVar, +} from '~/concepts/connectionTypes/utils'; import { isEnumMember } from '~/utilities/utils'; import DashboardPopupIconButton from '~/concepts/dashboard/DashboardPopupIconButton'; import DataFieldPropertiesForm from '~/pages/connectionTypes/manage/DataFieldPropertiesForm'; import { prepareFieldForSave } from '~/pages/connectionTypes/manage/manageFieldUtils'; -const ENV_VAR_NAME_REGEX = new RegExp('^[-._a-zA-Z][-._a-zA-Z0-9]*$'); - const isConnectionTypeFieldType = ( fieldType: string | number | undefined, ): fieldType is ConnectionTypeFieldType => @@ -77,7 +79,7 @@ export const ConnectionTypeDataFieldModal: React.FC = ({ [fields, field, envVar], ); - const isEnvVarValid = !envVar || ENV_VAR_NAME_REGEX.test(envVar); + const isEnvVarValid = !envVar || isValidEnvVar(envVar); const isValid = !!fieldType && isPropertiesValid && !!name && !!envVar && isEnvVarValid; @@ -188,19 +190,15 @@ export const ConnectionTypeDataFieldModal: React.FC = ({ validated={!isEnvVarValid ? 'error' : isEnvVarConflict ? 'warning' : 'default'} /> - {!isEnvVarValid ? ( - - } variant="error"> - {`Invalid variable name. The name must consist of alphabetic characters, digits, '_', '-', or '.', and must not start with a digit.`} - - - ) : ( - - - Valid characters include uppercase letters, numbers, and underscores ( _ ). - - - )} + + } + > + Valid characters include letters, numbers, and underscores ( _ ), and must not start + with a number. + + {isEnvVarConflict ? ( } variant="warning"> diff --git a/frontend/src/pages/connectionTypes/manage/__tests__/ConnectionTypeDataFieldModal.spec.tsx b/frontend/src/pages/connectionTypes/manage/__tests__/ConnectionTypeDataFieldModal.spec.tsx index 971d95d20a..ce392865ab 100644 --- a/frontend/src/pages/connectionTypes/manage/__tests__/ConnectionTypeDataFieldModal.spec.tsx +++ b/frontend/src/pages/connectionTypes/manage/__tests__/ConnectionTypeDataFieldModal.spec.tsx @@ -236,13 +236,13 @@ describe('ConnectionTypeDataFieldModal', () => { const field: ShortTextField = { type: 'short-text', name: 'test', - envVar: 'test-envvar', + envVar: 'test_envvar', properties: {}, }; const field2: TextField = { type: 'text', name: 'test-2', - envVar: 'test-envvar', + envVar: 'test_envvar', properties: {}, }; render( diff --git a/frontend/src/pages/connectionTypes/manage/__tests__/ManageConnectionTypeFieldsTableRow.spec.tsx b/frontend/src/pages/connectionTypes/manage/__tests__/ManageConnectionTypeFieldsTableRow.spec.tsx index e266970a21..5a7d664c90 100644 --- a/frontend/src/pages/connectionTypes/manage/__tests__/ManageConnectionTypeFieldsTableRow.spec.tsx +++ b/frontend/src/pages/connectionTypes/manage/__tests__/ManageConnectionTypeFieldsTableRow.spec.tsx @@ -37,13 +37,13 @@ describe('ManageConnectionTypeFieldsTableRow', () => { const field: ShortTextField = { type: 'short-text', name: 'test', - envVar: 'test-envvar', + envVar: 'test_envvar', properties: {}, }; const field2: TextField = { type: 'text', name: 'test-2', - envVar: 'test-envvar', + envVar: 'test_envvar', properties: {}, };