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

🪟 Display connection state in connection setting page #13394

Merged
merged 20 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
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
2 changes: 1 addition & 1 deletion airbyte-webapp/nginx/default.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ server {
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;

add_header Content-Security-Policy "script-src * 'unsafe-inline';";
add_header Content-Security-Policy "script-src * 'unsafe-inline'; worker-src self blob:;";

location / {
root /usr/share/nginx/html;
Expand Down
2,208 changes: 1,146 additions & 1,062 deletions airbyte-webapp/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions airbyte-webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@fortawesome/free-solid-svg-icons": "^6.1.1",
"@fortawesome/react-fontawesome": "^0.1.18",
"@fullstory/browser": "^1.5.1",
"@monaco-editor/react": "^4.4.5",
"@sentry/react": "^6.19.6",
"@sentry/tracing": "^6.19.6",
"classnames": "^2.3.1",
Expand Down
26 changes: 26 additions & 0 deletions airbyte-webapp/src/components/CodeEditor/CodeEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Editor from "@monaco-editor/react";
import React from "react";

interface CodeEditorProps {
height?: string;
code: string;
language?: string;
}

export const CodeEditor: React.FC<CodeEditorProps> = ({ code, height, language }) => {
return (
<Editor
height={height ?? "200px"}
language={language}
value={code}
options={{
lineNumbersMinChars: 2,
readOnly: true,
matchBrackets: "always",
minimap: {
enabled: false,
},
}}
/>
);
};
1 change: 1 addition & 0 deletions airbyte-webapp/src/components/CodeEditor/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./CodeEditor";
3 changes: 2 additions & 1 deletion airbyte-webapp/src/components/base/Card/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import styled from "styled-components";

export const Card = styled.div<{ full?: boolean }>`
export const Card = styled.div<{ full?: boolean; $withPadding?: boolean }>`
width: ${({ full }) => (full ? "100%" : "auto")};
background: ${({ theme }) => theme.whiteColor};
border-radius: 10px;
box-shadow: 0 2px 4px ${({ theme }) => theme.cardShadowColor};
padding: ${({ $withPadding }) => ($withPadding ? "20px" : undefined)};
//border: 1px solid ${({ theme }) => theme.greyColor20};
`;
1 change: 1 addition & 0 deletions airbyte-webapp/src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from "./base";

export * from "./ArrayOfObjectsEditor";
export * from "./ContentCard";
export * from "./CodeEditor";
export * from "./DefaultLogoCatalog";
export * from "./ImageBlock";
export * from "./Label";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deleteConnection, resetConnection, syncConnection } from "../../request/AirbyteClient";
import { deleteConnection, resetConnection, syncConnection, getState } from "../../request/AirbyteClient";
import { AirbyteRequestService } from "../../request/AirbyteRequestService";

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

public getState(connectionId: string) {
return getState({ connectionId }, this.requestOptions);
}
}
8 changes: 8 additions & 0 deletions airbyte-webapp/src/hooks/services/useConnectionHook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const connectionsKeys = {
lists: () => [...connectionsKeys.all, "list"] as const,
list: (filters: string) => [...connectionsKeys.lists(), { filters }] as const,
detail: (connectionId: string) => [...connectionsKeys.all, "details", connectionId] as const,
getState: (connectionId: string) => [...connectionsKeys.all, "getState", connectionId] as const,
};

export interface ValuesProps {
Expand Down Expand Up @@ -215,11 +216,18 @@ const invalidateConnectionsList = async (queryClient: QueryClient) => {
await queryClient.invalidateQueries(connectionsKeys.lists());
};

const useGetConnectionState = (connectionId: string) => {
const service = useConnectionService();

return useSuspenseQuery(connectionsKeys.getState(connectionId), () => service.getState(connectionId));
};

export {
useConnectionList,
useGetConnection,
useUpdateConnection,
useCreateConnection,
useDeleteConnection,
invalidateConnectionsList,
useGetConnectionState,
};
2 changes: 2 additions & 0 deletions airbyte-webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@
"tables.sourceDeleteModalText": "This can not be un-done without a full re-sync. Note that:\n - All connections with this source will be deleted, including their past logs and configurations.\n - No existing data in the destination will be altered",
"tables.destinationDeleteModalText": "This can not be un-done. Note that:\n - All connections with this destination will be deleted, including their past logs and configurations.\n - No existing data in the destination will be altered.",
"tables.connectionDeleteModalText": "This can not be un-done without a full re-sync. Note that:\n - All past logs and configurations will be deleted\n - Updates of new data will stop\n - No existing data in the destination will be altered",
"tables.connectionState.title": "Connection State",
"tables.connectionState.noConnectionState": "This connection doesn't have a state (yet).",
evantahler marked this conversation as resolved.
Show resolved Hide resolved

"admin.destinations": "Destinations",
"admin.sources": "Sources",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import DeleteBlock from "components/DeleteBlock";

import { useDeleteConnection } from "hooks/services/useConnectionHook";

import { StateBlock } from "./StateBlock";

interface IProps {
connectionId: string;
}
Expand All @@ -22,6 +24,7 @@ const SettingsView: React.FC<IProps> = ({ connectionId }) => {

return (
<Content>
<StateBlock connectionId={connectionId} />
<DeleteBlock type="connection" onDelete={onDelete} />
</Content>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { useMemo } from "react";
import { FormattedMessage, useIntl } from "react-intl";

import { H5, Card, CodeEditor } from "components";

import { useGetConnectionState } from "hooks/services/useConnectionHook";

interface StateBlockProps {
connectionId: string;
}

export const StateBlock: React.FC<StateBlockProps> = ({ connectionId }) => {
const { formatMessage } = useIntl();
const state = useGetConnectionState(connectionId);

const stateString = useMemo(() => {
return state?.state
? JSON.stringify(state.state, null, 2)
: formatMessage({ id: "tables.connectionState.noConnectionState" });
}, [formatMessage, state.state]);

return (
<Card $withPadding>
<H5 bold>
<FormattedMessage id={"tables.connectionState.title"} />
</H5>
<CodeEditor code={stateString} language={state?.state ? "json" : undefined} />
</Card>
);
};
2 changes: 1 addition & 1 deletion airbyte-webapp/src/setupProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = (app) => {
// Set the CSP header in development to detect potential breakages.
// This should always match the header in airbyte-webapp/nginx/default.conf.template
app.use((req, resp, next) => {
resp.header("Content-Security-Policy", "script-src * 'unsafe-inline';");
resp.header("Content-Security-Policy", "script-src * 'unsafe-inline'; worker-src self blob:;");
next();
});
// Serve the doc markdowns and assets that are also bundled into the docker image
Expand Down