Skip to content

Commit

Permalink
Merge pull request #382 from frappe/develop
Browse files Browse the repository at this point in the history
chore: Merge develop to main
  • Loading branch information
shariquerik authored Sep 27, 2024
2 parents 73e262d + 454973c commit 6769558
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 11 deletions.
2 changes: 2 additions & 0 deletions crm/api/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def get_deal_activities(name):
"bcc": communication.bcc,
"attachments": get_attachments('Communication', communication.name),
"read_by_recipient": communication.read_by_recipient,
"delivery_status": communication.delivery_status,
},
"is_lead": False,
}
Expand Down Expand Up @@ -238,6 +239,7 @@ def get_lead_activities(name):
"bcc": communication.bcc,
"attachments": get_attachments('Communication', communication.name),
"read_by_recipient": communication.read_by_recipient,
"delivery_status": communication.delivery_status,
},
"is_lead": True,
}
Expand Down
1 change: 1 addition & 0 deletions crm/api/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ def get_fields(doctype: str, allow_all_fieldtypes: bool = False):
"depends_on": field.depends_on,
"mandatory_depends_on": field.mandatory_depends_on,
"read_only_depends_on": field.read_only_depends_on,
"link_filters": field.get("link_filters"),
})

return _fields
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/components/Activities/EmailArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
/>
</div>
<div class="flex items-center gap-2 shrink-0">
<Badge
v-if="status.label"
:label="__(status.label)"
variant="subtle"
:theme="status.color"
/>
<Tooltip :text="dateFormat(activity.creation, dateTooltipFormat)">
<div class="text-sm text-gray-600">
{{ __(timeAgo(activity.creation)) }}
Expand Down Expand Up @@ -87,6 +93,7 @@ import AttachmentItem from '@/components/AttachmentItem.vue'
import EmailContent from '@/components/Activities/EmailContent.vue'
import { Badge, Tooltip } from 'frappe-ui'
import { timeAgo, dateFormat, dateTooltipFormat } from '@/utils'
import { computed } from 'vue'
const props = defineProps({
activity: Object,
Expand Down Expand Up @@ -140,4 +147,19 @@ function reply(email, reply_all = false) {
.focus('start')
.run()
}
const status = computed(() => {
let _status = props.activity?.data?.delivery_status
let indicator_color = 'red'
if (['Sent', 'Clicked'].includes(_status)) {
indicator_color = 'green'
} else if (['Sending', 'Scheduled'].includes(_status)) {
indicator_color = 'orange'
} else if (['Opened', 'Read'].includes(_status)) {
indicator_color = 'blue'
} else if (_status == 'Error') {
indicator_color = 'red'
}
return { label: _status, color: indicator_color }
})
</script>
6 changes: 6 additions & 0 deletions frontend/src/components/Controls/Link.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ const props = defineProps({
type: String,
required: true,
},
filters: {
type: Array,
default: () => [],
},
modelValue: {
type: String,
default: '',
Expand Down Expand Up @@ -122,6 +126,7 @@ const options = createResource({
params: {
txt: text.value,
doctype: props.doctype,
filters: props.filters,
},
transform: (data) => {
let allData = data.map((option) => {
Expand Down Expand Up @@ -152,6 +157,7 @@ function reload(val) {
params: {
txt: val,
doctype: props.doctype,
filters: props.filters,
},
})
options.reload()
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/Fields.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
class="form-control flex-1"
:value="data[field.name]"
:doctype="field.options"
:filters="field.filters"
@change="(v) => (data[field.name] = v)"
:placeholder="__(field.placeholder || field.label)"
:onCreate="field.create"
Expand All @@ -110,6 +111,7 @@
class="form-control"
:value="getUser(data[field.name]).full_name"
:doctype="field.options"
:filters="field.filters"
@change="(v) => (data[field.name] = v)"
:placeholder="__(field.placeholder || field.label)"
:hideMe="true"
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/SectionFields.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
class="form-control"
:value="data[field.name] && getUser(data[field.name]).full_name"
doctype="User"
:filters="field.filters"
@change="(data) => emit('update', field.name, data)"
:placeholder="'Select' + ' ' + field.label + '...'"
:hideMe="true"
Expand All @@ -88,6 +89,7 @@
class="form-control select-text"
:value="data[field.name]"
:doctype="field.doctype"
:filters="field.filters"
:placeholder="field.placeholder"
@change="(data) => emit('update', field.name, data)"
:onCreate="field.create"
Expand Down Expand Up @@ -144,6 +146,7 @@ const _fields = computed(() => {
if (df?.depends_on) evaluate_depends_on(df.depends_on, field)
all_fields.push({
...field,
filters: df.link_filters && JSON.parse(df.link_filters),
placeholder: field.placeholder || field.label,
})
})
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Settings/SettingsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ const sections = computed(() => {
} else {
_sections[_sections.length - 1].fields.push({
...field,
filters: field.link_filters && JSON.parse(field.link_filters),
display_via_depends_on: evaluate_depends_on_value(
field.depends_on,
data.doc,
Expand Down
80 changes: 80 additions & 0 deletions frontend/src/composables/useActiveTabManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import { useDebounceFn, useStorage } from '@vueuse/core'

export function useActiveTabManager(tabs, storageKey) {
const activieTab = useStorage(storageKey, 'activity')
const route = useRoute()

const preserveLastVisitedTab = useDebounceFn((tabName) => {
activieTab.value = tabName.toLowerCase()
}, 300)

function setActiveTabInUrl(tabName) {
window.location.hash = '#' + tabName.toLowerCase()
}

function getActiveTabFromUrl() {
return route.hash.replace('#', '')
}

function findTabIndex(tabName) {
return tabs.value.findIndex(
(tabOptions) => tabOptions.name.toLowerCase() === tabName,
)
}

function getTabIndex(tabName) {
let index = findTabIndex(tabName)
return index !== -1 ? index : 0 // Default to the first tab if not found
}

function getActiveTabFromLocalStorage() {
return activieTab.value
}

function getActiveTab() {
let activeTab = getActiveTabFromUrl()
if (activeTab) {
let index = findTabIndex(activeTab)
if (index !== -1) {
preserveLastVisitedTab(activeTab)
return index
}
return 0
}

let lastVisitedTab = getActiveTabFromLocalStorage()
if (lastVisitedTab) {
setActiveTabInUrl(lastVisitedTab)
return getTabIndex(lastVisitedTab)
}

return 0 // Default to the first tab if nothing is found
}

const tabIndex = ref(getActiveTab())

watch(tabIndex, (tabIndexValue) => {
let currentTab = tabs.value[tabIndexValue].name
setActiveTabInUrl(currentTab)
preserveLastVisitedTab(currentTab)
})

watch(
() => route.hash,
(tabValue) => {
if (!tabValue) return

let tabName = tabValue.replace('#', '')
let index = findTabIndex(tabName)
if (index === -1) index = 0

let currentTab = tabs.value[index].name
preserveLastVisitedTab(currentTab)
tabIndex.value = index
},
)

return { tabIndex }
}
15 changes: 10 additions & 5 deletions frontend/src/pages/Deal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ import {
} from 'frappe-ui'
import { ref, computed, h, onMounted, onBeforeUnmount } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useActiveTabManager } from '@/composables/useActiveTabManager'
const { $dialog, $socket, makeCall } = globalStore()
const { statusOptions, getDealStatus } = statusesStore()
Expand All @@ -376,10 +378,13 @@ const deal = createResource({
params: { name: props.dealId },
cache: ['deal', props.dealId],
onSuccess: async (data) => {
organization.update({
params: { doctype: 'CRM Organization', name: data.organization },
})
organization.fetch()
if (data.organization) {
organization.update({
params: { doctype: 'CRM Organization', name: data.organization },
})
organization.fetch()
}
let obj = {
doc: data,
$dialog,
Expand Down Expand Up @@ -513,7 +518,6 @@ usePageMeta(() => {
}
})
const tabIndex = ref(0)
const tabs = computed(() => {
let tabOptions = [
{
Expand Down Expand Up @@ -556,6 +560,7 @@ const tabs = computed(() => {
]
return tabOptions.filter((tab) => (tab.condition ? tab.condition() : true))
})
const { tabIndex } = useActiveTabManager(tabs, 'lastDealTab')
const fieldsLayout = createResource({
url: 'crm.api.doc.get_sidebar_fields',
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/pages/Lead.vue
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ import {
} from 'frappe-ui'
import { ref, computed, onMounted, watch } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { useActiveTabManager } from '@/composables/useActiveTabManager'
const { $dialog, $socket, makeCall } = globalStore()
const { getContactByName, contacts } = contactsStore()
Expand Down Expand Up @@ -463,8 +464,6 @@ usePageMeta(() => {
}
})
const tabIndex = ref(0)
const tabs = computed(() => {
let tabOptions = [
{
Expand Down Expand Up @@ -508,6 +507,8 @@ const tabs = computed(() => {
return tabOptions.filter((tab) => (tab.condition ? tab.condition() : true))
})
const { tabIndex } = useActiveTabManager(tabs, 'lastLeadTab')
watch(tabs, (value) => {
if (value && route.params.tabName) {
let index = value.findIndex(
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/pages/MobileDeal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,13 @@ const deal = createResource({
params: { name: props.dealId },
cache: ['deal', props.dealId],
onSuccess: async (data) => {
organization.update({
params: { doctype: 'CRM Organization', name: data.organization },
})
organization.fetch()
if (data.organization) {
organization.update({
params: { doctype: 'CRM Organization', name: data.organization },
})
organization.fetch()
}
let obj = {
doc: data,
$dialog,
Expand Down

0 comments on commit 6769558

Please sign in to comment.