-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only checkUpdates if AllowUpdateConnectors enabled (#21138)
- Loading branch information
1 parent
19c05f7
commit 79b4c7a
Showing
1 changed file
with
29 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
); | ||
} |