Skip to content

Commit ddeca6a

Browse files
committed
refactor(viewers): rewrite plaintext-viewer to be SSRed
1 parent 7ef51e3 commit ddeca6a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+570
-769
lines changed

components/DatasetsTable/DatasetDetails/DatasetDetails.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import { Labels } from "../../labels/Labels";
1010
import { NewLabelButton } from "../../labels/NewLabelButton";
1111
import { ModalWrapper } from "../../modals/ModalWrapper";
1212
import { PageSection } from "../../PageSection";
13-
import { VersionInfoSection } from "./VersionInfoSection/VersionInfoSection";
1413
import { ManageDatasetEditorsSection } from "./ManageDatasetEditorsSection";
1514
import { NewVersionListItem } from "./NewVersionListItem";
1615
import { VersionActionsSection } from "./VersionActionsSection";
16+
import { VersionInfoSection } from "./VersionInfoSection";
1717
import { VersionViewSection } from "./VersionViewSection";
1818
import { WorkingVersionSection } from "./WorkingVersionSection";
1919

components/DatasetsTable/DatasetDetails/VersionViewSection/DatasetPlainTextViewerListItem.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { Description } from "@mui/icons-material";
22
import { ListItem, ListItemText } from "@mui/material";
33
import NextLink from "next/link";
44

