Skip to content

Commit

Permalink
feat(web): add function editor theme, json editor, app model
Browse files Browse the repository at this point in the history
* feat: add function editor theme & component

* feat: add depnedence panel

* feat: add database json editor

* update: function page content

* refactor: page container

* feat: create app modal
  • Loading branch information
LeezQ authored Nov 28, 2022
1 parent 36dcf0b commit 8ffecbf
Show file tree
Hide file tree
Showing 46 changed files with 1,568 additions and 1,175 deletions.
27 changes: 27 additions & 0 deletions web/components/CopyText/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, { useEffect } from "react";
import { CopyIcon } from "@chakra-ui/icons";
import { useClipboard, useToast } from "@chakra-ui/react";

export default function CopyText(props: { text: string }) {
const { onCopy, setValue } = useClipboard("");
const toast = useToast();

const text = props.text;
useEffect(() => {
setValue(text);
}, [setValue, text]);

return (
<CopyIcon
onClick={() => {
onCopy();
toast({
position: "bottom",
title: "复制成功",
status: "success",
duration: 600,
});
}}
/>
);
}
48 changes: 48 additions & 0 deletions web/components/Editor/FunctionEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React, { useEffect } from "react";
import Editor, { useMonaco } from "@monaco-editor/react";

export default function FunctionEditor(props: { value: string }) {
const { value } = props;
const monaco = useMonaco();

monaco?.editor.defineTheme("lafEditorTheme", {
base: "vs",
inherit: true,
rules: [],
colors: {
"editorLineNumber.foreground": "#aaa",
"editorOverviewRuler.border": "#fff",
"editor.lineHighlightBackground": "#F5F6F8",
"scrollbarSlider.background": "#E8EAEC",
"editorIndentGuide.activeBackground": "#ddd",
"editorIndentGuide.background": "#eee",
},
});

useEffect(() => {
setTimeout(() => {
monaco?.editor.setTheme("lafEditorTheme");
}, 0);
}, [monaco]);

return (
<Editor
options={{
automaticLayout: true,
minimap: {
enabled: false,
},
scrollbar: {
verticalScrollbarSize: 6,
},
lineNumbersMinChars: 4,
fontSize: "14px",
// fontFamily: "monospace",
scrollBeyondLastLine: false,
}}
height="100%"
defaultLanguage="javascript"
value={value}
/>
);
}
57 changes: 57 additions & 0 deletions web/components/Editor/JsonEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React, { useEffect } from "react";
import Editor, { useMonaco } from "@monaco-editor/react";

