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
4 changes: 2 additions & 2 deletions src/lib/scss/custom/pages/_agent.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
gap: 15px;
align-items: center;

@media (max-width: 576px) {
@media (max-width: 1024px) {
flex-direction: column;
justify-content: center;
gap: 12px;
Expand All @@ -23,7 +23,7 @@
gap: 10px;
align-items: center;

@media (max-width: 576px) {
@media (max-width: 1024px) {
width: 100%;
flex-direction: column;
gap: 8px;
Expand Down
55 changes: 39 additions & 16 deletions src/routes/page/agent/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@
/** @type {import('$commonTypes').LabelValuePair[]} */
let agentLabelOptions = [];

/** @type {string[]} */
let selectedAgentTypes = [];
/** @type {string[]} */
let selectedAgentLabels = [];
/** @type {{ name: string, types: string[], labels: string[] }} */
let searchItem = {
name: '',
types: [],
labels: []
};

onMount(async () => {
isPageMounted = true;
Expand Down Expand Up @@ -98,8 +100,8 @@
page: firstPage,
count: 0
},
types: selectedAgentTypes?.length > 0 ? selectedAgentTypes : null,
labels: selectedAgentLabels?.length > 0 ? selectedAgentLabels : null,
types: searchItem.types?.length > 0 ? searchItem.types : null,
labels: searchItem.labels?.length > 0 ? searchItem.labels : null,
similarName: event.payload?.trim() || null
};

Expand Down Expand Up @@ -221,17 +223,34 @@

getPagedAgents();
}

/** @param {any} e */
function changeSearchName(e) {
searchItem.name = e.target.value || '';
filter = {
...filter,
similarName: searchItem.name?.trim()
};
}

/** @param {any} e */
function searchKeyDown(e) {
if (e.key === 'Enter' && filter?.similarName) {
e.preventDefault();
search();
}
}

/** @param {any} e */
function selectAgentTypeOption(e) {
// @ts-ignore
selectedAgentTypes = e.detail.selecteds?.map(x => x.label) || [];
searchItem.types = e.detail.selecteds?.map(x => x.label) || [];
}

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

function search() {
Expand All @@ -241,8 +260,11 @@
}

function reset() {
selectedAgentTypes = [];
selectedAgentLabels = [];
searchItem = {
name: '',
types: [],
labels: []
};

filter = { ...initFilter };
getPagedAgents();
Expand All @@ -251,8 +273,8 @@
function refreshFilter() {
filter = {
...filter,
types: selectedAgentTypes?.length > 0 ? selectedAgentTypes : null,
labels: selectedAgentLabels?.length > 0 ? selectedAgentLabels : null,
types: searchItem.types?.length > 0 ? searchItem.types : null,
labels: searchItem.labels?.length > 0 ? searchItem.labels : null,
pager: initFilter.pager
};
}
Expand Down Expand Up @@ -285,16 +307,17 @@
type="text"
placeholder="Search by name"
style="width: fit-content;"
value={filter.similarName}
on:input={e => filter.similarName = e.target.value?.trim()}
value={searchItem.name}
on:input={e => changeSearchName(e)}
on:keydown={e => searchKeyDown(e)}
/>
<Select
tag={'agent-label-select'}
placeholder={'Select labels'}
selectedText={'labels'}
multiSelect
searchMode
selectedValues={selectedAgentLabels}
selectedValues={searchItem.labels}
options={agentLabelOptions}
on:select={e => selectAgentLabelOption(e)}
/>
Expand All @@ -304,7 +327,7 @@
selectedText={'types'}
multiSelect
searchMode
selectedValues={selectedAgentTypes}
selectedValues={searchItem.types}
options={agentTypeOptions}
on:select={e => selectAgentTypeOption(e)}
/>
Expand Down