Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Allow browsing integrations in Flyout from Data Sources page #1562

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions common/utils/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = { [k: string]: Nested<T> | T }` then you can't accumulate because `T` is not `Nested<T>`
* 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<T = unknown>(obj: Record<string, any>, 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;
}

Expand Down Expand Up @@ -33,3 +43,19 @@

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);

Check warning on line 57 in common/utils/shared.ts

View check run for this annotation

Codecov / codecov/patch

common/utils/shared.ts#L57

Added line #L57 was not covered by tests
} else {
return link;
}
};
Loading
Loading