Skip to content

Commit

Permalink
Merge pull request #2117 from RitvikSardana/listview-reload
Browse files Browse the repository at this point in the history
fix(api): get_list_data
  • Loading branch information
RitvikSardana authored Dec 30, 2024
2 parents 423d1aa + 938975f commit 441d201
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 104 deletions.
2 changes: 1 addition & 1 deletion desk/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { stopSession } from "@/telemetry";
import { Dialogs } from "frappe-ui";
useConfigStore();
onMounted(async () => {
onMounted(() => {
window.addEventListener("online", () => {
createToast({
title: "You are now online",
Expand Down
12 changes: 11 additions & 1 deletion desk/src/components/EmailEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,15 @@ import {
TextEditorFixedMenu,
createResource,
} from "frappe-ui";
import { validateEmail } from "@/utils";
import { createToast, validateEmail } from "@/utils";
import {
MultiSelectInput,
AttachmentItem,
CannedResponseSelectorModal,
} from "@/components";
import { AttachmentIcon, EmailIcon } from "@/components/icons";
import { PreserveVideoControls } from "@/tiptap-extensions";
import { useError } from "@/composables/error";
const editorRef = ref(null);
const showCannedResponseSelectorModal = ref(false);
Expand Down Expand Up @@ -242,6 +243,15 @@ function submitMail() {
emit("submit");
loading.value = false;
},
onError: (err) => {
loading.value = false;
createToast({
title: err.exc_type,
text: err.messages[0],
icon: "x",
iconClasses: "text-red-500",
});
},
});
sendMail.submit();
Expand Down
102 changes: 50 additions & 52 deletions desk/src/components/ListViewBuilder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
>
<QuickFilters v-if="!isMobileView" />
<div class="flex items-center gap-2" v-if="!isMobileView">
<Reload @click="reload" :loding="list.loading" />
<Reload @click="reload" :loading="list.loading" />
<Filter :default_filters="defaultParams.filters" />
<SortBy :hide-label="isMobileView" />
</div>
Expand All @@ -21,57 +21,55 @@
</FadedScrollableDiv>

<!-- List View -->
<slot v-bind="{ list }">
<ListView
v-if="list.data?.data.length > 0"
class="flex-1"
:columns="columns"
:rows="rows"
row-key="name"
:options="{
selectable: props.options.selectable ?? true ,
showTooltip: true,
resizeColumn: false,
onRowClick: (row: Object) => emit('rowClick', row['name']),
emptyState,
}"
>
<ListHeader class="sm:mx-5 mx-3">
<ListHeaderItem
v-for="column in columns"
:key="column.key"
:item="column"
@columnWidthUpdated="(width) => console.log(width)"
/>
</ListHeader>
<ListRows class="sm:mx-5 mx-3">
<ListRow
v-for="row in rows"
:key="row.name"
v-slot="{ idx, column, item }"
:row="row"
class="truncate text-base"
>
<ListRowItem :item="item" :row="row" :column="column">
<!-- TODO: filters on click of other columns -->
<!-- and not on first column, it should emit the event -->
<div v-if="idx === 0" class="truncate">
{{ item }}
</div>
<div v-else-if="column.type === 'Datetime'">
{{ dayjs.tz(item).fromNow() }}
</div>
<div v-else-if="column.type === 'status'">
<Badge v-bind="handleStatusColor(item)" />
</div>
<div v-else class="truncate">
{{ item }}
</div>
</ListRowItem>
</ListRow>
</ListRows>
</ListView>
</slot>
<ListView
v-if="list.data?.data.length > 0"
class="flex-1"
:columns="columns"
:rows="rows"
row-key="name"
:options="{
selectable: props.options.selectable ?? true ,
showTooltip: true,
resizeColumn: false,
onRowClick: (row: Object) => emit('rowClick', row['name']),
emptyState,
}"
>
<ListHeader class="sm:mx-5 mx-3">
<ListHeaderItem
v-for="column in columns"
:key="column.key"
:item="column"
@columnWidthUpdated="(width) => console.log(width)"
/>
</ListHeader>
<ListRows class="sm:mx-5 mx-3">
<ListRow
v-for="row in rows"
:key="row.name"
v-slot="{ idx, column, item }"
:row="row"
class="truncate text-base"
>
<ListRowItem :item="item" :row="row" :column="column">
<!-- TODO: filters on click of other columns -->
<!-- and not on first column, it should emit the event -->
<div v-if="idx === 0" class="truncate">
{{ item }}
</div>
<div v-else-if="column.type === 'Datetime'">
{{ dayjs.tz(item).fromNow() }}
</div>
<div v-else-if="column.type === 'status'">
<Badge v-bind="handleStatusColor(item)" />
</div>
<div v-else class="truncate">
{{ item }}
</div>
</ListRowItem>
</ListRow>
</ListRows>
</ListView>

<!-- List Footer -->
<div
Expand Down
2 changes: 1 addition & 1 deletion desk/src/components/view-controls/Reload.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<Button label="Refresh" @click="reload()" :loading="loading">
<Button label="Refresh" :loading="loading">
<template #icon>
<RefreshIcon class="h-4 w-4" />
</template>
Expand Down
6 changes: 4 additions & 2 deletions helpdesk/api/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ def get_list_data(
)
rows = list.default_list_data().get("rows")

if rows is None:
rows = []

# check if rows has all keys from columns if not add them
for column in columns:
if column.get("key") not in rows:
Expand Down Expand Up @@ -221,8 +224,7 @@ def get_list_data(
return {
"data": data,
"columns": columns,
"rows": rows,
"fields": fields,
"fields": fields if doctype == "HD Ticket" else [],
"total_count": len(frappe.get_list(doctype, filters=filters)),
"row_count": len(data),
}
Expand Down
17 changes: 6 additions & 11 deletions helpdesk/helpdesk/doctype/hd_agent/hd_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def default_list_data():
},
{
"label": "Email",
"key": "email",
"key": "user.email as email",
"width": "24rem",
"type": "Data",
},
Expand All @@ -41,16 +41,11 @@ def default_list_data():
"type": "Datetime",
},
]
rows = [
"name",
"is_active",
"user.full_name",
"user.user_image",
"user.email",
"user.username",
"modified",
"creation",
]
rows = ["modified"]
# modified row is needed because
# we have a link table for HD Agent to User
# and sql gets confused which modified to take from those 2 tables
# hence throws ambiguous error
return {"columns": columns, "rows": rows}


Expand Down
11 changes: 1 addition & 10 deletions helpdesk/helpdesk/doctype/hd_article/hd_article.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,7 @@ def default_list_data():
"width": "8rem",
},
]
rows = [
"name",
"title",
"category",
"status",
"author",
"published_on",
"modified",
]
return {"columns": columns, "rows": rows}
return {"columns": columns}

@frappe.whitelist()
def set_feedback(self, value):
Expand Down
9 changes: 1 addition & 8 deletions helpdesk/helpdesk/doctype/hd_customer/hd_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,4 @@ def default_list_data():
"type": "Datetime",
},
]
rows = [
"name",
"image",
"domain",
"modified",
"creation",
]
return {"columns": columns, "rows": rows}
return {"columns": columns}
9 changes: 1 addition & 8 deletions helpdesk/helpdesk/doctype/hd_team/hd_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,4 @@ def default_list_data():
"type": "Datetime",
},
]
rows = [
"name",
"assignment_rule",
"ignore_restrictions",
"modified",
"creation",
]
return {"columns": columns, "rows": rows}
return {"columns": columns}
11 changes: 1 addition & 10 deletions helpdesk/overrides/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,4 @@ def default_list_data():
"width": "8rem",
},
]
rows = [
"name",
"full_name",
"company_name",
"email_id",
"phone",
"modified",
"image",
]
return {"columns": columns, "rows": rows}
return {"columns": columns}

0 comments on commit 441d201

Please sign in to comment.