1
0
Fork 0
freesewing/packages/react/components/Editor/components/views/LogView.mjs
Jonathan Haas b4a5393290 [react] feat: Improved error handling when pattern drafting fails (#205)
If drafting a part fails, the logs store contains an array [message, stacktrace] instead of a simple string. Handle this in the LogView.

Also display an error message in the DraftView when there were errors during drafting.

![image](/attachments/62cdebe3-7825-4382-88fd-395337cda58b)

after clicking the button:

![image](/attachments/f909887b-b9bd-467e-9e13-f850c38d76b3)

(could also display the stack traces, but they're quite unhelpful and you can find them in the browser console anyway, the code for that is commented out)

Closes #163

Reviewed-on: https://codeberg.org/freesewing/freesewing/pulls/205
Reviewed-by: Joost De Cock <joostdecock@noreply.codeberg.org>
Co-authored-by: Jonathan Haas <haasjona@gmail.com>
Co-committed-by: Jonathan Haas <haasjona@gmail.com>
2025-04-06 14:42:42 +00:00

64 lines
2 KiB
JavaScript

// Dependencies
import { draft } from '../../lib/index.mjs'
// Hooks
import React from 'react'
// Components
import { H1, H3 } from '@freesewing/react/components/Heading'
import { HeaderMenu } from '../HeaderMenu.mjs'
import { Tabs, Tab } from '@freesewing/react/components/Tab'
import { LogEntry } from './LogEntry.mjs'
// The log levels
const levels = ['error', 'warn', 'info', 'debug']
/**
* This is the log view, it shows the pattern logs
*
* @param {Object} props - All the props
* @param {Function} props.config - The editor configuration
* @param {Object} props.state - The editor state object
* @param {Object} props.update - Helper object for updating the editor state
*/
export const LogView = (props) => {
const { state, config, update } = props
const { pattern } = draft(props.Design, state.settings)
return (
<>
<HeaderMenu state={state} {...{ config, update }} />
<div className="tw-m-auto tw-mt-8 tw-max-w-2xl tw-px-4 tw-mb-8">
<H1>Pattern Logs</H1>
<Tabs tabs="Set 0 Logs, Pattern Logs">
<Tab tabId="Set 0 Logs">
{levels.map((level) => (
<div key={level}>
{pattern.setStores[0].logs[level].length > 0 ? (
<>
<H3>{level}</H3>
{pattern.setStores[0].logs[level].map((line, i) => (
<LogEntry key={i} logEntry={line} />
))}
</>
) : null}
</div>
))}
</Tab>
<Tab tabId="Pattern Logs">
{levels.map((level) => (
<div key={level}>
{pattern.store.logs[level].length > 0 ? (
<>
<H3>{level}</H3>
{pattern.store.logs[level].map((line, i) => (
<LogEntry key={i} logEntry={line} />
))}
</>
) : null}
</div>
))}
</Tab>
</Tabs>
</div>
</>
)
}