fix(tabsContext.tsx): remove unnecessary noticeData setting when downloading a file

feat(tabsContext.tsx): change the order of arguments in addFlow function call to improve readability
feat(exportModal/index.tsx): add alertContext and setNoticeData to display a warning when saving a file with API keys
feat(exportModal/index.tsx): add a caution message to inform users about the consequences of saving with API keys
This commit is contained in:
anovazzi1 2023-10-16 13:53:36 -03:00 • committed by anovazzi1
commit 466c158f15
2 changed files with 15 additions and 7 deletions

View file

@ -260,9 +260,6 @@ export function TabsProvider({ children }: { children: ReactNode }) {
// simulate a click on the link element to trigger the download // simulate a click on the link element to trigger the download
link.click(); link.click();
setNoticeData({
title: "Warning: Critical data, JSON file may include API keys.",
});
} }
function downloadFlows() { function downloadFlows() {
@ -300,7 +297,7 @@ export function TabsProvider({ children }: { children: ReactNode }) {
let fileData = JSON.parse(text); let fileData = JSON.parse(text);
if (fileData.flows) { if (fileData.flows) {
fileData.flows.forEach((flow: FlowType) => { fileData.flows.forEach((flow: FlowType) => {
id = addFlow(flow, newProject); id = addFlow(newProject, flow);
}); });
} }
// parse the text into a JSON object // parse the text into a JSON object

View file

@ -4,6 +4,7 @@ import IconComponent from "../../components/genericIconComponent";
import { Button } from "../../components/ui/button"; import { Button } from "../../components/ui/button";
import { Checkbox } from "../../components/ui/checkbox"; import { Checkbox } from "../../components/ui/checkbox";
import { EXPORT_DIALOG_SUBTITLE } from "../../constants/constants"; import { EXPORT_DIALOG_SUBTITLE } from "../../constants/constants";
import { alertContext } from "../../contexts/alertContext";
import { TabsContext } from "../../contexts/tabsContext"; import { TabsContext } from "../../contexts/tabsContext";
import { removeApiKeys } from "../../utils/reactflowUtils"; import { removeApiKeys } from "../../utils/reactflowUtils";
import BaseModal from "../baseModal"; import BaseModal from "../baseModal";
@ -11,7 +12,8 @@ import BaseModal from "../baseModal";
const ExportModal = forwardRef( const ExportModal = forwardRef(
(props: { children: ReactNode }, ref): JSX.Element => { (props: { children: ReactNode }, ref): JSX.Element => {
const { flows, tabId, downloadFlow } = useContext(TabsContext); const { flows, tabId, downloadFlow } = useContext(TabsContext);
const [checked, setChecked] = useState(false); const { setNoticeData } = useContext(alertContext);
const [checked, setChecked] = useState(true);
const flow = flows.find((f) => f.id === tabId); const flow = flows.find((f) => f.id === tabId);
useEffect(() => { useEffect(() => {
setName(flow!.name); setName(flow!.name);
@ -44,6 +46,7 @@ const ExportModal = forwardRef(
<div className="mt-3 flex items-center space-x-2"> <div className="mt-3 flex items-center space-x-2">
<Checkbox <Checkbox
id="terms" id="terms"
checked={checked}
onCheckedChange={(event: boolean) => { onCheckedChange={(event: boolean) => {
setChecked(event); setChecked(event);
}} }}
@ -52,18 +55,26 @@ const ExportModal = forwardRef(
Save with my API keys Save with my API keys
</label> </label>
</div> </div>
<span className="text-xs text-destructive">
Caution: Uncheck this box only removes API keys from fields
specifically designated for API keys.
</span>
</BaseModal.Content> </BaseModal.Content>
<BaseModal.Footer> <BaseModal.Footer>
<Button <Button
onClick={() => { onClick={() => {
if (checked) if (checked) {
downloadFlow( downloadFlow(
flows.find((flow) => flow.id === tabId)!, flows.find((flow) => flow.id === tabId)!,
name!, name!,
description description
); );
else setNoticeData({
title:
"Warning: Critical data, JSON file may include API keys.",
});
} else
downloadFlow( downloadFlow(
removeApiKeys(flows.find((flow) => flow.id === tabId)!), removeApiKeys(flows.find((flow) => flow.id === tabId)!),
name!, name!,