export default function JsonEditor(props: { value: string | object }) {
const { value } = props;
const monaco = useMonaco();

monaco?.editor.defineTheme("lafJsonEditorTheme", {
base: "vs",
inherit: true,
rules: [],
colors: {
"editorLineNumber.foreground": "#aaa",
"editorOverviewRuler.border": "#fff",
"editor.lineHighlightBackground": "#F5F6F8",
"scrollbarSlider.background": "#E8EAEC",
"editorIndentGuide.activeBackground": "#ddd",
"editorIndentGuide.background": "#eee",
},
});

useEffect(() => {
setTimeout(() => {
monaco?.editor.setTheme("lafJsonEditorTheme");
}, 0);
}, [monaco]);

return (
<Editor
language="json"
value={JSON.stringify(value, null, 2)}
width={"600"}
height="100%"
options={{
lineNumber: false,
guides: {
indentation: false,
},
minimap: {
enabled: false,
},
lineHighlightBackground: "red",
scrollbar: {
verticalScrollbarSize: 0,
alwaysConsumeMouseWheel: false,
},
lineNumbers: "off",
lineNumbersMinChars: 0,
fontSize: 14,
scrollBeyondLastLine: false,
folding: false,
overviewRulerBorder: false,
tabSize: 2, // tab 缩进长度
}}
/>
);
}
2 changes: 1 addition & 1 deletion web/components/FileTypeIcon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default function FileTypeIcon(props: { type: string }) {
<Icon viewBox="0 0 20 20" fontSize={14} className="align-middle">
<path
d="M17.2039 3.6986L10.6238 0.308337C10.2279 0.105682 9.7895 0 9.34474 0C8.89998 0 8.46159 0.105682 8.06569 0.308337L1.48558 3.71914C1.03222 3.93986 0.651482 4.2857 0.388334 4.71583C0.125186 5.14595 -0.00938599 5.6424 0.000508938 6.14654V13.8314C0.00572326 14.3348 0.146366 14.8275 0.407673 15.2578C0.668979 15.6881 1.04131 16.0401 1.48558 16.2769L8.10739 19.6877C8.50118 19.8963 8.94083 20.0032 9.38644 19.9989C9.83149 19.9985 10.27 19.8918 10.6655 19.6877L17.2045 16.2974C17.6527 16.0654 18.0283 15.7144 18.2902 15.2831C18.5522 14.8517 18.6903 14.3566 18.6896 13.852V6.12537C18.6888 5.62341 18.5499 5.13134 18.2879 4.70315C18.0259 4.27496 17.6511 3.92718 17.2045 3.69798L17.2039 3.6986ZM8.72606 1.52017C8.91675 1.41815 9.12856 1.3619 9.34474 1.35585C9.5599 1.3497 9.77301 1.39922 9.96341 1.49963L16.5435 4.88989C16.6374 4.93704 16.7271 4.992 16.8118 5.05421L9.3242 8.9175L1.83662 5.11645C1.90958 5.03848 2.00227 4.98171 2.10487 4.95213L8.72606 1.52017ZM2.14595 15.0408C1.91488 14.9288 1.72044 14.7534 1.58532 14.5351C1.4502 14.3168 1.37998 14.0645 1.38288 13.8078V6.3899L4.147 7.80775V10.9105C4.14412 11.0381 4.17774 11.1638 4.2439 11.273C4.31005 11.3821 4.40599 11.4701 4.52044 11.5266L5.01837 11.7756C5.05918 11.8079 5.1111 11.8226 5.16277 11.8167C5.20932 11.8189 5.25582 11.8114 5.2993 11.7946C5.34277 11.7778 5.38227 11.7521 5.41525 11.7192C5.44823 11.6863 5.47398 11.6468 5.49084 11.6034C5.50771 11.5599 5.51532 11.5134 5.51319 11.4669V8.50796L8.62523 10.0901V18.4124L2.14595 15.0408ZM16.5441 15.0408L10.0257 18.431V10.0907L17.3078 6.39239V13.8103C17.3107 14.067 17.2405 14.3193 17.1054 14.5376C16.9703 14.7559 16.7758 14.9313 16.5448 15.0433L16.5441 15.0408Z"
fill="#553C9A"
fill="green"
/>
</Icon>
);
Expand Down
8 changes: 4 additions & 4 deletions web/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React from "react";
import { BiHelpCircle } from "react-icons/bi";
import { GiDragonfly } from "react-icons/gi";
import { GrGithub, GrLanguage } from "react-icons/gr";
import { Button, HStack, Tag, TagLabel } from "@chakra-ui/react";
import { HStack, Tag, TagLabel } from "@chakra-ui/react";
import { useRouter } from "next/router";

