Skip to content

🪟 🔧 Refactor webapp configuration provider #21456

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

Merged
merged 31 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
34f23b6
first pass
joeykmh Nov 29, 2022
28af138
Merge branch 'master' into joey/refactor-config-providers
joeykmh Dec 7, 2022
5fcc0f5
merge oss config providers in static object
joeykmh Dec 7, 2022
20bb6ff
Merge branch 'master' into joey/refactor-config-providers
joeykmh Jan 16, 2023
7bc28f3
make OSS config static
joeykmh Jan 16, 2023
7bbf7b7
rename config to be more specific
joeykmh Jan 17, 2023
0f4d870
fallback connector builder api url
joeykmh Jan 17, 2023
39c435a
remove comments
joeykmh Jan 17, 2023
d680628
expand default config object
joeykmh Jan 17, 2023
fb72243
remove separate cloud config object
joeykmh Jan 17, 2023
54196d0
remove connector builder api from webapp .env
joeykmh Jan 17, 2023
074fd82
newline
joeykmh Jan 18, 2023
7eb471a
remove configProvider logic
joeykmh Jan 18, 2023
54d1add
rename newStaticConfig > config
joeykmh Jan 18, 2023
bb7c231
ci bump
joeykmh Jan 18, 2023
87a6971
Merge branch 'master' into joey/refactor-config-providers
joeykmh Jan 18, 2023
d0444a7
fix free ab connectors
joeykmh Jan 18, 2023
399a930
Merge branch 'master' into joey/refactor-config-providers
Jan 18, 2023
da5e1c7
merge master
joeykmh Jan 19, 2023
cf9111b
Merge branch 'master' into joey/refactor-config-providers
Jan 19, 2023
b513266
segment_token on window object is optional
joeykmh Jan 19, 2023
8e751cf
add explicit protocol to urls
Jan 23, 2023
2d7e6d5
Merge branch 'master' into joey/refactor-config-providers
joeykmh Jan 23, 2023
cfbd267
remove unconfigurable health check interval from config
joeykmh Jan 23, 2023
7d15c84
Merge branch 'master' into joey/refactor-config-providers
joeykmh Jan 23, 2023
dfc5a6d
move datadog config to config.ts
joeykmh Jan 23, 2023
70a8f09
add sentry to config.ts
joeykmh Jan 23, 2023
54b672d
Merge branch 'master' into joey/refactor-config-providers
Jan 24, 2023
1550b3a
remove types related to configProvider
joeykmh Jan 24, 2023
4ab4102
Merge branch 'master' into joey/refactor-config-providers
Jan 25, 2023
de0cad3
Merge branch 'master' into joey/refactor-config-providers
joeykmh Jan 27, 2023
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
1 change: 1 addition & 0 deletions airbyte-webapp/.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ REACT_APP_FULL_STORY_ORG=13AXQ4
REACT_APP_SENTRY_DSN=
REACT_APP_INTERCOM_APP_ID=nj1oam7s
REACT_APP_OSANO=16A0CTTE7vE8m1Qif/67beec9b-e563-4736-bdb4-4fe4adc39d48
REACT_APP_CONNECTOR_BUILDER_API_URL=/connector-builder-api
14 changes: 3 additions & 11 deletions airbyte-webapp/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ThemeProvider } from "styled-components";

import { ApiErrorBoundary } from "components/common/ApiErrorBoundary";

import { newStaticConfig } from "config/config";
import { ApiServices } from "core/ApiServices";
import { I18nProvider } from "core/i18n";
import { ServicesProvider } from "core/servicesProvider";
Expand All @@ -18,14 +19,7 @@ import { AnalyticsProvider } from "views/common/AnalyticsProvider";
import { StoreProvider } from "views/common/StoreProvider";

import LoadingPage from "./components/LoadingPage";
import {
Config,
ConfigServiceProvider,
defaultConfig,
envConfigProvider,
ValueProvider,
windowConfigProvider,
} from "./config";
import { ConfigServiceProvider } from "./config";
import en from "./locales/en.json";
import { Routing } from "./pages/routes";
import { WorkspaceServiceProvider } from "./services/workspaces/WorkspacesService";
Expand All @@ -35,8 +29,6 @@ const StyleProvider: React.FC<React.PropsWithChildren<unknown>> = ({ children })
<ThemeProvider theme={theme}>{children}</ThemeProvider>
);

const configProviders: ValueProvider<Config> = [envConfigProvider, windowConfigProvider];

