Skip to content

Commit

Permalink
🪟 🔧 Add auto-detect schema changes feature flag (#20035)
Browse files Browse the repository at this point in the history
* Add auto-detect schema changes feature flag

* Update schema changes enabled in StatusCell

* Mock useIsAutoDetectSchemaChangesEnabled hook in tests
  • Loading branch information
edmundito authored Dec 6, 2022
1 parent 86f61a5 commit b5fdbaf
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 24 deletions.
7 changes: 4 additions & 3 deletions airbyte-webapp/src/components/EntityTable/ConnectionTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CellProps } from "react-table";
import { Table, SortableTableHeader } from "components/ui/Table";

import { ConnectionScheduleType, SchemaChange } from "core/request/AirbyteClient";
import { useIsAutoDetectSchemaChangesEnabled } from "hooks/connection/useIsAutoDetectSchemaChangesEnabled";
import { FeatureItem, useFeature } from "hooks/services/Feature";
import { useQuery } from "hooks/useQuery";

Expand All @@ -28,7 +29,7 @@ interface IProps {
const ConnectionTable: React.FC<IProps> = ({ data, entity, onClickRow, onSync }) => {
const navigate = useNavigate();
const query = useQuery<{ sortBy?: string; order?: SortOrderEnum }>();
const isSchemaChangesFeatureEnabled = process.env.REACT_APP_AUTO_DETECT_SCHEMA_CHANGES === "true";
const isSchemaChangesEnabled = useIsAutoDetectSchemaChangesEnabled();
const allowSync = useFeature(FeatureItem.AllowSync);

const sortBy = query.sortBy || "entityName";
Expand Down Expand Up @@ -163,7 +164,7 @@ const ConnectionTable: React.FC<IProps> = ({ data, entity, onClickRow, onSync })
isSyncing={row.original.isSyncing}
isManual={row.original.scheduleType === ConnectionScheduleType.manual}
onSync={onSync}
hasBreakingChange={isSchemaChangesFeatureEnabled && row.original.schemaChange === SchemaChange.breaking}
hasBreakingChange={isSchemaChangesEnabled && row.original.schemaChange === SchemaChange.breaking}
allowSync={allowSync}
/>
),
Expand All @@ -175,7 +176,7 @@ const ConnectionTable: React.FC<IProps> = ({ data, entity, onClickRow, onSync })
Cell: ({ cell }: CellProps<ITableDataItem>) => <ConnectionSettingsCell id={cell.value} />,
},
],
[sortBy, sortOrder, entity, onSortClick, onSync, allowSync, isSchemaChangesFeatureEnabled]
[sortBy, sortOrder, entity, onSortClick, onSync, allowSync, isSchemaChangesEnabled]
);

return <Table columns={columns} data={sortingData} onClickRow={onClickRow} erroredRows />;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";

import { SchemaChange } from "core/request/AirbyteClient";
import { useIsAutoDetectSchemaChangesEnabled } from "hooks/connection/useIsAutoDetectSchemaChangesEnabled";

import { ChangesStatusIcon } from "./ChangesStatusIcon";
import styles from "./StatusCell.module.scss";
Expand All @@ -27,7 +28,7 @@ export const StatusCell: React.FC<StatusCellProps> = ({
schemaChange,
hasBreakingChange,
}) => {
const isSchemaChangesFeatureEnabled = process.env.REACT_APP_AUTO_DETECT_SCHEMA_CHANGES === "true";
const isSchemaChangesEnabled = useIsAutoDetectSchemaChangesEnabled();

return (
<div className={styles.container}>
Expand All @@ -40,7 +41,7 @@ export const StatusCell: React.FC<StatusCellProps> = ({
hasBreakingChange={hasBreakingChange}
allowSync={allowSync}
/>
{isSchemaChangesFeatureEnabled && <ChangesStatusIcon schemaChange={schemaChange} />}
{isSchemaChangesEnabled && <ChangesStatusIcon schemaChange={schemaChange} />}
</div>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { useExperiment } from "hooks/services/Experiment";

const isEnabledInEnv = process.env.REACT_APP_AUTO_DETECT_SCHEMA_CHANGES === "true";

export const useIsAutoDetectSchemaChangesEnabled = () =>
useExperiment("connection.autoDetectSchemaChanges", isEnabledInEnv);
8 changes: 5 additions & 3 deletions airbyte-webapp/src/hooks/connection/useSchemaChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { useMemo } from "react";

import { SchemaChange } from "core/request/AirbyteClient";

import { useIsAutoDetectSchemaChangesEnabled } from "./useIsAutoDetectSchemaChangesEnabled";

export const useSchemaChanges = (schemaChange: SchemaChange) => {
const isSchemaChangesFeatureEnabled = process.env.REACT_APP_AUTO_DETECT_SCHEMA_CHANGES === "true";
const isSchemaChangesEnabled = useIsAutoDetectSchemaChangesEnabled();

return useMemo(() => {
const hasSchemaChanges = isSchemaChangesFeatureEnabled && schemaChange !== SchemaChange.no_change;
const hasSchemaChanges = isSchemaChangesEnabled && schemaChange !== SchemaChange.no_change;
const hasBreakingSchemaChange = hasSchemaChanges && schemaChange === SchemaChange.breaking;
const hasNonBreakingSchemaChange = hasSchemaChanges && schemaChange === SchemaChange.non_breaking;

Expand All @@ -16,5 +18,5 @@ export const useSchemaChanges = (schemaChange: SchemaChange) => {
hasBreakingSchemaChange,
hasNonBreakingSchemaChange,
};
}, [isSchemaChangesFeatureEnabled, schemaChange]);
}, [isSchemaChangesEnabled, schemaChange]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ export interface Experiments {
"authPage.oauth.position": "top" | "bottom";
"connection.onboarding.sources": string;
"connection.onboarding.destinations": string;
"connection.autoDetectSchemaChanges": boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@ jest.doMock("views/Connection/ConnectionForm/components/refreshSourceSchemaWithC
useRefreshSourceSchemaWithConfirmationOnDirty: mockUseRefreshSourceSchemaWithConfirmationOnDirty,
}));

jest.mock("hooks/connection/useIsAutoDetectSchemaChangesEnabled", () => ({
useIsAutoDetectSchemaChangesEnabled: () => true,
}));

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { SchemaChangesDetected } = require("./SchemaChangesDetected");

describe("<SchemaChangesDetected />", () => {
beforeAll(() => {
process.env.REACT_APP_AUTO_DETECT_SCHEMA_CHANGES = "true";
});

afterAll(() => {
delete process.env.REACT_APP_AUTO_DETECT_SCHEMA_CHANGES;
});

beforeEach(() => {
mockUseConnectionEditService.mockReturnValue({
connection: mockConnection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,14 @@ jest.doMock("views/Connection/ConnectionForm/components/refreshSourceSchemaWithC
useRefreshSourceSchemaWithConfirmationOnDirty: jest.fn(),
}));

jest.mock("hooks/connection/useIsAutoDetectSchemaChangesEnabled", () => ({
useIsAutoDetectSchemaChangesEnabled: () => true,
}));

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { StatusMainInfo } = require("./StatusMainInfo");

describe("<StatusMainInfo />", () => {
beforeAll(() => {
process.env.REACT_APP_AUTO_DETECT_SCHEMA_CHANGES = "true";
});

afterAll(() => {
delete process.env.REACT_APP_AUTO_DETECT_SCHEMA_CHANGES;
});

beforeEach(() => {
mockUseConnectionEditService.mockReturnValue({
connection: mockConnection,
Expand Down

0 comments on commit b5fdbaf

Please sign in to comment.