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

feat(web): support toggle panels in function page #623

Merged
merged 2 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions web/src/components/Editor/JsonEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ function JsonEditor(props: {
onChange(editorRef.current?.getValue());
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [onChange]);

useEffect(() => {
if (monacoEl && editorRef.current && value !== editorRef.current?.getValue()) {
Expand Down
40 changes: 34 additions & 6 deletions web/src/components/Grid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,43 @@ function Grid() {
return <div>Grid</div>;
}

function Row(props: { className?: string; children: React.ReactNode }) {
const { className } = props;
return <div className={clsx(className, "flex flex-1 space-x-2 w-full")}>{props.children}</div>;
function Row(props: {
className?: string;
style?: React.CSSProperties;
children: React.ReactNode;
}) {
const { className, style } = props;
return (
<div
className={clsx(
"flex space-x-2 w-full",
style?.height ? "flex-none" : "flex-grow",
className,
)}
style={style}
>
{props.children}
</div>
);
}

function Col(props: { className?: string; children: React.ReactNode }) {
const { className } = props;
function Col(props: {
className?: string;
style?: React.CSSProperties;
children: React.ReactNode;
}) {
const { className, style } = props;
return (
<div className={clsx(className, "flex flex-col space-y-2 flex-1 h-full")}>{props.children}</div>
<div
className={clsx(
"flex flex-col space-y-2 h-full",
style?.width ? "flex-none" : "flex-grow",
className,
)}
style={style}
>
{props.children}
</div>
);
}

Expand Down
5 changes: 4 additions & 1 deletion web/src/components/Panel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ const Panel = (props: {
}) => {
const { className, style = {} } = props;
return (
<div style={style} className={clsx("bg-white rounded px-4 flex flex-col h-full", className)}>
<div
style={style}
className={clsx("bg-white rounded px-4 flex flex-col h-full w-full", className)}
>
{props.children}
</div>
);
Expand Down
26 changes: 26 additions & 0 deletions web/src/pages/app/database/BottomPanel/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from "react";
import { Button, HStack } from "@chakra-ui/react";

import Panel from "@/components/Panel";

import useCustomSettingStore from "@/pages/customSetting";

function BottomPanel() {
const store = useCustomSettingStore();

return (
<Panel className=" justify-between !flex-row">
<HStack spacing={2}>
<Button
size="xs"
variant="plain"
onClick={() => store.togglePanel("collectionPage", "SiderBar")}
>
集合列表
</Button>
</HStack>
</Panel>
);
}

export default BottomPanel;
6 changes: 2 additions & 4 deletions web/src/pages/app/database/CollectionDataList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { useTranslation } from "react-i18next";
import { AddIcon } from "@chakra-ui/icons";
import { Button } from "@chakra-ui/react";

import { Col } from "@/components/Grid";

import CreateCollectionModal from "../mods/CreateCollectionModal";
import useDBMStore from "../store";

Expand All @@ -15,7 +13,7 @@ export default function CollectionDataList() {
const { t } = useTranslation();
const store = useDBMStore((state) => state);
return (
<Col>
<>
{store.currentDB === undefined ? (
<div className="h-full flex items-center justify-center">
<CreateCollectionModal>
Expand Down Expand Up @@ -58,6 +56,6 @@ export default function CollectionDataList() {
</TabPanel>
</TabPanels>
</Tabs > */}
</Col>
</>
);
}
117 changes: 57 additions & 60 deletions web/src/pages/app/database/CollectionListPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import clsx from "clsx";

// import CopyText from "@/components/CopyText";
import FileTypeIcon, { FileType } from "@/components/FileTypeIcon";
import { Col } from "@/components/Grid";
import IconWrap from "@/components/IconWrap";
import Panel from "@/components/Panel";
import SectionList from "@/components/SectionList";
Expand All @@ -18,7 +17,7 @@ import useDBMStore from "../store";

import MoreButton from "./MoreButton";

export default function CollectionListPanel(props: { isHidden?: boolean }) {
export default function CollectionListPanel() {
const store = useDBMStore((store) => store);
const { t } = useTranslation();
const collectionListQuery = useCollectionListQuery({
Expand All @@ -34,65 +33,63 @@ export default function CollectionListPanel(props: { isHidden?: boolean }) {
const [search, setSearch] = useState("");

return (
<Col className=" max-w-[300px]">
<Panel>
<Panel.Header
title="集合列表"
actions={[
<CreateCollectionModal key={"create_database"}>
<IconWrap tooltip={t("CollectionPanel.CollectionAdd").toString()} size={20}>
<AddIcon fontSize={10} />
</IconWrap>
</CreateCollectionModal>,
]}
/>
<div className="flex items-center mb-3 w-full">
<InputGroup>
<InputLeftElement
height={"8"}
pointerEvents="none"
children={<Search2Icon color="gray.300" />}
/>
<Input
rounded={"full"}
placeholder="输入集合ID搜索"
size="sm"
bg={"gray.100"}
onChange={(e) => setSearch(e.target.value)}
/>
</InputGroup>
</div>
<Panel>
<Panel.Header
title="集合列表"
actions={[
<CreateCollectionModal key={"create_database"}>
<IconWrap tooltip={t("CollectionPanel.CollectionAdd").toString()} size={20}>
<AddIcon fontSize={10} />
</IconWrap>
</CreateCollectionModal>,
]}
/>
<div className="flex items-center mb-3 w-full">
<InputGroup>
<InputLeftElement
height={"8"}
pointerEvents="none"
children={<Search2Icon color="gray.300" />}
/>
<Input
rounded={"full"}
placeholder="输入集合ID搜索"
size="sm"
bg={"gray.100"}
onChange={(e) => setSearch(e.target.value)}
/>
</InputGroup>
</div>

<SectionList>
{(collectionListQuery?.data?.data || [])
.filter((db: any) => db.name.indexOf(search) >= 0)
.map((db: any) => {
return (
<SectionList.Item
isActive={db.name === store.currentDB?.name}
key={db.name}
onClick={() => {
store.setCurrentDB(db);
}}
>
<div className="w-full flex justify-between group">
<div className="leading-loose">
<FileTypeIcon type={FileType.db} />
<span className="ml-2 text-base">{db.name}</span>
</div>
<div
className={clsx("flex group-hover:inline ", {
hidden: db.name !== store.currentDB?.name,
})}
>
<MoreButton data={db} />
</div>
<SectionList>
{(collectionListQuery?.data?.data || [])
.filter((db: any) => db.name.indexOf(search) >= 0)
.map((db: any) => {
return (
<SectionList.Item
isActive={db.name === store.currentDB?.name}
key={db.name}
onClick={() => {
store.setCurrentDB(db);
}}
>
<div className="w-full flex justify-between group">
<div className="leading-loose">
<FileTypeIcon type={FileType.db} />
<span className="ml-2 text-base">{db.name}</span>
</div>
</SectionList.Item>
);
})}
</SectionList>
</Panel>
</Col>
<div
className={clsx("flex group-hover:inline ", {
hidden: db.name !== store.currentDB?.name,
})}
>
<MoreButton data={db} />
</div>
</div>
</SectionList.Item>
);
})}
</SectionList>
</Panel>
);
}
36 changes: 14 additions & 22 deletions web/src/pages/app/database/index.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
/****************************
* cloud functions database page
***************************/
import { useState } from "react";
import { Button } from "@chakra-ui/react";

import Content from "@/components/Content";
import { Row } from "@/components/Grid";
import Panel from "@/components/Panel";
import { Col, Row } from "@/components/Grid";

import BottomPanel from "./BottomPanel";
import CollectionDataList from "./CollectionDataList";
import CollectionListPanel from "./CollectionListPanel";

import useCustomSettingStore from "@/pages/customSetting";

function DatabasePage() {
const [hideList, setHideList] = useState<boolean>(false);
const collectionPageConfig = useCustomSettingStore((store) => store.layoutInfo.collectionPage);
return (
<Content>
<Row className="flex-grow">
<CollectionListPanel isHidden={hideList} />
<Row>
<Col {...collectionPageConfig.SiderBar}>
<CollectionListPanel />
</Col>

<CollectionDataList />
<Col>
<CollectionDataList />
</Col>
</Row>
<Row className="!flex-none">
<Panel className="w-full h-[40px]">
<Panel.Header>
<Button
size="xs"
variant="plain"
onClick={() => {
setHideList((pre) => !pre);
}}
>
集合列表
</Button>
</Panel.Header>
</Panel>
<Row {...collectionPageConfig.Bottom}>
<BottomPanel />
</Row>
</Content>
);
Expand Down
Loading