Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions src/lib/common/MultiSelect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/** @type {string} */
export let tag;

/** @type {{key: string, value: string}[]} */
/** @type {import('$commonTypes').LabelValuePair[]} */
export let options = [];

/** @type {boolean} */
Expand All @@ -24,7 +24,7 @@
export let selectedText = '';

/** @type {string[]} */
export let selectedKeys;
export let selectedLabels;

/** @type {string} */
export let containerClasses = "";
Expand All @@ -51,10 +51,10 @@
/** @type {boolean} */
let showOptionList = false;

/** @type {{key: string, value: string, checked: boolean}[]} */
/** @type {{label: string, value: string, checked: boolean}[]} */
let innerOptions = [];

/** @type {{key: string, value: string, checked: boolean}[]} */
/** @type {{label: string, value: string, checked: boolean}[]} */
let refOptions = [];

/** @type {string} */
Expand All @@ -66,15 +66,15 @@
onMount(() => {
innerOptions = options.map(x => {
return {
key: x.key,
label: x.label,
value: x.value,
checked: false
}
});

refOptions = options.map(x => {
return {
key: x.key,
label: x.label,
value: x.value,
checked: false
}
Expand All @@ -83,22 +83,22 @@

$: {
innerOptions = innerOptions.map(x => {
x.checked = !!selectedKeys?.includes(x.key);
x.checked = !!selectedLabels?.includes(x.label);
return {...x};
});
refOptions = refOptions.map(x => {
x.checked = !!selectedKeys?.includes(x.key);
x.checked = !!selectedLabels?.includes(x.label);
return {...x};
});
changeDisplayText();
}

$: {
if (options.length > refOptions.length) {
const curKeys = refOptions.map(x => x.key);
const newOptions = options.filter(x => !curKeys.includes(x.key)).map(x => {
const curKeys = refOptions.map(x => x.label);
const newOptions = options.filter(x => !curKeys.includes(x.label)).map(x => {
return {
key: x.key,
label: x.label,
value: x.value,
checked: false
};
Expand Down Expand Up @@ -147,14 +147,14 @@
*/
function checkOption(e, option) {
innerOptions = innerOptions.map(x => {
if (x.key == option.key) {
if (x.label == option.label) {
x.checked = e == null ? !x.checked : e.target.checked;
}
return { ...x };
});

refOptions = refOptions.map(x => {
if (x.key == option.key) {
if (x.label == option.label) {
x.checked = e == null ? !x.checked : e.target.checked;
}
return { ...x };
Expand All @@ -178,9 +178,9 @@

/** @param {boolean} checked */
function syncChangesToRef(checked) {
const keys = innerOptions.map(x => x.key);
const keys = innerOptions.map(x => x.label);
refOptions = refOptions.map(x => {
if (keys.includes(x.key)) {
if (keys.includes(x.label)) {
return {
...x,
checked: checked
Expand Down Expand Up @@ -229,7 +229,7 @@

function sendEvent() {
svelteDispatch("select", {
selecteds: refOptions.filter(x => !!x.checked).map(x => ({ key: x.key, value: x.value }))
selecteds: refOptions.filter(x => !!x.checked).map(x => ({ label: x.label, value: x.value }))
});
}

Expand Down Expand Up @@ -343,7 +343,7 @@
/>
</div>
<div class="line-align-center select-name">
{option.value}
{option.label}
</div>
</li>
{/each}
Expand Down
16 changes: 13 additions & 3 deletions src/lib/helpers/types/agentTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,20 @@

/**
* @typedef {Object} AgentUtility
* @property {string} category
* @property {string} name
* @property {boolean} disabled
* @property {import('$commonTypes').NameBase[]} functions
* @property {import('$commonTypes').NameBase[]} templates
* @property {boolean} disabled
* @property {string?} [visibility_expression]
* @property {UtilityItem[]} items
*/

/**
* @typedef {Object} UtilityItem
* @property {string?} [function_name]
* @property {string?} [function_display_name]
* @property {string?} [template_name]
* @property {string?} [template_display_name]
* @property {string?} [visibility_expression]
*/

/**
Expand Down
6 changes: 6 additions & 0 deletions src/lib/helpers/types/commonTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
* @property {string} name - The name.
*/

/**
* @typedef {Object} LabelValuePair
* @property {string} label - The label.
* @property {string} value - The value.
*/

/**
* @template T
* @typedef {Object} PagedItems<T>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/helpers/utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export function formatObject(object) {


/**
* @param {string?} str
* @param {string?} prefix
* @param {string | null | undefined} str
* @param {string | null | undefined} prefix
*/
export function truncateByPrefix(str, prefix) {
if (!str || !prefix) {
Expand Down
18 changes: 10 additions & 8 deletions src/routes/page/agent/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@
/** @type {any} */
let unsubscriber;

/** @type {import('$commonTypes').LabelValuePair[]} */
const agentTypeOptions = Object.entries(AgentType).map(([k, v]) => (
{ key: v, value: v }
));
{ label: v, value: v }
)).sort((a, b) => a.label.localeCompare(b.label));

/** @type {{ key: string, value: string }[]} */
/** @type {import('$commonTypes').LabelValuePair[]} */
let agentLabelOptions = [];

/** @type {string[]} */
Expand Down Expand Up @@ -91,7 +92,7 @@

function getAgentLabelOptions() {
return getAgentLabels().then(res => {
agentLabelOptions = res?.map(x => ({ key: x, value: x })) || [];
agentLabelOptions = res?.map(x => ({ label: x, value: x })) || [];
}).catch(() => {
agentLabelOptions = [];
});
Expand Down Expand Up @@ -166,13 +167,13 @@
/** @param {any} e */
function selectAgentTypeOption(e) {
// @ts-ignore
selectedAgentTypes = e.detail.selecteds?.map(x => x.key) || [];
selectedAgentTypes = e.detail.selecteds?.map(x => x.label) || [];
}

/** @param {any} e */
function selectAgentLabelOption(e) {
// @ts-ignore
selectedAgentLabels = e.detail.selecteds?.map(x => x.key) || [];
selectedAgentLabels = e.detail.selecteds?.map(x => x.label) || [];
}

function search() {
Expand Down Expand Up @@ -221,15 +222,16 @@
placeholder={'Select labels'}
selectedText={'labels'}
searchMode
selectedKeys={selectedAgentLabels}
selectedLabels={selectedAgentLabels}
options={agentLabelOptions}
on:select={e => selectAgentLabelOption(e)}
/>
<MultiSelect
tag={'agent-type-select'}
placeholder={'Select types'}
selectedText={'types'}
selectedKeys={selectedAgentTypes}
searchMode
selectedLabels={selectedAgentTypes}
options={agentTypeOptions}
on:select={e => selectAgentTypeOption(e)}
/>
Expand Down
Loading