Skip to content

Commit

Permalink
调整JsonForm;滚动条
Browse files Browse the repository at this point in the history
  • Loading branch information
cnwhy committed Jun 25, 2024
1 parent 2e90a63 commit 1d3d620
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 136 deletions.
13 changes: 0 additions & 13 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,6 @@ body {
}
}

.ant-space-item > .ant-tag {
margin-inline-end: inherit;
}

.ant-tag.editor-json {
cursor: pointer;
}

.antd-cord-boxShadow {
box-shadow: 0 1px 2px -2px #00000029,0 3px 6px #0000001f,0 5px 12px 4px #00000017;
border-color: transparent;
}

.home-form {
width: 380px;
max-width: 100%;
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/Manage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ const Manage = () => {
overflow: "auto",
}}
>
<Row gutter={[16, 16]} style={{ overflow: "hidden" }}>
<Row gutter={[16, 16]}>
{/* <Col {...colSpan} xxl={16}> */}
<ServiceCard colSpan={colSpan}></ServiceCard>
{/* </Col> */}
Expand Down
34 changes: 24 additions & 10 deletions src/components/Forms/AddButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,32 @@ const AddButton: React.FC<Props> = (props) => {
const { comm } = useContext(CardCtx);
const templates = UseTemplates({ name: keyName! });

const _props = {
title: t("title.add", { name: title }),
templates: templates,
onFinish: async (values: any) => {
const { value } = values;
const json = jsonParse(value);
await comm!.addValue(json);
return true;
},
};

// return (
// <JsonForm
// trigger={<Button icon={<PlusOutlined />} size="small" />}
// {..._props}
// ></JsonForm>
// );

return (
<JsonForm
title={t("title.add", { name: title })}
templates={templates}
trigger={<Button icon={<PlusOutlined />} size="small" />}
onFinish={async (values: any) => {
const { value } = values;
const json = jsonParse(value);
await comm!.addValue(json);
return true;
<Button
icon={<PlusOutlined />}
size="small"
onClick={() => {
JsonForm.show(_props);
}}
></JsonForm>
/>
);
};
export default AddButton;
37 changes: 10 additions & 27 deletions src/components/Forms/Json.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import { Template } from "../../templates";
import ModalForm, { ModalFormProps } from "../ModalForm";
import { CodeEditor } from "../../uitls/useMonacoEdit";
import { globalConfig } from "antd/es/config-provider";
import { HookAPI } from "antd/es/modal/useModal";
import { useTranslation } from "react-i18next";
import { getLabel } from "../../uitls/i18n";
import "./index.less";

const template2menu: any = (template: Template) => {
const { children, ...other } = template;
Expand All @@ -36,28 +36,17 @@ const template2menu: any = (template: Template) => {
}
};

{
/* <Dropdown menu={menuProps}>
<Button>
<Space>
Button
<DownOutlined />
</Space>
</Button>
</Dropdown> */
}

// const TemplateBar = (props: any) => {
// const { templates, onhandle } = props;
// return <Space></Space>;
// };

type JsonFromProps = ModalFormProps & {
templates?: Template[];
};

const JsonForm: React.FC<JsonFromProps> = (props) => {
const { templates, ...other } = props;
interface Jsonform extends React.FC<JsonFromProps> {
show: (props: JsonFromProps) => void;
}

const JsonForm: Jsonform = (props) => {
const { templates, modalProps, ...other } = props;
const { t } = useTranslation();
const formRef = useRef<FormInstance<any>>();
const templateHandle = (json: string) => {
Expand Down Expand Up @@ -102,13 +91,11 @@ const JsonForm: React.FC<JsonFromProps> = (props) => {
modalProps={{
destroyOnClose: true,
maskClosable: false,
...modalProps,
}}
>
{hasTemplate ? (
<Space
size={"small"}
style={{ marginBottom: 5, width: "100%", overflow: "auto" }}
>
<Space size={"small"} className="template-box scroll-small">
<span>{t("terms.template")}:</span>
{templates.map((template, index) => {
if (template.children?.length) {
Expand Down Expand Up @@ -204,7 +191,7 @@ const JsonForm: React.FC<JsonFromProps> = (props) => {
);
};

export const showJsonForm = (props: JsonFromProps) => {
JsonForm.show = (props: JsonFromProps) => {
const { onOpenChange, open: propOpen, ...other } = props;
let timeoutId: ReturnType<typeof setTimeout>;
const container = document.createDocumentFragment();
Expand Down Expand Up @@ -236,8 +223,4 @@ export const showJsonForm = (props: JsonFromProps) => {
});
};

// export const showUpModelForm = (props: any) => {
// const { name, root, model } = props;
// };

export default JsonForm;
5 changes: 5 additions & 0 deletions src/components/Forms/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.template-box {
padding-bottom: 5px;
width: 100%;
overflow: auto;
}
5 changes: 3 additions & 2 deletions src/components/List/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, {
import { Button, Popconfirm, Space, Table, App } from "antd";
import { red, green } from "@ant-design/colors";
import { getRESTfulApi } from "../../api";
import { showJsonForm } from "../Forms/Json";
import JsonForm from "../Forms/Json";
import { jsonFormatValue, jsonParse } from "../../uitls";
import {
CheckCircleOutlined,
Expand All @@ -22,6 +22,7 @@ import Ctx, { CardCtx } from "../../uitls/ctx";
import { useListData1, UseTemplates } from "../ListCard/hooks";
import { configEvent } from "../../uitls/events";
import { useTranslation } from "react-i18next";
const showJsonForm = JsonForm.show;

export type PublicListProps = {
name: string;
Expand Down Expand Up @@ -135,7 +136,7 @@ const PublicList: React.FC<PublicListProps> = (props) => {
return () => {
configEvent.off(`edit:${name}`, onEdit);
};
}, []);
}, [name, t, updateLocal, updateValue]);
return (
<div style={{ height: 348, overflow: "auto" }}>
<Table
Expand Down
4 changes: 2 additions & 2 deletions src/components/ListCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const ListCard: React.FC<ListCardProps> = (props) => {
},
...props,
};
}, [props]);
}, [props, t]);
const [keyword, setKeyword] = useState("");
const _prop = {
title: subTitle || "",
Expand Down Expand Up @@ -154,7 +154,7 @@ const ListCard: React.FC<ListCardProps> = (props) => {
// updateLocalList?.();
},
};
}, [api, dataSource, localApi, name]);
}, [api, dataSource, localApi, name, t]);

useEffect(() => {
return commBindEvent(name, comm);
Expand Down
4 changes: 2 additions & 2 deletions src/components/viewer/chain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Space, Tag, Tooltip } from "antd";
import { ChainConfig, Config, HopConfig } from "../../api/types";
import { ViewHop, viewHops } from "./hop";
import { RightOutlined } from "@ant-design/icons";
import { showJsonForm } from "../Forms/Json";
import JsonForm from "../Forms/Json";
import { jsonFormatValue, jsonParse } from "../../uitls";
import { useContext } from "react";
import { UpdateCtx } from "../List/Public";
Expand Down Expand Up @@ -34,7 +34,7 @@ export function ViewHops(props: { hops: HopConfig[]; root: any }) {
className="editor-json"
title={t("text.doubleClickEdit")}
onDoubleClick={() => {
showJsonForm({
JsonForm.show({
title: t('base.cmd.edit'),
initialValues: { value: jsonFormatValue(hop) },
onFinish: async (values: any) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/viewer/node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Config, ForwardNodeConfig, NodeConfig } from "../../api/types";
import { useContext, useMemo } from "react";
import Ctx, { CardCtx } from "../../uitls/ctx";
import { Space, Tag, Tooltip } from "antd";
import { showJsonForm } from "../Forms/Json";
import JsonForm from "../Forms/Json";
import { jsonFormatValue, jsonParse } from "../../uitls";
import { UpdateCtx } from "../List/Public";
import { useTranslation } from "react-i18next";
Expand Down Expand Up @@ -62,7 +62,7 @@ export function ViewNode<T extends { name: string; addr: string }>({
return {
className: "editor-json",
onDoubleClick: () => {
showJsonForm({
JsonForm.show({
title: t("base.cmd.edit"),
initialValues: { value: jsonFormatValue(node) },
onFinish: async (values: any) => {
Expand Down
76 changes: 0 additions & 76 deletions src/index.css

This file was deleted.

Loading

0 comments on commit 1d3d620

Please sign in to comment.