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

bugfix: preview arter before save data, width attribute display #202

Merged
merged 1 commit into from
Oct 14, 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
166 changes: 73 additions & 93 deletions solidui-web/src/pages/Designer/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@

import React, { useEffect } from "react";
import { useNavigate, useSearchParams } from "react-router-dom";
import { Button, Tooltip, Drawer, message } from "antd";
import { ChartHistogramTwo } from "@icon-park/react";
import { eventbus, mm } from "@/utils/index";
import { Button, Drawer, message } from "antd";
import { mm } from "@/utils/index";
import Apis from "@/apis";
import {
ProjectPageViewsCreationDataType,
Expand All @@ -35,6 +34,73 @@ function Header() {
const [previewVisible, setPreviewVisible] = React.useState(false);
const [title, setTitle] = React.useState("");

async function handlePreview() {
await handleSave();
const page = mm.getCurrentPage();
const project = mm.getModel();
if (isNil(project) || isNil(page)) {
message.warn("please select a page first");
return;
}
setPreviewVisible(true);
}

async function handleSave() {
const model = mm.getPrepareSavingModel();
const page = mm.getCurrentPage();

if (isNil(model) || isNil(page)) {
return;
}
const views = page.views || [];
const _views: PageViewCreationDataType[] = [];
views.forEach((view) => {
const v: any = {
title: view.title,
position: {
top: `${view.position.top}`,
left: `${view.position.left}`,
},
size: {
width: `${view.size.width}`,
height: `${view.size.height}`,
},
type: view.type,
data: {
dataSourceId: `${view.data.dataSourceId || ""}`,
dataSourceName: `${view.data.dataSourceName || ""}`,
dataSourceTypeId: `${view.data.dataSourceTypeId || ""}`,
dataSourceTypeName: `${view.data.dataSourceTypeName || ""}`,
sql: view.data.sql || "",
table: view.data.table || "",
},
};
if (view.options !== null && undefined !== view.options) {
v.options = view.options;
}
if (!startsWith(view.id, "visual")) {
v.id = view.id;
}
_views.push(v);
});
const data: ProjectPageViewsCreationDataType = {
projectId: model.id,
page: {
id: page.id,
name: page.title,
},
size: {
width: page.size.width,
height: page.size.height,
},
views: _views,
};
const res = await Apis.model.updateProjectPageViews(data);
if (res.ok) {
message.success("Save success");
}
}

function renderPreviewPopup() {
if (!previewVisible) {
return undefined;
Expand Down Expand Up @@ -115,103 +181,17 @@ function Header() {
<span style={{ marginLeft: "10px" }}>{title}</span>
</div>
</div>
<div className="header-center">
{/* <Tooltip title="Bar Chart">
<ChartHistogramTwo
theme="two-tone"
size="32"
fill={["#379aff", "#4890f3"]}
strokeLinejoin="bevel"
strokeLinecap="square"
style={{
cursor: "pointer",
}}
onClick={() => {
eventbus.emit("onDraw", {
viewType: "echarts_bar",
});
}}
/>
</Tooltip> */}
</div>
<div className="header-center">{}</div>
<div className="header-right">
<Button
type="primary"
size="small"
style={{
marginRight: 10,
}}
onClick={() => {
const page = mm.getCurrentPage();
const project = mm.getModel();
if (isNil(project) || isNil(page)) {
message.warn("please select a page first");
return;
}
setPreviewVisible(true);
}}
style={{ marginRight: 10 }}
onClick={handlePreview}
>
Preview
</Button>
<Button
type="primary"
size="small"
onClick={async () => {
const model = mm.getPrepareSavingModel();
const page = mm.getCurrentPage();

if (isNil(model) || isNil(page)) {
return;
}
const views = page.views || [];
const _views: PageViewCreationDataType[] = [];
views.forEach((view) => {
const v: any = {
title: view.title,
position: {
top: `${view.position.top}`,
left: `${view.position.left}`,
},
size: {
width: `${view.size.width}`,
height: `${view.size.height}`,
},
type: view.type,
data: {
dataSourceId: `${view.data.dataSourceId || ""}`,
dataSourceName: `${view.data.dataSourceName || ""}`,
dataSourceTypeId: `${view.data.dataSourceTypeId || ""}`,
dataSourceTypeName: `${view.data.dataSourceTypeName || ""}`,
sql: view.data.sql || "",
table: view.data.table || "",
},
};
if (view.options !== null && undefined !== view.options) {
v.options = view.options;
}
if (!startsWith(view.id, "visual")) {
v.id = view.id;
}
_views.push(v);
});
const data: ProjectPageViewsCreationDataType = {
projectId: model.id,
page: {
id: page.id,
name: page.title,
},
size: {
width: page.size.width,
height: page.size.height,
},
views: _views,
};
const res = await Apis.model.updateProjectPageViews(data);
if (res.ok) {
message.success("Save success");
}
}}
>
<Button type="primary" size="small" onClick={handleSave}>
Save
</Button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ import { PropertyElement, InputNumber } from "@/components";
import { mm, eventbus } from "@/utils";

export default function PagePagePropertiesPanel() {
const [size] = useState<{ width: number; height: number }>();
const page = mm.getCurrentPage();

const [size] = useState<{ width: number; height: number }>({
width: page?.size.width || 1024,
height: page?.size.height || 768,
});

return (
<>
Expand Down
Loading