Skip to content

Commit 7f36386

Browse files
author
Joe Reuter
authored
🪟🔧 Refactor ConnectorsView (#21531)
* WIP * WIP * wip * more fixes * fix test * remove some more styled components and improve memoization * review comment
1 parent a95cf22 commit 7f36386

File tree

18 files changed

+394
-417
lines changed

18 files changed

+394
-417
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@use "scss/colors";
2+
3+
.indicator {
4+
height: 10px;
5+
width: 10px;
6+
border-radius: 50%;
7+
background: colors.$red;
8+
}
9+
10+
.hidden {
11+
background-color: transparent;
12+
}
Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
import styled from "styled-components";
1+
import classNames from "classnames";
22

3-
export const Indicator = styled.div`
4-
height: 10px;
5-
width: 10px;
6-
border-radius: 50%;
7-
background: ${({ theme }) => theme.dangerColor};
8-
`;
3+
import styles from "./Indicator.module.scss";
4+
5+
export interface IndicatorProps {
6+
/**
7+
* Set to true to render an invisible indicator so reserve the space in the UI
8+
*/
9+
hidden?: boolean;
10+
className?: string;
11+
}
12+
13+
export const Indicator: React.FC<IndicatorProps> = ({ hidden, className }) => (
14+
<div className={classNames(className, styles.indicator, { [styles.hidden]: hidden })} />
15+
);

airbyte-webapp/src/components/ReleaseStageBadge/ReleaseStageBadge.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const ReleaseStageBadge: React.FC<ReleaseStageBadgeProps> = ({
2626
}) => {
2727
const { formatMessage } = useIntl();
2828

29-
if (!stage || stage === ReleaseStage.custom) {
29+
if (!stage) {
3030
return null;
3131
}
3232

airbyte-webapp/src/locales/en.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,6 @@
530530
"admin.downloadSchedulerLogs": "Download Scheduler Logs",
531531
"admin.upgradeAll": "Upgrade all",
532532
"admin.upgraded": "Upgraded!",
533-
"admin.customImage": "custom",
534533

535534
"settings.accountSettings": "Account Settings",
536535
"settings.webhook": "Connection status Webhook",

airbyte-webapp/src/pages/SettingsPage/pages/ConnectorsPage/DestinationsPage.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useMemo, useState } from "react";
1+
import React, { useCallback, useMemo, useRef, useState } from "react";
22
import { useIntl } from "react-intl";
33
import { useAsyncFn } from "react-use";
44

@@ -22,28 +22,34 @@ const DestinationsPage: React.FC = () => {
2222
const { destinations } = useDestinationList();
2323

2424
const [feedbackList, setFeedbackList] = useState<Record<string, string>>({});
25+
const feedbackListRef = useRef(feedbackList);
26+
feedbackListRef.current = feedbackList;
2527

2628
const { mutateAsync: updateDestinationDefinition } = useUpdateDestinationDefinition();
29+
const [updatingDefinitionId, setUpdatingDefinitionId] = useState<string>();
2730

2831
const { hasNewDestinationVersion } = useGetConnectorsOutOfDate();
2932

3033
const onUpdateVersion = useCallback(
3134
async ({ id, version }: { id: string; version: string }) => {
3235
try {
36+
setUpdatingDefinitionId(id);
3337
await updateDestinationDefinition({
3438
destinationDefinitionId: id,
3539
dockerImageTag: version,
3640
});
37-
setFeedbackList({ ...feedbackList, [id]: "success" });
41+
setFeedbackList({ ...feedbackListRef.current, [id]: "success" });
3842
} catch (e) {
3943
const messageId = e.status === 422 ? "form.imageCannotFound" : "form.someError";
4044
setFeedbackList({
41-
...feedbackList,
45+
...feedbackListRef.current,
4246
[id]: formatMessage({ id: messageId }),
4347
});
48+
} finally {
49+
setUpdatingDefinitionId(undefined);
4450
}
4551
},
46-
[feedbackList, formatMessage, updateDestinationDefinition]
52+
[formatMessage, updateDestinationDefinition]
4753
);
4854

4955
const usedDestinationDefinitions = useMemo<DestinationDefinitionRead[]>(() => {
@@ -80,6 +86,7 @@ const DestinationsPage: React.FC = () => {
8086
onUpdateVersion={onUpdateVersion}
8187
usedConnectorsDefinitions={usedDestinationDefinitions}
8288
connectorsDefinitions={destinationDefinitions}
89+
updatingDefinitionId={updatingDefinitionId}
8390
loading={loading}
8491
error={error}
8592
onUpdate={onUpdate}

airbyte-webapp/src/pages/SettingsPage/pages/ConnectorsPage/SourcesPage.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useMemo, useState } from "react";
1+
import React, { useCallback, useMemo, useRef, useState } from "react";
22
import { useIntl } from "react-intl";
33
import { useAsyncFn } from "react-use";
44

@@ -15,33 +15,39 @@ const SourcesPage: React.FC = () => {
1515

1616
const [isUpdateSuccess, setIsUpdateSuccess] = useState(false);
1717
const [feedbackList, setFeedbackList] = useState<Record<string, string>>({});
18+
const feedbackListRef = useRef(feedbackList);
19+
feedbackListRef.current = feedbackList;
1820

1921
const { formatMessage } = useIntl();
2022
const { sources } = useSourceList();
2123
const { sourceDefinitions } = useSourceDefinitionList();
2224

2325
const { mutateAsync: updateSourceDefinition } = useUpdateSourceDefinition();
26+
const [updatingDefinitionId, setUpdatingDefinitionId] = useState<string>();
2427

2528
const { hasNewSourceVersion } = useGetConnectorsOutOfDate();
2629
const { updateAllSourceVersions } = useUpdateSourceDefinitions();
2730

2831
const onUpdateVersion = useCallback(
2932
async ({ id, version }: { id: string; version: string }) => {
3033
try {
34+
setUpdatingDefinitionId(id);
3135
await updateSourceDefinition({
3236
sourceDefinitionId: id,
3337
dockerImageTag: version,
3438
});
35-
setFeedbackList({ ...feedbackList, [id]: "success" });
39+
setFeedbackList({ ...feedbackListRef.current, [id]: "success" });
3640
} catch (e) {
3741
const messageId = e.status === 422 ? "form.imageCannotFound" : "form.someError";
3842
setFeedbackList({
39-
...feedbackList,
43+
...feedbackListRef.current,
4044
[id]: formatMessage({ id: messageId }),
4145
});
46+
} finally {
47+
setUpdatingDefinitionId(undefined);
4248
}
4349
},
44-
[feedbackList, formatMessage, updateSourceDefinition]
50+
[formatMessage, updateSourceDefinition]
4551
);
4652

4753
const usedSourcesDefinitions: SourceDefinitionRead[] = useMemo(() => {
@@ -72,6 +78,7 @@ const SourcesPage: React.FC = () => {
7278
<ConnectorsView
7379
type="sources"
7480
loading={loading}
81+
updatingDefinitionId={updatingDefinitionId}
7582
error={error}
7683
isUpdateSuccess={isUpdateSuccess}
7784
hasNewConnectorVersion={hasNewSourceVersion}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.iconContainer {
2+
height: 25px;
3+
}

airbyte-webapp/src/pages/SettingsPage/pages/ConnectorsPage/components/ConnectorCell.tsx

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,29 @@
11
import React from "react";
2-
import { FormattedMessage } from "react-intl";
3-
import styled from "styled-components";
42

53
import Indicator from "components/Indicator";
64
import { ReleaseStageBadge } from "components/ReleaseStageBadge";
5+
import { FlexContainer } from "components/ui/Flex";
76

87
import { ReleaseStage } from "core/request/AirbyteClient";
98
import { getIcon } from "utils/imageUtils";
109

10+
import styles from "./ConnectorCell.module.scss";
11+
1112
interface ConnectorCellProps {
1213
connectorName: string;
1314
img?: string;
1415
hasUpdate?: boolean;
1516
releaseStage?: ReleaseStage;
1617
}
1718

18-
const Content = styled.div<{ enabled?: boolean }>`
19-
display: flex;
20-
align-items: center;
21-
padding-left: 30px;
22-
position: relative;
23-
margin: -5px 0;
24-
min-width: 290px;
25-
gap: 8px;
26-
`;
27-
28-
const Image = styled.div`
29-
height: 25px;
30-
width: 17px;
31-
`;
32-
33-
const Notification = styled(Indicator)`
34-
position: absolute;
35-
left: 8px;
36-
`;
37-
38-
const CustomAnnotation = styled.span`
39-
color: ${({ theme }) => theme.greyColor40};
40-
`;
41-
4219
const ConnectorCell: React.FC<ConnectorCellProps> = ({ connectorName, img, hasUpdate, releaseStage }) => {
4320
return (
44-
<Content>
45-
{hasUpdate && <Notification />}
46-
<Image>{getIcon(img)}</Image>
47-
<span>{connectorName}</span>
21+
<FlexContainer alignItems="center" gap="lg">
22+
<Indicator hidden={!hasUpdate} />
23+
<div className={styles.iconContainer}>{getIcon(img)}</div>
24+
<div>{connectorName}</div>
4825
<ReleaseStageBadge small tooltip={false} stage={releaseStage} />
49-
{releaseStage === "custom" && (
50-
<CustomAnnotation>
51-
(<FormattedMessage id="admin.customImage" />)
52-
</CustomAnnotation>
53-
)}
54-
</Content>
26+
</FlexContainer>
5527
);
5628
};
5729

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@use "scss/variables";
2+
@use "scss/colors";
3+
4+
.changeToHeader {
5+
margin-left: 200px;
6+
}
7+
8+
.connectorsTable {
9+
td {
10+
padding-top: variables.$spacing-sm;
11+
padding-bottom: variables.$spacing-sm;
12+
}
13+
}

0 commit comments

Comments
 (0)