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

🪟 🎉 Custom connectors in cloud UI #20483

Merged
merged 6 commits into from
Dec 15, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ interface ConnectorCellProps {
connectorName: string;
img?: string;
hasUpdate?: boolean;
isDeprecated?: boolean;
releaseStage?: ReleaseStage;
}

Expand Down Expand Up @@ -40,14 +39,14 @@ const CustomAnnotation = styled.span`
color: ${({ theme }) => theme.greyColor40};
`;

const ConnectorCell: React.FC<ConnectorCellProps> = ({ connectorName, img, hasUpdate, isDeprecated, releaseStage }) => {
const ConnectorCell: React.FC<ConnectorCellProps> = ({ connectorName, img, hasUpdate, releaseStage }) => {
return (
<Content>
{hasUpdate && <Notification />}
<Image>{getIcon(img)}</Image>
<span>{connectorName}</span>
<ReleaseStageBadge small tooltip={false} stage={releaseStage} />
{isDeprecated && (
{releaseStage === "custom" && (
<CustomAnnotation>
(<FormattedMessage id="admin.customImage" />)
</CustomAnnotation>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import { useCallback } from "react";
import { FormattedMessage } from "react-intl";
import { CellProps } from "react-table";

Expand All @@ -8,7 +8,7 @@ import { Table } from "components/ui/Table";
import { Connector, ConnectorDefinition } from "core/domain/connector";
import { DestinationDefinitionRead, SourceDefinitionRead } from "core/request/AirbyteClient";
import { useAvailableConnectorDefinitions } from "hooks/domain/connector/useAvailableConnectorDefinitions";
import { FeatureItem, IfFeatureEnabled, useFeature } from "hooks/services/Feature";
import { FeatureItem, useFeature } from "hooks/services/Feature";
import { useCurrentWorkspace } from "hooks/services/useWorkspace";

import ConnectorCell from "./ConnectorCell";
Expand Down Expand Up @@ -47,14 +47,27 @@ const ConnectorsView: React.FC<ConnectorsViewProps> = ({
connectorsDefinitions,
}) => {
const allowUpdateConnectors = useFeature(FeatureItem.AllowUpdateConnectors);
const allowUploadCustomImage = useFeature(FeatureItem.AllowUploadCustomImage);
const workspace = useCurrentWorkspace();
const availableConnectorDefinitions = useAvailableConnectorDefinitions<ConnectorDefinition>(
connectorsDefinitions,
workspace
);
const showVersionUpdateColumn = useCallback(
(definitions: ConnectorDefinition[]) => {
if (allowUpdateConnectors) {
return true;
}
if (allowUploadCustomImage && definitions.some((definition) => definition.releaseStage === "custom")) {
return true;
}
return false;
},
[allowUpdateConnectors, allowUploadCustomImage]
);

const columns = React.useMemo(
() => [
const renderColumns = useCallback(
(showVersionUpdateColumn: boolean) => [
{
Header: <FormattedMessage id="admin.connectors" />,
accessor: "name",
Expand All @@ -64,7 +77,6 @@ const ConnectorsView: React.FC<ConnectorsViewProps> = ({
connectorName={cell.value}
img={row.original.icon}
hasUpdate={allowUpdateConnectors && Connector.hasNewerVersion(row.original)}
isDeprecated={Connector.isDeprecated(row.original)}
releaseStage={row.original.releaseStage}
/>
),
Expand All @@ -82,7 +94,7 @@ const ConnectorsView: React.FC<ConnectorsViewProps> = ({
accessor: "dockerImageTag",
customWidth: 10,
},
...(allowUpdateConnectors
...(showVersionUpdateColumn
? [
{
Header: (
Expand All @@ -92,29 +104,28 @@ const ConnectorsView: React.FC<ConnectorsViewProps> = ({
),
accessor: "latestDockerImageTag",
collapse: true,
Cell: ({ cell, row }: CellProps<ConnectorDefinition>) => (
<VersionCell
version={cell.value || row.original.dockerImageTag}
id={Connector.id(row.original)}
onChange={onUpdateVersion}
feedback={feedbackList[Connector.id(row.original)]}
currentVersion={row.original.dockerImageTag}
/>
),
Cell: ({ cell, row }: CellProps<ConnectorDefinition>) =>
allowUpdateConnectors || (allowUploadCustomImage && row.original.releaseStage === "custom") ? (
<VersionCell
version={cell.value || row.original.dockerImageTag}
id={Connector.id(row.original)}
onChange={onUpdateVersion}
feedback={feedbackList[Connector.id(row.original)]}
currentVersion={row.original.dockerImageTag}
/>
) : null,
},
]
: []),
],
[feedbackList, onUpdateVersion, allowUpdateConnectors]
[feedbackList, onUpdateVersion, allowUpdateConnectors, allowUploadCustomImage]
);

const renderHeaderControls = (section: "used" | "available") =>
((section === "used" && usedConnectorsDefinitions.length > 0) ||
(section === "available" && usedConnectorsDefinitions.length === 0)) && (
<div className={styles.buttonsContainer}>
<IfFeatureEnabled feature={FeatureItem.AllowUploadCustomImage}>
<CreateConnector type={type} />
</IfFeatureEnabled>
{allowUploadCustomImage && <CreateConnector type={type} />}
{(hasNewConnectorVersion || isUpdateSuccess) && allowUpdateConnectors && (
<UpgradeAllButton
isLoading={loading}
Expand All @@ -137,7 +148,11 @@ const ConnectorsView: React.FC<ConnectorsViewProps> = ({
<FormattedMessage id={type === "sources" ? "admin.manageSource" : "admin.manageDestination"} />
{renderHeaderControls("used")}
</Title>
<Table columns={columns} data={usedConnectorsDefinitions} sortBy={defaultSorting} />
<Table
columns={renderColumns(showVersionUpdateColumn(usedConnectorsDefinitions))}
data={usedConnectorsDefinitions}
sortBy={defaultSorting}
/>
</Block>
)}

Expand All @@ -146,7 +161,11 @@ const ConnectorsView: React.FC<ConnectorsViewProps> = ({
<FormattedMessage id={type === "sources" ? "admin.availableSource" : "admin.availableDestinations"} />
{renderHeaderControls("available")}
</Title>
<Table columns={columns} data={availableConnectorDefinitions} sortBy={defaultSorting} />
<Table
columns={renderColumns(showVersionUpdateColumn(availableConnectorDefinitions))}
data={availableConnectorDefinitions}
sortBy={defaultSorting}
/>
</Block>
</>
);
Expand Down