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

[Connector Builder] Add ability to click on logs to expand them #19195

Merged
merged 12 commits into from
Nov 10, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
align-items: center;
gap: variables.$spacing-md;
padding: variables.$spacing-sm variables.$spacing-md;
border: none;
cursor: pointer;
flex: 0 0 25px;
}

.numLogsDisplay {
Expand Down
13 changes: 9 additions & 4 deletions airbyte-webapp/src/components/StreamTestingPanel/LogsDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
import { useMemo } from "react";
import { FormattedMessage } from "react-intl";

import { Text } from "components/ui/Text";

import { StreamReadLogsItem } from "core/request/ConnectorBuilderClient";

import styles from "./LogsDisplay.module.scss";
import { formatJson } from "./utils";

interface LogsDisplayProps {
logs: StreamReadLogsItem[];
onTitleClick: () => void;
}

export const LogsDisplay: React.FC<LogsDisplayProps> = ({ logs }) => {
export const LogsDisplay: React.FC<LogsDisplayProps> = ({ logs, onTitleClick }) => {
const formattedLogs = useMemo(() => formatJson(logs), [logs]);

return (
<div className={styles.container}>
<div className={styles.header}>
<button className={styles.header} onClick={onTitleClick}>
<Text size="sm" bold>
<FormattedMessage id="connectorBuilder.connectorLogs" />
</Text>
<Text className={styles.numLogsDisplay} size="xs" bold>
{logs.length}
</Text>
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have a NumberBadge component that should ideally be used here. (I know not directly relevant to this PR, but I just noticed it). We can extend that for more colors if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was not aware of that, thanks!

</div>
</button>
<div className={styles.logsDisplay}>
<pre>{JSON.stringify(logs, null, 2)}</pre>
<pre>{formattedLogs}</pre>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,16 @@
max-height: 100%;
overflow-y: auto;
}

// add a fade at the bottom of the tabPanel
.tabPanel::after {
content: "";
position: absolute;
z-index: 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We usually tend to maintain all z-indexes (since they are a global numbering system across all of the webapp) in the _z-indices.scss utility. Given that the purpose here is only to lift it slightly above the content, i.e. doing a "+1" I feel we can keep this in place here.

bottom: 0;
left: 0;
pointer-events: none;
background-image: linear-gradient(to bottom, colors.$transparentColor, colors.$white 100%);
width: 100%;
height: 2vh;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a specific reason we're having this height in dependance to the viewport height, instead of just a static (e.g. rem or px) height?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking that if the window height is small, the blur should be smaller so that more of the content is visible. But looking back on that decision, I think it makes more sense to just always keep the blur a small pixel value, since it doesn't really ever need to be large

}
28 changes: 17 additions & 11 deletions airbyte-webapp/src/components/StreamTestingPanel/PageDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { Tab } from "@headlessui/react";
import classNames from "classnames";
import { useMemo } from "react";
import { useIntl } from "react-intl";

import { Text } from "components/ui/Text";

import {
HttpRequest,
HttpResponse,
StreamReadSlicesItemPagesItem,
StreamReadSlicesItemPagesItemRecordsItem,
} from "core/request/ConnectorBuilderClient";
import { StreamReadSlicesItemPagesItem } from "core/request/ConnectorBuilderClient";

import styles from "./PageDisplay.module.scss";
import { formatJson } from "./utils";

interface PageDisplayProps {
page: StreamReadSlicesItemPagesItem;
Expand All @@ -21,26 +18,35 @@ interface PageDisplayProps {
interface TabData {
title: string;
key: string;
content: StreamReadSlicesItemPagesItemRecordsItem[] | HttpRequest | HttpResponse;
content: string;
}

export const PageDisplay: React.FC<PageDisplayProps> = ({ page, className }) => {
const { formatMessage } = useIntl();

const formattedRecords = useMemo(() => formatJson(page.records), [page.records]);
const formattedRequest = useMemo(() => formatJson(page.request), [page.request]);
const formattedResponse = useMemo(() => formatJson(page.response), [page.response]);

const tabs: TabData[] = [
{
title: `${formatMessage({ id: "connectorBuilder.recordsTab" })} (${page.records.length})`,
key: "records",
content: page.records,
content: formattedRecords,
},
];
if (page.request) {
tabs.push({ title: formatMessage({ id: "connectorBuilder.requestTab" }), key: "request", content: page.request });
tabs.push({
title: formatMessage({ id: "connectorBuilder.requestTab" }),
key: "request",
content: formattedRequest,
});
}
if (page.response) {
tabs.push({
title: formatMessage({ id: "connectorBuilder.responseTab" }),
key: "response",
content: page.response,
content: formattedResponse,
});
}

Expand All @@ -59,7 +65,7 @@ export const PageDisplay: React.FC<PageDisplayProps> = ({ page, className }) =>
<Tab.Panels className={styles.tabPanelContainer}>
{tabs.map((tab) => (
<Tab.Panel className={styles.tabPanel} key={tab.key}>
<pre>{JSON.stringify(tab.content, null, 2)}</pre>
<pre>{tab.content}</pre>
</Tab.Panel>
))}
</Tab.Panels>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
display: flex;
flex-direction: column;
gap: variables.$spacing-sm;
position: relative;
}

.paginator {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useState } from "react";
import { useIntl } from "react-intl";

import { ResizablePanels } from "components/ui/ResizablePanels";
Expand All @@ -19,6 +20,12 @@ export const StreamTestingPanel: React.FC<unknown> = () => {
stream: selectedStream.name,
config: configJson,
});
const [logsFlex, setLogsFlex] = useState(0);

const handleLogsTitleClick = () => {
// expand to 50% if it is currently less than 50%, otherwise minimize it
setLogsFlex((prevFlex) => (prevFlex < 0.5 ? 0.5 : 0));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor nitpick: my personal feeling would be that we should always collapse it if it's somewhat open and open to 50% if it's completely closed. It feels a bit more aligned with what I personally would expect, but not having extremely strong feelings around that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that would make sense too! I was going back and forth between that approach and the one I implemented, so your comment has convinced me

};

return (
<div className={styles.container}>
Expand All @@ -39,9 +46,14 @@ export const StreamTestingPanel: React.FC<unknown> = () => {
}}
secondPanel={{
className: styles.logsContainer,
children: <LogsDisplay logs={streamReadData.logs} />,
children: <LogsDisplay logs={streamReadData.logs} onTitleClick={handleLogsTitleClick} />,
minWidth: 30,
flex: 0,
flex: logsFlex,
onStopResize: (newFlex) => {
if (newFlex) {
setLogsFlex(newFlex);
}
},
}}
hideSecondPanel={streamReadData.logs.length === 0}
/>
Expand Down
5 changes: 5 additions & 0 deletions airbyte-webapp/src/components/StreamTestingPanel/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Take in any, because that is what JSON.stringify() takes in
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function formatJson(json: any): string {
lmossman marked this conversation as resolved.
Show resolved Hide resolved
return JSON.stringify(json, null, 2);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface PanelProps {
className?: string;
flex?: number;
overlay?: Overlay;
onStopResize?: (newFlex: number | undefined) => void;
}

interface Overlay {
Expand Down Expand Up @@ -78,6 +79,11 @@ export const ResizablePanels: React.FC<ResizablePanelsProps> = ({
propagateDimensions
minSize={firstPanel.minWidth}
flex={firstPanel.flex}
onStopResize={(args) => {
if (firstPanel.onStopResize) {
firstPanel.onStopResize(args.component.props.flex);
}
lmossman marked this conversation as resolved.
Show resolved Hide resolved
}}
>
<PanelContainer className={firstPanel.className} overlay={firstPanel.overlay}>
{firstPanel.children}
Expand Down Expand Up @@ -107,6 +113,11 @@ export const ResizablePanels: React.FC<ResizablePanelsProps> = ({
propagateDimensions
minSize={secondPanel.minWidth}
flex={secondPanel.flex}
onStopResize={(args) => {
if (secondPanel.onStopResize) {
secondPanel.onStopResize(args.component.props.flex);
}
lmossman marked this conversation as resolved.
Show resolved Hide resolved
}}
>
<PanelContainer className={secondPanel.className} overlay={secondPanel.overlay}>
{secondPanel.children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const ConnectorBuilderPageInner: React.FC = () => {
firstPanel={{
children: <YamlEditor />,
className: styles.leftPanel,
minWidth: 400,
minWidth: 100,
}}
secondPanel={{
children: <StreamTestingPanel />,
Expand Down