Skip to content

Commit

Permalink
Only checkUpdates if AllowUpdateConnectors enabled (#21138)
Browse files Browse the repository at this point in the history
  • Loading branch information
ambirdsall authored Feb 1, 2023
1 parent 19c05f7 commit 79b4c7a
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions airbyte-webapp/src/services/connector/ConnectorService.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
import { useConfig } from "config";
import { webBackendCheckUpdates, WebBackendCheckUpdatesRead } from "core/request/AirbyteClient";
import { AirbyteRequestService } from "core/request/AirbyteRequestService";
import { RequestMiddleware } from "core/request/RequestMiddleware";
import { FeatureItem, useFeature } from "hooks/services/Feature";
import { useDefaultRequestMiddlewares } from "services/useDefaultRequestMiddlewares";
import { useInitService } from "services/useInitService";
import { isCloudApp } from "utils/app";

const NO_UPDATES: WebBackendCheckUpdatesRead = {
destinationDefinitions: 0,
sourceDefinitions: 0,
};

type EnabledFeatures = Partial<Record<FeatureItem, boolean>>;

class ConnectorService extends AirbyteRequestService {
checkUpdates(): Promise<WebBackendCheckUpdatesRead> {
if (isCloudApp()) {
return Promise.resolve({ sourceDefinitions: 0, destinationDefinitions: 0 });
constructor(
rootUrl: string,
middlewares: RequestMiddleware[] = [],
private readonly enabledFeatures: EnabledFeatures
) {
super(rootUrl, middlewares);
this.enabledFeatures = enabledFeatures;
}
checkUpdates() {
if (this.enabledFeatures[FeatureItem.AllowUpdateConnectors]) {
return webBackendCheckUpdates(this.requestOptions);
}
return webBackendCheckUpdates(this.requestOptions);
return Promise.resolve(NO_UPDATES);
}
}

export function useConnectorService() {
const { apiUrl } = useConfig();

const enabledFeatures = {
[FeatureItem.AllowUpdateConnectors]: useFeature(FeatureItem.AllowUpdateConnectors),
};

const requestAuthMiddleware = useDefaultRequestMiddlewares();

return useInitService(() => new ConnectorService(apiUrl, requestAuthMiddleware), [apiUrl, requestAuthMiddleware]);
return useInitService(
() => new ConnectorService(apiUrl, requestAuthMiddleware, enabledFeatures),
[apiUrl, requestAuthMiddleware]
);
}

0 comments on commit 79b4c7a

Please sign in to comment.