Skip to content

Commit

Permalink
fix: ui updates
Browse files Browse the repository at this point in the history
  • Loading branch information
saravmajestic committed Dec 26, 2024
1 parent c863373 commit 0569ddb
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 79 deletions.
6 changes: 6 additions & 0 deletions webview_panels/.storybook/preview-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
/> -->

<style>
body {
--vscode-panel-background: rgb(248, 248, 248);
}
body.vscode-dark {
--vscode-panel-background: rgb(30, 30, 30);
}
perspective-viewer {
height: 100vh !important;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import CoachAiIfModified from "./components/docGenerator/CoachAiIfModified";
import Citations from "./components/docGenerator/Citations";
import { Citation } from "@lib";
import SearchColumnsInput from "./components/search/SearchColumnsInput";
import BulkGenerateButton from "./components/docGenerator/BulkGenerateButton";

const DocumentationEditor = (): JSX.Element => {
const {
Expand Down Expand Up @@ -112,10 +113,11 @@ const DocumentationEditor = (): JSX.Element => {
return (
<div className={`${classes.documentationWrapper} ${classes.limitWidth}`}>
<Stack className="mb-2 justify-content-between">
<SearchColumnsInput />
<Stack>
<SearchColumnsInput />
<BulkGenerateButton />
<CommonActionButtons />
</Stack>
<CommonActionButtons />
</Stack>
<div className={classes.docGenerator}>
<Stack className={classes.bodyWrap}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import { updateColumnsInCurrentDocsData } from "@modules/documentationEditor/sta
import { DBTDocumentationColumn } from "@modules/documentationEditor/state/types";
import useDocumentationContext from "@modules/documentationEditor/state/useDocumentationContext";
import { panelLogger } from "@modules/logger";
import { Button, DropdownButton, List, Popover, PopoverBody } from "@uicore";
import { Button, DropdownButton, List, PopoverWithButton } from "@uicore";
import { useRef, useState } from "react";
import classes from "../../styles.module.scss";
import { mergeCurrentAndIncomingDocumentationColumns } from "@modules/documentationEditor/utils";
import DocGenSelectedColumns from "./DocGenSelectedColumns";
import { noop } from "antd/es/_util/warning";

enum SidePanelState {
DOCUMENTATION_SELECTED = "documentationSelected",
}

const BulkGenerateButton = (): JSX.Element => {
const [openPopover, setOpenPopover] = useState(false);
const [sidePanelState, setSidePanelState] = useState<
SidePanelState | undefined
>();
Expand All @@ -28,10 +28,6 @@ const BulkGenerateButton = (): JSX.Element => {
dispatch,
} = useDocumentationContext();

const onToggleClick = () => {
setOpenPopover((prev) => !prev);
};

const resetSidepanelState = () => {
setSidePanelState(undefined);
};
Expand Down Expand Up @@ -117,7 +113,6 @@ const BulkGenerateButton = (): JSX.Element => {
};

const onOptionSelect = async (value: string) => {
setOpenPopover(false);
const startTime = Date.now();
sendTelemetryEvent(value);

Expand Down Expand Up @@ -151,41 +146,50 @@ const BulkGenerateButton = (): JSX.Element => {
return (
<>
<div ref={ref}>
<DropdownButton onToggleClick={onToggleClick} onClick={onToggleClick}>
<ShinesIcon /> Bulk generate
</DropdownButton>
<Popover
isOpen={openPopover}
target={ref}
placement="bottom"
hideArrow
className={classes.popover}
<PopoverWithButton
width="auto"
button={
<DropdownButton onToggleClick={noop} onClick={noop}>
<ShinesIcon /> Bulk generate
</DropdownButton>
}
popoverProps={{
placement: "bottom",
hideArrow: true,
}}
>
<PopoverBody>
<List>
{Object.entries(options).map(([key, actions]) => (
<>
<li>{key}</li>
{actions.map((option) => (
<li key={option.label}>
<Button
color="link"
onClick={() => onOptionSelect(option.value)}
>
{option.label}
</Button>
</li>
{({ styles, close }) => (
<div className={classes.popover}>
<div className={styles.popoverActions}>
<List>
{Object.entries(options).map(([key, actions]) => (
<>
<li className={classes.sectionTitle}>{key}</li>
{actions.map((option) => (
<li key={option.label}>
<Button
color="secondary"
onClick={() => {
close();
void onOptionSelect(option.value);
}}
>
{option.label}
</Button>
</li>
))}
</>
))}
</>
))}
</List>
</PopoverBody>
</Popover>
</List>
</div>
</div>
)}
</PopoverWithButton>
</div>
{sidePanelState === SidePanelState.DOCUMENTATION_SELECTED ? (
<DocGenSelectedColumns
onClose={resetSidepanelState}
generateForColumns={(c) => bulkGenerateDocs(c, false)}
generateForColumns={bulkGenerateDocs}
/>
) : null}
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DocsIcon, SearchIcon } from "@assets/icons";
import { DBTDocumentationColumn } from "@modules/documentationEditor/state/types";
import useDocumentationContext from "@modules/documentationEditor/state/useDocumentationContext";
import {
Expand All @@ -7,19 +8,27 @@ import {
Input,
List,
ListGroupItem,
LoadingButton,
Stack,
Tooltip,
} from "@uicore";
import { ChangeEvent, useEffect, useMemo, useRef, useState } from "react";
import classes from "../../styles.module.scss";
import { panelLogger } from "@modules/logger";

interface Props {
onClose: () => void;
generateForColumns: (columns: DBTDocumentationColumn[]) => void;
generateForColumns: (
columns: DBTDocumentationColumn[],
isAll: boolean,
) => Promise<DBTDocumentationColumn[]>;
}
const DocGenSelectedColumns = ({
onClose,
generateForColumns,
}: Props): JSX.Element => {
const drawerRef = useRef<DrawerRef | null>(null);
const [isGenerating, setIsGenerating] = useState(false);
const [searchQuery, setsearchQuery] = useState("");
const [selectedColumns, setSelectedColumns] = useState<string[]>([]);
const {
Expand All @@ -38,12 +47,21 @@ const DocGenSelectedColumns = ({
);
}, [searchQuery, currentDocsData?.columns]);

const handleGenerate = () => {
const handleGenerate = async () => {
const columns = currentDocsData?.columns.filter((column) =>
selectedColumns.includes(column.name),
);
if (!columns) return;
generateForColumns(columns);
setIsGenerating(true);
try {
await generateForColumns(columns, false);
drawerRef.current?.close();
onClose();
} catch (error) {
panelLogger.error("error while generating documentation", error);
} finally {
setIsGenerating(false);
}
};

const handleFilterChange = (e: ChangeEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -74,23 +92,42 @@ const DocGenSelectedColumns = ({
}
};

const handleSelectedColumns = (e: ChangeEvent<HTMLInputElement>) => {
const { value } = e.target;
if (selectedColumns.includes(value)) {
setSelectedColumns(selectedColumns.filter((column) => column !== value));
} else {
setSelectedColumns([...selectedColumns, value]);
}
};

return (
<Drawer ref={drawerRef} onClose={onClose}>
<Stack direction="column" className="h-100">
<Stack className="justify-content-between">
Generate documentation{" "}
<Button onClick={handleGenerate}>Generate</Button>
<LoadingButton
disabled={selectedColumns.length === 0}
loading={isGenerating}
color="primary"
onClick={handleGenerate}
>
Generate{" "}
{selectedColumns.length ? `(${selectedColumns.length})` : ""}
</LoadingButton>
</Stack>
<div>
<Stack className={classes.search}>
<SearchIcon />
<Input placeholder="Search columns" onChange={handleFilterChange} />
</div>
</Stack>
<div></div>
<Stack>
<Button onClick={() => handleSelectColumns("all")}>Select All</Button>
<Button
color="success"
onClick={() => handleSelectColumns("documented")}
>
Documented
<DocsIcon className={classes.docsIconInBtn} /> Documented
</Button>
<Button
color="warning"
Expand All @@ -100,18 +137,27 @@ const DocGenSelectedColumns = ({
</Button>
</Stack>
<Stack className="overflow-auto">
<List>
<List className="m-0 p-0">
{filteredColumns.map((column) => (
<ListGroupItem
key={`${column.name}-${column.type}`}
tag={"label"}
className="mb-1"
>
<Input
type="checkbox"
value={column.name}
checked={selectedColumns.includes(column.name)}
/>
{column.name}
<Stack>
<Input
type="checkbox"
value={column.name}
checked={selectedColumns.includes(column.name)}
onChange={handleSelectedColumns}
/>
{column.name}
{column.description ? (
<Tooltip title="Documented" placement="top">
<DocsIcon className={classes.docsIcon} />
</Tooltip>
) : null}
</Stack>
</ListGroupItem>
))}
</List>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import useDocumentationContext from "@modules/documentationEditor/state/useDocum
import { Alert, Stack } from "@uicore";
import DocGeneratorColumn from "./DocGeneratorColumn";
import classes from "../../styles.module.scss";
import BulkGenerateButton from "./BulkGenerateButton";
import SyncWithDatabase from "./SyncWithDatabase";
import { useMemo } from "react";
import { DBTModelTest } from "@modules/documentationEditor/state/types";
Expand Down Expand Up @@ -49,7 +48,6 @@ const DocGeneratorColumnsList = (): JSX.Element => {
<h3>Columns</h3>
<SyncWithDatabase />
</Stack>
<BulkGenerateButton />
</Stack>
<Alert color="warning">
Note: If you don’t want to override existing documentation, please
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { SearchIcon } from "@assets/icons";
import { setSearchQuery } from "@modules/documentationEditor/state/documentationSlice";
import useDocumentationContext from "@modules/documentationEditor/state/useDocumentationContext";
import { Input } from "@uicore";
import { Input, Stack } from "@uicore";
import styles from "../../styles.module.scss";

const SearchColumnsInput = (): JSX.Element => {
const { dispatch } = useDocumentationContext();
Expand All @@ -9,7 +11,18 @@ const SearchColumnsInput = (): JSX.Element => {
dispatch(setSearchQuery(e.target.value));
};

return <Input onChange={handleChange} placeholder="Search by column name" />;
return (
<Stack className={styles.search}>
<SearchIcon />
<Input
aria-label="Search by column name"
role="search"
type="search"
onChange={handleChange}
placeholder="Search by column name"
/>
</Stack>
);
};

export default SearchColumnsInput;
Loading

0 comments on commit 0569ddb

Please sign in to comment.