Skip to content

Commit

Permalink
Add placeholder text and move component conditional out of render method
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Bolton <[email protected]>
  • Loading branch information
ibolton336 committed Apr 12, 2024
1 parent 4a5abd9 commit e0474d9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.empty-cell {
color: #6a6e73;
font-style: italic;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./file-all-incidents-table.css";
import * as React from "react";
import { Table, Thead, Tr, Th, Tbody, Td } from "@patternfly/react-table";
import { useSelectionState } from "@migtools/lib-ui";
Expand Down Expand Up @@ -123,9 +124,7 @@ export const FileAllIncidentsTable: React.FC<
colSpan={2}
{...getTdProps({ columnKey: "message" })}
>
<ReactMarkdown components={markdownPFComponents}>
{`${getFirstNonEmptyLine(incident.message)} ...`}
</ReactMarkdown>
{messageDisplayComponent(incident.message)}
</Td>
</TableRowContentWithControls>
</Tr>
Expand All @@ -144,7 +143,19 @@ export const FileAllIncidentsTable: React.FC<
);
};

const getFirstNonEmptyLine = (message: string) => {
const getFirstNonEmptyLine = (message: string): string | null => {
const lines = message.split("\n");
return lines.find((line) => line.trim() !== "") || "No content available.";
const nonEmptyLine = lines.find((line) => line.trim() !== "");
return nonEmptyLine || null;
};

const messageDisplayComponent = (message: string) => {
const content = getFirstNonEmptyLine(message);
console.log("content", content);
if (content === null) {
return <div className="empty-cell">No content available.</div>;
}
return (
<ReactMarkdown components={markdownPFComponents}>{content}</ReactMarkdown>
);
};

0 comments on commit e0474d9

Please sign in to comment.