Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: custom actions not loading on second visit #511

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions frontend/src/components/Activities/EmailContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ watch(iframeRef, (iframe) => {
iframe.contentWindow.document.querySelector('.email-content')
let parent = emailContent.closest('html')

let theme = document.documentElement.getAttribute('data-theme')
parent.setAttribute('data-theme', theme)

iframe.style.height = parent.offsetHeight + 1 + 'px'

let replyCollapsers = emailContent.querySelectorAll('.replyCollapser')
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/CustomActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</template>

<script setup>
import { computed, h } from 'vue'
import { computed } from 'vue'
import { Dropdown } from 'frappe-ui'
import { isMobileView } from '@/composables/settings'

Expand Down
10 changes: 8 additions & 2 deletions frontend/src/components/FilesUploader/FilesUploaderArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</div>
<div v-else>
<div
class="flex flex-col items-center justify-center gap-4 rounded-lg border border-dashed min-h-64 text-ink-gray-5"
class="flex flex-col items-center justify-center gap-4 rounded-lg border border-dashed border-outline-gray-modals min-h-64 text-ink-gray-5"
@dragover.prevent="dragover"
@dragleave.prevent="dragleave"
@drop.prevent="dropfiles"
Expand Down Expand Up @@ -128,7 +128,7 @@ import FileAudioIcon from '@/components/Icons/FileAudioIcon.vue'
import FileVideoIcon from '@/components/Icons/FileVideoIcon.vue'
import { createToast, formatDate, convertSize } from '@/utils'
import { FormControl, CircularProgressBar, createResource } from 'frappe-ui'
import { ref, onMounted } from 'vue'
import { ref, onMounted, watch, onUnmounted } from 'vue'

const props = defineProps({
doctype: {
Expand Down Expand Up @@ -383,6 +383,12 @@ function fileIcon(type) {
return FileTextIcon
}

watch(showCamera, (value) => {
if (!value) stopStream()
})

onUnmounted(() => stopStream())

defineExpose({
showFileBrowser,
showWebLink,
Expand Down
38 changes: 3 additions & 35 deletions frontend/src/components/Kanban/KanbanView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
size="sm"
class="hover:!bg-surface-gray-2"
>
<IndicatorIcon
:class="colorClasses(column.column.color, true)"
/>
<IndicatorIcon :class="parseColor(column.column.color)" />
</Button>
</template>
<template #body="{ close }">
Expand All @@ -33,13 +31,12 @@
>
<div class="flex gap-1">
<Button
:class="colorClasses(color)"
variant="ghost"
v-for="color in colors"
:key="color"
@click="() => (column.column.color = color)"
>
<IndicatorIcon />
<IndicatorIcon :class="parseColor(color)" />
</Button>
</div>
<div class="flex flex-row-reverse">
Expand Down Expand Up @@ -172,7 +169,7 @@
import Autocomplete from '@/components/frappe-ui/Autocomplete.vue'
import NestedPopover from '@/components/NestedPopover.vue'
import IndicatorIcon from '@/components/Icons/IndicatorIcon.vue'
import { isTouchScreenDevice } from '@/utils'
import { isTouchScreenDevice, colors, parseColor } from '@/utils'
import Draggable from 'vuedraggable'
import { Dropdown } from 'frappe-ui'
import { computed } from 'vue'
Expand Down Expand Up @@ -265,33 +262,4 @@ function updateColumn(d) {

emit('update', data)
}

function colorClasses(color, onlyIcon = false) {
let textColor = `!text-${color}-600`
if (color == 'black') {
textColor = '!text-ink-gray-9'
} else if (['gray', 'green'].includes(color)) {
textColor = `!text-${color}-700`
}

let bgColor = `!bg-${color}-100 hover:!bg-${color}-200 active:!bg-${color}-300`

return [textColor, onlyIcon ? '' : bgColor]
}

const colors = [
'gray',
'blue',
'green',
'red',
'pink',
'orange',
'amber',
'yellow',
'cyan',
'teal',
'violet',
'purple',
'black',
]
</script>
2 changes: 1 addition & 1 deletion frontend/src/components/Modals/DealModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const tabs = createResource({
if (field.fieldname == 'status') {
field.fieldtype = 'Select'
field.options = dealStatuses.value
field.prefix = getDealStatus(deal.status).iconColorClass
field.prefix = getDealStatus(deal.status).color
}

if (field.fieldtype === 'Table') {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Modals/LeadModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const tabs = createResource({
if (field.fieldname == 'status') {
field.fieldtype = 'Select'
field.options = leadStatuses.value
field.prefix = getLeadStatus(lead.status).iconColorClass
field.prefix = getLeadStatus(lead.status).color
}

if (field.fieldtype === 'Table') {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Contact.vue
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ function getDealRowObject(deal) {
annual_revenue: getFormattedCurrency('annual_revenue', deal),
status: {
label: deal.status,
color: getDealStatus(deal.status)?.iconColorClass,
color: getDealStatus(deal.status)?.color,
},
email: deal.email,
mobile_no: deal.mobile_no,
Expand Down
30 changes: 13 additions & 17 deletions frontend/src/pages/Deal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@
</Breadcrumbs>
</template>
<template #right-header>
<CustomActions v-if="customActions" :actions="customActions" />
<CustomActions
v-if="deal.data._customActions?.length"
:actions="deal.data._customActions"
/>
<AssignTo
v-model="deal.data._assignedTo"
:data="deal.data"
doctype="CRM Deal"
/>
<Dropdown :options="statusOptions('deal', updateField, customStatuses)">
<Dropdown
:options="statusOptions('deal', updateField, deal.data._customStatuses)"
>
<template #default="{ open }">
<Button
:label="deal.data.status"
:class="getDealStatus(deal.data.status).colorClass"
>
<Button :label="deal.data.status">
<template #prefix>
<IndicatorIcon />
<IndicatorIcon :class="getDealStatus(deal.data.status).color" />
</template>
<template #suffix>
<FeatherIcon
Expand Down Expand Up @@ -317,22 +319,20 @@ const props = defineProps({
},
})

const customActions = ref([])
const customStatuses = ref([])

const deal = createResource({
url: 'crm.fcrm.doctype.crm_deal.api.get_deal',
params: { name: props.dealId },
cache: ['deal', props.dealId],
onSuccess: async (data) => {
onSuccess: (data) => {
if (data.organization) {
organization.update({
params: { doctype: 'CRM Organization', name: data.organization },
})
organization.fetch()
}

let obj = {
setupAssignees(deal)
setupCustomizations(deal, {
doc: data,
$dialog,
$socket,
Expand All @@ -346,11 +346,7 @@ const deal = createResource({
sections,
},
call,
}
setupAssignees(data)
let customization = await setupCustomizations(data, obj)
customActions.value = customization.actions || []
customStatuses.value = customization.statuses || []
})
},
})

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/Deals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ function getGroupedByRows(listRows, groupByField, columns) {
if (groupByField.name == 'status') {
groupDetail.icon = () =>
h(IndicatorIcon, {
class: getDealStatus(option)?.iconColorClass,
class: getDealStatus(option)?.color,
})
}
groupedRows.push(groupDetail)
Expand Down Expand Up @@ -421,7 +421,7 @@ function parseRows(rows, columns = []) {
} else if (row == 'status') {
_rows[row] = {
label: deal.status,
color: getDealStatus(deal.status)?.iconColorClass,
color: getDealStatus(deal.status)?.color,
}
} else if (row == 'sla_status') {
let value = deal.sla_status
Expand Down
37 changes: 16 additions & 21 deletions frontend/src/pages/Lead.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@
</Breadcrumbs>
</template>
<template #right-header>
<CustomActions v-if="customActions" :actions="customActions" />
<CustomActions
v-if="lead.data._customActions?.length"
:actions="lead.data._customActions"
/>
<AssignTo
v-model="lead.data._assignedTo"
:data="lead.data"
doctype="CRM Lead"
/>
<Dropdown :options="statusOptions('lead', updateField, customStatuses)">
<Dropdown
:options="statusOptions('lead', updateField, lead.data._customStatuses)"
>
<template #default="{ open }">
<Button
:label="lead.data.status"
:class="getLeadStatus(lead.data.status).colorClass"
>
<Button :label="lead.data.status">
<template #prefix>
<IndicatorIcon />
<IndicatorIcon
:class="getLeadStatus(lead.data.status).color"
/>
</template>
<template #suffix>
<FeatherIcon
Expand Down Expand Up @@ -329,32 +333,23 @@ const props = defineProps({
},
})

const customActions = ref([])
const customStatuses = ref([])

const lead = createResource({
url: 'crm.fcrm.doctype.crm_lead.api.get_lead',
params: { name: props.leadId },
cache: ['lead', props.leadId],
onSuccess: async (data) => {
let obj = {
onSuccess: (data) => {
setupAssignees(lead)
setupCustomizations(lead, {
doc: data,
$dialog,
$socket,
router,
updateField,
createToast,
deleteDoc: deleteLead,
resource: {
lead,
sections,
},
resource: { lead, sections },
call,
}
setupAssignees(data)
let customization = await setupCustomizations(data, obj)
customActions.value = customization.actions || []
customStatuses.value = customization.statuses || []
})
},
})

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/Leads.vue
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ function getGroupedByRows(listRows, groupByField, columns) {
if (groupByField.name == 'status') {
groupDetail.icon = () =>
h(IndicatorIcon, {
class: getLeadStatus(option)?.iconColorClass,
class: getLeadStatus(option)?.color,
})
}
groupedRows.push(groupDetail)
Expand Down Expand Up @@ -444,7 +444,7 @@ function parseRows(rows, columns = []) {
} else if (row == 'status') {
_rows[row] = {
label: lead.status,
color: getLeadStatus(lead.status)?.iconColorClass,
color: getLeadStatus(lead.status)?.color,
}
} else if (row == 'sla_status') {
let value = lead.sla_status
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/MobileContact.vue
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ function getDealRowObject(deal) {
annual_revenue: getFormattedCurrency('annual_revenue', deal),
status: {
label: deal.status,
color: getDealStatus(deal.status)?.iconColorClass,
color: getDealStatus(deal.status)?.color,
},
email: deal.email,
mobile_no: deal.mobile_no,
Expand Down
Loading
Loading