-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add quick filter in view controls for list view
- Loading branch information
1 parent
f9a6bca
commit ec0f12b
Showing
7 changed files
with
164 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<template> | ||
<FormControl | ||
v-if="filter.type == 'Check'" | ||
:label="filter.label" | ||
type="checkbox" | ||
v-model="filter.value" | ||
@change.stop="updateFilter(filter, $event.target.checked)" | ||
/> | ||
<FormControl | ||
v-else-if="filter.type === 'Select'" | ||
class="form-control cursor-pointer [&_select]:cursor-pointer" | ||
type="select" | ||
v-model="filter.value" | ||
:options="filter.options" | ||
:placeholder="filter.label" | ||
@change.stop="updateFilter(filter, $event.target.value)" | ||
/> | ||
<Link | ||
v-else-if="filter.type === 'Link'" | ||
:value="filter.value" | ||
:doctype="filter.options" | ||
:placeholder="filter.label" | ||
@change="(data) => updateFilter(filter, data)" | ||
/> | ||
<component | ||
v-else-if="['Date', 'Datetime'].includes(filter.type)" | ||
class="border-none" | ||
:is="filter.type === 'Date' ? DatePicker : DateTimePicker" | ||
:value="filter.value" | ||
@change="(v) => updateFilter(filter, v)" | ||
:placeholder="filter.label" | ||
/> | ||
<TextInput | ||
v-else | ||
v-model="filter.value" | ||
type="text" | ||
:placeholder="filter.label" | ||
@input.stop="debouncedFn(filter, $event.target.value)" | ||
/> | ||
</template> | ||
<script setup> | ||
import { | ||
TextInput, | ||
FormControl, | ||
DatePicker, | ||
DateTimePicker, | ||
Link, | ||
} from "frappe-ui"; | ||
import { useDebounceFn } from "@vueuse/core"; | ||
const props = defineProps({ | ||
filter: { | ||
type: Object, | ||
required: true, | ||
}, | ||
}); | ||
const emit = defineEmits(["applyQuickFilter"]); | ||
const debouncedFn = useDebounceFn((f, value) => { | ||
emit("applyQuickFilter", f, value); | ||
}, 500); | ||
function updateFilter(f, value) { | ||
emit("applyQuickFilter", f, value); | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<template> | ||
<div | ||
v-if="!quickFilters.loading" | ||
class="flex items-center justify-between gap-2 px-5 py-4" | ||
> | ||
<FadedScrollableDiv | ||
class="flex flex-1 items-center overflow-x-auto -ml-1" | ||
orientation="horizontal" | ||
> | ||
<div | ||
v-for="filter in quickFilters.data" | ||
:key="filter.name" | ||
class="m-1 min-w-36" | ||
> | ||
<QuickFilterField | ||
:filter="filter" | ||
@applyQuickFilter="(f, v) => applyQuickFilter(f, v)" | ||
/> | ||
</div> | ||
</FadedScrollableDiv> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { inject } from "vue"; | ||
import { FadedScrollableDiv } from "@/components"; | ||
import QuickFilterField from "./QuickFilterField.vue"; | ||
const listViewData = inject("listViewData"); | ||
const listViewActions = inject("listViewActions"); | ||
const { list, quickFilters } = listViewData; | ||
function applyQuickFilter(filter, value) { | ||
let filters = { ...list.params.filters }; | ||
let field = filter.name; | ||
if (value) { | ||
if (["Check", "Select", "Link", "Date", "Datetime"].includes(filter.type)) { | ||
filters[field] = value; | ||
} else { | ||
filters[field] = ["LIKE", `%${value}%`]; | ||
} | ||
filter["value"] = value; | ||
} else { | ||
delete filters[field]; | ||
filter["value"] = ""; | ||
} | ||
listViewActions.applyFilters(filters); | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { default as Filter } from "./Filter.vue"; | ||
export { default as SortBy } from "./SortBy.vue"; | ||
// | ||
export { default as QuickFilters } from "./QuickFilters.vue"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters