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

Use the new get out of date connectors endpoint #20155

Merged
merged 16 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
73 changes: 0 additions & 73 deletions airbyte-webapp/src/hooks/services/useConnector.test.tsx

This file was deleted.

52 changes: 25 additions & 27 deletions airbyte-webapp/src/hooks/services/useConnector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ConnectionConfiguration } from "core/domain/connection";
import { Connector } from "core/domain/connector";
import { DestinationService } from "core/domain/connector/DestinationService";
import { SourceService } from "core/domain/connector/SourceService";
import { useGetOutOfDateConnectorsCount } from "services/connector/ConnectorDefinitions";
import {
useDestinationDefinitionList,
useUpdateDestinationDefinition,
Expand All @@ -16,30 +17,12 @@ import { useInitService } from "services/useInitService";

import { CheckConnectionRead } from "../../core/request/AirbyteClient";

interface ConnectorService {
hasNewVersions: boolean;
hasNewSourceVersion: boolean;
hasNewDestinationVersion: boolean;
countNewSourceVersion: number;
countNewDestinationVersion: number;
updateAllSourceVersions: () => Promise<void>;
updateAllDestinationVersions: () => Promise<void>;
}

const useConnector = (): ConnectorService => {
export const useUpdateSourceDefinitions = () => {
const { sourceDefinitions } = useSourceDefinitionList();
const { destinationDefinitions } = useDestinationDefinitionList();

const { mutateAsync: updateSourceDefinition } = useUpdateSourceDefinition();
const { mutateAsync: updateDestinationDefinition } = useUpdateDestinationDefinition();

const newSourceDefinitions = useMemo(() => sourceDefinitions.filter(Connector.hasNewerVersion), [sourceDefinitions]);

const newDestinationDefinitions = useMemo(
() => destinationDefinitions.filter(Connector.hasNewerVersion),
[destinationDefinitions]
);

const updateAllSourceVersions = async () => {
await Promise.all(
newSourceDefinitions?.map((item) =>
Expand All @@ -51,6 +34,18 @@ const useConnector = (): ConnectorService => {
);
};

return { updateAllSourceVersions };
};

export const useUpdateDestinationDefinitions = () => {
const { destinationDefinitions } = useDestinationDefinitionList();
const { mutateAsync: updateDestinationDefinition } = useUpdateDestinationDefinition();

const newDestinationDefinitions = useMemo(
() => destinationDefinitions.filter(Connector.hasNewerVersion),
[destinationDefinitions]
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two methods were just moved into their own hooks so definitions aren't loaded for the count any more.

const updateAllDestinationVersions = async () => {
await Promise.all(
newDestinationDefinitions?.map((item) =>
Expand All @@ -62,18 +57,23 @@ const useConnector = (): ConnectorService => {
);
};

const hasNewSourceVersion = newSourceDefinitions.length > 0;
const hasNewDestinationVersion = newDestinationDefinitions.length > 0;
return { updateAllDestinationVersions };
};

export const useGetConnectorsOutOfDate = () => {
const outOfDateConnectors = useGetOutOfDateConnectorsCount();

const hasNewSourceVersion = outOfDateConnectors.sourceDefinitions > 0;
const hasNewDestinationVersion = outOfDateConnectors.destinationDefinitions > 0;
const hasNewVersions = hasNewSourceVersion || hasNewDestinationVersion;

return {
hasNewVersions,
hasNewSourceVersion,
hasNewDestinationVersion,
updateAllSourceVersions,
updateAllDestinationVersions,
countNewSourceVersion: newSourceDefinitions.length,
countNewDestinationVersion: newDestinationDefinitions.length,
countNewSourceVersion: outOfDateConnectors.sourceDefinitions,
countNewDestinationVersion: outOfDateConnectors.destinationDefinitions,
outOfDateConnectors,
};
};

Expand Down Expand Up @@ -151,5 +151,3 @@ export const useCheckConnector = (formType: "source" | "destination") => {
});
});
};

export default useConnector;
4 changes: 2 additions & 2 deletions airbyte-webapp/src/pages/SettingsPage/SettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import LoadingPage from "components/LoadingPage";
import { PageHeader } from "components/ui/PageHeader";
import { SideMenu, CategoryItem, SideMenuItem } from "components/ui/SideMenu";

import useConnector from "hooks/services/useConnector";
import { useGetConnectorsOutOfDate } from "hooks/services/useConnector";

import AccountPage from "./pages/AccountPage";
import ConfigurationsPage from "./pages/ConfigurationsPage";
Expand Down Expand Up @@ -38,7 +38,7 @@ export const SettingsRoute = {
const SettingsPage: React.FC<SettingsPageProps> = ({ pageConfig }) => {
const push = useNavigate();
const { pathname } = useLocation();
const { countNewSourceVersion, countNewDestinationVersion } = useConnector();
const { countNewSourceVersion, countNewDestinationVersion } = useGetConnectorsOutOfDate();

const menuItems: CategoryItem[] = pageConfig?.menuConfig || [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useAsyncFn } from "react-use";

import { DestinationDefinitionRead } from "core/request/AirbyteClient";
import { useTrackPage, PageTrackingCodes } from "hooks/services/Analytics";
import useConnector from "hooks/services/useConnector";
import { useGetConnectorsOutOfDate, useUpdateDestinationDefinitions } from "hooks/services/useConnector";
import {
useDestinationDefinitionList,
useUpdateDestinationDefinition,
Expand All @@ -25,7 +25,7 @@ const DestinationsPage: React.FC = () => {

const { mutateAsync: updateDestinationDefinition } = useUpdateDestinationDefinition();

const { hasNewDestinationVersion } = useConnector();
const { hasNewDestinationVersion } = useGetConnectorsOutOfDate();

const onUpdateVersion = useCallback(
async ({ id, version }: { id: string; version: string }) => {
Expand Down Expand Up @@ -61,7 +61,7 @@ const DestinationsPage: React.FC = () => {
return Array.from(destinationDefinitionMap.values());
}, [destinations, destinationDefinitions]);

const { updateAllDestinationVersions } = useConnector();
const { updateAllDestinationVersions } = useUpdateDestinationDefinitions();

const [{ loading, error }, onUpdate] = useAsyncFn(async () => {
setIsUpdateSuccess(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useAsyncFn } from "react-use";

import { SourceDefinitionRead } from "core/request/AirbyteClient";
import { useTrackPage, PageTrackingCodes } from "hooks/services/Analytics";
import useConnector from "hooks/services/useConnector";
import { useGetConnectorsOutOfDate, useUpdateSourceDefinitions } from "hooks/services/useConnector";
import { useSourceList } from "hooks/services/useSourceHook";
import { useSourceDefinitionList, useUpdateSourceDefinition } from "services/connector/SourceDefinitionService";

Expand All @@ -13,7 +13,7 @@ import ConnectorsView from "./components/ConnectorsView";
const SourcesPage: React.FC = () => {
useTrackPage(PageTrackingCodes.SETTINGS_SOURCE);

const [isUpdateSuccess, setIsUpdateSucces] = useState(false);
const [isUpdateSuccess, setIsUpdateSuccess] = useState(false);
const [feedbackList, setFeedbackList] = useState<Record<string, string>>({});

const { formatMessage } = useIntl();
Expand All @@ -22,7 +22,8 @@ const SourcesPage: React.FC = () => {

const { mutateAsync: updateSourceDefinition } = useUpdateSourceDefinition();

const { hasNewSourceVersion, updateAllSourceVersions } = useConnector();
const { hasNewSourceVersion } = useGetConnectorsOutOfDate();
const { updateAllSourceVersions } = useUpdateSourceDefinitions();

const onUpdateVersion = useCallback(
async ({ id, version }: { id: string; version: string }) => {
Expand Down Expand Up @@ -59,11 +60,11 @@ const SourcesPage: React.FC = () => {
}, [sources, sourceDefinitions]);

const [{ loading, error }, onUpdate] = useAsyncFn(async () => {
setIsUpdateSucces(false);
setIsUpdateSuccess(false);
await updateAllSourceVersions();
setIsUpdateSucces(true);
setIsUpdateSuccess(true);
setTimeout(() => {
setIsUpdateSucces(false);
setIsUpdateSuccess(false);
}, 2000);
}, [updateAllSourceVersions]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@ const ConnectorsView: React.FC<ConnectorsViewProps> = ({
onChange={onUpdateVersion}
feedback={feedbackList[Connector.id(row.original)]}
currentVersion={row.original.dockerImageTag}
updating={loading}
/>
) : null,
},
]
: []),
],
[feedbackList, onUpdateVersion, allowUpdateConnectors, allowUploadCustomImage]
[allowUpdateConnectors, allowUploadCustomImage, onUpdateVersion, feedbackList, loading]
);

const renderHeaderControls = (section: "used" | "available") =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import { DEV_IMAGE_TAG } from "core/domain/connector/constants";

import { FormContent } from "./PageComponents";

interface IProps {
interface VersionCellProps {
version: string;
currentVersion: string;
id: string;
onChange: ({ version, id }: { version: string; id: string }) => void;
feedback?: "success" | string;
updating: boolean;
}

const VersionInput = styled(Input)`
Expand Down Expand Up @@ -64,7 +65,7 @@ const ErrorMessage = styled(SuccessMessage)`
line-height: 14px;
`;

const VersionCell: React.FC<IProps> = ({ id, version, onChange, feedback, currentVersion }) => {
const VersionCell: React.FC<VersionCellProps> = ({ id, version, onChange, feedback, currentVersion, updating }) => {
const { formatMessage } = useIntl();

const renderFeedback = (dirty: boolean, feedback?: string) => {
Expand Down Expand Up @@ -109,7 +110,7 @@ const VersionCell: React.FC<IProps> = ({ id, version, onChange, feedback, curren
</Field>
<Button
size="xs"
isLoading={isSubmitting}
isLoading={isSubmitting || updating}
type="submit"
disabled={(isSubmitting || !dirty) && !isConnectorUpdatable}
>
Expand Down
7 changes: 7 additions & 0 deletions airbyte-webapp/src/services/connector/ConnectorDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DestinationDefinitionRead, SourceDefinitionRead } from "core/request/Ai
import { SCOPE_WORKSPACE } from "services/Scope";
import { useCurrentWorkspaceId } from "services/workspaces/WorkspacesService";

import { useConnectorService } from "./ConnectorService";
import { useGetDestinationDefinitionService } from "./DestinationDefinitionService";
import { useGetSourceDefinitionService } from "./SourceDefinitionService";
import { useSuspenseQuery } from "./useSuspenseQuery";
Expand All @@ -14,6 +15,7 @@ interface ConnectorSpecifications {
export const connectorDefinitionKeys = {
all: [SCOPE_WORKSPACE, "connectorDefinition"] as const,
lists: () => [...connectorDefinitionKeys.all, "list"] as const,
count: () => [...connectorDefinitionKeys.all, "count"] as const,
};

/**
Expand All @@ -36,3 +38,8 @@ export const useConnectorSpecifications = (): ConnectorSpecifications => {
return { sourceDefinitions, destinationDefinitions };
});
};

export const useGetOutOfDateConnectorsCount = () => {
const service = useConnectorService();
return useSuspenseQuery(connectorDefinitionKeys.count(), () => service.checkUpdates());
};
krishnaglick marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 19 additions & 0 deletions airbyte-webapp/src/services/connector/ConnectorService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useConfig } from "config";
import { webBackendCheckUpdates } from "core/request/AirbyteClient";
import { AirbyteRequestService } from "core/request/AirbyteRequestService";
import { useDefaultRequestMiddlewares } from "services/useDefaultRequestMiddlewares";
import { useInitService } from "services/useInitService";

class ConnectorService extends AirbyteRequestService {
checkUpdates() {
return webBackendCheckUpdates(this.requestOptions);
}
}

export function useConnectorService() {
const { apiUrl } = useConfig();

const requestAuthMiddleware = useDefaultRequestMiddlewares();

return useInitService(() => new ConnectorService(apiUrl, requestAuthMiddleware), [apiUrl, requestAuthMiddleware]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { isDefined } from "utils/common";

import { DestinationDefinitionCreate, DestinationDefinitionRead } from "../../core/request/AirbyteClient";
import { SCOPE_WORKSPACE } from "../Scope";
import { connectorDefinitionKeys } from "./ConnectorDefinitions";
import { useSuspenseQuery } from "./useSuspenseQuery";

export const destinationDefinitionKeys = {
Expand Down Expand Up @@ -117,6 +118,8 @@ const useUpdateDestinationDefinition = () => {
) ?? [],
})
);

queryClient.invalidateQueries(connectorDefinitionKeys.count());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be the best way to handle this. Open to suggestions.

},
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { isDefined } from "utils/common";

import { SourceDefinitionCreate, SourceDefinitionRead } from "../../core/request/AirbyteClient";
import { SCOPE_WORKSPACE } from "../Scope";
import { connectorDefinitionKeys } from "./ConnectorDefinitions";
import { useSuspenseQuery } from "./useSuspenseQuery";

export const sourceDefinitionKeys = {
Expand Down Expand Up @@ -114,6 +115,8 @@ const useUpdateSourceDefinition = () => {
[],
})
);

queryClient.invalidateQueries(connectorDefinitionKeys.count());
},
});
};
Expand Down
Loading