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: Tabs layout (frappe-ui) #518

Merged
merged 3 commits into from
Jan 7, 2025
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
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@vueuse/core": "^10.3.0",
"@vueuse/integrations": "^10.3.0",
"feather-icons": "^4.28.0",
"frappe-ui": "^0.1.98",
"frappe-ui": "^0.1.99",
"gemoji": "^8.1.0",
"lodash": "^4.17.21",
"mime": "^4.0.1",
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/components/Activities/DataFields.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
/>
</div>
<div class="flex gap-1">
<Button v-if="isManager()" @click="showDataFieldsModal = true">
<Button
v-if="isManager() && !isMobileView"
@click="showDataFieldsModal = true"
>
<EditIcon class="h-4 w-4" />
</Button>
<Button
Expand Down Expand Up @@ -60,6 +63,7 @@ import { Badge, createResource, createDocumentResource } from 'frappe-ui'
import LoadingIndicator from '@/components/Icons/LoadingIndicator.vue'
import { createToast } from '@/utils'
import { usersStore } from '@/stores/users'
import { isMobileView } from '@/composables/settings'
import { ref } from 'vue'

const props = defineProps({
Expand Down
474 changes: 247 additions & 227 deletions frontend/src/components/FieldLayout.vue

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion frontend/src/components/Modals/AddressModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>
<div class="flex items-center gap-1">
<Button
v-if="isManager()"
v-if="isManager() && !isMobileView"
variant="ghost"
class="w-7"
@click="openQuickEntryModal"
Expand Down Expand Up @@ -53,6 +53,7 @@ import QuickEntryModal from '@/components/Modals/QuickEntryModal.vue'
import FieldLayout from '@/components/FieldLayout.vue'
import EditIcon from '@/components/Icons/EditIcon.vue'
import { usersStore } from '@/stores/users'
import { isMobileView } from '@/composables/settings'
import { capture } from '@/telemetry'
import { FeatherIcon, createResource, ErrorMessage } from 'frappe-ui'
import { ref, nextTick, watch, computed } from 'vue'
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/Modals/ContactModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>
<div class="flex items-center gap-1">
<Button
v-if="isManager()"
v-if="isManager() && !isMobileView"
variant="ghost"
class="w-7"
@click="openQuickEntryModal"
Expand Down Expand Up @@ -48,6 +48,7 @@
import FieldLayout from '@/components/FieldLayout.vue'
import EditIcon from '@/components/Icons/EditIcon.vue'
import { usersStore } from '@/stores/users'
import { isMobileView } from '@/composables/settings'
import { capture } from '@/telemetry'
import { call, createResource } from 'frappe-ui'
import { ref, nextTick, watch } from 'vue'
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/Modals/DealModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>
<div class="flex items-center gap-1">
<Button
v-if="isManager()"
v-if="isManager() && !isMobileView"
variant="ghost"
class="w-7"
@click="openQuickEntryModal"
Expand Down Expand Up @@ -75,6 +75,7 @@ import EditIcon from '@/components/Icons/EditIcon.vue'
import FieldLayout from '@/components/FieldLayout.vue'
import { usersStore } from '@/stores/users'
import { statusesStore } from '@/stores/statuses'
import { isMobileView } from '@/composables/settings'
import { capture } from '@/telemetry'
import { Switch, createResource } from 'frappe-ui'
import { computed, ref, reactive, onMounted, nextTick, watch } from 'vue'
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/Modals/LeadModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>
<div class="flex items-center gap-1">
<Button
v-if="isManager()"
v-if="isManager() && !isMobileView"
variant="ghost"
class="w-7"
@click="openQuickEntryModal"
Expand Down Expand Up @@ -46,6 +46,7 @@ import EditIcon from '@/components/Icons/EditIcon.vue'
import FieldLayout from '@/components/FieldLayout.vue'
import { usersStore } from '@/stores/users'
import { statusesStore } from '@/stores/statuses'
import { isMobileView } from '@/composables/settings'
import { capture } from '@/telemetry'
import { createResource } from 'frappe-ui'
import { computed, onMounted, ref, reactive, nextTick } from 'vue'
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/Modals/OrganizationModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>
<div class="flex items-center gap-1">
<Button
v-if="isManager()"
v-if="isManager() && !isMobileView"
variant="ghost"
class="w-7"
@click="openQuickEntryModal"
Expand Down Expand Up @@ -48,6 +48,7 @@
import FieldLayout from '@/components/FieldLayout.vue'
import EditIcon from '@/components/Icons/EditIcon.vue'
import { usersStore } from '@/stores/users'
import { isMobileView } from '@/composables/settings'
import { capture } from '@/telemetry'
import { call, FeatherIcon, createResource } from 'frappe-ui'
import { ref, nextTick, watch } from 'vue'
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Section.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div>
<slot name="header" v-bind="{ opened, hide, open, close, toggle }">
<div v-if="!hide" class="column-header flex items-center justify-between">
<div v-if="!hide" class="column-header h-8 flex items-center justify-between">
<div
class="flex text-ink-gray-9 max-w-fit cursor-pointer items-center gap-2 text-base"
:class="labelClass"
Expand Down
10 changes: 6 additions & 4 deletions frontend/src/components/SidePanelLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
v-if="i !== firstVisibleIndex()"
class="w-full section-border h-px border-t"
/>
<div class="p-3">
<div class="p-1 sm:p-3">
<Section
labelClass="px-2 font-semibold"
:label="section.label"
Expand Down Expand Up @@ -97,11 +97,11 @@
<NestedPopover>
<template #target="{ open }">
<Button
:label="data[field.name]"
:label="data[field.fieldname]"
class="dropdown-button flex w-full items-center justify-between rounded border border-gray-100 bg-surface-gray-2 px-2 py-1.5 text-base text-ink-gray-8 placeholder-ink-gray-4 transition-colors hover:border-outline-gray-modals hover:bg-surface-gray-3 focus:border-outline-gray-4 focus:bg-surface-white focus:shadow-sm focus:outline-none focus:ring-0 focus-visible:ring-2 focus-visible:ring-outline-gray-3"
>
<div v-if="data[field.name]" class="truncate">
{{ data[field.name] }}
<div v-if="data[field.fieldname]" class="truncate">
{{ data[field.fieldname] }}
</div>
<div
v-else
Expand Down Expand Up @@ -396,6 +396,7 @@ import UserAvatar from '@/components/UserAvatar.vue'
import SidePanelModal from '@/components/Modals/SidePanelModal.vue'
import { getMeta } from '@/stores/meta'
import { usersStore } from '@/stores/users'
import { isMobileView } from '@/composables/settings'
import { getFormat, evaluateDependsOnValue } from '@/utils'
import { flt } from '@/utils/numberFormat.js'
import { Tooltip, DateTimePicker, DatePicker } from 'frappe-ui'
Expand Down Expand Up @@ -481,6 +482,7 @@ function parsedField(field) {
function parsedSection(section, editButtonAdded) {
let isContactSection = section.name == 'contacts_section'
section.showEditButton = !(
isMobileView.value ||
!isManager() ||
isContactSection ||
editButtonAdded
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/pages/Contact.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@
/>
</div>
</Resizer>
<Tabs class="!h-full" v-model="tabIndex" :tabs="tabs">
<template #tab="{ tab, selected }">
<Tabs as="div" v-model="tabIndex" :tabs="tabs">
<template #tab-item="{ tab, selected }">
<button
class="group flex items-center gap-2 border-b border-transparent py-2.5 text-base text-ink-gray-5 duration-300 ease-in-out hover:border-outline-gray-3 hover:text-ink-gray-9"
:class="{ 'text-ink-gray-9': selected }"
Expand All @@ -148,7 +148,7 @@
</Badge>
</button>
</template>
<template #default="{ tab }">
<template #tab-panel="{ tab }">
<DealsListView
v-if="tab.label === 'Deals' && rows.length"
class="mt-4"
Expand Down
20 changes: 11 additions & 9 deletions frontend/src/pages/Deal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@
</template>
</LayoutHeader>
<div v-if="deal.data" class="flex h-full overflow-hidden">
<Tabs v-model="tabIndex" :tabs="tabs" class="!h-full">
<Activities
ref="activities"
doctype="CRM Deal"
:tabs="tabs"
v-model:reload="reload"
v-model:tabIndex="tabIndex"
v-model="deal"
/>
<Tabs as="div" v-model="tabIndex" :tabs="tabs">
<template #tab-panel>
<Activities
ref="activities"
doctype="CRM Deal"
:tabs="tabs"
v-model:reload="reload"
v-model:tabIndex="tabIndex"
v-model="deal"
/>
</template>
</Tabs>
<Resizer side="right" class="flex flex-col justify-between border-l">
<div
Expand Down
24 changes: 12 additions & 12 deletions frontend/src/pages/Lead.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
<template #default="{ open }">
<Button :label="lead.data.status">
<template #prefix>
<IndicatorIcon
:class="getLeadStatus(lead.data.status).color"
/>
<IndicatorIcon :class="getLeadStatus(lead.data.status).color" />
</template>
<template #suffix>
<FeatherIcon
Expand All @@ -44,15 +42,17 @@
</template>
</LayoutHeader>
<div v-if="lead?.data" class="flex h-full overflow-hidden">
<Tabs v-model="tabIndex" class="!h-full" :tabs="tabs">
<Activities
ref="activities"
doctype="CRM Lead"
:tabs="tabs"
v-model:reload="reload"
v-model:tabIndex="tabIndex"
v-model="lead"
/>
<Tabs as="div" v-model="tabIndex" :tabs="tabs">
<template #tab-panel>
<Activities
ref="activities"
doctype="CRM Lead"
:tabs="tabs"
v-model:reload="reload"
v-model:tabIndex="tabIndex"
v-model="lead"
/>
</template>
</Tabs>
<Resizer class="flex flex-col justify-between border-l" side="right">
<div
Expand Down
58 changes: 22 additions & 36 deletions frontend/src/pages/MobileContact.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,8 @@
</div>
</template>
</FileUploader>
<Tabs
v-model="tabIndex"
:tabs="tabs"
tablistClass="!px-4"
class="overflow-auto"
>
<template #tab="{ tab, selected }">
<Tabs as="div" v-model="tabIndex" :tabs="tabs" class="overflow-auto">
<TabList class="!px-4" v-slot="{ tab, selected }">
<button
v-if="tab.name == 'Deals'"
class="group flex items-center gap-2 border-b border-transparent py-2.5 text-base text-ink-gray-5 duration-300 ease-in-out hover:border-outline-gray-3 hover:text-ink-gray-9"
Expand All @@ -127,31 +122,20 @@
{{ tab.count }}
</Badge>
</button>
</template>
<template #default="{ tab }">
</TabList>
<TabPanel v-slot="{ tab }">
<div v-if="tab.name == 'Details'">
<div
v-if="fieldsLayout.data"
v-if="sections.data"
class="flex flex-1 flex-col justify-between overflow-hidden"
>
<div class="flex flex-col overflow-y-auto">
<div
v-for="(section, i) in fieldsLayout.data"
:key="section.name"
class="flex flex-col px-2 py-3 sm:p-3"
:class="{ 'border-b': i !== fieldsLayout.data.length - 1 }"
>
<Section :label="section.label" :opened="section.opened">
<SidePanelLayout
:fields="section.columns[0].fields"
:isLastSection="i == fieldsLayout.data.length - 1"
doctype="Contact"
v-model="contact.data"
@update="updateField"
/>
</Section>
</div>
</div>
<SidePanelLayout
v-model="contact.data"
:sections="sections.data"
doctype="Contact"
@update="updateField"
@reload="sections.reload"
/>
</div>
</div>
<DealsListView
Expand All @@ -170,15 +154,14 @@
<div>{{ __('No {0} Found', [__(tab.label)]) }}</div>
</div>
</div>
</template>
</TabPanel>
</Tabs>
</div>
<AddressModal v-model="showAddressModal" v-model:address="_address" />
</template>

<script setup>
import Icon from '@/components/Icon.vue'
import Section from '@/components/Section.vue'
import SidePanelLayout from '@/components/SidePanelLayout.vue'
import LayoutHeader from '@/components/LayoutHeader.vue'
import DetailsIcon from '@/components/Icons/DetailsIcon.vue'
Expand All @@ -201,6 +184,8 @@ import {
Avatar,
FileUploader,
Tabs,
TabList,
TabPanel,
call,
createResource,
usePageMeta,
Expand Down Expand Up @@ -347,19 +332,19 @@ const rows = computed(() => {
return deals.data.map((row) => getDealRowObject(row))
})

const fieldsLayout = createResource({
const sections = createResource({
url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_sidepanel_sections',
cache: ['sidePanelSections', 'Contact'],
params: { doctype: 'Contact' },
auto: true,
transform: (data) => getParsedFields(data),
transform: (data) => getParsedSections(data),
})

function getParsedFields(data) {
return data.map((section) => {
function getParsedSections(_sections) {
return _sections.map((section) => {
section.columns = section.columns.map((column) => {
column.fields = column.fields.map((field) => {
if (field.name === 'email_id') {
if (field.fieldname === 'email_id') {
return {
...field,
type: 'dropdown',
Expand Down Expand Up @@ -418,7 +403,8 @@ function getParsedFields(data) {
} else if (field.name === 'mobile_no') {
return {
...field,
type: 'dropdown',
read_only: false,
fieldtype: 'dropdown',
options:
contact.data?.phone_nos?.map((phone) => {
return {
Expand Down
Loading
Loading