Skip to content

Commit

Permalink
fix: include type of the column field to render it correctly on list row
Browse files Browse the repository at this point in the history
  • Loading branch information
shariquerik committed Nov 28, 2023
1 parent 00e97d1 commit 72a7770
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 16 deletions.
35 changes: 22 additions & 13 deletions crm/api/doc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import frappe
from frappe.model.document import get_controller
from frappe.model import no_value_fields
from pypika import Criterion


Expand Down Expand Up @@ -77,22 +78,30 @@ def get_list_data(doctype: str, filters: dict, order_by: str):
page_length=20,
) or []

not_allowed_fieldtypes = [
"Section Break",
"Column Break",
"Tab Break",
]

fields = frappe.get_meta(doctype).fields
fields = [field for field in fields if field.fieldtype not in not_allowed_fieldtypes]
fields = [{"label": field.label, "value": field.fieldname} for field in fields if field.label and field.fieldname]
fields = [field for field in fields if field.fieldtype not in no_value_fields]
fields = [
{
"label": field.label,
"type": field.fieldtype,
"value": field.fieldname,
"options": field.options,
}
for field in fields
if field.label and field.fieldname
]

std_fields = [
{'label': 'Name', 'value': 'name'},
{'label': 'Created On', 'value': 'creation'},
{'label': 'Last Modified', 'value': 'modified'},
{'label': 'Modified By', 'value': 'modified_by'},
{'label': 'Owner', 'value': 'owner'},
{"label": "Name", "type": "Data", "value": "name"},
{"label": "Created On", "type": "Datetime", "value": "creation"},
{"label": "Last Modified", "type": "Datetime", "value": "modified"},
{
"label": "Modified By",
"type": "Link",
"value": "modified_by",
"options": "User",
},
{"label": "Owner", "type": "Link", "value": "owner", "options": "User"},
]

for field in std_fields:
Expand Down
9 changes: 9 additions & 0 deletions crm/fcrm/doctype/crm_deal/crm_deal.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,36 +62,45 @@ def default_list_data():
columns = [
{
'label': 'Organization',
'type': 'Link',
'key': 'organization',
'options': 'CRM Organization',
'width': '11rem',
},
{
'label': 'Amount',
'type': 'Currency',
'key': 'annual_revenue',
'width': '9rem',
},
{
'label': 'Status',
'type': 'Select',
'key': 'status',
'width': '10rem',
},
{
'label': 'Email',
'type': 'Data',
'key': 'email',
'width': '12rem',
},
{
'label': 'Mobile no',
'type': 'Data',
'key': 'mobile_no',
'width': '11rem',
},
{
'label': 'Deal owner',
'type': 'Link',
'key': 'deal_owner',
'options': 'User',
'width': '10rem',
},
{
'label': 'Last modified',
'type': 'Datetime',
'key': 'modified',
'width': '8rem',
},
Expand Down
9 changes: 9 additions & 0 deletions crm/fcrm/doctype/crm_lead/crm_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,36 +141,45 @@ def default_list_data():
columns = [
{
'label': 'Name',
'type': 'Data',
'key': 'lead_name',
'width': '12rem',
},
{
'label': 'Organization',
'type': 'Link',
'key': 'organization',
'options': 'CRM Organization',
'width': '10rem',
},
{
'label': 'Status',
'type': 'Select',
'key': 'status',
'width': '8rem',
},
{
'label': 'Email',
'type': 'Data',
'key': 'email',
'width': '12rem',
},
{
'label': 'Mobile no',
'type': 'Data',
'key': 'mobile_no',
'width': '11rem',
},
{
'label': 'Lead owner',
'type': 'Link',
'key': 'lead_owner',
'options': 'User',
'width': '10rem',
},
{
'label': 'Last modified',
'type': 'Datetime',
'key': 'modified',
'width': '8rem',
},
Expand Down
5 changes: 5 additions & 0 deletions crm/overrides/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,31 @@ def default_list_data():
columns = [
{
'label': 'Name',
'type': 'Data',
'key': 'full_name',
'width': '17rem',
},
{
'label': 'Email',
'type': 'Data',
'key': 'email_id',
'width': '12rem',
},
{
'label': 'Phone',
'type': 'Data',
'key': 'mobile_no',
'width': '12rem',
},
{
'label': 'Organization',
'type': 'Data',
'key': 'company_name',
'width': '12rem',
},
{
'label': 'Last modified',
'type': 'Datetime',
'key': 'modified',
'width': '8rem',
},
Expand Down
19 changes: 17 additions & 2 deletions frontend/src/components/ListViews/ContactsListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
:columns="columns"
:rows="rows"
:options="{
getRowRoute: (row) => ({ name: 'Contact', params: { contactId: row.name } }),
getRowRoute: (row) => ({
name: 'Contact',
params: { contactId: row.name },
}),
selectable: options.selectable,
}"
row-key="name"
Expand Down Expand Up @@ -41,9 +44,20 @@
<PhoneIcon class="h-4 w-4" />
</div>
</template>
<div v-if="column.key === 'modified'" class="truncate text-base">
<div
v-if="['modified', 'creation'].includes(column.key)"
class="truncate text-base"
>
{{ item.timeAgo }}
</div>
<div v-else-if="column.type === 'Check'">
<FormControl
type="checkbox"
:modelValue="item"
:disabled="true"
class="text-gray-900"
/>
</div>
</ListRowItem>
</ListRow>
</ListRows>
Expand All @@ -60,6 +74,7 @@ import {
ListRow,
ListSelectBanner,
ListRowItem,
FormControl,
} from 'frappe-ui'
const props = defineProps({
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/components/ListViews/DealsListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
<div v-if="['modified', 'creation'].includes(column.key)" class="truncate text-base">
{{ item.timeAgo }}
</div>
<div v-else-if="column.type === 'Check'">
<FormControl
type="checkbox"
:modelValue="item"
:disabled="true"
class="text-gray-900"
/>
</div>
</ListRowItem>
</ListRow>
</ListRows>
Expand All @@ -65,6 +73,7 @@ import {
ListRow,
ListRowItem,
ListSelectBanner,
FormControl,
} from 'frappe-ui'
const props = defineProps({
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/components/ListViews/LeadsListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
<div v-if="['modified', 'creation'].includes(column.key)" class="truncate text-base">
{{ item.timeAgo }}
</div>
<div v-else-if="column.type === 'Check'">
<FormControl
type="checkbox"
:modelValue="item"
:disabled="true"
class="text-gray-900"
/>
</div>
</ListRowItem>
</ListRow>
</ListRows>
Expand All @@ -74,6 +82,7 @@ import {
ListRow,
ListSelectBanner,
ListRowItem,
FormControl,
} from 'frappe-ui'
const props = defineProps({
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/components/ListViews/OrganizationsListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,17 @@
/>
</div>
</template>
<div v-if="column.key === 'modified'" class="truncate text-base">
<div v-if="['modified', 'creation'].includes(column.key)" class="truncate text-base">
{{ item.timeAgo }}
</div>
<div v-else-if="column.type === 'Check'">
<FormControl
type="checkbox"
:modelValue="item"
:disabled="true"
class="text-gray-900"
/>
</div>
</ListRowItem>
</ListRow>
</ListRows>
Expand All @@ -50,6 +58,7 @@ import {
ListRow,
ListSelectBanner,
ListRowItem,
FormControl,
} from 'frappe-ui'
const props = defineProps({
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/ViewSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ const fields = computed(() => {
async function addColumn(c) {
let _column = {
label: c.label,
type: c.type,
key: c.value,
width: '10rem',
}
Expand Down

0 comments on commit 72a7770

Please sign in to comment.