fix: better caching in lead/deal page

This commit is contained in:
Shariq Ansari 2024-02-05 17:51:00 +05:30
parent 1fc0e74098
commit cd697de6e1
5 changed files with 46 additions and 15 deletions

View File

@ -772,7 +772,7 @@ import {
call,
} from 'frappe-ui'
import { useElementVisibility } from '@vueuse/core'
import { ref, computed, h, defineModel, markRaw, watch, nextTick } from 'vue'
import { ref, computed, h, defineModel, markRaw, watch, nextTick, onMounted } from 'vue'
import { useRoute } from 'vue-router'
const { makeCall } = globalStore()
@ -799,7 +799,21 @@ const versions = createResource({
url: 'crm.api.activities.get_activities',
params: { name: doc.value.data.name },
cache: ['activity', doc.value.data.name],
auto: true,
})
onMounted(() => {
if (versions.data == null) {
versions.fetch()
}
if (calls.data == null) {
calls.fetch()
}
if (notes.data == null) {
notes.fetch()
}
if (tasks.data == null) {
tasks.fetch()
}
})
const calls = createListResource({
@ -824,7 +838,6 @@ const calls = createListResource({
filters: { reference_docname: doc.value.data.name },
orderBy: 'creation desc',
pageLength: 999,
auto: true,
transform: (docs) => {
docs.forEach((doc) => {
doc.show_recording = false
@ -869,7 +882,6 @@ const notes = createListResource({
filters: { reference_docname: doc.value.data.name },
orderBy: 'modified desc',
pageLength: 999,
auto: true,
})
const tasks = createListResource({
@ -890,7 +902,6 @@ const tasks = createListResource({
filters: { reference_docname: doc.value.data.name },
orderBy: 'modified desc',
pageLength: 999,
auto: true,
})
function all_activities() {
@ -911,15 +922,15 @@ const activities = computed(() => {
.filter((activity) => activity.activity_type === 'communication')
.sort((a, b) => new Date(a.creation) - new Date(b.creation))
} else if (props.title == 'Calls') {
return calls.data.sort(
return calls.data?.sort(
(a, b) => new Date(a.creation) - new Date(b.creation)
)
} else if (props.title == 'Tasks') {
return tasks.data.sort(
return tasks.data?.sort(
(a, b) => new Date(a.creation) - new Date(b.creation)
)
} else if (props.title == 'Notes') {
return notes.data.sort(
return notes.data?.sort(
(a, b) => new Date(a.creation) - new Date(b.creation)
)
}

View File

@ -129,6 +129,13 @@ const options = createResource({
})
function reload(val) {
if (
options.data?.length &&
val === options.params?.txt &&
props.doctype === options.params?.doctype
)
return
options.update({
params: {
txt: val,

View File

@ -63,7 +63,7 @@
<script setup>
import EmailTemplateModal from '@/components/Modals/EmailTemplateModal.vue'
import { TextEditor, createListResource } from 'frappe-ui'
import { defineModel, ref, computed, nextTick, watch } from 'vue'
import { defineModel, ref, computed, nextTick, watch, onMounted } from 'vue'
const props = defineProps({
doctype: {
@ -85,7 +85,7 @@ const search = ref('')
const templates = createListResource({
type: 'list',
doctype: 'Email Template',
cache: ['Email Templates', props.doctype],
cache: ['emailTemplates', props.doctype],
fields: [
'name',
'enabled',
@ -98,7 +98,12 @@ const templates = createListResource({
filters: { enabled: 1, reference_doctype: props.doctype },
orderBy: 'modified desc',
pageLength: 99999,
auto: true,
})
onMounted(() => {
if (templates.data == null) {
templates.fetch()
}
})
const filteredTemplates = computed(() => {

View File

@ -325,7 +325,7 @@ import {
Breadcrumbs,
call,
} from 'frappe-ui'
import { ref, computed, h } from 'vue'
import { ref, computed, h, onMounted } from 'vue'
import { useRouter } from 'vue-router'
const { $dialog, makeCall } = globalStore()
@ -345,7 +345,6 @@ const deal = createResource({
url: 'crm.fcrm.doctype.crm_deal.api.get_deal',
params: { name: props.dealId },
cache: ['deal', props.dealId],
auto: true,
onSuccess: (data) => {
setupAssignees(data)
setupCustomActions(data, {
@ -360,6 +359,11 @@ const deal = createResource({
},
})
onMounted(() => {
if (deal.data) return
deal.fetch()
})
const reload = ref(false)
const showOrganizationModal = ref(false)
const showAssignmentModal = ref(false)

View File

@ -290,7 +290,7 @@ import {
Breadcrumbs,
call,
} from 'frappe-ui'
import { ref, computed } from 'vue'
import { ref, computed, onMounted } from 'vue'
import { useRouter } from 'vue-router'
const { $dialog, makeCall } = globalStore()
@ -310,7 +310,6 @@ const lead = createResource({
url: 'crm.fcrm.doctype.crm_lead.api.get_lead',
params: { name: props.leadId },
cache: ['lead', props.leadId],
auto: true,
onSuccess: (data) => {
setupAssignees(data)
setupCustomActions(data, {
@ -325,6 +324,11 @@ const lead = createResource({
},
})
onMounted(() => {
if (lead.data) return
lead.fetch()
})
const reload = ref(false)
const showAssignmentModal = ref(false)