1+ <script >
2+ import { Button } from " @sveltestrap/sveltestrap" ;
3+ import { fly } from ' svelte/transition' ;
4+ import Loader from " $lib/common/Loader.svelte" ;
5+ import JSONTree from ' svelte-json-tree' ;
6+ import { formatObject , splitTextByCase } from " $lib/helpers/utils/common" ;
7+
8+ /** @type {any} */
9+ export let item;
10+
11+ /** @type {import('$commonTypes').TableItemConfig[]} */
12+ export let columns;
13+
14+ /** @type {string | null} */
15+ export let detailKey = null ;
16+
17+ /** @type {boolean} */
18+ export let useJsonDisplay = false ;
19+
20+ /** @type {boolean} */
21+ export let open = false ;
22+
23+ let isLoading = false ;
24+ let loadMore = false ;
25+
26+ $: {
27+ if (! open) {
28+ loadMore = false ;
29+ }
30+ }
31+
32+ function toggleDetail () {
33+ open = ! open;
34+ }
35+ </script >
36+
37+ {#if isLoading }
38+ <Loader />
39+ {/if }
40+
41+ <tr in:fly ={{ y : - 5 , duration : 800 }}>
42+ {#if columns ?.length > 0 }
43+ {#each columns as column , idx (idx )}
44+ <td style ={` max-width: 50px; width: ${80 / columns .length }%; ` }>
45+ <div class ="ellipsis" >{item [column .dataName ] || ' ' }</div >
46+ </td >
47+ {/each }
48+ {/if }
49+ <td class =" knowledge-op" >
50+ <ul class =" list-unstyled hstack gap-1 mb-0 knowledge-op-list" >
51+ {#if detailKey }
52+ <li data-bs-toggle =" tooltip" data-bs-placement =" top" title =" View Detail" >
53+ <Button
54+ class =" btn btn-sm btn-soft-primary"
55+ on:click ={() => toggleDetail ()}
56+ >
57+ {#if open }
58+ <i class =" bx bx-hide" />
59+ {:else }
60+ <i class =" mdi mdi-eye-outline" />
61+ {/if }
62+ </Button >
63+ </li >
64+ {/if }
65+ </ul >
66+ </td >
67+ </tr >
68+
69+ {#if open }
70+ <tr in:fly ={{ y : - 5 , duration : 800 }} out:fly ={{ y : - 5 , duration : 300 }}>
71+ <td colspan =" 12" >
72+ <div class =" knowledge-detail" >
73+ <ul >
74+ {#each columns as column , idx (idx )}
75+ <li >
76+ <div class =" wrappable fw-bold text-primary" >
77+ {column .displayName || column .dataName }
78+ </div >
79+ <div class =" wrappable" >
80+ {item [column .dataName ] || ' ' }
81+ </div >
82+ </li >
83+ {/each }
84+ </ul >
85+ <div class =" more-detail" >
86+ <Button class ='toggle-btn btn-sm' color ="link" on:click ={() => loadMore = ! loadMore }>
87+ {` ${loadMore ? ' Less -' : ' More +' } ` }
88+ </Button >
89+ </div >
90+ {#if loadMore }
91+ <ul
92+ class =" more-detail-list text-secondary"
93+ in:fly ={{ y : - 5 , duration : 300 }}
94+ out:fly ={{ y : - 5 , duration : 200 }}
95+ >
96+ {#if detailKey && item [detailKey ]}
97+ {#if useJsonDisplay }
98+ <JSONTree
99+ value ={formatObject (item [detailKey ])}
100+ defaultExpandedLevel ={1 }
101+ --json-tree-number-color =" var(--bs-info)"
102+ --json-tree-boolean-color =" var(--bs-info)"
103+ --json-tree-string-color =" var(--bs-info)"
104+ />
105+ {:else }
106+ {#each Object .keys (item [detailKey ]) as key , idx (idx )}
107+ <li class =" more-detail-item wrappable" >
108+ <span >{splitTextByCase (key )}: </span >
109+ <span >{item [detailKey ][key ]}</span >
110+ </li >
111+ {/each }
112+ {/if }
113+ {/if }
114+ </ul >
115+ {/if }
116+ </div >
117+ </td >
118+ </tr >
119+ {/if }
0 commit comments