refactor: remove TemplateOption component usage and simplify dropdown options in multiple components
(cherry picked from commit ac34ac9b87b9c671be75401a545e09e0e83ac378) # Conflicts: # frontend/src/components/Settings/Users.vue
This commit is contained in:
parent
84d24a384b
commit
ce4af4907a
@ -110,7 +110,6 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { TemplateOption } from '@/utils'
|
||||
import {
|
||||
Autocomplete,
|
||||
Button,
|
||||
@ -191,31 +190,17 @@ const dropdownOptions = computed(() => {
|
||||
|
||||
options.push({
|
||||
label: __('Remove'),
|
||||
component: (props) =>
|
||||
TemplateOption({
|
||||
option: __('Remove'),
|
||||
icon: 'trash-2',
|
||||
active: props.active,
|
||||
variant: 'danger',
|
||||
onClick: () => {
|
||||
emit('remove')
|
||||
},
|
||||
}),
|
||||
icon: 'trash-2',
|
||||
variant: 'red',
|
||||
onClick: () => emit('remove'),
|
||||
condition: () => !props.isGroup,
|
||||
})
|
||||
|
||||
options.push({
|
||||
label: __('Remove group'),
|
||||
component: (props) =>
|
||||
TemplateOption({
|
||||
option: __('Remove group'),
|
||||
icon: 'trash-2',
|
||||
active: props.active,
|
||||
variant: 'danger',
|
||||
onClick: () => {
|
||||
emit('remove')
|
||||
},
|
||||
}),
|
||||
icon: 'trash-2',
|
||||
variant: 'red',
|
||||
onClick: () => emit('remove'),
|
||||
condition: () => props.isGroup,
|
||||
})
|
||||
|
||||
|
||||
@ -72,7 +72,6 @@ import {
|
||||
toast,
|
||||
} from 'frappe-ui'
|
||||
import { inject, ref } from 'vue'
|
||||
import { TemplateOption } from '@/utils'
|
||||
|
||||
const assignmentRulesList = inject('assignmentRulesList')
|
||||
const updateStep = inject('updateStep')
|
||||
@ -128,29 +127,19 @@ const dropdownOptions = [
|
||||
},
|
||||
{
|
||||
label: __('Delete'),
|
||||
component: (props) =>
|
||||
TemplateOption({
|
||||
option: __('Delete'),
|
||||
icon: 'trash-2',
|
||||
active: props.active,
|
||||
onClick: (e) => {
|
||||
e.preventDefault()
|
||||
e.stopImmediatePropagation()
|
||||
isConfirmingDelete.value = true
|
||||
},
|
||||
}),
|
||||
icon: 'trash-2',
|
||||
onClick: (e) => {
|
||||
e.preventDefault()
|
||||
e.stopImmediatePropagation()
|
||||
isConfirmingDelete.value = true
|
||||
},
|
||||
condition: () => !isConfirmingDelete.value,
|
||||
},
|
||||
{
|
||||
label: __('Confirm Delete'),
|
||||
component: (props) =>
|
||||
TemplateOption({
|
||||
option: __('Confirm Delete'),
|
||||
icon: 'trash-2',
|
||||
active: props.active,
|
||||
theme: 'danger',
|
||||
onClick: () => deleteAssignmentRule(),
|
||||
}),
|
||||
icon: 'trash-2',
|
||||
theme: 'red',
|
||||
onClick: () => deleteAssignmentRule(),
|
||||
condition: () => isConfirmingDelete.value,
|
||||
},
|
||||
]
|
||||
|
||||
@ -148,7 +148,6 @@
|
||||
</div>
|
||||
</template>
|
||||
<script setup>
|
||||
import { TemplateOption } from '@/utils'
|
||||
import {
|
||||
TextInput,
|
||||
FormControl,
|
||||
@ -223,43 +222,28 @@ function getDropdownOptions(template) {
|
||||
let options = [
|
||||
{
|
||||
label: __('Duplicate'),
|
||||
component: (props) =>
|
||||
TemplateOption({
|
||||
option: __('Duplicate'),
|
||||
icon: 'copy',
|
||||
active: props.active,
|
||||
onClick: () => emit('updateStep', 'new-template', { ...template }),
|
||||
}),
|
||||
icon: 'copy',
|
||||
onClick: () => emit('updateStep', 'new-template', { ...template }),
|
||||
},
|
||||
{
|
||||
label: __('Delete'),
|
||||
component: (props) =>
|
||||
TemplateOption({
|
||||
option: __('Delete'),
|
||||
icon: 'trash-2',
|
||||
active: props.active,
|
||||
onClick: (e) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
confirmDelete.value = true
|
||||
},
|
||||
}),
|
||||
icon: 'trash-2',
|
||||
onClick: (e) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
confirmDelete.value = true
|
||||
},
|
||||
condition: () => !confirmDelete.value,
|
||||
},
|
||||
{
|
||||
label: __('Confirm Delete'),
|
||||
component: (props) =>
|
||||
TemplateOption({
|
||||
option: __('Confirm Delete'),
|
||||
icon: 'trash-2',
|
||||
active: props.active,
|
||||
theme: 'danger',
|
||||
onClick: () => deleteTemplate(template),
|
||||
}),
|
||||
icon: 'trash-2',
|
||||
theme: 'red',
|
||||
onClick: () => deleteTemplate(template),
|
||||
condition: () => confirmDelete.value,
|
||||
},
|
||||
]
|
||||
|
||||
return options.filter((option) => option.condition?.() || true)
|
||||
return options
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -169,8 +169,21 @@
|
||||
import AddExistingUserModal from '@/components/Modals/AddExistingUserModal.vue'
|
||||
import { activeSettingsPage } from '@/composables/settings'
|
||||
import { usersStore } from '@/stores/users'
|
||||
<<<<<<< HEAD
|
||||
import { TemplateOption, DropdownOption } from '@/utils'
|
||||
import { Avatar, TextInput, toast, call, FeatherIcon, Tooltip } from 'frappe-ui'
|
||||
=======
|
||||
import { DropdownOption } from '@/utils'
|
||||
import {
|
||||
Dropdown,
|
||||
Avatar,
|
||||
TextInput,
|
||||
toast,
|
||||
call,
|
||||
FeatherIcon,
|
||||
Tooltip,
|
||||
} from 'frappe-ui'
|
||||
>>>>>>> ac34ac9b (refactor: remove TemplateOption component usage and simplify dropdown options in multiple components)
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
|
||||
const { users, isAdmin, isManager } = usersStore()
|
||||
@ -208,29 +221,19 @@ function getMoreOptions(user) {
|
||||
let options = [
|
||||
{
|
||||
label: __('Remove'),
|
||||
component: (props) =>
|
||||
TemplateOption({
|
||||
option: __('Remove'),
|
||||
icon: 'trash-2',
|
||||
active: props.active,
|
||||
onClick: (e) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
confirmRemove.value = true
|
||||
},
|
||||
}),
|
||||
icon: 'trash-2',
|
||||
onClick: (e) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
confirmRemove.value = true
|
||||
},
|
||||
condition: () => !confirmRemove.value,
|
||||
},
|
||||
{
|
||||
label: __('Confirm Remove'),
|
||||
component: (props) =>
|
||||
TemplateOption({
|
||||
option: __('Confirm Remove'),
|
||||
icon: 'trash-2',
|
||||
active: props.active,
|
||||
theme: 'danger',
|
||||
onClick: () => removeUser(user, true),
|
||||
}),
|
||||
icon: 'trash-2',
|
||||
theme: 'red',
|
||||
onClick: () => removeUser(user, true),
|
||||
condition: () => confirmRemove.value,
|
||||
},
|
||||
]
|
||||
@ -242,38 +245,35 @@ function getDropdownOptions(user) {
|
||||
let options = [
|
||||
{
|
||||
label: __('Admin'),
|
||||
component: (props) =>
|
||||
component: () =>
|
||||
DropdownOption({
|
||||
option: __('Admin'),
|
||||
icon: 'shield',
|
||||
active: props.active,
|
||||
selected: user.role === 'System Manager',
|
||||
onClick: () => updateRole(user, 'System Manager'),
|
||||
}),
|
||||
onClick: () => updateRole(user, 'System Manager'),
|
||||
condition: () => isAdmin(),
|
||||
},
|
||||
{
|
||||
label: __('Manager'),
|
||||
component: (props) =>
|
||||
component: () =>
|
||||
DropdownOption({
|
||||
option: __('Manager'),
|
||||
icon: 'briefcase',
|
||||
active: props.active,
|
||||
selected: user.role === 'Sales Manager',
|
||||
onClick: () => updateRole(user, 'Sales Manager'),
|
||||
}),
|
||||
onClick: () => updateRole(user, 'Sales Manager'),
|
||||
condition: () => isManager(),
|
||||
},
|
||||
{
|
||||
label: __('Sales User'),
|
||||
component: (props) =>
|
||||
component: () =>
|
||||
DropdownOption({
|
||||
option: __('Sales User'),
|
||||
icon: 'user-check',
|
||||
active: props.active,
|
||||
selected: user.role === 'Sales User',
|
||||
onClick: () => updateRole(user, 'Sales User'),
|
||||
}),
|
||||
onClick: () => updateRole(user, 'Sales User'),
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
@ -462,23 +462,12 @@ export function runSequentially(functions) {
|
||||
}, Promise.resolve())
|
||||
}
|
||||
|
||||
export function DropdownOption({
|
||||
active,
|
||||
option,
|
||||
theme,
|
||||
icon,
|
||||
onClick,
|
||||
selected,
|
||||
}) {
|
||||
export function DropdownOption({ option, icon, selected }) {
|
||||
return h(
|
||||
'button',
|
||||
{
|
||||
class: [
|
||||
active ? 'bg-surface-gray-2' : 'text-ink-gray-8',
|
||||
'group flex w-full justify-between items-center rounded-md px-2 py-2 text-sm',
|
||||
theme == 'danger' ? 'text-ink-red-3 hover:bg-ink-red-1' : '',
|
||||
],
|
||||
onClick: !selected ? onClick : null,
|
||||
class:
|
||||
'group flex w-full text-ink-gray-8 justify-between items-center rounded-md px-2 py-2 text-sm hover:bg-surface-gray-2',
|
||||
},
|
||||
[
|
||||
h('div', { class: 'flex gap-2' }, [
|
||||
@ -501,30 +490,6 @@ export function DropdownOption({
|
||||
)
|
||||
}
|
||||
|
||||
export function TemplateOption({ active, option, theme, icon, onClick }) {
|
||||
return h(
|
||||
'button',
|
||||
{
|
||||
class: [
|
||||
active ? 'bg-surface-gray-2 text-ink-gray-8' : 'text-ink-gray-7',
|
||||
'group flex w-full gap-2 items-center rounded-md px-2 py-2 text-sm',
|
||||
theme == 'danger' ? 'text-ink-red-3 hover:bg-ink-red-1' : '',
|
||||
],
|
||||
onClick: onClick,
|
||||
},
|
||||
[
|
||||
icon
|
||||
? h(FeatherIcon, {
|
||||
name: icon,
|
||||
class: ['h-4 w-4 shrink-0'],
|
||||
'aria-hidden': true,
|
||||
})
|
||||
: null,
|
||||
h('span', { class: 'whitespace-nowrap' }, option),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
export function copy(obj) {
|
||||
if (!obj) return obj
|
||||
return JSON.parse(JSON.stringify(obj))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user