Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
skamril committed Jan 10, 2024
1 parent a1203c8 commit 3ec1855
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Box, Button, Divider } from "@mui/material";
import { useRef } from "react";
import { useTranslation } from "react-i18next";
import * as R from "ramda";
import { Pred } from "ramda";
import HotTable from "@handsontable/react";
import Handsontable from "handsontable";
import { StudyMetadata } from "../../../../../../../../common/types";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {
} from "../../../../../../../services/api/study";
import { Header, Root } from "./style";
import SimpleLoader from "../../../../../../common/loaders/SimpleLoader";
import JSONEditor from "../../../../../../common/JSONEditor";
import JSONEditor, {
JSONEditorProps,
} from "../../../../../../common/JSONEditor";
import usePromiseWithSnackbarError from "../../../../../../../hooks/usePromiseWithSnackbarError";
import UsePromiseCond from "../../../../../../common/utils/UsePromiseCond";
import SimpleContent from "../../../../../../common/page/SimpleContent";
Expand All @@ -29,7 +31,7 @@ function JsonView({ path, studyId }: Props) {
const [jsonData, setJsonData] = useState<string | null>(null);
const [isSaveAllowed, setSaveAllowed] = useState(false);

const json = usePromiseWithSnackbarError(
const res = usePromiseWithSnackbarError(
() => getStudyData(studyId, path, -1),
{
errorMessage: t("studies.error.retrieveData"),
Expand Down Expand Up @@ -60,8 +62,15 @@ function JsonView({ path, studyId }: Props) {
}
};

const handleJsonChange = (newJson: string) => {
setJsonData(newJson);
const handleJsonChange: JSONEditorProps["onChange"] = (
content,
previousContent,
status,
) => {
console.log({
status,
});
// setJsonData(newJson);
setSaveAllowed(true);
};

Expand All @@ -83,22 +92,22 @@ function JsonView({ path, studyId }: Props) {
</Button>
</Header>
<UsePromiseCond
response={json}
response={res}
ifPending={() => <SimpleLoader />}
ifResolved={() => (
ifResolved={(json) => (
<Box
sx={{
width: 1,
height: 1,
}}
>
<JSONEditor
json={json.data}
onChangeJSON={handleJsonChange}
onChangeText={handleJsonChange} // only for code mode
modes={["tree", "code"]}
enableSort={false}
enableTransform={false}
content={{ json }}
onChange={handleJsonChange}
// onChangeText={handleJsonChange} // only for code mode
// modes={["tree", "code"]}
// enableSort={false}
// enableTransform={false}
/>
</Box>
)}
Expand Down

0 comments on commit 3ec1855

Please sign in to comment.