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: remove custom list view #2111

Merged
merged 14 commits into from
Dec 23, 2024
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
45 changes: 39 additions & 6 deletions desk/src/components/ListViewBuilder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
:rows="rows"
row-key="name"
:options="{
selectable: true,
selectable: props.options.selectable ?? true ,
showTooltip: true,
resizeColumn: false,
onRowClick: (row: Object) => emit('rowClick', row['name']),
Expand Down Expand Up @@ -61,6 +61,9 @@
<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>
Expand Down Expand Up @@ -109,13 +112,16 @@ import {
ListRow,
ListHeader,
ListHeaderItem,
Badge,
} from "frappe-ui";

import { Filter, SortBy, QuickFilters } from "@/components/view-controls";
import { dayjs } from "@/dayjs";
import FadedScrollableDiv from "./FadedScrollableDiv.vue";
import Reload from "./view-controls/Reload.vue";
import { useScreenSize } from "@/composables/screen";
import EmptyState from "./EmptyState.vue";
import { BadgeStatus } from "@/types";

interface P {
options: {
Expand All @@ -126,6 +132,9 @@ interface P {
icon?: HTMLElement | string;
title: string;
};
hideViewControls?: boolean;
selectable?: boolean;
statusMap?: Record<string, BadgeStatus>;
};
}

Expand All @@ -134,7 +143,15 @@ interface E {
(event: "rowClick", row: any): void;
}

const props = defineProps<P>();
const props = withDefaults(defineProps<P>(), {
options: () => {
return {
doctype: "",
hideViewControls: false,
selectable: true,
};
},
});

const emit = defineEmits<E>();
const { isMobileView } = useScreenSize();
Expand Down Expand Up @@ -190,10 +207,21 @@ function handleColumnConfig(column) {
return column;
}

const statusMap: Record<string, BadgeStatus> = props.options
.statusMap as Record<string, BadgeStatus>;
function handleStatusColor(status: "Published" | "Draft"): BadgeStatus {
if (!statusMap)
return {
label: status,
theme: "gray",
};
return statusMap[status];
}

const filterableFields = createResource({
url: "helpdesk.api.doc.get_filterable_fields",
cache: ["DocField", props.options.doctype],
auto: true,
auto: !props.options.hideViewControls,
params: {
doctype: props.options.doctype,
append_assign: true,
Expand All @@ -212,15 +240,15 @@ const filterableFields = createResource({

const sortableFields = createResource({
url: "helpdesk.api.doc.sort_options",
auto: true,
auto: !props.options.hideViewControls,
params: {
doctype: props.options.doctype,
},
});

const quickFilters = createResource({
url: "helpdesk.api.doc.get_quick_filters",
auto: true,
auto: !props.options.hideViewControls,
params: {
doctype: props.options.doctype,
},
Expand All @@ -232,7 +260,12 @@ const quickFilters = createResource({
});

const showViewControls = computed(() => {
return filterableFields.data && sortableFields.data && quickFilters.data;
return (
!props.options.hideViewControls &&
filterableFields.data &&
sortableFields.data &&
quickFilters.data
);
});

const listViewData = reactive({
Expand Down
16 changes: 7 additions & 9 deletions desk/src/components/desk/global/NewContactDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
ErrorMessage,
createResource,
Autocomplete,
createListResource,
} from "frappe-ui";
import zod from "zod";

Expand Down Expand Up @@ -141,20 +142,17 @@ const open = computed({
},
});

const customerResource = createResource({
url: "helpdesk.extends.client.get_list",
params: {
doctype: "HD Customer",
fields: ["name", "customer_name"],
},
const customerResource = createListResource({
doctype: "HD Customer",
fields: ["name"],
cache: "customers",
transform: (data) => {
let allData = data.map((option) => {
return data.map((option) => {
return {
label: option.name,
value: option.customer_name,
value: option.name,
};
});
return allData;
},
auto: true,
});
Expand Down
1 change: 0 additions & 1 deletion desk/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export { default as AttachmentItem } from "./AttachmentItem.vue";
export { default as CommandPalette } from "./command-palette/CP.vue";
export { default as HCard } from "./HCard.vue";
export { default as ListView } from "./list-view/LV.vue";
export { default as NestedPopover } from "./NestedPopover.vue";
export { default as Notifications } from "./notifications/Notifications.vue";
export { default as PageTitle } from "./PageTitle.vue";
Expand Down
108 changes: 0 additions & 108 deletions desk/src/components/list-view/LV.vue

This file was deleted.

17 changes: 0 additions & 17 deletions desk/src/components/list-view/LVEmpty.vue

This file was deleted.

40 changes: 0 additions & 40 deletions desk/src/components/list-view/LVHeader.vue

This file was deleted.

31 changes: 0 additions & 31 deletions desk/src/components/list-view/LVLoading.vue

This file was deleted.

36 changes: 0 additions & 36 deletions desk/src/components/list-view/LVNavigation.vue

This file was deleted.

Loading
Loading