Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Website UI: Explain the Logs modal #1666

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 39 additions & 24 deletions packages/playground/website/src/components/log-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export function LogModal(props: { description?: JSX.Element; title?: string }) {
const [logs, setLogs] = useState<string[]>([]);
const [searchTerm, setSearchTerm] = useState('');

const filteredLogs = logs.filter((log) =>
log.toLowerCase().includes(searchTerm.toLowerCase())
);

useEffect(() => {
getLogs();
logger.addEventListener(logEventType, getLogs);
Expand All @@ -37,20 +41,15 @@ export function LogModal(props: { description?: JSX.Element; title?: string }) {
}

function logList() {
return logs
.filter((log) =>
log.toLowerCase().includes(searchTerm.toLowerCase())
)
.reverse()
.map((log, index) => (
<div
className={css.logModalLog}
key={index}
dangerouslySetInnerHTML={{
__html: log.replace(/Error:|Fatal:/, '<mark>$&</mark>'),
}}
/>
));
return filteredLogs.reverse().map((log, index) => (
<div
className={css.logModalLog}
key={index}
dangerouslySetInnerHTML={{
__html: log.replace(/Error:|Fatal:/, '<mark>$&</mark>'),
}}
/>
));
}

const styles = {
Expand All @@ -60,18 +59,34 @@ export function LogModal(props: { description?: JSX.Element; title?: string }) {
return (
<Modal isOpen={true} onRequestClose={onClose} styles={styles}>
<header>
<h2>{props.title || 'Logs'}</h2>
<h2>{props.title || 'Error Logs'}</h2>
{props.description}
<TextControl
aria-label="Search"
placeholder="Search logs"
value={searchTerm}
onChange={setSearchTerm}
autoFocus={true}
className={css.logModalSearch}
/>
{logs.length > 0 ? (
<TextControl
aria-label="Search"
placeholder="Search logs"
value={searchTerm}
onChange={setSearchTerm}
autoFocus={true}
className={css.logModalSearch}
/>
) : null}
</header>
<main className={css.logModalMain}>{logList()}</main>
{filteredLogs.length > 0 ? (
<main className={css.logModalMain}>{logList()}</main>
) : logs.length > 0 ? (
<div className={css.logModalEmptyPlaceholder}>
No matching logs found.
</div>
) : (
<div className={css.logModalEmptyPlaceholder}>
Error logs for Playground, WordPress, and PHP will show up
here when something goes wrong.
<br />
<br />
No problems so far – yay! 🎉
</div>
)}
</Modal>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
padding-bottom: 20px;
}

.log-modal__empty_placeholder {
/* text-align: center; */
font-size: 1.3rem;
padding-bottom: 20px;
}

.log-modal__search {
/* Title margin bottom + log margin top */
margin-bottom: 1.33rem;
Expand Down
Loading