diff --git a/common/utils/shared.ts b/common/utils/shared.ts index 7615723d3..0729946c8 100644 --- a/common/utils/shared.ts +++ b/common/utils/shared.ts @@ -3,7 +3,17 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { coreRefs } from '../../public/framework/core_refs'; + +/** + * TODO making this method type-safe is nontrivial: if you just define + * `Nested = { [k: string]: Nested | T }` then you can't accumulate because `T` is not `Nested` + * There might be a way to define a recursive type that accumulates cleanly but it's probably not + * worth the effort. + */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any export function get(obj: Record, path: string, defaultValue?: T): T { + // eslint-disable-next-line @typescript-eslint/no-explicit-any return path.split('.').reduce((acc: any, part: string) => acc && acc[part], obj) || defaultValue; } @@ -33,3 +43,19 @@ export function combineSchemaAndDatarows( return combinedData; } + +/** + * Safely prepend the `basePath` from `coreRefs` to the given link. + * If `coreRefs.http.basePath` exists (always true in normal operation), prepend it to the link. + * If it doesn't exist (usually during unit testing), return the link as-is. + * + * @param link The link to prepend with `coreRefs.http.basePath`. + * @returns The link with the prepended `basePath` if it exists, otherwise the unmodified link. + */ +export const basePathLink = (link: string): string => { + if (coreRefs.http?.basePath) { + return coreRefs.http.basePath.prepend(link); + } else { + return link; + } +}; diff --git a/public/components/datasources/components/__tests__/__snapshots__/installed_integrations_table.test.tsx.snap b/public/components/datasources/components/__tests__/__snapshots__/installed_integrations_table.test.tsx.snap index ada6cb932..97ee1a1bf 100644 --- a/public/components/datasources/components/__tests__/__snapshots__/installed_integrations_table.test.tsx.snap +++ b/public/components/datasources/components/__tests__/__snapshots__/installed_integrations_table.test.tsx.snap @@ -2,6 +2,7 @@ exports[`Installed Integrations Table test Renders the empty installed integrations table 1`] = ` @@ -13,7 +14,9 @@ exports[`Installed Integrations Table test Renders the empty installed integrati @@ -159,6 +167,7 @@ exports[`Installed Integrations Table test Renders the empty installed integrati exports[`Installed Integrations Table test Renders the installed integrations table 1`] = ` - - - - - - Add Integration + + Add Integrations + - - - - - + + + + + @@ -844,3 +859,3588 @@ exports[`Installed Integrations Table test Renders the installed integrations ta `; + +exports[`Installed Integrations Table test Renders the installed integrations table flyout 1`] = ` + + + + + +