fix: implemented ListBulkAction component in all List View

This commit is contained in:
Shariq Ansari 2024-05-20 22:32:44 +05:30
parent f34e9bdaeb
commit e291f2068c
6 changed files with 65 additions and 448 deletions

View File

@ -135,7 +135,7 @@ const customListActions = ref([])
function bulkActions(selections, unselectAll) {
let actions = []
debugger
if (!props.options.hideEdit) {
actions.push({
label: __('Edit'),

View File

@ -80,7 +80,9 @@
</ListRows>
<ListSelectBanner>
<template #actions="{ selections, unselectAll }">
<Dropdown :options="bulkActions(selections, unselectAll)">
<Dropdown
:options="listBulkActionsRef.bulkActions(selections, unselectAll)"
>
<Button icon="more-horizontal" variant="ghost" />
</Dropdown>
</template>
@ -95,8 +97,18 @@
}"
@loadMore="emit('loadMore')"
/>
<ListBulkActions
ref="listBulkActionsRef"
v-model="list"
doctype="CRM Call Log"
:options="{
hideEdit: true,
hideAssign: true,
}"
/>
</template>
<script setup>
import ListBulkActions from '@/components/ListBulkActions.vue'
import {
Avatar,
ListView,
@ -108,12 +120,8 @@ import {
ListFooter,
Tooltip,
Dropdown,
call,
} from 'frappe-ui'
import { setupListActions, createToast } from '@/utils'
import { globalStore } from '@/stores/global'
import { onMounted, ref, watch } from 'vue'
import { useRouter } from 'vue-router'
import { ref, watch } from 'vue'
const props = defineProps({
rows: {
@ -146,89 +154,14 @@ const emit = defineEmits([
const pageLengthCount = defineModel()
const list = defineModel('list')
const router = useRouter()
const { $dialog } = globalStore()
watch(pageLengthCount, (val, old_value) => {
if (val === old_value) return
emit('updatePageCount', val)
})
function deleteValues(selections, unselectAll) {
$dialog({
title: 'Delete',
message: `Are you sure you want to delete ${selections.size} item${
selections.size > 1 ? 's' : ''
}?`,
variant: 'danger',
actions: [
{
label: 'Delete',
variant: 'solid',
theme: 'red',
onClick: (close) => {
call('frappe.desk.reportview.delete_items', {
items: JSON.stringify(Array.from(selections)),
doctype: 'CRM Call Log',
}).then(() => {
createToast({
title: 'Deleted successfully',
icon: 'check',
iconClasses: 'text-green-600',
})
unselectAll()
list.value.reload()
close()
})
},
},
],
})
}
const customBulkActions = ref([])
const customListActions = ref([])
function bulkActions(selections, unselectAll) {
let actions = [
{
label: 'Delete',
onClick: () => deleteValues(selections, unselectAll),
},
]
customBulkActions.value.forEach((action) => {
actions.push({
label: action.label,
onClick: () =>
action.onClick({
list: list.value,
selections,
unselectAll,
call,
createToast,
$dialog,
router,
}),
})
})
return actions
}
onMounted(() => {
if (!list.value?.data) return
setupListActions(list.value.data, {
list: list.value,
call,
createToast,
$dialog,
router,
})
customBulkActions.value = list.value?.data?.bulkActions || []
customListActions.value = list.value?.data?.listActions || []
})
const listBulkActionsRef = ref(null)
defineExpose({
customListActions,
customListActions: listBulkActionsRef.value?.customListActions,
})
</script>

View File

@ -82,7 +82,9 @@
</ListRows>
<ListSelectBanner>
<template #actions="{ selections, unselectAll }">
<Dropdown :options="bulkActions(selections, unselectAll)">
<Dropdown
:options="listBulkActionsRef.bulkActions(selections, unselectAll)"
>
<Button icon="more-horizontal" variant="ghost" />
</Dropdown>
</template>
@ -98,18 +100,18 @@
}"
@loadMore="emit('loadMore')"
/>
<EditValueModal
v-model="showEditModal"
<ListBulkActions
ref="listBulkActionsRef"
v-model="list"
doctype="Contact"
:selectedValues="selectedValues"
@reload="reload"
:options="{
hideAssign: true,
}"
/>
</template>
<script setup>
import PhoneIcon from '@/components/Icons/PhoneIcon.vue'
import EditValueModal from '@/components/Modals/EditValueModal.vue'
import { globalStore } from '@/stores/global'
import { setupListActions, createToast } from '@/utils'
import ListBulkActions from '@/components/ListBulkActions.vue'
import {
Avatar,
ListView,
@ -121,10 +123,8 @@ import {
ListFooter,
Tooltip,
Dropdown,
call,
} from 'frappe-ui'
import { ref, watch, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ref, watch } from 'vue'
const props = defineProps({
rows: {
@ -157,92 +157,14 @@ const emit = defineEmits([
const pageLengthCount = defineModel()
const list = defineModel('list')
const router = useRouter()
const { $dialog } = globalStore()
watch(pageLengthCount, (val, old_value) => {
if (val === old_value) return
emit('updatePageCount', val)
})
const showEditModal = ref(false)
const selectedValues = ref([])
const unselectAllAction = ref(() => {})
function editValues(selections, unselectAll) {
selectedValues.value = selections
showEditModal.value = true
unselectAllAction.value = unselectAll
}
function deleteValues(selections, unselectAll) {
$dialog({
title: __('Delete'),
message: __('Are you sure you want to delete {0} item(s)?', [
selections.size,
]),
variant: 'danger',
actions: [
{
label: __('Delete'),
variant: 'solid',
theme: 'red',
onClick: (close) => {
call('frappe.desk.reportview.delete_items', {
items: JSON.stringify(Array.from(selections)),
doctype: 'Contact',
}).then(() => {
createToast({
title: __('Deleted successfully'),
icon: 'check',
iconClasses: 'text-green-600',
})
unselectAll()
list.value.reload()
close()
})
},
},
],
})
}
const customListActions = ref([])
function bulkActions(selections, unselectAll) {
let actions = [
{
label: __('Edit'),
onClick: () => editValues(selections, unselectAll),
},
{
label: __('Delete'),
onClick: () => deleteValues(selections, unselectAll),
},
]
return actions
}
function reload() {
unselectAllAction.value?.()
list.value?.reload()
}
onMounted(() => {
if (!list.value?.data) return
setupListActions(list.value.data, {
list: list.value,
call,
createToast,
$dialog,
router,
})
// customBulkActions.value = list.value?.data?.bulkActions || []
customListActions.value = list.value?.data?.listActions || []
})
const listBulkActionsRef = ref(null)
defineExpose({
customListActions,
customListActions: listBulkActionsRef.value?.customListActions,
})
</script>

View File

@ -69,7 +69,7 @@
</ListRows>
<ListSelectBanner>
<template #actions="{ selections, unselectAll }">
<Dropdown :options="bulkActions(selections, unselectAll)">
<Dropdown :options="listBulkActionsRef.bulkActions(selections, unselectAll)">
<Button icon="more-horizontal" variant="ghost" />
</Dropdown>
</template>
@ -84,17 +84,17 @@
}"
@loadMore="emit('loadMore')"
/>
<EditValueModal
v-model="showEditModal"
<ListBulkActions
ref="listBulkActionsRef"
v-model="list"
doctype="Email Template"
:selectedValues="selectedValues"
@reload="reload"
:options="{
hideAssign: true,
}"
/>
</template>
<script setup>
import EditValueModal from '@/components/Modals/EditValueModal.vue'
import { globalStore } from '@/stores/global'
import { setupListActions, createToast } from '@/utils'
import ListBulkActions from '@/components/ListBulkActions.vue'
import {
ListView,
ListHeader,
@ -104,11 +104,9 @@ import {
ListRowItem,
ListFooter,
Dropdown,
call,
Tooltip,
} from 'frappe-ui'
import { ref, watch, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ref, watch } from 'vue'
const props = defineProps({
rows: {
@ -142,92 +140,14 @@ const emit = defineEmits([
const pageLengthCount = defineModel()
const list = defineModel('list')
const router = useRouter()
const { $dialog } = globalStore()
watch(pageLengthCount, (val, old_value) => {
if (val === old_value) return
emit('updatePageCount', val)
})
const showEditModal = ref(false)
const selectedValues = ref([])
const unselectAllAction = ref(() => {})
function editValues(selections, unselectAll) {
selectedValues.value = selections
showEditModal.value = true
unselectAllAction.value = unselectAll
}
function deleteValues(selections, unselectAll) {
$dialog({
title: __('Delete'),
message: __('Are you sure you want to delete {0} item(s)?', [
selections.size,
]),
variant: 'danger',
actions: [
{
label: __('Delete'),
variant: 'solid',
theme: 'red',
onClick: (close) => {
call('frappe.desk.reportview.delete_items', {
items: JSON.stringify(Array.from(selections)),
doctype: 'Email Template',
}).then(() => {
createToast({
title: __('Deleted successfully'),
icon: 'check',
iconClasses: 'text-green-600',
})
unselectAll()
list.value.reload()
close()
})
},
},
],
})
}
const customListActions = ref([])
function bulkActions(selections, unselectAll) {
let actions = [
{
label: __('Edit'),
onClick: () => editValues(selections, unselectAll),
},
{
label: __('Delete'),
onClick: () => deleteValues(selections, unselectAll),
},
]
return actions
}
function reload() {
unselectAllAction.value?.()
list.value?.reload()
}
onMounted(() => {
if (!list.value?.data) return
setupListActions(list.value.data, {
list: list.value,
call,
createToast,
$dialog,
router,
})
// customBulkActions.value = list.value?.data?.bulkActions || []
customListActions.value = list.value?.data?.listActions || []
})
const listBulkActionsRef = ref(null)
defineExpose({
customListActions,
customListActions: listBulkActionsRef.value?.customListActions,
})
</script>

View File

@ -69,7 +69,9 @@
</ListRows>
<ListSelectBanner>
<template #actions="{ selections, unselectAll }">
<Dropdown :options="bulkActions(selections, unselectAll)">
<Dropdown
:options="listBulkActionsRef.bulkActions(selections, unselectAll)"
>
<Button icon="more-horizontal" variant="ghost" />
</Dropdown>
</template>
@ -84,17 +86,17 @@
}"
@loadMore="emit('loadMore')"
/>
<EditValueModal
v-model="showEditModal"
<ListBulkActions
ref="listBulkActionsRef"
v-model="list"
doctype="CRM Organization"
:selectedValues="selectedValues"
@reload="reload"
:options="{
hideAssign: true,
}"
/>
</template>
<script setup>
import EditValueModal from '@/components/Modals/EditValueModal.vue'
import { globalStore } from '@/stores/global'
import { setupListActions, createToast } from '@/utils'
import ListBulkActions from '@/components/ListBulkActions.vue'
import {
Avatar,
ListView,
@ -106,10 +108,8 @@ import {
ListFooter,
Tooltip,
Dropdown,
call,
} from 'frappe-ui'
import { ref, watch, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ref, watch } from 'vue'
const props = defineProps({
rows: {
@ -142,92 +142,14 @@ const emit = defineEmits([
const pageLengthCount = defineModel()
const list = defineModel('list')
const router = useRouter()
const { $dialog } = globalStore()
watch(pageLengthCount, (val, old_value) => {
if (val === old_value) return
emit('updatePageCount', val)
})
const showEditModal = ref(false)
const selectedValues = ref([])
const unselectAllAction = ref(() => {})
function editValues(selections, unselectAll) {
selectedValues.value = selections
showEditModal.value = true
unselectAllAction.value = unselectAll
}
function deleteValues(selections, unselectAll) {
$dialog({
title: __('Delete'),
message: __('Are you sure you want to delete {0} item(s)?', [
selections.size,
]),
variant: 'danger',
actions: [
{
label: __('Delete'),
variant: 'solid',
theme: 'red',
onClick: (close) => {
call('frappe.desk.reportview.delete_items', {
items: JSON.stringify(Array.from(selections)),
doctype: 'CRM Organization',
}).then(() => {
createToast({
title: __('Deleted successfully'),
icon: 'check',
iconClasses: 'text-green-600',
})
unselectAll()
list.value.reload()
close()
})
},
},
],
})
}
const customListActions = ref([])
function bulkActions(selections, unselectAll) {
let actions = [
{
label: __('Edit'),
onClick: () => editValues(selections, unselectAll),
},
{
label: __('Delete'),
onClick: () => deleteValues(selections, unselectAll),
},
]
return actions
}
function reload() {
unselectAllAction.value?.()
list.value?.reload()
}
onMounted(() => {
if (!list.value?.data) return
setupListActions(list.value.data, {
list: list.value,
call,
createToast,
$dialog,
router,
})
// customBulkActions.value = list.value?.data?.bulkActions || []
customListActions.value = list.value?.data?.listActions || []
})
const listBulkActionsRef = ref(null)
defineExpose({
customListActions,
customListActions: listBulkActionsRef.value?.customListActions,
})
</script>

View File

@ -82,7 +82,7 @@
</ListRows>
<ListSelectBanner>
<template #actions="{ selections, unselectAll }">
<Dropdown :options="bulkActions(selections, unselectAll)">
<Dropdown :options="listBulkActionsRef.bulkActions(selections, unselectAll)">
<Button icon="more-horizontal" variant="ghost" />
</Dropdown>
</template>
@ -97,21 +97,21 @@
}"
@loadMore="emit('loadMore')"
/>
<EditValueModal
v-model="showEditModal"
<ListBulkActions
ref="listBulkActionsRef"
v-model="list"
doctype="CRM Task"
:selectedValues="selectedValues"
@reload="reload"
:options="{
hideAssign: true,
}"
/>
</template>
<script setup>
import TaskStatusIcon from '@/components/Icons/TaskStatusIcon.vue'
import TaskPriorityIcon from '@/components/Icons/TaskPriorityIcon.vue'
import CalendarIcon from '@/components/Icons/CalendarIcon.vue'
import EditValueModal from '@/components/Modals/EditValueModal.vue'
import ListBulkActions from '@/components/ListBulkActions.vue'
import { dateFormat } from '@/utils'
import { globalStore } from '@/stores/global'
import { setupListActions, createToast } from '@/utils'
import {
Avatar,
ListView,
@ -122,11 +122,9 @@ import {
ListRowItem,
ListFooter,
Dropdown,
call,
Tooltip,
} from 'frappe-ui'
import { ref, watch, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ref, watch } from 'vue'
const props = defineProps({
rows: {
@ -160,92 +158,14 @@ const emit = defineEmits([
const pageLengthCount = defineModel()
const list = defineModel('list')
const router = useRouter()
const { $dialog } = globalStore()
watch(pageLengthCount, (val, old_value) => {
if (val === old_value) return
emit('updatePageCount', val)
})
const showEditModal = ref(false)
const selectedValues = ref([])
const unselectAllAction = ref(() => {})
function editValues(selections, unselectAll) {
selectedValues.value = selections
showEditModal.value = true
unselectAllAction.value = unselectAll
}
function deleteValues(selections, unselectAll) {
$dialog({
title: __('Delete'),
message: __('Are you sure you want to delete {0} item(s)?', [
selections.size,
]),
variant: 'danger',
actions: [
{
label: __('Delete'),
variant: 'solid',
theme: 'red',
onClick: (close) => {
call('frappe.desk.reportview.delete_items', {
items: JSON.stringify(Array.from(selections)),
doctype: 'CRM Task',
}).then(() => {
createToast({
title: __('Deleted successfully'),
icon: 'check',
iconClasses: 'text-green-600',
})
unselectAll()
list.value.reload()
close()
})
},
},
],
})
}
const customListActions = ref([])
function bulkActions(selections, unselectAll) {
let actions = [
{
label: __('Edit'),
onClick: () => editValues(selections, unselectAll),
},
{
label: __('Delete'),
onClick: () => deleteValues(selections, unselectAll),
},
]
return actions
}
function reload() {
unselectAllAction.value?.()
list.value?.reload()
}
onMounted(() => {
if (!list.value?.data) return
setupListActions(list.value.data, {
list: list.value,
call,
createToast,
$dialog,
router,
})
// customBulkActions.value = list.value?.data?.bulkActions || []
customListActions.value = list.value?.data?.listActions || []
})
const listBulkActionsRef = ref(null)
defineExpose({
customListActions,
customListActions: listBulkActionsRef.value?.customListActions,
})
</script>