From ce4af4907a5471ab185e9b7b64c00b0f744f9f27 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Wed, 17 Sep 2025 13:01:49 +0530 Subject: [PATCH] refactor: remove TemplateOption component usage and simplify dropdown options in multiple components (cherry picked from commit ac34ac9b87b9c671be75401a545e09e0e83ac378) # Conflicts: # frontend/src/components/Settings/Users.vue --- .../ConditionsFilter/CFCondition.vue | 27 ++------- .../AssignmentRuleListItem.vue | 29 +++------- .../Settings/EmailTemplate/EmailTemplates.vue | 40 ++++--------- frontend/src/components/Settings/Users.vue | 56 +++++++++---------- frontend/src/utils/index.js | 41 +------------- 5 files changed, 58 insertions(+), 135 deletions(-) diff --git a/frontend/src/components/ConditionsFilter/CFCondition.vue b/frontend/src/components/ConditionsFilter/CFCondition.vue index 943ad231..4f1411af 100644 --- a/frontend/src/components/ConditionsFilter/CFCondition.vue +++ b/frontend/src/components/ConditionsFilter/CFCondition.vue @@ -110,7 +110,6 @@ diff --git a/frontend/src/components/Settings/Users.vue b/frontend/src/components/Settings/Users.vue index 420f8b0c..5a0fce6d 100644 --- a/frontend/src/components/Settings/Users.vue +++ b/frontend/src/components/Settings/Users.vue @@ -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'), }, ] diff --git a/frontend/src/utils/index.js b/frontend/src/utils/index.js index d96cdae5..14b5ade9 100644 --- a/frontend/src/utils/index.js +++ b/frontend/src/utils/index.js @@ -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))