import { SmallNavHeight } from "@/constants/index";
Expand All @@ -22,14 +22,14 @@ export default function Header(props: { size: "sm" | "lg" }) {
>
<div className="flex items-center">
<div
className=" rounded-xl bg-black p-1 mr-4"
className="rounded-full bg-black p-1 mr-5"
onClick={() => {
router.push("/");
}}
>
<GiDragonfly color="white" />
<GiDragonfly color="white" fontSize={22} />
</div>
<span className="mr-4">Allecne</span>
<span className="mr-4 font-bold text-lg">Allence</span>
<Tag size="sm" borderRadius="full" variant="solid" colorScheme="green">
<TagLabel>Free</TagLabel>
</Tag>
Expand Down
10 changes: 8 additions & 2 deletions web/components/Panel/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ import clsx from "clsx";

import styles from "./index.module.scss";

export default function PanelHeader(props: { children: React.ReactNode }) {
export default function PanelHeader(props: { children: React.ReactNode; className?: string }) {
return (
<div className={clsx(styles.sectionHeader, "flex items-center justify-between border-b")}>
<div
className={clsx(
styles.sectionHeader,
props.className,
"flex items-center justify-between border-b",
)}
>
{props.children}
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion web/components/Panel/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
padding: 0 4px;
padding-right: 8px;
justify-content: space-between;
border-bottom: 1px solid #eaeaea;
border-bottom: 1px solid #d8dee4;

h4 {
font-weight: bold;
Expand Down
2 changes: 1 addition & 1 deletion web/components/Panel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function Panel(props: {
const { title, actions } = props;
return (
<div>
<div className={styles.sectionHeader + " flex justify-between"}>
<div className={styles.sectionHeader + " flex justify-between bg-white"}>
<h4>
<ChevronDownIcon fontSize={16} />
{title}
Expand Down
7 changes: 3 additions & 4 deletions web/components/SectionList/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
li {
cursor: pointer;
display: flex;
height: 30px;
line-height: 30px;
height: 32px;
align-items: center;
justify-content: space-between;
padding: 4px 16px;
padding: 2px 16px;

span {
vertical-align: middle;
}

&:hover,
&.active {
background-color: #f2f3f8;
background-color: var(--chakra-colors-gray-100);
color: #000 !important;
}

Expand Down
11 changes: 9 additions & 2 deletions web/components/SectionList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react";
import clsx from "clsx";

import styles from "./index.module.scss";

Expand All @@ -13,12 +14,18 @@ function SectionList(props: { children: React.ReactNode; style?: React.CSSProper
function Item(props: {
children: React.ReactNode;
isActive: boolean;
className?: string;
key: string;
onClick: () => void;
}) {
const { children, isActive, onClick } = props;
const { children, isActive, onClick, className } = props;
return (
<li className={isActive ? styles.active : ""} onClick={onClick}>
<li
className={clsx(className, {
[styles.active]: isActive,
})}
onClick={onClick}
>
{children}
</li>
);
Expand Down
2 changes: 1 addition & 1 deletion web/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const SiderBarWidth = 60;
export const SmallNavHeight = 32;
export const SmallNavHeight = 42;

export const Pages = {
function: "function",
Expand Down
29 changes: 29 additions & 0 deletions web/hooks/useHotKey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useCallback, useEffect } from "react";

function useHotKey(keyMap: string, trigger: () => void) {
const handleKeyDown = useCallback(
(event: any) => {
if (event.key === keyMap && (event.ctrlKey || event.metaKey)) {
event.preventDefault();

// remove test log when api called
trigger();
}
},
[keyMap, trigger],
);

useEffect(() => {
// attach the event listener
document.addEventListener("keydown", handleKeyDown);

// remove the event listener
return () => {
document.removeEventListener("keydown", handleKeyDown);
};
}, [handleKeyDown]);

return "⌘" + keyMap;
}

export default useHotKey;
1 change: 0 additions & 1 deletion web/pages/api/dbm_entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export default async function handler(req: NextApiRequest, resp: NextApiResponse
query: { name },
method,
} = req;
console.log(123, name);

switch (method) {
case "GET":
Expand Down
14 changes: 8 additions & 6 deletions web/pages/app/[app_id]/database/CollectionDataList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { Tab, TabList, TabPanel, TabPanels, Tabs } from "@chakra-ui/react";
import { calc, Tab, TabList, TabPanel, TabPanels, Tabs } from "@chakra-ui/react";

import RightPanel from "../../mods/RightPanel";

import ColPannel from "./mods/ColPannel";
import DataPannel from "./mods/DataPannel";
import IndexPannel from "./mods/IndexPannel";

export default function CollectionDataList() {
return (
<div className="flex-1 ">
<Tabs>
<RightPanel>
<Tabs className="h-full">
<TabList>
<Tab>数据管理</Tab>
<Tab>索引管理</Tab>
<Tab>集合结构</Tab>
</TabList>
<TabPanels>
<TabPanel>
<TabPanels className="h-full">
<TabPanel className="overflow-hidden relative" style={{ height: "calc(100% - 55px)" }}>
<DataPannel />
</TabPanel>
<TabPanel>
Expand All @@ -25,6 +27,6 @@ export default function CollectionDataList() {
</TabPanel>
</TabPanels>
</Tabs>
</div>
</RightPanel>
);
}
Loading

0 comments on commit 8ffecbf

Please sign in to comment.