const Services: React.FC<React.PropsWithChildren<unknown>> = ({ children }) => (
<AnalyticsProvider>
<AppMonitoringServiceProvider>
Expand Down Expand Up @@ -69,7 +61,7 @@ const App: React.FC = () => {
<StoreProvider>
<ServicesProvider>
<Suspense fallback={<LoadingPage />}>
<ConfigServiceProvider defaultConfig={defaultConfig} providers={configProviders}>
<ConfigServiceProvider defaultConfig={newStaticConfig}>
<Router>
<Services>
<Routing />
Expand Down
10 changes: 5 additions & 5 deletions airbyte-webapp/src/config/ConfigServiceProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { useAsync } from "react-use";
import { LoadingPage } from "components";

import { applyProviders } from "./configProviders";
import { Config, ValueProvider } from "./types";
import { AirbyteWebappConfig, ValueProvider } from "./types";

export interface ConfigContextData<T extends Config = Config> {
export interface ConfigContextData<T extends AirbyteWebappConfig = AirbyteWebappConfig> {
config: T;
}

export const ConfigContext = React.createContext<ConfigContextData | null>(null);

export function useConfig<T extends Config>(): T {
export function useConfig<T extends AirbyteWebappConfig>(): T {
const configService = useContext(ConfigContext);

if (configService === null) {
Expand All @@ -24,8 +24,8 @@ export function useConfig<T extends Config>(): T {

const ConfigServiceInner: React.FC<
React.PropsWithChildren<{
defaultConfig: Config;
providers?: ValueProvider<Config>;
defaultConfig: AirbyteWebappConfig;
providers?: ValueProvider<AirbyteWebappConfig>;
}>
> = ({ children, defaultConfig, providers }) => {
const { loading, value } = useAsync(
Expand Down
17 changes: 17 additions & 0 deletions airbyte-webapp/src/config/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { AirbyteWebappConfig } from "./types";

export const newStaticConfig: AirbyteWebappConfig = {
segment: {
token: window.SEGMENT_TOKEN ?? process.env.REACT_APP_SEGMENT_TOKEN ?? "",
enabled: window.TRACKING_STRATEGY === "segment",
},
apiUrl:
window.API_URL ??
process.env.REACT_APP_API_URL ??
`${window.location.protocol}//${window.location.hostname}:8001/api`,
connectorBuilderApiUrl:
process.env.REACT_APP_CONNECTOR_BUILDER_API_URL ?? `${window.location.protocol}//${window.location.hostname}:8003`,
healthCheckInterval: 20000,
version: window.AIRBYTE_VERSION ?? "dev",
integrationUrl: process.env.REACT_APP_INTEGRATION_DOCS_URLS ?? "/docs",
};
4 changes: 2 additions & 2 deletions airbyte-webapp/src/config/defaultConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Config } from "./types";
import { AirbyteWebappConfig } from "./types";

const defaultConfig: Config = {
const defaultConfig: AirbyteWebappConfig = {
segment: { enabled: true, token: "" },
healthCheckInterval: 20000,
version: "dev",
Expand Down
17 changes: 13 additions & 4 deletions airbyte-webapp/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,30 @@ declare global {
REACT_APP_WEBAPP_TAG?: string;
REACT_APP_INTERCOM_APP_ID?: string;
REACT_APP_INTEGRATION_DOCS_URLS?: string;
SEGMENT_TOKEN?: string;
SEGMENT_TOKEN: string;
LAUNCHDARKLY_KEY?: string;
analytics: SegmentAnalytics.AnalyticsJS;
}
}

export interface Config {
export interface AirbyteWebappConfig {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to make it more clear what this is a config for

segment: { token: string; enabled: boolean };
apiUrl: string;
connectorBuilderApiUrl: string;
oauthRedirectUrl: string;
oauthRedirectUrl?: string;
healthCheckInterval: number;
version?: string;
integrationUrl: string;
launchDarkly?: string;
cloudApiUrl?: string;
firebase?: {
apiKey?: string;
authDomain?: string;
authEmulatorHost?: string;
};
intercom?: {
appId?: string;
};
}

export type DeepPartial<T> = {
Expand All @@ -39,4 +48,4 @@ export type Provider<T> = () => T;

export type ValueProvider<T> = Array<ProviderAsync<DeepPartial<T>>>;

export type ConfigProvider<T extends Config = Config> = ProviderAsync<DeepPartial<T>>;
export type ConfigProvider<T extends AirbyteWebappConfig = AirbyteWebappConfig> = ProviderAsync<DeepPartial<T>>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think most of those types could still be removed or the Provider which seems to be used in the auth service, just inlined there instead (and most likely doesn't need a named type).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, forgot that I wanted to clean up (remove) these unnecessary types!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed here 1550b3a

4 changes: 2 additions & 2 deletions airbyte-webapp/src/core/request/apiOverride.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Config } from "../../config";
import { AirbyteWebappConfig } from "../../config";
import { CommonRequestError } from "./CommonRequestError";
import { RequestMiddleware } from "./RequestMiddleware";
import { VersionError } from "./VersionError";

export interface ApiOverrideRequestOptions {
config: Pick<Config, "apiUrl">;
config: Pick<AirbyteWebappConfig, "apiUrl">;
middlewares: RequestMiddleware[];
signal?: RequestInit["signal"];
}
Expand Down
18 changes: 9 additions & 9 deletions airbyte-webapp/src/packages/cloud/services/ConfigProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React from "react";

import { Config, ConfigServiceProvider, ValueProvider, envConfigProvider, windowConfigProvider } from "config";

import {
cloudEnvConfigProvider,
// fileConfigProvider,
defaultConfig,
cloudWindowConfigProvider,
} from "./config";
AirbyteWebappConfig,
ConfigServiceProvider,
ValueProvider,
envConfigProvider,
windowConfigProvider,
} from "config";

import { cloudEnvConfigProvider, defaultConfig, cloudWindowConfigProvider } from "./config";

const configProviders: ValueProvider<Config> = [
// fileConfigProvider,
const configProviders: ValueProvider<AirbyteWebappConfig> = [
cloudEnvConfigProvider,
cloudWindowConfigProvider,
envConfigProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,6 @@ import type { CloudConfig } from "./types";

import type { ConfigProvider } from "config/types";

const CONFIG_PATH = "/config.json";

const fileConfigProvider: ConfigProvider<CloudConfig> = async () => {
const response = await fetch(CONFIG_PATH);

if (response.ok) {
try {
const config = await response.json();

return config;
} catch (e) {
console.error("error occurred while parsing the json config");
return {};
}
}

return {};
};

const cloudWindowConfigProvider: ConfigProvider<CloudConfig> = async () => {
return {
intercom: {
Expand Down Expand Up @@ -52,4 +33,4 @@ const cloudEnvConfigProvider: ConfigProvider<CloudConfig> = async () => {
};
};

export { fileConfigProvider, cloudWindowConfigProvider, cloudEnvConfigProvider };
export { cloudWindowConfigProvider, cloudEnvConfigProvider };
27 changes: 27 additions & 0 deletions airbyte-webapp/src/packages/cloud/services/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,30 @@ export const defaultConfig: CloudConfig = {

export * from "./configProviders";
export * from "./types";

// export const newStaticConfig: Config = {
// segment: {
// token: window.SEGMENT_TOKEN ?? process.env.REACT_APP_SEGMENT_TOKEN ?? "",
// enabled: window.TRACKING_STRATEGY === "segment",
// },
// apiUrl:
// window.API_URL ??
// process.env.REACT_APP_API_URL ??
// `${window.location.protocol}//${window.location.hostname}:8001/api`,
// connectorBuilderApiUrl: process.env.REACT_APP_CONNECTOR_BUILDER_API_URL ?? "",
// oauthRedirectUrl: "string",
// healthCheckInterval: 20000,
// version: window.AIRBYTE_VERSION ?? "dev",
// integrationUrl: process.env.REACT_APP_INTEGRATION_DOCS_URLS ?? "/docs",
// launchDarkly: "string",
// // Cloud-only values:
// cloudApiUrl: process.env.REACT_APP_CLOUD_API_URL ?? window.CLOUD_API_URL,
// firebase: {
// apiKey: process.env.REACT_APP_FIREBASE_API_KEY ?? window.FIREBASE_API_KEY,
// authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN ?? window.FIREBASE_AUTH_DOMAIN,
// authEmulatorHost: process.env.REACT_APP_FIREBASE_AUTH_EMULATOR_HOST ?? window.FIREBASE_AUTH_EMULATOR_HOST,
// },
// intercom: {
// appId: process.env.REACT_APP_INTERCOM_APP_ID,
// },
// };
4 changes: 2 additions & 2 deletions airbyte-webapp/src/packages/cloud/services/config/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config } from "config";
import { AirbyteWebappConfig } from "config";

declare global {
interface Window {
Expand All @@ -24,4 +24,4 @@ export interface CloudConfigExtension {
};
}

export type CloudConfig = Config & CloudConfigExtension;
export type CloudConfig = AirbyteWebappConfig & CloudConfigExtension;