-
-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): add function fetch button (#1163)
* feat(web): request methods persistence * feat(web): add function label select * feat(web): add fetch button * feat(web): add invitecode to homepage and login * Revert "feat(web): add invitecode to homepage and login" This reverts commit 69daa00.
- Loading branch information
1 parent
7a5fe76
commit 77369e4
Showing
12 changed files
with
191 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { | ||
Button, | ||
Modal, | ||
ModalBody, | ||
ModalCloseButton, | ||
ModalContent, | ||
ModalFooter, | ||
ModalHeader, | ||
ModalOverlay, | ||
useDisclosure, | ||
} from "@chakra-ui/react"; | ||
import { t } from "i18next"; | ||
|
||
import CommonDiffEditor from "@/components/Editor/CommonDiffEditor"; | ||
|
||
import { useFunctionDetailQuery } from "../../service"; | ||
import useFunctionStore from "../../store"; | ||
|
||
import useFunctionCache from "@/hooks/useFunctionCache"; | ||
import useGlobalStore from "@/pages/globalStore"; | ||
|
||
export default function FetchButton() { | ||
const functionCache = useFunctionCache(); | ||
const { isOpen, onOpen, onClose } = useDisclosure(); | ||
const store = useFunctionStore((state) => state); | ||
const { currentFunction, updateFunctionCode, setIsFetchButtonClicked } = store; | ||
const functionDetailQuery = useFunctionDetailQuery(store.currentFunction.name, { | ||
enabled: isOpen, | ||
}); | ||
const data = functionDetailQuery.data?.data?.source?.code; | ||
const { showSuccess } = useGlobalStore((state) => state); | ||
|
||
return ( | ||
<> | ||
<Button | ||
variant={"text"} | ||
isLoading={functionDetailQuery.isFetching} | ||
disabled={store.getFunctionUrl() === ""} | ||
onClick={() => { | ||
onOpen(); | ||
}} | ||
> | ||
{t("FunctionPanel.Fetch")} | ||
</Button> | ||
|
||
{isOpen && !functionDetailQuery.isFetching ? ( | ||
<Modal isOpen={isOpen} onClose={onClose} size="6xl" isCentered> | ||
<ModalOverlay /> | ||
<ModalContent maxW={"80%"}> | ||
<ModalHeader>Code Diff</ModalHeader> | ||
<ModalCloseButton /> | ||
<ModalBody borderBottom={"1px"} borderBottomColor="gray.200"> | ||
<CommonDiffEditor | ||
modified={data} | ||
original={functionCache.getCache( | ||
currentFunction?.id, | ||
currentFunction?.source?.code, | ||
)} | ||
/> | ||
</ModalBody> | ||
|
||
<ModalFooter> | ||
<Button variant="ghost" mr={3} onClick={onClose}> | ||
{t("Cancel")} | ||
</Button> | ||
<Button | ||
variant="primary" | ||
onClick={() => { | ||
updateFunctionCode(currentFunction, data || ""); | ||
functionCache.setCache(currentFunction!.id, data || ""); | ||
setIsFetchButtonClicked(); | ||
onClose(); | ||
showSuccess(t("FunctionPanel.FetchSuccess")); | ||
}} | ||
> | ||
{t("FunctionPanel.ConfirmFetch")} | ||
</Button> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
) : null} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.