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

🪟 Per-Stream state new flow #14634

Merged
merged 29 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
78c9d6b
[WIP] new per stream flow
timroes Jul 12, 2022
efa5c98
Start work on ModalSerice
timroes Jul 12, 2022
6ab269c
Merge branch 'master' into tim/per-stream-flow
timroes Jul 13, 2022
654d502
Continue work
timroes Jul 13, 2022
b89cc19
Fix typo
timroes Jul 13, 2022
2657d88
Change wording
timroes Jul 13, 2022
6fce4f0
Add todos and remove dead code
timroes Jul 13, 2022
5a9cbcc
Remove dead message
timroes Jul 13, 2022
13be9e8
Merge branch 'master' into tim/per-stream-flow
timroes Jul 13, 2022
7d1fbeb
Merge branch 'master' into tim/per-stream-flow
timroes Jul 13, 2022
9266bb5
Adjust to new API
timroes Jul 13, 2022
ee1c329
Merge branch 'master' into tim/per-stream-flow
timroes Jul 14, 2022
871df8a
Adjust to new modal changes
timroes Jul 14, 2022
f0515e8
Remove debug output
timroes Jul 14, 2022
8de44f9
Fix e2e test
timroes Jul 14, 2022
e08d0e5
Add data-testids
timroes Jul 14, 2022
6fd68b1
Adjust for PR review
timroes Jul 15, 2022
9e7fd01
Merge branch 'master' into tim/per-stream-flow
timroes Jul 15, 2022
22036c0
Merge branch 'master' into tim/per-stream-flow
timroes Jul 15, 2022
4787a78
Switch to new ModalFooter/Body components
timroes Jul 15, 2022
a0cb0ce
Add ModalService tests
timroes Jul 15, 2022
8cbe3fe
Merge branch 'master' into tim/per-stream-flow
timroes Jul 15, 2022
7cadda6
Merge branch 'master' into tim/per-stream-flow
timroes Jul 18, 2022
f736e2e
Downgrade user-events again
timroes Jul 18, 2022
4984735
Merge branch 'master' into tim/per-stream-flow
timroes Jul 19, 2022
b92807b
Only compare selected streams
timroes Jul 19, 2022
1f0b868
Update airbyte-webapp/src/locales/en.json
timroes Jul 19, 2022
5e759ca
Update airbyte-webapp/src/locales/en.json
timroes Jul 19, 2022
95a90b6
Remove redundant space
timroes Jul 19, 2022
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
9 changes: 6 additions & 3 deletions airbyte-webapp/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ServicesProvider } from "core/servicesProvider";
import { ConfirmationModalService } from "hooks/services/ConfirmationModal";
import { FeatureService } from "hooks/services/Feature";
import { FormChangeTrackerService } from "hooks/services/FormChangeTracker";
import { ModalServiceProvider } from "hooks/services/Modal";
import NotificationService from "hooks/services/Notification";
import { AnalyticsProvider } from "views/common/AnalyticsProvider";
import { StoreProvider } from "views/common/StoreProvider";
Expand Down Expand Up @@ -44,9 +45,11 @@ const Services: React.FC = ({ children }) => (
<FeatureService>
<NotificationService>
<ConfirmationModalService>
<FormChangeTrackerService>
<ApiServices>{children}</ApiServices>
</FormChangeTrackerService>
<ModalServiceProvider>
<FormChangeTrackerService>
<ApiServices>{children}</ApiServices>
</FormChangeTrackerService>
</ModalServiceProvider>
</ConfirmationModalService>
</NotificationService>
</FeatureService>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export interface ConfirmationModalProps {
title: string;
text: string;
submitButtonText: string;
onSubmit: () => void;
secondaryButtonText?: string;
secondaryButtonDataId?: string;
onSubmit: (button: "primary" | "secondary") => void;
submitButtonDataId?: string;
cancelButtonText?: string;
}
Expand All @@ -43,10 +45,13 @@ export const ConfirmationModal: React.FC<ConfirmationModalProps> = ({
onSubmit,
submitButtonText,
submitButtonDataId,
secondaryButtonText,
secondaryButtonDataId,
cancelButtonText,
}) => {
const { isLoading, startAction } = useLoadingState();
const onSubmitBtnClick = () => startAction({ action: () => onSubmit() });
const onSubmitBtnClick = () => startAction({ action: () => onSubmit("primary") });
const onSecondaryBtnClick = () => startAction({ action: () => onSubmit("secondary") });

return (
<Modal onClose={onClose} title={<FormattedMessage id={title} />}>
Expand All @@ -56,6 +61,17 @@ export const ConfirmationModal: React.FC<ConfirmationModalProps> = ({
<ButtonWithMargin onClick={onClose} type="button" secondary disabled={isLoading}>
<FormattedMessage id={cancelButtonText ?? "form.cancel"} />
</ButtonWithMargin>
{secondaryButtonText && (
<ButtonWithMargin
danger
type="button"
onClick={onSecondaryBtnClick}
data-testid={secondaryButtonDataId}
disabled={isLoading}
>
<FormattedMessage id={secondaryButtonText} />
</ButtonWithMargin>
)}
<LoadingButton danger onClick={onSubmitBtnClick} data-id={submitButtonDataId} isLoading={isLoading}>
<FormattedMessage id={submitButtonText} />
</LoadingButton>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deleteConnection, resetConnection, syncConnection, getState } from "../../request/AirbyteClient";
import { deleteConnection, resetConnection, syncConnection, getState, getStateType } from "../../request/AirbyteClient";
import { AirbyteRequestService } from "../../request/AirbyteRequestService";

export class ConnectionService extends AirbyteRequestService {
Expand All @@ -17,4 +17,8 @@ export class ConnectionService extends AirbyteRequestService {
public getState(connectionId: string) {
return getState({ connectionId }, this.requestOptions);
}

public getStateType(connectionId: string) {
return getStateType({ connectionId }, this.requestOptions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export const ConfirmationModalService = ({ children }: { children: React.ReactNo
submitButtonText={state.confirmationModal.submitButtonText}
submitButtonDataId={state.confirmationModal.submitButtonDataId}
cancelButtonText={state.confirmationModal.cancelButtonText}
secondaryButtonText={state.confirmationModal.secondaryButtonText}
secondaryButtonDataId={state.confirmationModal.secondaryButtonDataId}
/>
) : null}
</>
Expand Down
54 changes: 54 additions & 0 deletions airbyte-webapp/src/hooks/services/Modal/ModalService.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, { useContext, useMemo, useRef, useState } from "react";
import { firstValueFrom, Subject } from "rxjs";

import { Modal } from "components";

import { ModalOptions, ModalResult, ModalServiceContextType } from "./types";

const ModalServiceContext = React.createContext<ModalServiceContextType | undefined>(undefined);
timroes marked this conversation as resolved.
Show resolved Hide resolved

export const ModalServiceProvider: React.FC = ({ children }) => {
const [modalOptions, setModalOptions] = useState<ModalOptions>();
const promiseRef = useRef<Subject<ModalResult>>();

const service: ModalServiceContextType = useMemo(
() => ({
openModal: (options) => {
promiseRef.current = new Subject();
setModalOptions(options);

return firstValueFrom(promiseRef.current).then((reason) => {
setModalOptions(undefined);
promiseRef.current = undefined;
return reason;
});
},
closeModal: () => {
promiseRef.current?.next({ type: "canceled" });
},
}),
[]
);

return (
<ModalServiceContext.Provider value={service}>
{children}
{modalOptions && (
<Modal title={modalOptions.title} onClose={() => promiseRef.current?.next({ type: "canceled" })}>
<modalOptions.content
onCancel={() => promiseRef.current?.next({ type: "canceled" })}
onClose={(reason: unknown) => promiseRef.current?.next({ type: "closed", reason })}
/>
</Modal>
)}
</ModalServiceContext.Provider>
);
};

export const useModalService = () => {
const context = useContext(ModalServiceContext);
if (!context) {
throw new Error("Can't use ModalService outside ModalServiceProvider");
}
return context;
};
1 change: 1 addition & 0 deletions airbyte-webapp/src/hooks/services/Modal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./ModalService";
18 changes: 18 additions & 0 deletions airbyte-webapp/src/hooks/services/Modal/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from "react";

export interface ModalOptions {
title: React.ReactNode;
content: React.ComponentType<ModalContentProps>;
}

export type ModalResult = { type: "canceled" } | { type: "closed"; reason: unknown };

interface ModalContentProps {
onClose: (reason: unknown) => void;
onCancel: () => void;
}

export interface ModalServiceContextType {
openModal: (options: ModalOptions) => Promise<ModalResult>;
closeModal: () => void;
}
2 changes: 1 addition & 1 deletion airbyte-webapp/src/hooks/services/useConnectionHook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function useWebConnectionService() {
);
}

function useConnectionService() {
export function useConnectionService() {
const config = useConfig();
const middlewares = useDefaultRequestMiddlewares();
return useInitService(() => new ConnectionService(config.apiUrl, middlewares), [config.apiUrl, middlewares]);
Expand Down
5 changes: 1 addition & 4 deletions airbyte-webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@
"form.destinationConnector": "Destination connector",
"form.addItems": "Add",
"form.items": "Items",
"form.toSaveSchema": "To save the new schema, click on Save changes.",
"form.noteStartSync": "Note that it will delete all the data in your destination and start syncing from scratch. ",
"form.pkSelected": "{count, plural, =0 { } one {{items}} other {# keys selected}}",
"form.url.error": "field must be a valid URL",
"form.setupGuide": "Setup Guide",
Expand Down Expand Up @@ -317,7 +315,7 @@
"syncMode.full_refresh": "Full refresh",
"syncMode.incremental": "Incremental",

"connection.warningUpdateSchema": "WARNING! Updating the schema will delete all the data for this connection in your destination and start syncing from scratch.",
"connection.updateSchemaWithoutReset": "Save without reset",
"connection.title": "Connection",
"connection.description": "<b>Connections</b> link Sources to Destinations.",
"connection.fromTo": "{source} → {destination}",
Expand All @@ -326,7 +324,6 @@
"connection.testsFailed": "The connection tests failed.",
"connection.destinationCheckSettings": "Check destination settings",
"connection.sourceCheckSettings": "Check source settings",
"connection.saveAndReset": "Save changes & reset data",
"connection.destinationTestAgain": "Test destination connection again",
"connection.sourceTestAgain": "Test source connection again",
"connection.resetData": "Reset your data",
Expand Down
21 changes: 12 additions & 9 deletions airbyte-webapp/src/packages/cloud/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { I18nProvider } from "core/i18n";
import { ConfirmationModalService } from "hooks/services/ConfirmationModal";
import { FeatureService } from "hooks/services/Feature";
import { FormChangeTrackerService } from "hooks/services/FormChangeTracker";
import { ModalServiceProvider } from "hooks/services/Modal";
import NotificationServiceProvider from "hooks/services/Notification";
import en from "locales/en.json";
import { Routing } from "packages/cloud/cloudRoutes";
Expand Down Expand Up @@ -37,15 +38,17 @@ const Services: React.FC = ({ children }) => (
<ApiErrorBoundary>
<NotificationServiceProvider>
<ConfirmationModalService>
<FormChangeTrackerService>
<FeatureService>
<AppServicesProvider>
<AuthenticationProvider>
<IntercomProvider>{children}</IntercomProvider>
</AuthenticationProvider>
</AppServicesProvider>
</FeatureService>
</FormChangeTrackerService>
<ModalServiceProvider>
<FormChangeTrackerService>
<FeatureService>
<AppServicesProvider>
<AuthenticationProvider>
<IntercomProvider>{children}</IntercomProvider>
</AuthenticationProvider>
</AppServicesProvider>
</FeatureService>
</FormChangeTrackerService>
</ModalServiceProvider>
</ConfirmationModalService>
</NotificationServiceProvider>
</ApiErrorBoundary>
Expand Down
Loading