-
Notifications
You must be signed in to change notification settings - Fork 700
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1864 from frappe/mergify/bp/version-15-hotfix/pr-…
…1855 refactor(PWA): setup frappe-ui git submodule & upgrade frappe-ui (backport #1855)
- Loading branch information
Showing
9 changed files
with
7,204 additions
and
68 deletions.
There are no files selected for viewing
Submodule frappe-ui
updated
76 files
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
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,97 @@ | ||
<template> | ||
<Autocomplete | ||
ref="autocompleteRef" | ||
size="sm" | ||
v-model="value" | ||
:placeholder="`Select ${doctype}`" | ||
:options="options.data" | ||
:class="disabled ? 'pointer-events-none' : ''" | ||
:disabled="disabled" | ||
/> | ||
</template> | ||
|
||
<script setup> | ||
import { createResource, Autocomplete, debounce } from "frappe-ui" | ||
import { ref, computed, watch } from "vue" | ||
const props = defineProps({ | ||
doctype: { | ||
type: String, | ||
required: true, | ||
}, | ||
modelValue: { | ||
type: String, | ||
required: false, | ||
default: "", | ||
}, | ||
filters: { | ||
type: Object, | ||
default: {}, | ||
}, | ||
disabled: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
}) | ||
const emit = defineEmits(["update:modelValue"]) | ||
const autocompleteRef = ref(null) | ||
const searchText = ref("") | ||
const value = computed({ | ||
get: () => props.modelValue, | ||
set: (val) => { | ||
emit("update:modelValue", val?.value || "") | ||
}, | ||
}) | ||
const options = createResource({ | ||
url: "frappe.desk.search.search_link", | ||
params: { | ||
doctype: props.doctype, | ||
txt: searchText.value, | ||
filters: props.filters, | ||
}, | ||
method: "POST", | ||
transform: (data) => { | ||
return data.map((doc) => { | ||
const title = doc?.description?.split(",")?.[0] | ||
return { | ||
label: title ? `${title} : ${doc.value}` : doc.value, | ||
value: doc.value, | ||
} | ||
}) | ||
}, | ||
}) | ||
const reloadOptions = debounce((searchTextVal) => { | ||
options.update({ | ||
params: { | ||
txt: searchTextVal, | ||
doctype: props.doctype, | ||
}, | ||
}) | ||
options.reload() | ||
}, 300) | ||
watch( | ||
() => props.doctype, | ||
() => { | ||
if (!props.doctype || props.doctype === options.doctype) return | ||
reloadOptions("") | ||
}, | ||
{ immediate: true } | ||
) | ||
watch( | ||
() => autocompleteRef.value?.query, | ||
(val) => { | ||
val = val || "" | ||
if (searchText.value === val) return | ||
searchText.value = val | ||
reloadOptions(val) | ||
}, | ||
{ immediate: true } | ||
) | ||
</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
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
Oops, something went wrong.