Skip to content

Commit

Permalink
fix(web): function return shows when not undefined & update current f…
Browse files Browse the repository at this point in the history
…unction after edit name (labring#1713)

* feat(web): add history modal tip

* fix(web): fix function return show when not undefined

* fix(web): fix change function name update
  • Loading branch information
newfish-cmyk authored Nov 29, 2023
1 parent 9daa9f8 commit 2b228d0
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 19 deletions.
4 changes: 3 additions & 1 deletion web/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@
"Restore": "Restore",
"Invite": "Invite",
"HistoryTips": "No historical versions available",
"NoDesc": "No Description"
"NoDesc": "No Description",
"CurrentVersion": "Current Version",
"HistoryVersion": "History version"
},
"HomePanel": {
"APP": "Android or iOS app",
Expand Down
4 changes: 3 additions & 1 deletion web/public/locales/zh-CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@
"Restore": "恢复",
"Invite": "邀请",
"HistoryTips": "暂无历史版本",
"NoDesc": "暂无描述"
"NoDesc": "暂无描述",
"CurrentVersion": "当前版本",
"HistoryVersion": "历史版本"
},
"HomePanel": {
"APP": "Android or iOS 应用",
Expand Down
4 changes: 3 additions & 1 deletion web/public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@
"Restore": "恢复",
"Invite": "邀请",
"HistoryTips": "暂无历史版本",
"NoDesc": "暂无描述"
"NoDesc": "暂无描述",
"CurrentVersion": "当前版本",
"HistoryVersion": "历史版本"
},
"HomePanel": {
"APP": "Android or iOS 应用",
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/app/functions/mods/DebugPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export default function DebugPanel(props: { containerRef: any }) {
</Center>
</div>
) : null}
{runningResData ? (
{runningResData !== undefined ? (
<JSONViewer
colorMode={colorMode}
code={JSON.stringify(runningResData, null, 2)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ const CreateModal = (props: {
const navigate = useNavigate();
const [searchKey, setSearchKey] = useState("");
const [templateOpen, setTemplateOpen] = useState(false);
const { recentFunctionList, setRecentFunctionList } = useFunctionStore();
const { recentFunctionList, setRecentFunctionList, setCurrentFunction, currentFunction } =
useFunctionStore();
const { setShowTemplateItem } = useTemplateStore();

const defaultValues = {
Expand Down Expand Up @@ -116,6 +117,7 @@ const CreateModal = (props: {
return item;
}),
);
setCurrentFunction({ ...currentFunction, name: data.name });
} else if (isEdit && functionItem.name === data.name) {
res = await updateFunctionMutation.mutateAsync(data);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from "react";
import {
Button,
Grid,
GridItem,
Modal,
ModalBody,
ModalCloseButton,
Expand All @@ -19,7 +21,7 @@ import useFunctionStore from "../../../store";
import useFunctionCache from "@/hooks/useFunctionCache";
import useGlobalStore from "@/pages/globalStore";

export default function FetchButton(props: { children: React.ReactElement; functionCode: string }) {
export default function FetchModal(props: { children: React.ReactElement; functionCode: string }) {
const { children, functionCode } = props;
const functionCache = useFunctionCache();
const { isOpen, onOpen, onClose } = useDisclosure();
Expand All @@ -43,12 +45,16 @@ export default function FetchButton(props: { children: React.ReactElement; funct
<ModalHeader>Code Diff</ModalHeader>
<ModalCloseButton />
<ModalBody borderBottom={"1px"} borderBottomColor="gray.200">
<Grid templateColumns="repeat(2, 1fr)" gap={6} mb={2} mt={-4}>
<GridItem>{t("FunctionPanel.HistoryVersion")}</GridItem>
<GridItem>{t("FunctionPanel.CurrentVersion")}</GridItem>
</Grid>
<CommonDiffEditor
modified={functionCode}
original={functionCache.getCache(
modified={functionCache.getCache(
currentFunction?._id,
currentFunction?.source?.code,
)}
original={functionCode}
/>
</ModalBody>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { formatDate } from "@/utils/format";
import { useFunctionHistoryQuery } from "../../service";
import useFunctionStore from "../../store";

import FetchButton from "./FetchButton";
import FetchModal from "./FetchModal";

export default function VersionHistoryPanel() {
const { currentFunction } = useFunctionStore((state) => state);
Expand All @@ -29,7 +29,7 @@ export default function VersionHistoryPanel() {
) : history.data?.data.length !== 0 ? (
history.data?.data.map((item: any, index: number) => {
return (
<FetchButton key={index} functionCode={item.source.code}>
<FetchModal key={index} functionCode={item.source.code}>
<div
className={clsx(
"text-12px mx-3 flex h-10 cursor-pointer items-center justify-between rounded",
Expand Down Expand Up @@ -65,7 +65,7 @@ export default function VersionHistoryPanel() {
#{history.data?.data.length - index}
</span>
</div>
</FetchButton>
</FetchModal>
);
})
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,18 @@ function mergeArrays(arrays: any) {
const newArrays = arrays.map((arr: any) => {
let frontPadding = 0;
let endPadding = 0;
const lastTime = new Date(arr[arr.length - 1].xData);
lastTime.setSeconds(0);
lastTime.setMilliseconds(0);
const firstTime = new Date(arr[0].xData);
firstTime.setSeconds(0);
firstTime.setMilliseconds(0);
for (let i = 0; i < longestArray.length; i++) {
const lastTime = new Date(arr[arr.length - 1].xData);
lastTime.setSeconds(0);
lastTime.setMilliseconds(0);
const firstTime = new Date(arr[0].xData);
firstTime.setSeconds(0);
firstTime.setMilliseconds(0);

if (longestArray[i].xData === firstTime.getTime()) {
frontPadding = i;
}
if (longestArray[i].xData === lastTime.getTime()) {
endPadding = longestArray.length - i - 1;
endPadding = longestArray.length - 1 - i;
}
}
return [
Expand Down

0 comments on commit 2b228d0

Please sign in to comment.