Skip to content

Commit 4b34bf2

Browse files
authored
Merge pull request #348 from iceljc/features/refine-chat-window
add utility visbility
2 parents 207af80 + 94f07c4 commit 4b34bf2

File tree

6 files changed

+265
-235
lines changed

6 files changed

+265
-235
lines changed

src/lib/common/MultiSelect.svelte

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/** @type {string} */
99
export let tag;
1010
11-
/** @type {{key: string, value: string}[]} */
11+
/** @type {import('$commonTypes').LabelValuePair[]} */
1212
export let options = [];
1313
1414
/** @type {boolean} */
@@ -24,7 +24,7 @@
2424
export let selectedText = '';
2525
2626
/** @type {string[]} */
27-
export let selectedKeys;
27+
export let selectedLabels;
2828
2929
/** @type {string} */
3030
export let containerClasses = "";
@@ -51,10 +51,10 @@
5151
/** @type {boolean} */
5252
let showOptionList = false;
5353
54-
/** @type {{key: string, value: string, checked: boolean}[]} */
54+
/** @type {{label: string, value: string, checked: boolean}[]} */
5555
let innerOptions = [];
5656
57-
/** @type {{key: string, value: string, checked: boolean}[]} */
57+
/** @type {{label: string, value: string, checked: boolean}[]} */
5858
let refOptions = [];
5959
6060
/** @type {string} */
@@ -66,15 +66,15 @@
6666
onMount(() => {
6767
innerOptions = options.map(x => {
6868
return {
69-
key: x.key,
69+
label: x.label,
7070
value: x.value,
7171
checked: false
7272
}
7373
});
7474
7575
refOptions = options.map(x => {
7676
return {
77-
key: x.key,
77+
label: x.label,
7878
value: x.value,
7979
checked: false
8080
}
@@ -83,22 +83,22 @@
8383
8484
$: {
8585
innerOptions = innerOptions.map(x => {
86-
x.checked = !!selectedKeys?.includes(x.key);
86+
x.checked = !!selectedLabels?.includes(x.label);
8787
return {...x};
8888
});
8989
refOptions = refOptions.map(x => {
90-
x.checked = !!selectedKeys?.includes(x.key);
90+
x.checked = !!selectedLabels?.includes(x.label);
9191
return {...x};
9292
});
9393
changeDisplayText();
9494
}
9595
9696
$: {
9797
if (options.length > refOptions.length) {
98-
const curKeys = refOptions.map(x => x.key);
99-
const newOptions = options.filter(x => !curKeys.includes(x.key)).map(x => {
98+
const curKeys = refOptions.map(x => x.label);
99+
const newOptions = options.filter(x => !curKeys.includes(x.label)).map(x => {
100100
return {
101-
key: x.key,
101+
label: x.label,
102102
value: x.value,
103103
checked: false
104104
};
@@ -147,14 +147,14 @@
147147
*/
148148
function checkOption(e, option) {
149149
innerOptions = innerOptions.map(x => {
150-
if (x.key == option.key) {
150+
if (x.label == option.label) {
151151
x.checked = e == null ? !x.checked : e.target.checked;
152152
}
153153
return { ...x };
154154
});
155155
156156
refOptions = refOptions.map(x => {
157-
if (x.key == option.key) {
157+
if (x.label == option.label) {
158158
x.checked = e == null ? !x.checked : e.target.checked;
159159
}
160160
return { ...x };
@@ -178,9 +178,9 @@
178178
179179
/** @param {boolean} checked */
180180
function syncChangesToRef(checked) {
181-
const keys = innerOptions.map(x => x.key);
181+
const keys = innerOptions.map(x => x.label);
182182
refOptions = refOptions.map(x => {
183-
if (keys.includes(x.key)) {
183+
if (keys.includes(x.label)) {
184184
return {
185185
...x,
186186
checked: checked
@@ -229,7 +229,7 @@
229229
230230
function sendEvent() {
231231
svelteDispatch("select", {
232-
selecteds: refOptions.filter(x => !!x.checked).map(x => ({ key: x.key, value: x.value }))
232+
selecteds: refOptions.filter(x => !!x.checked).map(x => ({ label: x.label, value: x.value }))
233233
});
234234
}
235235
@@ -343,7 +343,7 @@
343343
/>
344344
</div>
345345
<div class="line-align-center select-name">
346-
{option.value}
346+
{option.label}
347347
</div>
348348
</li>
349349
{/each}

src/lib/helpers/types/agentTypes.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,20 @@
131131

132132
/**
133133
* @typedef {Object} AgentUtility
134+
* @property {string} category
134135
* @property {string} name
135-
* @property {boolean} disabled
136-
* @property {import('$commonTypes').NameBase[]} functions
137-
* @property {import('$commonTypes').NameBase[]} templates
136+
* @property {boolean} disabled
137+
* @property {string?} [visibility_expression]
138+
* @property {UtilityItem[]} items
139+
*/
140+
141+
/**
142+
* @typedef {Object} UtilityItem
143+
* @property {string?} [function_name]
144+
* @property {string?} [function_display_name]
145+
* @property {string?} [template_name]
146+
* @property {string?} [template_display_name]
147+
* @property {string?} [visibility_expression]
138148
*/
139149

140150
/**

src/lib/helpers/types/commonTypes.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
* @property {string} name - The name.
1818
*/
1919

20+
/**
21+
* @typedef {Object} LabelValuePair
22+
* @property {string} label - The label.
23+
* @property {string} value - The value.
24+
*/
25+
2026
/**
2127
* @template T
2228
* @typedef {Object} PagedItems<T>

src/lib/helpers/utils/common.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ export function formatObject(object) {
5454

5555

5656
/**
57-
* @param {string?} str
58-
* @param {string?} prefix
57+
* @param {string | null | undefined} str
58+
* @param {string | null | undefined} prefix
5959
*/
6060
export function truncateByPrefix(str, prefix) {
6161
if (!str || !prefix) {

src/routes/page/agent/+page.svelte

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@
4343
/** @type {any} */
4444
let unsubscriber;
4545
46+
/** @type {import('$commonTypes').LabelValuePair[]} */
4647
const agentTypeOptions = Object.entries(AgentType).map(([k, v]) => (
47-
{ key: v, value: v }
48-
));
48+
{ label: v, value: v }
49+
)).sort((a, b) => a.label.localeCompare(b.label));
4950
50-
/** @type {{ key: string, value: string }[]} */
51+
/** @type {import('$commonTypes').LabelValuePair[]} */
5152
let agentLabelOptions = [];
5253
5354
/** @type {string[]} */
@@ -91,7 +92,7 @@
9192
9293
function getAgentLabelOptions() {
9394
return getAgentLabels().then(res => {
94-
agentLabelOptions = res?.map(x => ({ key: x, value: x })) || [];
95+
agentLabelOptions = res?.map(x => ({ label: x, value: x })) || [];
9596
}).catch(() => {
9697
agentLabelOptions = [];
9798
});
@@ -166,13 +167,13 @@
166167
/** @param {any} e */
167168
function selectAgentTypeOption(e) {
168169
// @ts-ignore
169-
selectedAgentTypes = e.detail.selecteds?.map(x => x.key) || [];
170+
selectedAgentTypes = e.detail.selecteds?.map(x => x.label) || [];
170171
}
171172
172173
/** @param {any} e */
173174
function selectAgentLabelOption(e) {
174175
// @ts-ignore
175-
selectedAgentLabels = e.detail.selecteds?.map(x => x.key) || [];
176+
selectedAgentLabels = e.detail.selecteds?.map(x => x.label) || [];
176177
}
177178
178179
function search() {
@@ -221,15 +222,16 @@
221222
placeholder={'Select labels'}
222223
selectedText={'labels'}
223224
searchMode
224-
selectedKeys={selectedAgentLabels}
225+
selectedLabels={selectedAgentLabels}
225226
options={agentLabelOptions}
226227
on:select={e => selectAgentLabelOption(e)}
227228
/>
228229
<MultiSelect
229230
tag={'agent-type-select'}
230231
placeholder={'Select types'}
231232
selectedText={'types'}
232-
selectedKeys={selectedAgentTypes}
233+
searchMode
234+
selectedLabels={selectedAgentTypes}
233235
options={agentTypeOptions}
234236
on:select={e => selectAgentTypeOption(e)}
235237
/>

0 commit comments

Comments
 (0)