Skip to content

Commit

Permalink
Filter out unavailable connectors in cloud connector settings
Browse files Browse the repository at this point in the history
* Move list of excluded connectors to connector constants
* Add hook to filter out available connectors
* Update settings connectorview component to filter out connectors
* Add isCloudApp utility to check if the app is in cloud mode correctly
  • Loading branch information
edmundito committed May 25, 2022
1 parent 073bbbc commit c756466
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 23 deletions.
13 changes: 13 additions & 0 deletions airbyte-webapp/src/core/domain/connector/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
import { isCloudApp } from "utils/app";

export const DEV_IMAGE_TAG = "dev";

export const getExcludedConnectorIds = (workspaceId: string) =>
isCloudApp()
? [
"200330b2-ea62-4d11-ac6d-cfe3e3f8ab2b", // Snapchat
"2470e835-feaf-4db6-96f3-70fd645acc77", // Salesforce Singer
...(workspaceId !== "54135667-ce73-4820-a93c-29fe1510d348" // Shopify workspace for review
? ["9da77001-af33-4bcd-be46-6252bf9342b9"] // Shopify
: []),
]
: [];
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useMemo } from "react";

import { Connector, ConnectorDefinition } from "core/domain/connector";
import { getExcludedConnectorIds } from "core/domain/connector/constants";
import { WorkspaceRead } from "core/request/AirbyteClient";

export const useAvailableConnectorDefinitions = (
connectionDefinitions: ConnectorDefinition[],
workspace: WorkspaceRead
) =>
useMemo(() => {
const excludedConnectorIds = getExcludedConnectorIds(workspace.workspaceId);
return connectionDefinitions.filter(
(connectorDefinition) => !excludedConnectorIds.includes(Connector.id(connectorDefinition))
);
}, [connectionDefinitions, workspace.workspaceId]);
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import Table from "components/Table";

import { Connector, ConnectorDefinition } from "core/domain/connector";
import { DestinationDefinitionRead, SourceDefinitionRead } from "core/request/AirbyteClient";
import { useAvailableConnectorDefinitions } from "hooks/domain/connector/useAvailableConnectorDefinitions";
import { FeatureItem, useFeatureService, WithFeature } from "hooks/services/Feature";
import { useCurrentWorkspace } from "hooks/services/useWorkspace";

import ConnectorCell from "./ConnectorCell";
import CreateConnector from "./CreateConnector";
Expand Down Expand Up @@ -45,6 +47,8 @@ const ConnectorsView: React.FC<ConnectorsViewProps> = ({
}) => {
const { hasFeature } = useFeatureService();
const allowUpdateConnectors = hasFeature(FeatureItem.AllowUpdateConnectors);
const workspace = useCurrentWorkspace();
const availableConnectorDefinitions = useAvailableConnectorDefinitions(connectorsDefinitions, workspace);

const columns = React.useMemo(
() => [
Expand Down Expand Up @@ -139,7 +143,7 @@ const ConnectorsView: React.FC<ConnectorsViewProps> = ({
<FormattedMessage id={type === "sources" ? "admin.availableSource" : "admin.availableDestinations"} />
{renderHeaderControls("available")}
</Title>
<Table columns={columns} data={connectorsDefinitions} sortBy={defaultSorting} />
<Table columns={columns} data={availableConnectorDefinitions} sortBy={defaultSorting} />
</Block>
</>
);
Expand Down
1 change: 1 addition & 0 deletions airbyte-webapp/src/utils/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isCloudApp = () => process.env.REACT_APP_CLOUD || window.CLOUD === "true";
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { GAIcon } from "components/icons/GAIcon";
import { Connector, ConnectorDefinition } from "core/domain/connector";
import { FormBaseItem } from "core/form/types";
import { ReleaseStage } from "core/request/AirbyteClient";
import { useAvailableConnectorDefinitions } from "hooks/domain/connector/useAvailableConnectorDefinitions";
import { useAnalyticsService } from "hooks/services/Analytics";
import { useExperiment } from "hooks/services/Experiment";
import { useCurrentWorkspace } from "hooks/services/useWorkspace";
Expand Down Expand Up @@ -173,31 +174,11 @@ const ConnectorServiceTypeControl: React.FC<{
const orderOverwrite = useExperiment("connector.orderOverwrite", {});
const [field, fieldMeta, { setValue }] = useField(property.path);
const analytics = useAnalyticsService();

// TODO Begin hack
// During the Cloud private beta, we let users pick any connector in our catalog.
// Later on, we realized we shouldn't have allowed using connectors whose platforms required oauth
// But by that point, some users were already leveraging them, so removing them would crash the app for users
// instead we'll filter out those connectors from this drop down menu, and retain them in the backend
// This way, they will not be available for usage in new connections, but they will be available for users
// already leveraging them.
// TODO End hack
const workspace = useCurrentWorkspace();
const disallowedOauthConnectors =
// I would prefer to use windowConfigProvider.cloud but that function is async
window.CLOUD === "true"
? [
"200330b2-ea62-4d11-ac6d-cfe3e3f8ab2b", // Snapchat
"2470e835-feaf-4db6-96f3-70fd645acc77", // Salesforce Singer
...(workspace.workspaceId !== "54135667-ce73-4820-a93c-29fe1510d348" // Shopify workspace for review
? ["9da77001-af33-4bcd-be46-6252bf9342b9"] // Shopify
: []),
]
: [];
const availableConnectorDefinitions = useAvailableConnectorDefinitions(availableServices, workspace);
const sortedDropDownData = useMemo(
() =>
availableServices
.filter((item) => !disallowedOauthConnectors.includes(Connector.id(item)))
availableConnectorDefinitions
.map((item) => ({
label: item.name,
value: Connector.id(item),
Expand Down

0 comments on commit c756466

Please sign in to comment.