Skip to content

Commit

Permalink
Merge pull request #1864 from frappe/mergify/bp/version-15-hotfix/pr-…
Browse files Browse the repository at this point in the history
…1855

refactor(PWA): setup frappe-ui git submodule & upgrade frappe-ui (backport #1855)
  • Loading branch information
ruchamahabal authored Jun 7, 2024
2 parents 883e0ea + c4e5808 commit 48ca806
Show file tree
Hide file tree
Showing 9 changed files with 7,204 additions and 68 deletions.
2 changes: 1 addition & 1 deletion frappe-ui
Submodule frappe-ui updated 76 files
+1 −1 .github/workflows/publish.yml
+0 −2 .gitignore
+0 −6 docs/.postcssrc.cjs
+0 −55 docs/.vitepress/RenderToIFrame.js
+0 −36 docs/.vitepress/Story.vue
+0 −58 docs/.vitepress/config.js
+0 −16 docs/.vitepress/theme/index.js
+0 −64 docs/.vitepress/theme/style.css
+0 −0 docs/Getting Started.story.md
+0 −0 docs/Introduction.story.md
+62 −0 docs/components/confirm-dialog.md
+1 −49 docs/other/Directives.story.md
+0 −0 docs/other/Utilities.story.md
+0 −1 docs/public/frappe-ui-logo.svg
+2 −2 docs/resources/Document Resource.story.md
+2 −2 docs/resources/List Resource.story.md
+8 −47 docs/resources/Resource.story.md
+0 −16 docs/tailwind.config.docs.js
+ frappe-ui-logo-200.png
+ frappe-ui-only-logo.png
+ frappe-ui-square.png
+ frappe-ui.png
+1 −0 frappe-ui.svg
+49 −5 histoire.config.ts
+9 −0 histoire.css
+5 −0 netlify.toml
+4 −7 package.json
+ public/frappe-ui-square.png
+2 −2 readme.md
+92 −14 src/components/Autocomplete.story.vue
+213 −98 src/components/Autocomplete.vue
+1 −0 src/components/Avatar.vue
+56 −0 src/components/ConfirmDialog.vue
+1 −1 src/components/Dialog.vue
+8 −0 src/components/Dialogs.vue
+5 −1 src/components/FileUploader.vue
+10 −9 src/components/FormControl.story.vue
+1 −1 src/components/ListFilter/ListFilter.vue
+1 −1 src/components/ListFilter/SearchComplete.vue
+27 −0 src/components/ListView.story.md
+243 −13 src/components/ListView.story.vue
+24 −0 src/components/ListView/ListEmptyState.vue
+63 −0 src/components/ListView/ListFooter.vue
+46 −0 src/components/ListView/ListGroupHeader.vue
+19 −0 src/components/ListView/ListGroupRows.vue
+24 −0 src/components/ListView/ListGroups.vue
+3 −0 src/components/ListView/ListHeader.vue
+79 −6 src/components/ListView/ListHeaderItem.vue
+38 −10 src/components/ListView/ListRow.vue
+28 −11 src/components/ListView/ListRowItem.vue
+56 −6 src/components/ListView/ListView.vue
+29 −7 src/components/Popover.vue
+8 −6 src/components/Progress.vue
+37 −14 src/components/Select.vue
+18 −7 src/components/Tabs.vue
+1 −1 src/components/TextEditor/FontColor.vue
+2 −2 src/components/TextEditor/InsertLink.vue
+1 −1 src/components/TextEditor/mention.js
+0 −11 src/components/Tooltip.story.vue
+0 −38 src/components/Tooltip.vue
+51 −0 src/components/Tooltip/Tooltip.story.vue
+64 −0 src/components/Tooltip/Tooltip.vue
+8 −0 src/icons/DownSolid.vue
+10 −3 src/index.js
+19 −1 src/resources/documentResource.js
+3 −3 src/resources/listResource.js
+5 −5 src/resources/local.js
+5 −2 src/resources/plugin.js
+12 −0 src/resources/resources.js
+25 −0 src/utils/confirmDialog.js
+1 −1 src/utils/frappeRequest.js
+1 −1 src/utils/pageMeta.js
+2 −1 src/utils/socketio.js
+7 −1 tsconfig.json
+14 −11 vite.js
+452 −532 yarn.lock
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@vitejs/plugin-vue": "^4.4.0",
"dayjs": "^1.11.7",
"feather-icons": "^4.28.0",
"frappe-ui": "^0.1.18",
"frappe-ui": "^0.1.59",
"vue": "^3.2.25",
"vue-router": "^4.0.12",
"autoprefixer": "^10.4.2",
Expand Down
66 changes: 21 additions & 45 deletions frontend/src/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,26 @@
{{ props.label }}
</span>

<!-- Link & Select -->
<!-- Select or Link field with predefined options -->
<Autocomplete
v-if="['Link', 'Select'].includes(props.fieldtype)"
ref="autocompleteRef"
v-if="props.fieldtype === 'Select' || props.documentList"
:class="isReadOnly ? 'pointer-events-none' : ''"
:value="modelValue"
:placeholder="`Select ${props.options}`"
:placeholder="`Select ${props.label}`"
:options="selectionList"
@change="(v) => emit('update:modelValue', v?.value)"
@update:query="(q) => updateLinkFieldOptions(q)"
:modelValue="modelValue"
v-bind="$attrs"
:disabled="isReadOnly"
@update:modelValue="(v) => emit('update:modelValue', v?.value)"
/>
<!-- Link field -->
<Link
v-else-if="props.fieldtype === 'Link'"
:doctype="props.options"
:modelValue="modelValue"
:filters="props.linkFilters"
:disabled="isReadOnly"
@update:modelValue="(v) => emit('update:modelValue', v)"
/>
<!-- Text -->
Expand Down Expand Up @@ -130,8 +138,10 @@
</template>
<script setup>
import { createResource, Autocomplete, ErrorMessage, debounce } from "frappe-ui"
import { ref, computed, onMounted, inject, watchEffect } from "vue"
import { Autocomplete, ErrorMessage } from "frappe-ui"
import { ref, computed, onMounted, inject } from "vue"
import Link from "@/components/Link.vue"
const props = defineProps({
fieldtype: String,
Expand Down Expand Up @@ -161,8 +171,6 @@ const emit = defineEmits(["change", "update:modelValue"])
const dayjs = inject("$dayjs")
let date = ref(null)
const autocompleteRef = ref(null)
const searchText = ref("")
const showField = computed(() => {
if (props.readOnly && !isLayoutField.value && !props.modelValue) return false
Expand All @@ -183,8 +191,8 @@ const isReadOnly = computed(() => {
})
const selectionList = computed(() => {
if (props.fieldtype == "Link" && props.options) {
return props.documentList || linkFieldList?.data
if (props.fieldtype === "Link" && props.documentList) {
return props.documentList
} else if (props.fieldtype == "Select" && props.options) {
const options = props.options.split("\n")
return options.map((option) => ({
Expand All @@ -196,24 +204,6 @@ const selectionList = computed(() => {
return []
})
const linkFieldList = createResource({
url: "frappe.desk.search.search_link",
params: {
doctype: props.options,
txt: searchText.value,
filters: props.linkFilters,
},
transform: (data) => {
return data.map((doc) => {
const title = doc?.description?.split(",")?.[0]
return {
label: title ? `${title} : ${doc.value}` : doc.value,
value: doc.value,
}
})
},
})
function setDefaultValue() {
// set default values
if (props.modelValue) return
Expand All @@ -235,20 +225,6 @@ function setDefaultValue() {
}
}
const updateLinkFieldOptions = debounce((query) => {
searchText.value = query || ""
linkFieldList.reload()
}, 500)
// get link field options from DB only when the field is clicked
watchEffect(() => {
if (autocompleteRef.value && props.fieldtype === "Link") {
autocompleteRef.value?.$refs?.search?.$el?.addEventListener("focus", () => {
linkFieldList.reload()
})
}
})
onMounted(() => {
setDefaultValue()
})
Expand Down
97 changes: 97 additions & 0 deletions frontend/src/components/Link.vue
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>
1 change: 1 addition & 0 deletions frontend/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
"./index.html",
"./src/**/*.{vue,js,ts,jsx,tsx}",
"./node_modules/frappe-ui/src/components/**/*.{vue,js,ts,jsx,tsx}",
"../node_modules/frappe-ui/src/components/**/*.{vue,js,ts,jsx,tsx}",
],
theme: {
extend: {
Expand Down
12 changes: 11 additions & 1 deletion frontend/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
import { VitePWA } from "vite-plugin-pwa"
import frappeui from "frappe-ui/vite"

import path from "path"
import fs from "fs"
Expand All @@ -12,6 +13,7 @@ export default defineConfig({
},
plugins: [
vue(),
frappeui(),
VitePWA({
registerType: "autoUpdate",
strategies: "injectManifest",
Expand Down Expand Up @@ -67,10 +69,18 @@ export default defineConfig({
commonjsOptions: {
include: [/tailwind.config.js/, /node_modules/],
},
sourcemap: true,
rollupOptions: {
output: {
manualChunks: {
"frappe-ui": ["frappe-ui"],
},
},
},
},
optimizeDeps: {
include: [
"feather-icons",
"frappe-ui > feather-icons",
"showdown",
"tailwind.config.js",
"engine.io-client",
Expand Down
Loading

0 comments on commit 48ca806

Please sign in to comment.