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) { function bulkActions(selections, unselectAll) {
let actions = [] let actions = []
debugger
if (!props.options.hideEdit) { if (!props.options.hideEdit) {
actions.push({ actions.push({
label: __('Edit'), label: __('Edit'),

View File

@ -80,7 +80,9 @@
</ListRows> </ListRows>
<ListSelectBanner> <ListSelectBanner>
<template #actions="{ selections, unselectAll }"> <template #actions="{ selections, unselectAll }">
<Dropdown :options="bulkActions(selections, unselectAll)"> <Dropdown
:options="listBulkActionsRef.bulkActions(selections, unselectAll)"
>
<Button icon="more-horizontal" variant="ghost" /> <Button icon="more-horizontal" variant="ghost" />
</Dropdown> </Dropdown>
</template> </template>
@ -95,8 +97,18 @@
}" }"
@loadMore="emit('loadMore')" @loadMore="emit('loadMore')"
/> />
<ListBulkActions
ref="listBulkActionsRef"
v-model="list"
doctype="CRM Call Log"
:options="{
hideEdit: true,
hideAssign: true,
}"
/>
</template> </template>
<script setup> <script setup>
import ListBulkActions from '@/components/ListBulkActions.vue'
import { import {
Avatar, Avatar,
ListView, ListView,
@ -108,12 +120,8 @@ import {
ListFooter, ListFooter,
Tooltip, Tooltip,
Dropdown, Dropdown,
call,
} from 'frappe-ui' } from 'frappe-ui'
import { setupListActions, createToast } from '@/utils' import { ref, watch } from 'vue'
import { globalStore } from '@/stores/global'
import { onMounted, ref, watch } from 'vue'
import { useRouter } from 'vue-router'
const props = defineProps({ const props = defineProps({
rows: { rows: {
@ -146,89 +154,14 @@ const emit = defineEmits([
const pageLengthCount = defineModel() const pageLengthCount = defineModel()
const list = defineModel('list') const list = defineModel('list')
const router = useRouter()
const { $dialog } = globalStore()
watch(pageLengthCount, (val, old_value) => { watch(pageLengthCount, (val, old_value) => {
if (val === old_value) return if (val === old_value) return
emit('updatePageCount', val) emit('updatePageCount', val)
}) })
function deleteValues(selections, unselectAll) { const listBulkActionsRef = ref(null)
$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 || []
})
defineExpose({ defineExpose({
customListActions, customListActions: listBulkActionsRef.value?.customListActions,
}) })
</script> </script>

View File

@ -82,7 +82,9 @@
</ListRows> </ListRows>
<ListSelectBanner> <ListSelectBanner>
<template #actions="{ selections, unselectAll }"> <template #actions="{ selections, unselectAll }">
<Dropdown :options="bulkActions(selections, unselectAll)"> <Dropdown
:options="listBulkActionsRef.bulkActions(selections, unselectAll)"
>
<Button icon="more-horizontal" variant="ghost" /> <Button icon="more-horizontal" variant="ghost" />
</Dropdown> </Dropdown>
</template> </template>
@ -98,18 +100,18 @@
}" }"
@loadMore="emit('loadMore')" @loadMore="emit('loadMore')"
/> />
<EditValueModal <ListBulkActions
v-model="showEditModal" ref="listBulkActionsRef"
v-model="list"
doctype="Contact" doctype="Contact"
:selectedValues="selectedValues" :options="{
@reload="reload" hideAssign: true,
}"
/> />
</template> </template>
<script setup> <script setup>
import PhoneIcon from '@/components/Icons/PhoneIcon.vue' import PhoneIcon from '@/components/Icons/PhoneIcon.vue'
import EditValueModal from '@/components/Modals/EditValueModal.vue' import ListBulkActions from '@/components/ListBulkActions.vue'
import { globalStore } from '@/stores/global'
import { setupListActions, createToast } from '@/utils'
import { import {
Avatar, Avatar,
ListView, ListView,
@ -121,10 +123,8 @@ import {
ListFooter, ListFooter,
Tooltip, Tooltip,
Dropdown, Dropdown,
call,
} from 'frappe-ui' } from 'frappe-ui'
import { ref, watch, onMounted } from 'vue' import { ref, watch } from 'vue'
import { useRouter } from 'vue-router'
const props = defineProps({ const props = defineProps({
rows: { rows: {
@ -157,92 +157,14 @@ const emit = defineEmits([
const pageLengthCount = defineModel() const pageLengthCount = defineModel()
const list = defineModel('list') const list = defineModel('list')
const router = useRouter()
const { $dialog } = globalStore()
watch(pageLengthCount, (val, old_value) => { watch(pageLengthCount, (val, old_value) => {
if (val === old_value) return if (val === old_value) return
emit('updatePageCount', val) emit('updatePageCount', val)
}) })
const showEditModal = ref(false) const listBulkActionsRef = ref(null)
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 || []
})
defineExpose({ defineExpose({
customListActions, customListActions: listBulkActionsRef.value?.customListActions,
}) })
</script> </script>

View File

@ -69,7 +69,7 @@
</ListRows> </ListRows>
<ListSelectBanner> <ListSelectBanner>
<template #actions="{ selections, unselectAll }"> <template #actions="{ selections, unselectAll }">
<Dropdown :options="bulkActions(selections, unselectAll)"> <Dropdown :options="listBulkActionsRef.bulkActions(selections, unselectAll)">
<Button icon="more-horizontal" variant="ghost" /> <Button icon="more-horizontal" variant="ghost" />
</Dropdown> </Dropdown>
</template> </template>
@ -84,17 +84,17 @@
}" }"
@loadMore="emit('loadMore')" @loadMore="emit('loadMore')"
/> />
<EditValueModal <ListBulkActions
v-model="showEditModal" ref="listBulkActionsRef"
v-model="list"
doctype="Email Template" doctype="Email Template"
:selectedValues="selectedValues" :options="{
@reload="reload" hideAssign: true,
}"
/> />
</template> </template>
<script setup> <script setup>
import EditValueModal from '@/components/Modals/EditValueModal.vue' import ListBulkActions from '@/components/ListBulkActions.vue'
import { globalStore } from '@/stores/global'
import { setupListActions, createToast } from '@/utils'
import { import {
ListView, ListView,
ListHeader, ListHeader,
@ -104,11 +104,9 @@ import {
ListRowItem, ListRowItem,
ListFooter, ListFooter,
Dropdown, Dropdown,
call,
Tooltip, Tooltip,
} from 'frappe-ui' } from 'frappe-ui'
import { ref, watch, onMounted } from 'vue' import { ref, watch } from 'vue'
import { useRouter } from 'vue-router'
const props = defineProps({ const props = defineProps({
rows: { rows: {
@ -142,92 +140,14 @@ const emit = defineEmits([
const pageLengthCount = defineModel() const pageLengthCount = defineModel()
const list = defineModel('list') const list = defineModel('list')
const router = useRouter()
const { $dialog } = globalStore()
watch(pageLengthCount, (val, old_value) => { watch(pageLengthCount, (val, old_value) => {
if (val === old_value) return if (val === old_value) return
emit('updatePageCount', val) emit('updatePageCount', val)
}) })
const showEditModal = ref(false) const listBulkActionsRef = ref(null)
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 || []
})
defineExpose({ defineExpose({
customListActions, customListActions: listBulkActionsRef.value?.customListActions,
}) })
</script> </script>

View File

@ -69,7 +69,9 @@
</ListRows> </ListRows>
<ListSelectBanner> <ListSelectBanner>
<template #actions="{ selections, unselectAll }"> <template #actions="{ selections, unselectAll }">
<Dropdown :options="bulkActions(selections, unselectAll)"> <Dropdown
:options="listBulkActionsRef.bulkActions(selections, unselectAll)"
>
<Button icon="more-horizontal" variant="ghost" /> <Button icon="more-horizontal" variant="ghost" />
</Dropdown> </Dropdown>
</template> </template>
@ -84,17 +86,17 @@
}" }"
@loadMore="emit('loadMore')" @loadMore="emit('loadMore')"
/> />
<EditValueModal <ListBulkActions
v-model="showEditModal" ref="listBulkActionsRef"
v-model="list"
doctype="CRM Organization" doctype="CRM Organization"
:selectedValues="selectedValues" :options="{
@reload="reload" hideAssign: true,
}"
/> />
</template> </template>
<script setup> <script setup>
import EditValueModal from '@/components/Modals/EditValueModal.vue' import ListBulkActions from '@/components/ListBulkActions.vue'
import { globalStore } from '@/stores/global'
import { setupListActions, createToast } from '@/utils'
import { import {
Avatar, Avatar,
ListView, ListView,
@ -106,10 +108,8 @@ import {
ListFooter, ListFooter,
Tooltip, Tooltip,
Dropdown, Dropdown,
call,
} from 'frappe-ui' } from 'frappe-ui'
import { ref, watch, onMounted } from 'vue' import { ref, watch } from 'vue'
import { useRouter } from 'vue-router'
const props = defineProps({ const props = defineProps({
rows: { rows: {
@ -142,92 +142,14 @@ const emit = defineEmits([
const pageLengthCount = defineModel() const pageLengthCount = defineModel()
const list = defineModel('list') const list = defineModel('list')
const router = useRouter()
const { $dialog } = globalStore()
watch(pageLengthCount, (val, old_value) => { watch(pageLengthCount, (val, old_value) => {
if (val === old_value) return if (val === old_value) return
emit('updatePageCount', val) emit('updatePageCount', val)
}) })
const showEditModal = ref(false) const listBulkActionsRef = ref(null)
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 || []
})
defineExpose({ defineExpose({
customListActions, customListActions: listBulkActionsRef.value?.customListActions,
}) })
</script> </script>

View File

@ -82,7 +82,7 @@
</ListRows> </ListRows>
<ListSelectBanner> <ListSelectBanner>
<template #actions="{ selections, unselectAll }"> <template #actions="{ selections, unselectAll }">
<Dropdown :options="bulkActions(selections, unselectAll)"> <Dropdown :options="listBulkActionsRef.bulkActions(selections, unselectAll)">
<Button icon="more-horizontal" variant="ghost" /> <Button icon="more-horizontal" variant="ghost" />
</Dropdown> </Dropdown>
</template> </template>
@ -97,21 +97,21 @@
}" }"
@loadMore="emit('loadMore')" @loadMore="emit('loadMore')"
/> />
<EditValueModal <ListBulkActions
v-model="showEditModal" ref="listBulkActionsRef"
v-model="list"
doctype="CRM Task" doctype="CRM Task"
:selectedValues="selectedValues" :options="{
@reload="reload" hideAssign: true,
}"
/> />
</template> </template>
<script setup> <script setup>
import TaskStatusIcon from '@/components/Icons/TaskStatusIcon.vue' import TaskStatusIcon from '@/components/Icons/TaskStatusIcon.vue'
import TaskPriorityIcon from '@/components/Icons/TaskPriorityIcon.vue' import TaskPriorityIcon from '@/components/Icons/TaskPriorityIcon.vue'
import CalendarIcon from '@/components/Icons/CalendarIcon.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 { dateFormat } from '@/utils'
import { globalStore } from '@/stores/global'
import { setupListActions, createToast } from '@/utils'
import { import {
Avatar, Avatar,
ListView, ListView,
@ -122,11 +122,9 @@ import {
ListRowItem, ListRowItem,
ListFooter, ListFooter,
Dropdown, Dropdown,
call,
Tooltip, Tooltip,
} from 'frappe-ui' } from 'frappe-ui'
import { ref, watch, onMounted } from 'vue' import { ref, watch } from 'vue'
import { useRouter } from 'vue-router'
const props = defineProps({ const props = defineProps({
rows: { rows: {
@ -160,92 +158,14 @@ const emit = defineEmits([
const pageLengthCount = defineModel() const pageLengthCount = defineModel()
const list = defineModel('list') const list = defineModel('list')
const router = useRouter()
const { $dialog } = globalStore()
watch(pageLengthCount, (val, old_value) => { watch(pageLengthCount, (val, old_value) => {
if (val === old_value) return if (val === old_value) return
emit('updatePageCount', val) emit('updatePageCount', val)
}) })
const showEditModal = ref(false) const listBulkActionsRef = ref(null)
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 || []
})
defineExpose({ defineExpose({
customListActions, customListActions: listBulkActionsRef.value?.customListActions,
}) })
</script> </script>