|
1 | | -import { For } from 'solid-js' |
| 1 | +import { For, Show, createMemo } from 'solid-js' |
2 | 2 | import { useTableDevtoolsContext } from '../TableContextProvider' |
3 | 3 | import { useTableStore } from '../useTableStore' |
4 | 4 | import { useStyles } from '../styles/use-styles' |
@@ -32,65 +32,57 @@ export function ColumnsPanel() { |
32 | 32 | const styles = useStyles() |
33 | 33 | const { table } = useTableDevtoolsContext() |
34 | 34 |
|
35 | | - const tableInstance = table() |
36 | 35 | const tableState = useTableStore( |
37 | | - tableInstance ? tableInstance.store : undefined, |
| 36 | + () => table()?.store, |
38 | 37 | (state) => state, |
39 | 38 | ) |
40 | 39 |
|
41 | | - if (!tableInstance) { |
42 | | - return <NoTableConnected title="Columns" /> |
43 | | - } |
44 | | - |
45 | | - const getColumns = (): Array<AnyColumn> => { |
46 | | - tableState?.() |
47 | | - const tableWithColumnFns = tableInstance as unknown as { |
48 | | - getAllFlatColumns?: () => Array<AnyColumn> |
49 | | - getAllLeafColumns?: () => Array<AnyColumn> |
| 40 | + const columns = createMemo<Array<AnyColumn>>(() => { |
| 41 | + const tableInstance = table() |
| 42 | + if (!tableInstance) { |
| 43 | + return [] |
50 | 44 | } |
51 | 45 |
|
52 | | - return ( |
53 | | - tableWithColumnFns.getAllFlatColumns?.() ?? |
54 | | - tableWithColumnFns.getAllLeafColumns?.() ?? |
55 | | - [] |
56 | | - ) |
57 | | - } |
| 46 | + tableState() |
58 | 47 |
|
59 | | - const columns = getColumns() |
| 48 | + return tableInstance.getAllFlatColumns() |
| 49 | + }) |
60 | 50 |
|
61 | 51 | return ( |
62 | | - <div class={styles().panelScroll}> |
63 | | - <div class={styles().sectionTitle}>Columns ({columns.length})</div> |
64 | | - <div class={styles().tableWrapper}> |
65 | | - <table class={styles().rowsTable}> |
66 | | - <thead> |
67 | | - <tr> |
68 | | - <th class={styles().headerCell}>#</th> |
69 | | - <th class={styles().headerCell}>id</th> |
70 | | - <th class={styles().headerCell}>depth</th> |
71 | | - <th class={styles().headerCell}>accessor</th> |
72 | | - <th class={styles().headerCell}>columnDef</th> |
73 | | - </tr> |
74 | | - </thead> |
75 | | - <tbody> |
76 | | - <For each={columns}> |
77 | | - {(column, index) => ( |
78 | | - <tr> |
79 | | - <td class={styles().bodyCellMono}>{index() + 1}</td> |
80 | | - <td class={styles().bodyCellMono}>{column.id}</td> |
81 | | - <td class={styles().bodyCellMono}>{column.depth}</td> |
82 | | - <td class={styles().bodyCellMono}> |
83 | | - {column.accessorFn ? '✓' : '○'} |
84 | | - </td> |
85 | | - <td class={styles().bodyCell}> |
86 | | - {getColumnDefSummary(column)} |
87 | | - </td> |
88 | | - </tr> |
89 | | - )} |
90 | | - </For> |
91 | | - </tbody> |
92 | | - </table> |
| 52 | + <Show fallback={<NoTableConnected title={'Columns'} />} when={table()}> |
| 53 | + <div class={styles().panelScroll}> |
| 54 | + <div class={styles().sectionTitle}>Columns ({columns().length})</div> |
| 55 | + <div class={styles().tableWrapper}> |
| 56 | + <table class={styles().rowsTable}> |
| 57 | + <thead> |
| 58 | + <tr> |
| 59 | + <th class={styles().headerCell}>#</th> |
| 60 | + <th class={styles().headerCell}>id</th> |
| 61 | + <th class={styles().headerCell}>depth</th> |
| 62 | + <th class={styles().headerCell}>accessor</th> |
| 63 | + <th class={styles().headerCell}>columnDef</th> |
| 64 | + </tr> |
| 65 | + </thead> |
| 66 | + <tbody> |
| 67 | + <For each={columns()}> |
| 68 | + {(column, index) => ( |
| 69 | + <tr> |
| 70 | + <td class={styles().bodyCellMono}>{index() + 1}</td> |
| 71 | + <td class={styles().bodyCellMono}>{column.id}</td> |
| 72 | + <td class={styles().bodyCellMono}>{column.depth}</td> |
| 73 | + <td class={styles().bodyCellMono}> |
| 74 | + {column.accessorFn ? '✓' : '○'} |
| 75 | + </td> |
| 76 | + <td class={styles().bodyCell}> |
| 77 | + {getColumnDefSummary(column)} |
| 78 | + </td> |
| 79 | + </tr> |
| 80 | + )} |
| 81 | + </For> |
| 82 | + </tbody> |
| 83 | + </table> |
| 84 | + </div> |
93 | 85 | </div> |
94 | | - </div> |
| 86 | + </Show> |
95 | 87 | ) |
96 | 88 | } |
0 commit comments