mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-18 13:06:32 +00:00
Make qFields handling more reliable
This commit is contained in:
parent
c2dda9599a
commit
8d0575937c
2 changed files with 22 additions and 7 deletions
|
@ -110,7 +110,8 @@ export function useQuickSearch() {
|
||||||
query: {
|
query: {
|
||||||
q: "",
|
q: "",
|
||||||
fieldSelector: "true",
|
fieldSelector: "true",
|
||||||
fields: [`Barcode=${validCode}`],
|
// TODO: Barcode= is a temporary approach to support this behavior.
|
||||||
|
fields: [encodeURIComponent(`Barcode=${validCode}`)],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -74,13 +74,17 @@
|
||||||
queryParamsInitialized.value = true;
|
queryParamsInitialized.value = true;
|
||||||
searchLocked.value = false;
|
searchLocked.value = false;
|
||||||
|
|
||||||
const qFields = route.query.fields as string[];
|
const qFields = route.query.fields as string[] | string;
|
||||||
if (qFields) {
|
if (qFields != null) {
|
||||||
fieldTuples.value = qFields.map(f => f.split("=") as [string, string]);
|
// Ensure qFields are represented as an array of string, as expected:
|
||||||
|
const qFieldsAsArray = Array.isArray(qFields) ? qFields : [qFields];
|
||||||
|
const parsedFieldTuples = qFieldsAsArray.map(f => decodeURIComponent(f).split("=") as [string, string]);
|
||||||
|
|
||||||
// After loading for the first time, we keep track of the field tuples at this point,
|
// After loading for the first time, we keep track of the field tuples at this point,
|
||||||
// and use them as possible field values even if they're not included in the list of values for
|
// and use them as possible field values even if they're not included in the list of values for
|
||||||
// the given field:
|
// the given field:
|
||||||
fieldTuplesOnMount.value = fieldTuples.value;
|
fieldTuples.value = parsedFieldTuples;
|
||||||
|
fieldTuplesOnMount.value = parsedFieldTuples;
|
||||||
|
|
||||||
for (const t of fieldTuples.value) {
|
for (const t of fieldTuples.value) {
|
||||||
if (t[0] && t[1]) {
|
if (t[0] && t[1]) {
|
||||||
|
@ -178,13 +182,20 @@
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Temporary approach to arbitrary field values, which merges search query input
|
||||||
|
* into the values cache for a given field.
|
||||||
|
*
|
||||||
|
* Since this relies on `onMounted`, and due to how search works, it's less than
|
||||||
|
* ideal, and supremely confusing when a value you saw 2 seconds ago suddenly disappears.
|
||||||
|
*/
|
||||||
function fieldValuesFromCache(field: string) {
|
function fieldValuesFromCache(field: string) {
|
||||||
const fieldValues = fieldValuesCache.value[field] ?? [];
|
const fieldValues = fieldValuesCache.value[field] ?? [];
|
||||||
const valuesFromFirstMount = fieldTuplesOnMount.value
|
const valuesFromFirstMount = fieldTuplesOnMount.value
|
||||||
.filter(([fieldName]) => fieldName === field)
|
.filter(([fieldName]) => fieldName === field)
|
||||||
.map(([_, fieldValue]) => fieldValue);
|
.map(([_, fieldValue]) => fieldValue);
|
||||||
|
|
||||||
return [...valuesFromFirstMount, ...fieldValues];
|
return [...new Set([...valuesFromFirstMount, ...fieldValues])];
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(advanced, (v, lv) => {
|
watch(advanced, (v, lv) => {
|
||||||
|
@ -259,7 +270,10 @@
|
||||||
initialSearch.value = false;
|
initialSearch.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
watchDebounced([page, pageSize, query, selectedLabels, selectedLocations], search, { debounce: 250, maxWait: 1000 });
|
watchDebounced([page, pageSize, query, selectedLabels, selectedLocations], search, {
|
||||||
|
debounce: 250,
|
||||||
|
maxWait: 1000,
|
||||||
|
});
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
// Set URL Params
|
// Set URL Params
|
||||||
|
|
Loading…
Reference in a new issue