5-
import { APP_ROUTES } from "../../../../constants/routes";
6-
75
export interface DatasetPlainTextViewerListItemProps {
86
datasetId: string;
97
version: number;
@@ -17,7 +15,8 @@ export const DatasetPlainTextViewerListItem = ({
1715
<NextLink
1816
passHref
1917
href={{
20-
pathname: APP_ROUTES.dataset.version(datasetId, version),
18+
pathname: "/dataset/[datasetId]/[datasetVersion]",
19+
query: { datasetId, datasetVersion: String(version) },
2120
}}
2221
>
2322
<ListItem button component="a" rel="noopener noreferrer" target="_blank">

components/DatasetsTable/DatasetDetails/VersionViewSection/VersionViewSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const VersionViewSection = ({ dataset, version }: VersionViewSectionProps
2929
component="a"
3030
href={
3131
process.env.NEXT_PUBLIC_BASE_PATH +
32-
API_ROUTES.datasetVersion(dataset.dataset_id, version.version, true)
32+
API_ROUTES.datasetVersion(dataset.dataset_id, version.version, "/api/viewer-proxy")
3333
}
3434
rel="noopener noreferrer"
3535
target="_blank"

components/DatasetsTable/DatasetDetails/WorkingVersionSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const WorkingVersionSection = ({
6161
<Box ml={2}>
6262
<DownloadButton
6363
disabled={!(version.processing_stage === "DONE")}
64-
href={API_ROUTES.datasetVersion(dataset.dataset_id, version.version)}
64+
href={API_ROUTES.datasetVersion(dataset.dataset_id, version.version, "/api/dm-api")}
6565
title="Download this version of the dataset"
6666
/>
6767
</Box>

components/DocsNav.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
1-
import type { ComponentProps } from "react";
2-
31
import { Button } from "@mui/material";
4-
import type Link from "next/link";
52
import NextLink from "next/link";
63
import { useRouter } from "next/router";
74

8-
type Links = Record<`/${string}`, ComponentProps<typeof Link>["href"]>;
9-
10-
const links: Links = {
5+
const links = {
116
"/docs/guided-tour": "Guided Tour",
127
"/docs/how-to": "How To",
138
"/docs/concepts": "Concepts guide",
149
};
1510

11+
type Routes = keyof typeof links;
12+
1613
export const DocsNav = () => {
1714
const router = useRouter();
1815

1916
return (
2017
<nav aria-label="Docs" role="navigation">
2118
{Object.entries(links).map(([href, title]) => (
22-
<NextLink passHref href={href} key={href}>
19+
<NextLink passHref href={{ pathname: href as Routes }} key={href}>
2320
<Button disabled={router.pathname === href}>{title}</Button>
2421
</NextLink>
2522
))}

components/FileUpload/FileUpload.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useGetFileTypes } from "@squonk/data-manager-client/type";
66

77
import CloudUploadRoundedIcon from "@mui/icons-material/CloudUploadRounded";
88
import { IconButton, Tooltip } from "@mui/material";
9+
import { captureException } from "@sentry/nextjs";
910
import type { AxiosError } from "axios";
1011

1112
import { useEnqueueError } from "../../hooks/useEnqueueStackError";
@@ -85,7 +86,8 @@ export const FileUpload = () => {
8586
setFiles(updatedFiles);
8687
enqueueError(errorMessage);
8788
} else {
88-
enqueueError("Unknown error"); // TODO: Add Sentry
89+
captureException(err);
90+
enqueueError("Unknown error");
8991
}
9092
}
9193
});

components/PlaintextViewer.tsx

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/* eslint-disable simple-import-sort/imports */
2+
import { Box, Chip, Divider, Paper, Typography } from "@mui/material";
3+
import fileSize from "filesize";
4+
5+
import { useEffect } from "react";
6+
7+
import Prism from "prismjs";
8+
import "prismjs/plugins/line-numbers/prism-line-numbers.js";
9+
import "prismjs/plugins/line-numbers/prism-line-numbers.css";
10+
11+
export interface PlaintextViewerProps {
12+
/**
13+
* Contents of a file to be displayed.
14+
*/
15+
content: string;
16+
/**
17+
*
18+
*/
19+
title: string;
20+
originalContentLength: number | null;
21+
truncated: boolean;
22+
compressed: boolean;
23+
}
24+
25+
/**
26+
* Component which displays contents of a file. The contents are provided as string, which is then
27+
* parsed into multiple lines and displayed.
28+
*/
29+
export const PlaintextViewer = ({
30+
content,
31+
title,
32+
originalContentLength,
33+
truncated,
34+
compressed,
35+
}: PlaintextViewerProps) => {
36+
const numberOfLines = content.split("\n").length;
37+
const linesText = numberOfLines === 1 ? "line" : "lines";
38+
39+
useEffect(() => {
40+
Prism.highlightAll();
41+
}, []);
42+
43+
return (
44+
<Paper sx={{ marginY: 2 }}>
45+
<Box
46+
alignItems="center"
47+
display="flex"
48+
paddingX={2}
49+
paddingY={1}
50+
sx={{
51+
bgcolor: (theme) => (theme.palette.mode === "light" ? "grey.200" : "grey.900"),
52+
boxShadow: 0,
53+
gap: 2,
54+
}}
55+
>
56+
<Box alignItems="center" display="flex" flex="1 1 auto" sx={{ gap: 1 }}>
57+
<Typography component="h1" fontFamily="monospace" sx={{ wordBreak: "break-all" }}>
58+
<b>{title}</b>
59+
</Typography>
60+
<Divider flexItem orientation="vertical" />
61+
<Typography>
62+
{numberOfLines} {linesText} of{" "}
63+
{originalContentLength ? fileSize(originalContentLength) : "unknown"}
64+
</Typography>
65+
{(compressed || truncated) && <Divider flexItem orientation="vertical" />}
66+
{compressed && <Chip label="Decompressed" size="small" variant="outlined" />}
67+
{truncated && <Chip label="Truncated" size="small" variant="outlined" />}
68+
</Box>
69+
</Box>
70+
<Box paddingBottom={1} paddingX={1}>
71+
<Box className="line-numbers" component="pre">
72+
<code className="language-">{content}</code>
73+
</Box>
74+
</Box>
75+
</Paper>
76+
);
77+
};

components/PlaintextViewer/PlaintextViewer.tsx

Lines changed: 0 additions & 95 deletions
This file was deleted.

components/PlaintextViewer/PlaintextViewerContent.tsx

Lines changed: 0 additions & 119 deletions
This file was deleted.

0 commit comments

Comments
 (0)