2022-02-12 14:31:17 +01:00
|
|
|
import Markdown from 'react-markdown'
|
2022-06-22 10:44:35 +02:00
|
|
|
import { formatMm } from 'shared/utils'
|
2022-02-12 14:31:17 +01:00
|
|
|
|
2022-03-24 11:35:55 +01:00
|
|
|
// Markdown wrapper to suppress creation of P tags
|
|
|
|
const Md = ({ children }) => <Markdown components={{ p: props => props.children }}>{children}</Markdown>
|
|
|
|
|
2022-06-22 10:44:35 +02:00
|
|
|
const Event = ({ evt, units }) => {
|
|
|
|
console.log(units)
|
|
|
|
if (Array.isArray(evt)) {
|
|
|
|
if (evt[1]?.mm) return <span dangerouslySetInnerHTML={{
|
|
|
|
__html: `${evt[0]}: <strong>${formatMm(evt[1].mm, units, 'html')}</strong>`
|
|
|
|
}}/>
|
|
|
|
else return evt.map(e => <Event evt={e} key={e} />)
|
|
|
|
}
|
2022-02-12 14:31:17 +01:00
|
|
|
|
2022-06-22 10:44:35 +02:00
|
|
|
if (typeof evt === 'string') return <Md>{evt}</Md>
|
|
|
|
|
|
|
|
return <Md>Note a recognized event: {JSON.stringify(evt, null ,2)}</Md>
|
|
|
|
}
|
|
|
|
|
|
|
|
const EventGroup = ({ type='info', events=[], units='metric' }) => events.length > 0 ? (
|
2022-02-12 14:31:17 +01:00
|
|
|
<div className="">
|
|
|
|
<h3 className="capitalize" id={`events-${type}`}>{type}</h3>
|
2022-03-24 11:35:55 +01:00
|
|
|
<table className="table w-full mdx">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th className="text-right w-16">#</th>
|
|
|
|
<th>Message</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{events.map((evt, i) => (
|
|
|
|
<tr key={i} className="leading-1 hover:bg-base-200 hover:bg-opacity-40">
|
|
|
|
<td className="text-right p-1 pr-4 font-bold opacity-80 text-accent">{i}</td>
|
2022-06-22 10:44:35 +02:00
|
|
|
<td className="p-1 pl-4"><Event evt={evt} units={units}/></td>
|
2022-03-24 11:35:55 +01:00
|
|
|
</tr>
|
|
|
|
))}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2022-02-12 14:31:17 +01:00
|
|
|
</div>
|
|
|
|
) : null
|
|
|
|
|
|
|
|
const order = [
|
|
|
|
'error',
|
|
|
|
'warning',
|
|
|
|
'info',
|
|
|
|
'debug'
|
|
|
|
]
|
2022-02-13 15:45:27 +01:00
|
|
|
const Events = props => props?.draft?.events
|
|
|
|
? (
|
|
|
|
<div className="max-w-screen-xl m-auto">
|
|
|
|
<div className="flex flex-col">
|
|
|
|
<ul className="flex flex-row row-wrap">
|
|
|
|
{order.map(type => (props.draft.events[type].length > 0)
|
|
|
|
? (
|
|
|
|
<li key={type} className="">
|
|
|
|
<a href={`#events-${type}`} className={`text-secondary font-bold capitalize text-xl`}>{type}</a>
|
|
|
|
{type === 'debug' ? '' : <span className="px-2 font-bold">|</span>}
|
|
|
|
</li>
|
|
|
|
) : (
|
|
|
|
<li key={type} className="text-base-content font-bold capitalize text-xl">
|
|
|
|
<span className="opacity-50">{type}</span>
|
|
|
|
{type === 'debug' ? '' : <span className="px-2 font-bold">|</span>}
|
|
|
|
</li>
|
|
|
|
)
|
|
|
|
)}
|
|
|
|
</ul>
|
2022-06-22 10:44:35 +02:00
|
|
|
{order.map(type => <EventGroup type={type} events={props.draft.events[type]} units={props.gist.units}/>)}
|
2022-02-13 15:45:27 +01:00
|
|
|
</div>
|
2022-02-12 14:31:17 +01:00
|
|
|
</div>
|
2022-02-13 15:45:27 +01:00
|
|
|
) : null
|
2022-02-12 14:31:17 +01:00
|
|
|
|
|
|
|
export default Events
|