Skip to content

Commit

Permalink
Enable Sorting on Search By Created and Updated At (#140)
Browse files Browse the repository at this point in the history
- Required updating query value to use first.value
  to set the value of the initial sort

- Ordering starts with name but can be changed to
  createdAt or updatedAt by the user
  • Loading branch information
Rshep3087 authored Jul 21, 2024
1 parent 01f54ae commit c9f31ef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion frontend/composables/use-route-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function useRouteQuery(q: string, def: any): WritableComputedRef<any> {
case "string":
return computed({
get: () => {
const qv = route.query[q];
const qv = first.value;
if (Array.isArray(qv)) {
return qv[0];
}
Expand Down
19 changes: 19 additions & 0 deletions frontend/pages/items.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
const includeArchived = useRouteQuery("archived", false);
const fieldSelector = useRouteQuery("fieldSelector", false);
const negateLabels = useRouteQuery("negateLabels", false);
const orderBy = useRouteQuery("orderBy", "name");
const totalPages = computed(() => Math.ceil(total.value / pageSize.value));
const hasNext = computed(() => page.value * pageSize.value < total.value);
Expand Down Expand Up @@ -169,6 +170,12 @@
}
});
watch(orderBy, (newV, oldV) => {
if (newV !== oldV) {
search();
}
});
async function fetchValues(field: string): Promise<string[]> {
if (fieldValuesCache.value[field]) {
return fieldValuesCache.value[field];
Expand Down Expand Up @@ -201,6 +208,7 @@
pageSize: pageSize.value,
includeArchived: includeArchived.value ? "true" : "false",
negateLabels: negateLabels.value ? "true" : "false",
orderBy: orderBy.value,
},
});
}
Expand Down Expand Up @@ -231,6 +239,7 @@
includeArchived: includeArchived.value,
page: page.value,
pageSize: pageSize.value,
orderBy: orderBy.value,
fields,
});
Expand Down Expand Up @@ -278,6 +287,7 @@
archived: includeArchived.value ? "true" : "false",
fieldSelector: fieldSelector.value ? "true" : "false",
negateLabels: negateLabels.value ? "true" : "false",
orderBy: orderBy.value,
pageSize: pageSize.value,
page: page.value,
q: query.value,
Expand Down Expand Up @@ -311,6 +321,7 @@
fieldSelector: "false",
pageSize: 10,
page: 1,
orderBy: "name",
q: "",
loc: [],
lab: [],
Expand Down Expand Up @@ -373,6 +384,14 @@
<input v-model="negateLabels" type="checkbox" class="toggle toggle-sm toggle-primary" />
<span class="label-text ml-4"> Negate selected labels </span>
</label>
<label class="label cursor-pointer mr-auto">
<select v-model="orderBy" class="select select-bordered select-sm">
<option value="name" selected>Name</option>
<option value="createdAt">Created At</option>
<option value="updatedAt">Updated At</option>
</select>
<span class="label-text ml-4"> Order By </span>
</label>
<hr class="my-2" />
<BaseButton class="btn-block btn-sm" @click="reset"> Reset Search</BaseButton>
</div>
Expand Down

0 comments on commit c9f31ef

Please sign in to comment.