Skip to content

Commit

Permalink
fix(ui-debug): prevent empty text files display
Browse files Browse the repository at this point in the history
  • Loading branch information
hdinia committed Dec 2, 2024
1 parent 39f8d91 commit 1af012f
Showing 1 changed file with 36 additions and 17 deletions.
53 changes: 36 additions & 17 deletions webapp/src/components/App/Singlestudy/explore/Debug/Data/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import DownloadButton from "../../../../../common/buttons/DownloadButton";
import { downloadFile } from "../../../../../../utils/fileUtils";
import { Filename, Flex, Menubar } from "./styles";
import UploadFileButton from "../../../../../common/buttons/UploadFileButton";
import EmptyView from "@/components/common/page/SimpleContent";
import GridOffIcon from "@mui/icons-material/GridOff";

SyntaxHighlighter.registerLanguage("xml", xml);
SyntaxHighlighter.registerLanguage("plaintext", plaintext);
Expand All @@ -42,6 +44,16 @@ const logsRegex = /^(\[[^\]]*\]){3}/;
// Ex: "EXP : 0"
const propertiesRegex = /^[^:]+ : [^:]+/;

function isEmptyContent(text: string | string[]): boolean {
if (Array.isArray(text)) {
return (
text.length === 0 ||
text.every((line) => typeof line === "string" && !line.trim())
);
}
return typeof text !== "string" || !text.trim();
}

function getSyntaxProps(data: string | string[]): SyntaxHighlighterProps {
const isArray = Array.isArray(data);
const text = isArray ? data.join("\n") : data;
Expand Down Expand Up @@ -111,24 +123,31 @@ function Text({ studyId, filePath, filename, canEdit }: DataCompProps) {
onUploadSuccessful={handleUploadSuccessful}
/>
)}
<DownloadButton onClick={handleDownload} />
</Menubar>
<Box sx={{ overflow: "auto" }}>
<SyntaxHighlighter
style={atomOneDark}
lineNumberStyle={{
opacity: 0.5,
paddingRight: theme.spacing(3),
}}
customStyle={{
margin: 0,
padding: theme.spacing(2),
borderRadius: theme.shape.borderRadius,
fontSize: theme.typography.body2.fontSize,
}}
{...getSyntaxProps(text)}
<DownloadButton
onClick={handleDownload}
disabled={isEmptyContent(text)}
/>
</Box>
</Menubar>
{isEmptyContent(text) ? (
<EmptyView icon={GridOffIcon} title={t("study.results.noData")} />
) : (
<Box sx={{ overflow: "auto" }}>
<SyntaxHighlighter
style={atomOneDark}
lineNumberStyle={{
opacity: 0.5,
paddingRight: theme.spacing(3),
}}
customStyle={{
margin: 0,
padding: theme.spacing(2),
borderRadius: theme.shape.borderRadius,
fontSize: theme.typography.body2.fontSize,
}}
{...getSyntaxProps(text)}
/>
</Box>
)}
</Flex>
)}
/>
Expand Down

0 comments on commit 1af012f

Please sign in to comment.