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

Do not update deprecated connectors #4674

Merged
merged 5 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
66 changes: 27 additions & 39 deletions airbyte-webapp/src/components/hooks/services/useConnector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ import { useFetcher, useResource } from "rest-hooks";
import config from "config";
import { useMemo } from "react";

import SourceDefinitionResource from "../../../core/resources/SourceDefinition";
import DestinationDefinitionResource from "../../../core/resources/DestinationDefinition";
import SourceDefinitionResource, {
SourceDefinition,
} from "core/resources/SourceDefinition";
import DestinationDefinitionResource, {
DestinationDefinition,
} from "core/resources/DestinationDefinition";
import { isConnectorDeprecated } from "core/domain/connector";

type ConnectorService = {
hasNewVersions: boolean;
Expand All @@ -15,6 +20,15 @@ type ConnectorService = {
updateAllDestinationVersions: () => void;
};

function hasLatestVersion(
connector: SourceDefinition | DestinationDefinition
): boolean {
return (
!isConnectorDeprecated(connector) &&
connector.latestDockerImageTag !== connector.dockerImageTag
);
}

const useConnector = (): ConnectorService => {
const { sourceDefinitions } = useResource(
SourceDefinitionResource.listShape(),
Expand All @@ -38,51 +52,30 @@ const useConnector = (): ConnectorService => {
);

const hasNewSourceVersion = useMemo(
() =>
sourceDefinitions.some(
(source) => source.latestDockerImageTag !== source.dockerImageTag
),
() => sourceDefinitions.some(hasLatestVersion),
[sourceDefinitions]
);

const hasNewDestinationVersion = useMemo(
() =>
destinationDefinitions.some(
(destination) =>
destination.latestDockerImageTag !== destination.dockerImageTag
),
() => destinationDefinitions.some(hasLatestVersion),
[destinationDefinitions]
);

const hasNewVersions = useMemo(
() => hasNewSourceVersion || hasNewDestinationVersion,
[hasNewSourceVersion, hasNewDestinationVersion]
);
const hasNewVersions = hasNewSourceVersion || hasNewDestinationVersion;

const countNewSourceVersion = useMemo(
() =>
sourceDefinitions.filter(
(source) => source.latestDockerImageTag !== source.dockerImageTag
).length,
const newSourceDefinitions = useMemo(
() => sourceDefinitions.filter(hasLatestVersion),
[sourceDefinitions]
);

const countNewDestinationVersion = useMemo(
() =>
destinationDefinitions.filter(
(destination) =>
destination.latestDockerImageTag !== destination.dockerImageTag
).length,
const newDestinationDefinitions = useMemo(
() => destinationDefinitions.filter(hasLatestVersion),
[destinationDefinitions]
);

const updateAllSourceVersions = async () => {
const updateList = sourceDefinitions.filter(
(source) => source.latestDockerImageTag !== source.dockerImageTag
);

await Promise.all(
updateList?.map((item) =>
newSourceDefinitions?.map((item) =>
updateSourceDefinition(
{},
{
Expand All @@ -95,13 +88,8 @@ const useConnector = (): ConnectorService => {
};

const updateAllDestinationVersions = async () => {
const updateList = destinationDefinitions.filter(
(destination) =>
destination.latestDockerImageTag !== destination.dockerImageTag
);

await Promise.all(
updateList?.map((item) =>
newDestinationDefinitions?.map((item) =>
updateDestinationDefinition(
{},
{
Expand All @@ -119,8 +107,8 @@ const useConnector = (): ConnectorService => {
hasNewDestinationVersion,
updateAllSourceVersions,
updateAllDestinationVersions,
countNewSourceVersion,
countNewDestinationVersion,
countNewSourceVersion: newSourceDefinitions.length,
countNewDestinationVersion: newDestinationDefinitions.length,
};
};

Expand Down
8 changes: 8 additions & 0 deletions airbyte-webapp/src/core/domain/connector/connector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { SourceDefinition } from "core/resources/SourceDefinition";
import { DestinationDefinition } from "core/resources/DestinationDefinition";

export function isConnectorDeprecated(
item: SourceDefinition | DestinationDefinition
): boolean {
return !item.latestDockerImageTag;
}
1 change: 1 addition & 0 deletions airbyte-webapp/src/core/domain/connector/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./connector";