Skip to content

Commit 7712141

Browse files
committed
cleaning up
1 parent 5126bd2 commit 7712141

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

frontend/src/components/visualizations/JSONVisualizer/JSONVisualizer.tsx

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ import {
88
} from "@mui/material";
99
import CodeMirror from "@uiw/react-codemirror"; // CodeMirror editor
1010
import { json } from "@codemirror/lang-json"; // JSON language support for CodeMirror
11+
1112
import { downloadVisData, fileDownloaded } from "../../../utils/visualization";
12-
import {
13-
fetchFileVersions,
14-
updateFile as updateFileAction,
15-
} from "../../../actions/file";
13+
import { updateFile as updateFileAction } from "../../../actions/file";
1614
import { readTextFromFile } from "../../../utils/common";
1715
import { downloadPublicVisData } from "../../../actions/public_visualization";
1816
import { filePublicDownloaded } from "../../../actions/public_file";
@@ -26,14 +24,11 @@ type jsonProps = {
2624
};
2725

2826
export default function JSONVisualizer(props: jsonProps) {
29-
const { visualizationId, publicView } = props;
30-
// TODO: Use fileData to get the fileid to reflect version change
31-
const fileId = useSelector((state: RootState) => state.file.fileSummary?.id);
32-
const versionNum = useSelector(
27+
const { fileId, visualizationId, publicView } = props;
28+
const selectedFileVersion = useSelector(
3329
(state: RootState) => state.file.selected_version_num
3430
);
3531
const fileSummary = useSelector((state: RootState) => state.file.fileSummary);
36-
const fileData = useSelector((state: RootState) => state.file);
3732

3833
// State to store the original content of the file and the displayed JSON content that can be edited
3934
const [originalContent, setOriginalContent] = useState<string | undefined>();
@@ -49,20 +44,13 @@ export default function JSONVisualizer(props: jsonProps) {
4944
const updateFile = async (file: File, fileId: string | undefined) =>
5045
dispatch(updateFileAction(file, fileId));
5146

52-
useEffect(() => {
53-
console.log("File Data: ", fileData);
54-
}, [fileData]);
55-
5647
useEffect(() => {
5748
if (fileSummary) {
5849
setFileName(fileSummary.name);
59-
console.log("File Summary: ", fileSummary);
6050
}
6151
}, [fileSummary]);
6252

6353
useEffect(() => {
64-
console.log("File ID: ", fileId);
65-
console.log("Version Num: ", versionNum);
6654
const fetchData = async () => {
6755
try {
6856
let blob;
@@ -73,7 +61,7 @@ export default function JSONVisualizer(props: jsonProps) {
7361
} else {
7462
blob = publicView
7563
? await filePublicDownloaded(fileId)
76-
: await fileDownloaded(fileId, versionNum);
64+
: await fileDownloaded(fileId, selectedFileVersion);
7765
}
7866

7967
const file = new File([blob], fileName);
@@ -85,7 +73,7 @@ export default function JSONVisualizer(props: jsonProps) {
8573
}
8674
};
8775
fetchData();
88-
}, [visualizationId, fileId, publicView, versionNum]);
76+
}, [visualizationId, fileId, publicView, selectedFileVersion]);
8977

9078
const validateJson = (jsonString: string) => {
9179
try {
@@ -125,6 +113,10 @@ export default function JSONVisualizer(props: jsonProps) {
125113
return originalContent === jsonContent || !validJson;
126114
};
127115

116+
// Flag for previous versions
117+
const isPreviousVersion = () => {
118+
return selectedFileVersion !== fileSummary?.version_num;
119+
};
128120
return (
129121
<Card>
130122
<CardContent>
@@ -140,14 +132,16 @@ export default function JSONVisualizer(props: jsonProps) {
140132
)}
141133
</CardContent>
142134
<CardActions>
143-
<Button
144-
variant="contained"
145-
color="primary"
146-
onClick={handleSave}
147-
disabled={disableSaveButton()}
148-
>
149-
Save Changes
150-
</Button>
135+
{!isPreviousVersion() && (
136+
<Button
137+
variant="contained"
138+
color="primary"
139+
onClick={handleSave}
140+
disabled={disableSaveButton()}
141+
>
142+
Save Changes
143+
</Button>
144+
)}
151145
</CardActions>
152146
</Card>
153147
);

0 commit comments

Comments
 (0)