dsh-solution-ledger 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +139 -2
- package/cordis.patch.yml +16 -0
- package/icon.svg +11 -0
- package/lib/client.js +617 -0
- package/lib/index.js +700 -0
- package/lib/search.js +206 -0
- package/lib/store.js +222 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +37 -4
package/lib/client.js
ADDED
|
@@ -0,0 +1,617 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Solution ledger settings page.
|
|
3
|
+
*
|
|
4
|
+
* The store lives in a Host-side JSON file, so this page is a thin client over
|
|
5
|
+
* the three routes the Host half registers: list, update, delete. Everything it
|
|
6
|
+
* renders comes from those responses, and every control writes back through
|
|
7
|
+
* them, which keeps one source of truth on disk.
|
|
8
|
+
*/
|
|
9
|
+
window.__ModuleLoader__.load({
|
|
10
|
+
id: 'dsh-solution-ledger',
|
|
11
|
+
factory(require) {
|
|
12
|
+
const React = require('react')
|
|
13
|
+
const h = React.createElement
|
|
14
|
+
|
|
15
|
+
const NS = 'solutionLedger'
|
|
16
|
+
/** Sidebar panel id; also the `main` panel key it pairs with. */
|
|
17
|
+
const PANEL_ID = 'solution-ledger'
|
|
18
|
+
const LIST_URL = '/solution-ledger/list'
|
|
19
|
+
const UPDATE_URL = '/solution-ledger/update'
|
|
20
|
+
const DELETE_URL = '/solution-ledger/delete'
|
|
21
|
+
|
|
22
|
+
const KINDS = ['troubleshoot', 'decision']
|
|
23
|
+
const DOMAINS = ['environment', 'tooling', 'code', 'config', 'process', 'other']
|
|
24
|
+
const STATUSES = ['draft', 'confirmed', 'deprecated']
|
|
25
|
+
|
|
26
|
+
const zh = {
|
|
27
|
+
nav: '问题账本',
|
|
28
|
+
close: '关闭',
|
|
29
|
+
intro: '跨会话积累的问题与取舍。确认过的条目才会在工具报错时自动带出。',
|
|
30
|
+
search: '搜索标题、解法或标签',
|
|
31
|
+
all: '全部',
|
|
32
|
+
kind: '类型',
|
|
33
|
+
status: '状态',
|
|
34
|
+
total: '总条数',
|
|
35
|
+
draftCount: '待确认',
|
|
36
|
+
confirmedCount: '已确认',
|
|
37
|
+
archivedCount: '已归档',
|
|
38
|
+
empty: '账本还是空的。遇到问题并解决后,让我用 solution_log 记一条。',
|
|
39
|
+
noMatch: '没有匹配的条目。',
|
|
40
|
+
loading: '读取中…',
|
|
41
|
+
loadFailed: '读取失败',
|
|
42
|
+
saveFailed: '保存失败',
|
|
43
|
+
confirm: '确认',
|
|
44
|
+
unconfirm: '退回草稿',
|
|
45
|
+
deprecate: '弃用',
|
|
46
|
+
restore: '恢复',
|
|
47
|
+
archive: '归档',
|
|
48
|
+
unarchive: '取消归档',
|
|
49
|
+
remove: '删除',
|
|
50
|
+
removeAsk: '确定删除这条记录?删除后无法恢复。',
|
|
51
|
+
expand: '展开',
|
|
52
|
+
collapse: '收起',
|
|
53
|
+
fields: {
|
|
54
|
+
title: '标题',
|
|
55
|
+
problem: '问题 / 症状',
|
|
56
|
+
resolution: '解法 / 选择',
|
|
57
|
+
rejected: '否决的方案',
|
|
58
|
+
verify: '怎么验证',
|
|
59
|
+
tags: '标签(逗号分隔)',
|
|
60
|
+
},
|
|
61
|
+
kindLabel: { troubleshoot: '踩坑', decision: '取舍' },
|
|
62
|
+
statusLabel: { draft: '草稿', confirmed: '已确认', deprecated: '已弃用' },
|
|
63
|
+
domainLabel: {
|
|
64
|
+
environment: '环境',
|
|
65
|
+
tooling: '工具',
|
|
66
|
+
code: '代码',
|
|
67
|
+
config: '配置',
|
|
68
|
+
process: '流程',
|
|
69
|
+
other: '其他',
|
|
70
|
+
},
|
|
71
|
+
hits: '命中',
|
|
72
|
+
store: '存储位置',
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const en = {
|
|
76
|
+
nav: 'Solution ledger',
|
|
77
|
+
close: 'Close',
|
|
78
|
+
intro: 'Problems and decisions accumulated across sessions. Only confirmed entries are surfaced automatically when a tool fails.',
|
|
79
|
+
search: 'Search titles, resolutions, or tags',
|
|
80
|
+
all: 'All',
|
|
81
|
+
kind: 'Kind',
|
|
82
|
+
status: 'Status',
|
|
83
|
+
total: 'Total',
|
|
84
|
+
draftCount: 'Awaiting',
|
|
85
|
+
confirmedCount: 'Confirmed',
|
|
86
|
+
archivedCount: 'Archived',
|
|
87
|
+
empty: 'The ledger is empty. After solving a problem, ask me to record it with solution_log.',
|
|
88
|
+
noMatch: 'No matching entries.',
|
|
89
|
+
loading: 'Loading…',
|
|
90
|
+
loadFailed: 'Load failed',
|
|
91
|
+
saveFailed: 'Save failed',
|
|
92
|
+
confirm: 'Confirm',
|
|
93
|
+
unconfirm: 'Back to draft',
|
|
94
|
+
deprecate: 'Deprecate',
|
|
95
|
+
restore: 'Restore',
|
|
96
|
+
archive: 'Archive',
|
|
97
|
+
unarchive: 'Unarchive',
|
|
98
|
+
remove: 'Delete',
|
|
99
|
+
removeAsk: 'Delete this entry? This cannot be undone.',
|
|
100
|
+
expand: 'Expand',
|
|
101
|
+
collapse: 'Collapse',
|
|
102
|
+
fields: {
|
|
103
|
+
title: 'Title',
|
|
104
|
+
problem: 'Problem',
|
|
105
|
+
resolution: 'Resolution',
|
|
106
|
+
rejected: 'Rejected approach',
|
|
107
|
+
verify: 'How to verify',
|
|
108
|
+
tags: 'Tags (comma separated)',
|
|
109
|
+
},
|
|
110
|
+
kindLabel: { troubleshoot: 'Troubleshoot', decision: 'Decision' },
|
|
111
|
+
statusLabel: { draft: 'Draft', confirmed: 'Confirmed', deprecated: 'Deprecated' },
|
|
112
|
+
domainLabel: {
|
|
113
|
+
environment: 'Environment',
|
|
114
|
+
tooling: 'Tooling',
|
|
115
|
+
code: 'Code',
|
|
116
|
+
config: 'Config',
|
|
117
|
+
process: 'Process',
|
|
118
|
+
other: 'Other',
|
|
119
|
+
},
|
|
120
|
+
hits: 'Hits',
|
|
121
|
+
store: 'Store',
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const CSS = [
|
|
125
|
+
// A `main` panel owns its own scroll box: the frame gives it a bounded
|
|
126
|
+
// height and does not scroll it. The two clearance variables keep the
|
|
127
|
+
// first row out from under the frame's floating top/leading controls.
|
|
128
|
+
'.dsl-page{display:flex;flex-direction:column;gap:12px;box-sizing:border-box;height:100%;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:calc(24px + var(--dsh-frame-top-clearance,0px)) 28px 24px max(28px,var(--dsh-frame-leading-clearance,0px))}',
|
|
129
|
+
'.dsl-intro{color:var(--dsw-alias-label-secondary);font-size:13px;line-height:20px;margin:0}',
|
|
130
|
+
'.dsl-bar{display:flex;align-items:center;gap:8px;flex-wrap:wrap}',
|
|
131
|
+
'.dsl-input{box-sizing:border-box;flex:1;min-width:180px;height:32px;padding:0 10px;border-radius:var(--dsw-radius-md);border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font-family:inherit;font-size:13px}',
|
|
132
|
+
'.dsl-input:focus{outline:none;border-color:var(--dsw-alias-brand-primary)}',
|
|
133
|
+
'.dsl-select{box-sizing:border-box;height:32px;padding:0 8px;border-radius:var(--dsw-radius-md);border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font-family:inherit;font-size:13px;cursor:pointer}',
|
|
134
|
+
'.dsl-stats{display:flex;align-items:center;gap:10px;flex-wrap:wrap;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px}',
|
|
135
|
+
'.dsl-dot{width:4px;height:4px;border-radius:50%;background:var(--dsw-alias-label-secondary);opacity:.5}',
|
|
136
|
+
'.dsl-list{display:flex;flex-direction:column;gap:8px}',
|
|
137
|
+
'.dsl-item{background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l1);border-radius:var(--dsw-radius-md);box-sizing:border-box;overflow:hidden}',
|
|
138
|
+
'.dsl-itemArchived{opacity:.62}',
|
|
139
|
+
'.dsl-itemHead{display:flex;align-items:flex-start;gap:10px;padding:12px 14px;cursor:pointer}',
|
|
140
|
+
'.dsl-itemHead:hover{background:var(--dsw-alias-interactive-bg-hover)}',
|
|
141
|
+
'.dsl-itemMain{flex:1;min-width:0}',
|
|
142
|
+
'.dsl-title{color:var(--dsw-alias-label-primary);font-size:13px;font-weight:500;line-height:20px;word-break:break-word}',
|
|
143
|
+
'.dsl-meta{display:flex;align-items:center;gap:6px;flex-wrap:wrap;margin-top:5px}',
|
|
144
|
+
'.dsl-badge{box-sizing:border-box;display:inline-flex;align-items:center;height:19px;padding:0 6px;border-radius:4px;font-size:11px;line-height:1;border:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);white-space:nowrap}',
|
|
145
|
+
'.dsl-badgeDraft{border-color:var(--dsw-alias-state-warning-primary,#c08a1e);color:var(--dsw-alias-state-warning-primary,#c08a1e)}',
|
|
146
|
+
'.dsl-badgeConfirmed{border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-brand-primary)}',
|
|
147
|
+
'.dsl-badgeDeprecated{opacity:.7}',
|
|
148
|
+
'.dsl-tags{color:var(--dsw-alias-label-secondary);font-size:11px;line-height:18px}',
|
|
149
|
+
'.dsl-chevron{flex:none;color:var(--dsw-alias-label-secondary);font-size:11px;padding-top:2px;user-select:none}',
|
|
150
|
+
'.dsl-body{display:flex;flex-direction:column;gap:10px;padding:0 14px 14px;border-top:1px solid var(--dsw-alias-border-l1)}',
|
|
151
|
+
'.dsl-field{display:flex;flex-direction:column;gap:4px;margin-top:10px}',
|
|
152
|
+
'.dsl-label{color:var(--dsw-alias-label-secondary);font-size:11px;line-height:16px}',
|
|
153
|
+
'.dsl-textarea{box-sizing:border-box;width:100%;min-height:56px;padding:7px 9px;border-radius:var(--dsw-radius-md);border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font-family:inherit;font-size:12px;line-height:18px;resize:vertical}',
|
|
154
|
+
'.dsl-textarea:focus{outline:none;border-color:var(--dsw-alias-brand-primary)}',
|
|
155
|
+
'.dsl-actions{display:flex;align-items:center;gap:6px;flex-wrap:wrap;margin-top:12px}',
|
|
156
|
+
'.dsl-btn{box-sizing:border-box;display:inline-flex;align-items:center;height:28px;padding:0 10px;border-radius:var(--dsw-radius-md);border:1px solid var(--dsw-alias-border-l1);background:transparent;color:var(--dsw-alias-label-primary);font-family:inherit;font-size:12px;line-height:18px;cursor:pointer}',
|
|
157
|
+
'.dsl-btn:hover{background:var(--dsw-alias-interactive-bg-hover)}',
|
|
158
|
+
'.dsl-btn:disabled{opacity:.45;cursor:default}',
|
|
159
|
+
'.dsl-btnPrimary{border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-brand-primary)}',
|
|
160
|
+
'.dsl-btnDanger{border-color:var(--dsw-alias-state-error-primary,#c0392b);color:var(--dsw-alias-state-error-primary,#c0392b)}',
|
|
161
|
+
'.dsl-empty{color:var(--dsw-alias-label-secondary);font-size:13px;line-height:20px;padding:18px 0}',
|
|
162
|
+
'.dsl-foot{display:flex;align-items:center;gap:6px;color:var(--dsw-alias-label-secondary);font-size:11px;line-height:18px;word-break:break-all}',
|
|
163
|
+
'.dsl-footErr{color:var(--dsw-alias-state-error-primary,#c0392b)}',
|
|
164
|
+
'.dsl-panelIcon{display:block}',
|
|
165
|
+
].join('\n')
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* The sidebar entry. `sidebar.panellist` pairs each list id with the `main`
|
|
169
|
+
* panel of the same id, so this component only draws the glyph: the owner
|
|
170
|
+
* supplies the button, its tooltip, and the selected state.
|
|
171
|
+
* @param props - `{ size, active }` from the panel row.
|
|
172
|
+
* @returns the icon element.
|
|
173
|
+
*/
|
|
174
|
+
function PanelIcon(props) {
|
|
175
|
+
const size = typeof props.size === 'number' && props.size > 0 ? props.size : 20
|
|
176
|
+
return h(
|
|
177
|
+
'svg',
|
|
178
|
+
{
|
|
179
|
+
className: 'dsl-panelIcon',
|
|
180
|
+
width: size,
|
|
181
|
+
height: size,
|
|
182
|
+
viewBox: '0 0 24 24',
|
|
183
|
+
fill: 'none',
|
|
184
|
+
'aria-hidden': true,
|
|
185
|
+
style: { opacity: props.active ? 1 : 0.82 },
|
|
186
|
+
},
|
|
187
|
+
h('rect', {
|
|
188
|
+
x: 3.5,
|
|
189
|
+
y: 3.5,
|
|
190
|
+
width: 17,
|
|
191
|
+
height: 17,
|
|
192
|
+
rx: 4,
|
|
193
|
+
stroke: 'currentColor',
|
|
194
|
+
strokeWidth: 1.6,
|
|
195
|
+
}),
|
|
196
|
+
h('path', {
|
|
197
|
+
d: 'M7.5 9h9M7.5 12.5h6.5M7.5 16h8',
|
|
198
|
+
stroke: 'currentColor',
|
|
199
|
+
strokeWidth: 1.6,
|
|
200
|
+
strokeLinecap: 'round',
|
|
201
|
+
}),
|
|
202
|
+
)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Read a JSON answer without assuming the body is JSON.
|
|
207
|
+
* @param response - the fetch response.
|
|
208
|
+
* @returns the parsed payload, or an explicit error object.
|
|
209
|
+
*/
|
|
210
|
+
async function readAnswer(response) {
|
|
211
|
+
const text = await response.text()
|
|
212
|
+
if (text.trim().length === 0) {
|
|
213
|
+
return {
|
|
214
|
+
ok: false,
|
|
215
|
+
error:
|
|
216
|
+
response.status === 404
|
|
217
|
+
? 'route not found — the plugin host half is not loaded'
|
|
218
|
+
: `empty response (HTTP ${response.status})`,
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
try {
|
|
222
|
+
return JSON.parse(text)
|
|
223
|
+
} catch {
|
|
224
|
+
return { ok: false, error: `not JSON (HTTP ${response.status})` }
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* One editable text field that saves on blur when it actually changed.
|
|
230
|
+
*/
|
|
231
|
+
function Field(props) {
|
|
232
|
+
const [draft, setDraft] = React.useState(props.value)
|
|
233
|
+
React.useEffect(() => setDraft(props.value), [props.value])
|
|
234
|
+
return h(
|
|
235
|
+
'label',
|
|
236
|
+
{ className: 'dsl-field' },
|
|
237
|
+
h('span', { className: 'dsl-label' }, props.label),
|
|
238
|
+
h('textarea', {
|
|
239
|
+
className: 'dsl-textarea',
|
|
240
|
+
value: draft,
|
|
241
|
+
rows: props.rows ?? 2,
|
|
242
|
+
disabled: props.disabled === true,
|
|
243
|
+
onChange: (event) => setDraft(event.target.value),
|
|
244
|
+
onBlur: () => {
|
|
245
|
+
if (draft !== props.value) props.onCommit(draft)
|
|
246
|
+
},
|
|
247
|
+
}),
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* The ledger page.
|
|
253
|
+
* @param props - slot props carrying the bound translator.
|
|
254
|
+
* @returns the page tree.
|
|
255
|
+
*/
|
|
256
|
+
function LedgerPage(props) {
|
|
257
|
+
const t = props.t
|
|
258
|
+
const [snapshot, setSnapshot] = React.useState({
|
|
259
|
+
phase: 'loading',
|
|
260
|
+
entries: [],
|
|
261
|
+
stats: null,
|
|
262
|
+
storePath: '',
|
|
263
|
+
error: null,
|
|
264
|
+
})
|
|
265
|
+
const [query, setQuery] = React.useState('')
|
|
266
|
+
const [kindFilter, setKindFilter] = React.useState('all')
|
|
267
|
+
const [statusFilter, setStatusFilter] = React.useState('all')
|
|
268
|
+
const [openId, setOpenId] = React.useState(null)
|
|
269
|
+
const [notice, setNotice] = React.useState(null)
|
|
270
|
+
|
|
271
|
+
const load = React.useCallback(async () => {
|
|
272
|
+
try {
|
|
273
|
+
const response = await fetch(LIST_URL, { headers: { Accept: 'application/json' } })
|
|
274
|
+
const answer = await readAnswer(response)
|
|
275
|
+
if (answer.ok !== true) throw new Error(answer.error ?? 'unavailable')
|
|
276
|
+
setSnapshot({
|
|
277
|
+
phase: 'ready',
|
|
278
|
+
entries: Array.isArray(answer.entries) ? answer.entries : [],
|
|
279
|
+
stats: answer.stats ?? null,
|
|
280
|
+
storePath: typeof answer.storePath === 'string' ? answer.storePath : '',
|
|
281
|
+
error: null,
|
|
282
|
+
})
|
|
283
|
+
} catch (error) {
|
|
284
|
+
setSnapshot((current) => ({ ...current, phase: 'failed', error: String(error) }))
|
|
285
|
+
}
|
|
286
|
+
}, [])
|
|
287
|
+
|
|
288
|
+
React.useEffect(() => {
|
|
289
|
+
void load()
|
|
290
|
+
}, [load])
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Send one patch and fold the answer back into the list.
|
|
294
|
+
* @param id - target entry id.
|
|
295
|
+
* @param patch - changed fields.
|
|
296
|
+
*/
|
|
297
|
+
const update = async (id, patch) => {
|
|
298
|
+
setNotice(null)
|
|
299
|
+
try {
|
|
300
|
+
const response = await fetch(UPDATE_URL, {
|
|
301
|
+
method: 'POST',
|
|
302
|
+
headers: { 'Content-Type': 'application/json' },
|
|
303
|
+
body: JSON.stringify({ id, patch }),
|
|
304
|
+
})
|
|
305
|
+
const answer = await readAnswer(response)
|
|
306
|
+
if (answer.ok !== true) throw new Error(answer.error ?? 'rejected')
|
|
307
|
+
setSnapshot((current) => ({
|
|
308
|
+
...current,
|
|
309
|
+
entries: current.entries.map((entry) => (entry.id === id ? answer.entry : entry)),
|
|
310
|
+
}))
|
|
311
|
+
void load()
|
|
312
|
+
} catch (error) {
|
|
313
|
+
setNotice({ text: `${t('saveFailed')}: ${String(error)}`, failed: true })
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Delete one entry after the browser confirms.
|
|
319
|
+
* @param id - target entry id.
|
|
320
|
+
*/
|
|
321
|
+
const remove = async (id) => {
|
|
322
|
+
if (typeof window !== 'undefined' && !window.confirm(t('removeAsk'))) return
|
|
323
|
+
setNotice(null)
|
|
324
|
+
try {
|
|
325
|
+
const response = await fetch(DELETE_URL, {
|
|
326
|
+
method: 'POST',
|
|
327
|
+
headers: { 'Content-Type': 'application/json' },
|
|
328
|
+
body: JSON.stringify({ ids: [id] }),
|
|
329
|
+
})
|
|
330
|
+
const answer = await readAnswer(response)
|
|
331
|
+
if (answer.ok !== true) throw new Error(answer.error ?? 'rejected')
|
|
332
|
+
setSnapshot((current) => ({ ...current, entries: current.entries.filter((entry) => entry.id !== id) }))
|
|
333
|
+
if (openId === id) setOpenId(null)
|
|
334
|
+
void load()
|
|
335
|
+
} catch (error) {
|
|
336
|
+
setNotice({ text: `${t('saveFailed')}: ${String(error)}`, failed: true })
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const needle = query.trim().toLowerCase()
|
|
341
|
+
const visible = snapshot.entries.filter((entry) => {
|
|
342
|
+
if (kindFilter !== 'all' && entry.kind !== kindFilter) return false
|
|
343
|
+
if (statusFilter !== 'all' && entry.status !== statusFilter) return false
|
|
344
|
+
if (needle.length === 0) return true
|
|
345
|
+
const haystack = [entry.title, entry.problem, entry.resolution, entry.rejected, entry.tags.join(' ')]
|
|
346
|
+
.join(' ')
|
|
347
|
+
.toLowerCase()
|
|
348
|
+
return haystack.includes(needle)
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
const stats = snapshot.stats
|
|
352
|
+
const summary = []
|
|
353
|
+
if (stats !== null) {
|
|
354
|
+
summary.push(`${t('total')} ${stats.total}`)
|
|
355
|
+
if (stats.draft > 0) summary.push(`${t('draftCount')} ${stats.draft}`)
|
|
356
|
+
if (stats.confirmed > 0) summary.push(`${t('confirmedCount')} ${stats.confirmed}`)
|
|
357
|
+
if (stats.archived > 0) summary.push(`${t('archivedCount')} ${stats.archived}`)
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const rows = visible.map((entry) => {
|
|
361
|
+
const open = openId === entry.id
|
|
362
|
+
const statusClass =
|
|
363
|
+
entry.status === 'confirmed'
|
|
364
|
+
? ' dsl-badgeConfirmed'
|
|
365
|
+
: entry.status === 'draft'
|
|
366
|
+
? ' dsl-badgeDraft'
|
|
367
|
+
: ' dsl-badgeDeprecated'
|
|
368
|
+
const badges = [
|
|
369
|
+
h('span', { key: 'kind', className: 'dsl-badge' }, t(`kindLabel.${entry.kind}`)),
|
|
370
|
+
h('span', { key: 'domain', className: 'dsl-badge' }, t(`domainLabel.${entry.domain}`)),
|
|
371
|
+
h('span', { key: 'status', className: `dsl-badge${statusClass}` }, t(`statusLabel.${entry.status}`)),
|
|
372
|
+
]
|
|
373
|
+
if (entry.archived) badges.push(h('span', { key: 'arch', className: 'dsl-badge' }, t('archive')))
|
|
374
|
+
if (entry.hits > 0) badges.push(h('span', { key: 'hits', className: 'dsl-badge' }, `${t('hits')} ${entry.hits}`))
|
|
375
|
+
|
|
376
|
+
return h(
|
|
377
|
+
'div',
|
|
378
|
+
{ key: entry.id, className: 'dsl-item' + (entry.archived ? ' dsl-itemArchived' : '') },
|
|
379
|
+
h(
|
|
380
|
+
'div',
|
|
381
|
+
{
|
|
382
|
+
className: 'dsl-itemHead',
|
|
383
|
+
role: 'button',
|
|
384
|
+
tabIndex: 0,
|
|
385
|
+
'aria-expanded': open,
|
|
386
|
+
onClick: () => setOpenId(open ? null : entry.id),
|
|
387
|
+
onKeyDown: (event) => {
|
|
388
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
389
|
+
event.preventDefault()
|
|
390
|
+
setOpenId(open ? null : entry.id)
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
h(
|
|
395
|
+
'div',
|
|
396
|
+
{ className: 'dsl-itemMain' },
|
|
397
|
+
h('div', { className: 'dsl-title' }, entry.title),
|
|
398
|
+
h('div', { className: 'dsl-meta' }, badges),
|
|
399
|
+
entry.tags.length > 0 ? h('div', { className: 'dsl-tags' }, entry.tags.join(' · ')) : null,
|
|
400
|
+
),
|
|
401
|
+
h('span', { className: 'dsl-chevron' }, open ? '▾' : '▸'),
|
|
402
|
+
),
|
|
403
|
+
open
|
|
404
|
+
? h(
|
|
405
|
+
'div',
|
|
406
|
+
{ className: 'dsl-body' },
|
|
407
|
+
h(Field, {
|
|
408
|
+
label: t('fields.title'),
|
|
409
|
+
value: entry.title,
|
|
410
|
+
rows: 1,
|
|
411
|
+
onCommit: (value) => update(entry.id, { title: value }),
|
|
412
|
+
}),
|
|
413
|
+
h(Field, {
|
|
414
|
+
label: t('fields.problem'),
|
|
415
|
+
value: entry.problem,
|
|
416
|
+
onCommit: (value) => update(entry.id, { problem: value }),
|
|
417
|
+
}),
|
|
418
|
+
h(Field, {
|
|
419
|
+
label: t('fields.resolution'),
|
|
420
|
+
value: entry.resolution,
|
|
421
|
+
rows: 4,
|
|
422
|
+
onCommit: (value) => update(entry.id, { resolution: value }),
|
|
423
|
+
}),
|
|
424
|
+
entry.kind === 'decision' || entry.rejected.length > 0
|
|
425
|
+
? h(Field, {
|
|
426
|
+
label: t('fields.rejected'),
|
|
427
|
+
value: entry.rejected,
|
|
428
|
+
onCommit: (value) => update(entry.id, { rejected: value }),
|
|
429
|
+
})
|
|
430
|
+
: null,
|
|
431
|
+
h(Field, {
|
|
432
|
+
label: t('fields.verify'),
|
|
433
|
+
value: entry.verify,
|
|
434
|
+
onCommit: (value) => update(entry.id, { verify: value }),
|
|
435
|
+
}),
|
|
436
|
+
h(Field, {
|
|
437
|
+
label: t('fields.tags'),
|
|
438
|
+
value: entry.tags.join(', '),
|
|
439
|
+
rows: 1,
|
|
440
|
+
onCommit: (value) =>
|
|
441
|
+
update(entry.id, {
|
|
442
|
+
tags: value
|
|
443
|
+
.split(',')
|
|
444
|
+
.map((tag) => tag.trim())
|
|
445
|
+
.filter((tag) => tag.length > 0),
|
|
446
|
+
}),
|
|
447
|
+
}),
|
|
448
|
+
h(
|
|
449
|
+
'div',
|
|
450
|
+
{ className: 'dsl-actions' },
|
|
451
|
+
entry.status === 'confirmed'
|
|
452
|
+
? h(
|
|
453
|
+
'button',
|
|
454
|
+
{
|
|
455
|
+
type: 'button',
|
|
456
|
+
className: 'dsl-btn',
|
|
457
|
+
onClick: () => update(entry.id, { status: 'draft' }),
|
|
458
|
+
},
|
|
459
|
+
t('unconfirm'),
|
|
460
|
+
)
|
|
461
|
+
: h(
|
|
462
|
+
'button',
|
|
463
|
+
{
|
|
464
|
+
type: 'button',
|
|
465
|
+
className: 'dsl-btn dsl-btnPrimary',
|
|
466
|
+
onClick: () => update(entry.id, { status: 'confirmed' }),
|
|
467
|
+
},
|
|
468
|
+
t('confirm'),
|
|
469
|
+
),
|
|
470
|
+
entry.status === 'deprecated'
|
|
471
|
+
? h(
|
|
472
|
+
'button',
|
|
473
|
+
{
|
|
474
|
+
type: 'button',
|
|
475
|
+
className: 'dsl-btn',
|
|
476
|
+
onClick: () => update(entry.id, { status: 'draft' }),
|
|
477
|
+
},
|
|
478
|
+
t('restore'),
|
|
479
|
+
)
|
|
480
|
+
: h(
|
|
481
|
+
'button',
|
|
482
|
+
{
|
|
483
|
+
type: 'button',
|
|
484
|
+
className: 'dsl-btn',
|
|
485
|
+
onClick: () => update(entry.id, { status: 'deprecated' }),
|
|
486
|
+
},
|
|
487
|
+
t('deprecate'),
|
|
488
|
+
),
|
|
489
|
+
h(
|
|
490
|
+
'button',
|
|
491
|
+
{
|
|
492
|
+
type: 'button',
|
|
493
|
+
className: 'dsl-btn',
|
|
494
|
+
onClick: () => update(entry.id, { archived: !entry.archived }),
|
|
495
|
+
},
|
|
496
|
+
entry.archived ? t('unarchive') : t('archive'),
|
|
497
|
+
),
|
|
498
|
+
h(
|
|
499
|
+
'button',
|
|
500
|
+
{
|
|
501
|
+
type: 'button',
|
|
502
|
+
className: 'dsl-btn dsl-btnDanger',
|
|
503
|
+
onClick: () => void remove(entry.id),
|
|
504
|
+
},
|
|
505
|
+
t('remove'),
|
|
506
|
+
),
|
|
507
|
+
),
|
|
508
|
+
)
|
|
509
|
+
: null,
|
|
510
|
+
)
|
|
511
|
+
})
|
|
512
|
+
|
|
513
|
+
let list = rows
|
|
514
|
+
if (snapshot.phase === 'loading') list = h('div', { className: 'dsl-empty' }, t('loading'))
|
|
515
|
+
else if (snapshot.phase === 'failed') list = h('div', { className: 'dsl-empty' }, `${t('loadFailed')}: ${snapshot.error}`)
|
|
516
|
+
else if (snapshot.entries.length === 0) list = h('div', { className: 'dsl-empty' }, t('empty'))
|
|
517
|
+
else if (rows.length === 0) list = h('div', { className: 'dsl-empty' }, t('noMatch'))
|
|
518
|
+
|
|
519
|
+
return h(
|
|
520
|
+
'div',
|
|
521
|
+
{ className: 'dsl-page' },
|
|
522
|
+
h('p', { className: 'dsl-intro' }, t('intro')),
|
|
523
|
+
h(
|
|
524
|
+
'div',
|
|
525
|
+
{ className: 'dsl-bar' },
|
|
526
|
+
h('input', {
|
|
527
|
+
className: 'dsl-input',
|
|
528
|
+
type: 'search',
|
|
529
|
+
value: query,
|
|
530
|
+
placeholder: t('search'),
|
|
531
|
+
'aria-label': t('search'),
|
|
532
|
+
onChange: (event) => setQuery(event.target.value),
|
|
533
|
+
}),
|
|
534
|
+
h(
|
|
535
|
+
'select',
|
|
536
|
+
{
|
|
537
|
+
className: 'dsl-select',
|
|
538
|
+
value: kindFilter,
|
|
539
|
+
'aria-label': t('kind'),
|
|
540
|
+
onChange: (event) => setKindFilter(event.target.value),
|
|
541
|
+
},
|
|
542
|
+
h('option', { value: 'all' }, `${t('kind')}: ${t('all')}`),
|
|
543
|
+
KINDS.map((kind) => h('option', { key: kind, value: kind }, t(`kindLabel.${kind}`))),
|
|
544
|
+
),
|
|
545
|
+
h(
|
|
546
|
+
'select',
|
|
547
|
+
{
|
|
548
|
+
className: 'dsl-select',
|
|
549
|
+
value: statusFilter,
|
|
550
|
+
'aria-label': t('status'),
|
|
551
|
+
onChange: (event) => setStatusFilter(event.target.value),
|
|
552
|
+
},
|
|
553
|
+
h('option', { value: 'all' }, `${t('status')}: ${t('all')}`),
|
|
554
|
+
STATUSES.map((status) => h('option', { key: status, value: status }, t(`statusLabel.${status}`))),
|
|
555
|
+
),
|
|
556
|
+
),
|
|
557
|
+
summary.length > 0
|
|
558
|
+
? h(
|
|
559
|
+
'div',
|
|
560
|
+
{ className: 'dsl-stats' },
|
|
561
|
+
summary.map((text, index) =>
|
|
562
|
+
index === 0
|
|
563
|
+
? h('span', { key: text }, text)
|
|
564
|
+
: [h('span', { key: `${text}-sep`, className: 'dsl-dot', 'aria-hidden': true }), h('span', { key: text }, text)],
|
|
565
|
+
),
|
|
566
|
+
)
|
|
567
|
+
: null,
|
|
568
|
+
h('div', { className: 'dsl-list' }, list),
|
|
569
|
+
notice === null
|
|
570
|
+
? null
|
|
571
|
+
: h('div', { className: 'dsl-foot' + (notice.failed ? ' dsl-footErr' : '') }, notice.text),
|
|
572
|
+
snapshot.storePath.length > 0
|
|
573
|
+
? h('div', { className: 'dsl-foot' }, `${t('store')}: ${snapshot.storePath}`)
|
|
574
|
+
: null,
|
|
575
|
+
)
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
return {
|
|
579
|
+
inject: ['slots', 'locale'],
|
|
580
|
+
apply(ctx) {
|
|
581
|
+
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'solution-ledger: dictionaries')
|
|
582
|
+
const t = ctx.locale.bind(NS)
|
|
583
|
+
|
|
584
|
+
// `main` carries no translator, so the bound `t` is closed over once and
|
|
585
|
+
// the wrapper identity stays stable across renders.
|
|
586
|
+
function MainPanel(props) {
|
|
587
|
+
return h(LedgerPage, { ...props, t })
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
const styleTag = document.createElement('style')
|
|
591
|
+
styleTag.setAttribute('data-plugin-css', 'dsh-solution-ledger/page')
|
|
592
|
+
styleTag.textContent = CSS
|
|
593
|
+
document.head.appendChild(styleTag)
|
|
594
|
+
ctx.effect(() => () => styleTag.remove(), 'solution-ledger: page styles')
|
|
595
|
+
|
|
596
|
+
// The panel id doubles as the `main` key: the sidebar owns the button
|
|
597
|
+
// and switches the main column to the panel registered under that id.
|
|
598
|
+
ctx.slots.inject('sidebar.panellist', () =>
|
|
599
|
+
ctx.slots.register(
|
|
600
|
+
{
|
|
601
|
+
name: 'sidebar.panellist',
|
|
602
|
+
id: PANEL_ID,
|
|
603
|
+
order: 30,
|
|
604
|
+
label: () => t('nav'),
|
|
605
|
+
locale: NS,
|
|
606
|
+
},
|
|
607
|
+
PanelIcon,
|
|
608
|
+
),
|
|
609
|
+
)
|
|
610
|
+
|
|
611
|
+
ctx.slots.inject('main', () =>
|
|
612
|
+
ctx.slots.register({ name: 'main', key: PANEL_ID }, MainPanel),
|
|
613
|
+
)
|
|
614
|
+
},
|
|
615
|
+
}
|
|
616
|
+
},
|
|
617
|
+
})
|