1 // Copyright 2020 Blue Static <https://www.bluestatic.org>
2 // This program is free software licensed under the GNU General Public License,
3 // version 3.0. The full text of the license can be found in LICENSE.txt.
4 // SPDX-License-Identifier: GPL-3.0-only
6 import { createDependentEffect, createMemo, createState } from 'solid-js';
7 import { For, Show } from 'solid-js/dom';
8 import { TaxReturn, Form, Line } from 'ustaxlib/core';
9 import { getLastTraceList } from 'ustaxlib/core/Trace';
11 const S = require('./FormView.css');
18 export default function FormView(props: FormProps) {
19 const lines = createMemo(() => {
20 const keys = Object.keys(props.form.lines);
21 keys.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }));
22 return keys.map(k => props.form.lines[k]);
27 <h2 class={S.formName}>Form {props.form.name}</h2>
29 <table class={S.table}>
31 {line => <LineView tr={props.tr} line={line} />}
43 function LineView(props: LineProps) {
44 const { tr, line } = props;
45 const value = createMemo(() => {
47 return JSON.stringify(line.value(tr), null, 1);
49 return <span class={S.error} title={e.stack}>{e.message}</span>;
53 const [ state, setState ] = createState({
58 createDependentEffect(() => setState('trace', JSON.stringify(getLastTraceList(), null, ' ')), [value]);
60 const toggleTrace = () => setState('showTrace', !state.showTrace);
64 <th class={S.id} onclick={toggleTrace}>{line.id}</th>
65 <td class={S.description}>
68 <Show when={state.showTrace}>
69 <TraceViewer line={line} trace={state.trace} />
72 <td class={S.value}>{value()}</td>
77 interface TraceProps {
82 function TraceViewer(props: TraceProps) {
84 <div class={S.traceViewer}>
85 <h2>Trace {props.line.id}</h2>
86 <div class={S.trace}>{props.trace}</div>