diff --git a/clients/admin-ui/src/features/datastore-connections/system_portal_config/forms/ConnectorParameters.tsx b/clients/admin-ui/src/features/datastore-connections/system_portal_config/forms/ConnectorParameters.tsx index a42c5554f3..b478ab7e61 100644 --- a/clients/admin-ui/src/features/datastore-connections/system_portal_config/forms/ConnectorParameters.tsx +++ b/clients/admin-ui/src/features/datastore-connections/system_portal_config/forms/ConnectorParameters.tsx @@ -51,23 +51,7 @@ import { ConnectorParametersForm, TestConnectionResponse, } from "./ConnectorParametersForm"; - -const generateIntegrationKey = ( - systemFidesKey: string, - connectionOption: ConnectionSystemTypeMap, -): string => { - let integrationKey = systemFidesKey; - - if (!systemFidesKey.includes(connectionOption.identifier)) { - integrationKey += `_${connectionOption.identifier}`; - } - - if (connectionOption.type === SystemType.SAAS) { - integrationKey += "_api"; - } - - return integrationKey; -}; +import { generateIntegrationKey } from "./helpers"; /** * Only handles creating saas connectors. The BE handler automatically diff --git a/clients/admin-ui/src/features/datastore-connections/system_portal_config/forms/helpers.test.ts b/clients/admin-ui/src/features/datastore-connections/system_portal_config/forms/helpers.test.ts new file mode 100644 index 0000000000..bdd4e2c4a3 --- /dev/null +++ b/clients/admin-ui/src/features/datastore-connections/system_portal_config/forms/helpers.test.ts @@ -0,0 +1,45 @@ +import { SystemType } from "~/types/api/models/SystemType"; + +import { generateIntegrationKey } from "./helpers"; + +describe("generateIntegrationKey", () => { + it("removes special characters except allowed ones", () => { + const result = generateIntegrationKey("test.system!@#$%^&*()", { + identifier: "test", + type: SystemType.DATABASE, + }); + expect(result).toBe("testsystem"); + }); + + it("keeps allowed characters (alphanumeric, hyphen, underscore)", () => { + const result = generateIntegrationKey("test-system_123", { + identifier: "test", + type: SystemType.DATABASE, + }); + expect(result).toBe("test-system_123"); + }); + + it("adds identifier if not present", () => { + const result = generateIntegrationKey("system", { + identifier: "postgres", + type: SystemType.DATABASE, + }); + expect(result).toBe("system_postgres"); + }); + + it("does not add identifier if already present", () => { + const result = generateIntegrationKey("system_postgres", { + identifier: "postgres", + type: SystemType.DATABASE, + }); + expect(result).toBe("system_postgres"); + }); + + it("adds API suffix for SaaS type", () => { + const result = generateIntegrationKey("system", { + identifier: "salesforce", + type: SystemType.SAAS, + }); + expect(result).toBe("system_salesforce_api"); + }); +}); diff --git a/clients/admin-ui/src/features/datastore-connections/system_portal_config/forms/helpers.ts b/clients/admin-ui/src/features/datastore-connections/system_portal_config/forms/helpers.ts index d4632039b4..e5878f01db 100644 --- a/clients/admin-ui/src/features/datastore-connections/system_portal_config/forms/helpers.ts +++ b/clients/admin-ui/src/features/datastore-connections/system_portal_config/forms/helpers.ts @@ -1,4 +1,6 @@ import { ConnectionTypeSecretSchemaResponse } from "~/features/connection-type/types"; +import { ConnectionSystemTypeMap } from "~/types/api/models/ConnectionSystemTypeMap"; +import { SystemType } from "~/types/api/models/SystemType"; /** * Fill in default values based off of a schema @@ -29,3 +31,25 @@ export const fillInDefaults = ( } return filledInValues; }; + +/** + * + * Auto-generate an integration key based on the system name + * + */ +export const generateIntegrationKey = ( + systemFidesKey: string, + connectionOption: Pick, +): string => { + let integrationKey = systemFidesKey.replace(/[^A-Za-z0-9\-_]/g, ""); + + if (!integrationKey.includes(connectionOption.identifier)) { + integrationKey += `_${connectionOption.identifier}`; + } + + if (connectionOption.type === SystemType.SAAS) { + integrationKey += "_api"; + } + + return integrationKey; +};