Skip to content

Commit

Permalink
fix(condo): DOMA-7004 move chart height to constant & add filters to …
Browse files Browse the repository at this point in the history
…TicketFeedback chart
  • Loading branch information
sitozzz committed Sep 11, 2023
1 parent 1482618 commit 691e018
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 27 deletions.
4 changes: 3 additions & 1 deletion apps/condo/domains/analytics/components/CustomChartView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { ChartConfigResult } from './TicketChart'
import type { CustomChartViewType, CustomChartMapType } from './CustomChart'
import type { BaseSimpleChart } from '@condo/domains/common/components/BaseChart'


type BaseDataType = Array<Record<string, unknown>>

interface ICustomChartViewProps<
Expand Down Expand Up @@ -48,6 +47,9 @@ const EMPTY_CONTAINER_STYLE: React.CSSProperties = {
alignItems: 'start',
}

export const CHART_CONTAINER_HEIGHT = 300
export const CHART_CONTAINER_BIG_HEIGHT = 350

const CustomChartView =
<
DataType extends BaseDataType,
Expand Down
42 changes: 34 additions & 8 deletions apps/condo/domains/analytics/components/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,23 @@ const TicketQualityControlDashboard = ({ data, translations, loading, organizati
const TicketFeedbackTitle = intl.formatMessage({ id: 'pages.reports.ticketFeedbackCount' })

const [isOpen, setIsOpen] = useState(false)
const [isChartLoading, setIsChartLoading] = useState(true)
const [localData, setLocalData] = useState([])
const [tickets, setTickets] = useState([])
const [ticketsCount, setTicketsCount] = useState(0)

const router = useRouter()
const { dateRange, SearchInput: DateRangeSearch } = useDateRangeFilter()
const { values, SearchInput } = usePropertyFilter({ organizationId })
const { offset } = useMemo(() => parseQuery(router.query), [router.query])
const currentPageIndex = useMemo(() => getPageIndexFromOffset(offset, MODAL_TABLE_PAGE_SIZE), [offset])


const { columns } = useTicketQualityTableColumns()

const [loadTicketFeedback, { loading: ticketFeedbackLoading }] = useLazyQuery(GET_OVERVIEW_DASHBOARD_MUTATION, {
onCompleted: (response) => {
setLocalData(get(response, 'result.overview.ticketQualityControlValue.tickets', []))
},
})
const [loadAllTickets, { loading: ticketsLoading }] = useLazyQuery(TicketGQL.GET_ALL_OBJS_WITH_COUNT_QUERY, {
onCompleted: (response) => {
setTickets(response.objs)
Expand All @@ -263,10 +268,30 @@ const TicketQualityControlDashboard = ({ data, translations, loading, organizati

useEffect(() => {
if (isOpen) {
loadTicketFeedback({
variables: {
data: {
dv: 1,
sender: getClientSideSenderInfo(),
where: {
organization: organizationId,
dateFrom: dateRange[0].toISOString(),
dateTo: dateRange[1].toISOString(),
propertyIds: values,
},
groupBy: { aggregatePeriod: 'day' },
entities: ['ticketQualityControlValue'],
},
},
})
loadAllTickets({
variables: {
where: {
organization: { id: organizationId },
AND: [
{ createdAt_gte: dateRange[0].toISOString() },
{ createdAt_lte: dateRange[1].toISOString() },
],
OR: [
{ qualityControlValue_in: QUALITY_CONTROL_VALUES },
{ feedbackValue_in: QUALITY_CONTROL_VALUES },
Expand All @@ -279,9 +304,7 @@ const TicketQualityControlDashboard = ({ data, translations, loading, organizati
},
})
}

setIsChartLoading(!isOpen)
}, [isOpen, organizationId, loadAllTickets, currentPageIndex, values])
}, [isOpen, organizationId, loadAllTickets, currentPageIndex, values, dateRange, loadTicketFeedback])

const ticketCardContent = useMemo(() => {
const goodKey = get(translations.find(t => t.value === TicketQualityControlValueType.Good), 'key')
Expand Down Expand Up @@ -351,12 +374,15 @@ const TicketQualityControlDashboard = ({ data, translations, loading, organizati
{loading ? <Skeleton active paragraph={{ rows: 3 }} /> : ticketCardContent}
</Card>
<Modal width='big' title={QualityControlTitle} open={isOpen} onCancel={onCancel}>
<Row gutter={[0, 40]}>
<Col span={24}>
<Row gutter={[24, 40]}>
<Col span={12}>
<DateRangeSearch disabled={ticketsLoading || ticketFeedbackLoading} />
</Col>
<Col span={12}>
{SearchInput}
</Col>
<Col span={24}>
<TicketQualityControlChart data={[data, translations]} loading={isChartLoading} />
<TicketQualityControlChart data={[localData, translations]} loading={ticketFeedbackLoading} />
</Col>
<Col span={24}>
<Table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useLazyQuery } from '@open-condo/next/apollo'
import { useIntl } from '@open-condo/next/intl'
import { Typography } from '@open-condo/ui'

import { CustomChartView } from '@condo/domains/analytics/components/CustomChartView'
import { CustomChartView, CHART_CONTAINER_HEIGHT } from '@condo/domains/analytics/components/CustomChartView'
import { CustomListView } from '@condo/domains/analytics/components/CustomListView'
import { GET_OVERVIEW_DASHBOARD_MUTATION } from '@condo/domains/analytics/gql'
import { usePropertyFilter, useDateRangeFilter } from '@condo/domains/analytics/hooks/useDashboardFilters'
Expand Down Expand Up @@ -63,7 +63,7 @@ const PaymentByPropertyChart: IPaymentChartCard = ({ data, organizationId }) =>
<CustomChartView
viewMode='pie'
mapperInstance={dataMapper}
chartConfig={{ chartOptions: { height: 300 }, animationEnabled: true }}
chartConfig={{ chartOptions: { height: CHART_CONTAINER_HEIGHT }, animationEnabled: true }}
data={localData}
loading={loading}
/>
Expand All @@ -85,7 +85,7 @@ const PaymentByPropertyChart: IPaymentChartCard = ({ data, organizationId }) =>
<CustomChartView
viewMode='pie'
mapperInstance={dataMapper}
chartConfig={{ chartOptions: { height: 300 }, animationEnabled: true }}
chartConfig={{ chartOptions: { height: CHART_CONTAINER_HEIGHT }, animationEnabled: true }}
data={data}
/>
</Col>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Info } from '@open-condo/icons'
import { useIntl } from '@open-condo/next/intl'
import { Typography, Tooltip, Space } from '@open-condo/ui'

import { CustomChartView } from '@condo/domains/analytics/components/CustomChartView'
import { CustomChartView, CHART_CONTAINER_HEIGHT } from '@condo/domains/analytics/components/CustomChartView'

import { PaymentReceiptDataMapper } from './dataMappers'

Expand Down Expand Up @@ -36,7 +36,7 @@ const PaymentReceiptChart: IPaymentChartCard = ({ data }) => {
viewMode='bar'
data={data}
mapperInstance={dataMapper}
chartConfig={{ chartOptions: { height: 300 }, animationEnabled: true }}
chartConfig={{ chartOptions: { height: CHART_CONTAINER_HEIGHT }, animationEnabled: true }}
/>
</Col>
</Row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { useMemo } from 'react'
import { useIntl } from '@open-condo/next/intl'
import { Typography } from '@open-condo/ui'

import { CustomChartView } from '@condo/domains/analytics/components/CustomChartView'
import { CustomChartView, CHART_CONTAINER_HEIGHT } from '@condo/domains/analytics/components/CustomChartView'

import { PaymentTotalDataMapper } from './dataMappers'

Expand All @@ -28,7 +28,7 @@ const PaymentTotalChart: IPaymentChartCard = ({ data }) => {
viewMode='bar'
data={data}
mapperInstance={dataMapper}
chartConfig={{ chartOptions: { height: 300 }, animationEnabled: true }}
chartConfig={{ chartOptions: { height: CHART_CONTAINER_HEIGHT }, animationEnabled: true }}
/>
</Col>
</Row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useLazyQuery } from '@open-condo/next/apollo'
import { useIntl } from '@open-condo/next/intl'
import { Typography, Tooltip } from '@open-condo/ui'

import { CustomChartView } from '@condo/domains/analytics/components/CustomChartView'
import { CustomChartView, CHART_CONTAINER_HEIGHT } from '@condo/domains/analytics/components/CustomChartView'
import { CustomListView } from '@condo/domains/analytics/components/CustomListView'
import { GET_OVERVIEW_DASHBOARD_MUTATION } from '@condo/domains/analytics/gql'
import { usePropertyFilter, useDateRangeFilter } from '@condo/domains/analytics/hooks/useDashboardFilters'
Expand Down Expand Up @@ -44,7 +44,7 @@ const ResidentByPropertyChart: IResidentChartCard = ({ data, organizationId }) =
<CustomChartView
data={localData}
viewMode='pie'
chartConfig={{ chartOptions: { height: 300 }, animationEnabled: true }}
chartConfig={{ chartOptions: { height: CHART_CONTAINER_HEIGHT }, animationEnabled: true }}
mapperInstance={dataMapper}
loading={loading}
/>
Expand Down Expand Up @@ -87,7 +87,7 @@ const ResidentByPropertyChart: IResidentChartCard = ({ data, organizationId }) =
<CustomChartView
data={data}
viewMode='pie'
chartConfig={{ chartOptions: { height: 300 }, animationEnabled: true }}
chartConfig={{ chartOptions: { height: CHART_CONTAINER_HEIGHT }, animationEnabled: true }}
mapperInstance={dataMapper}
/>
</Col>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from 'react'
import { useIntl } from '@open-condo/next/intl'
import { Typography } from '@open-condo/ui'

import { CHART_CONTAINER_HEIGHT } from '@condo/domains/analytics/components/CustomChartView'
import TicketChartView from '@condo/domains/analytics/components/TicketChartView'

import { AllTicketChartDataMapper } from './dataMappers'
Expand All @@ -25,7 +26,7 @@ const AllTicketsChart: ITicketChartCard = ({ data }) => {
mainGroup='status'
viewMode='line'
mapperInstance={AllTicketChartDataMapper}
chartConfig={{ chartOptions: { height: 300 }, animationEnabled: true }}
chartConfig={{ chartOptions: { height: CHART_CONTAINER_HEIGHT }, animationEnabled: true }}
/>
</Col>
</Row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useLazyQuery } from '@open-condo/next/apollo'
import { useIntl } from '@open-condo/next/intl'
import { Typography } from '@open-condo/ui'

import { CHART_CONTAINER_HEIGHT } from '@condo/domains/analytics/components/CustomChartView'
import { CustomListView } from '@condo/domains/analytics/components/CustomListView'
import TicketChartView from '@condo/domains/analytics/components/TicketChartView'
import { GET_OVERVIEW_DASHBOARD_MUTATION } from '@condo/domains/analytics/gql'
Expand Down Expand Up @@ -64,7 +65,7 @@ const TicketByCategoryChart: ITicketChartCard = ({ data, organizationId }) => {
data={localData}
viewMode='bar'
mapperInstance={TicketByCategoryDataMapper}
chartConfig={{ chartOptions: { height: 300 }, animationEnabled: true }}
chartConfig={{ chartOptions: { height: CHART_CONTAINER_HEIGHT }, animationEnabled: true }}
loading={loading}
/>
), [localData, loading])
Expand All @@ -80,7 +81,7 @@ const TicketByCategoryChart: ITicketChartCard = ({ data, organizationId }) => {
data={data}
viewMode='bar'
mapperInstance={TicketByCategoryDataMapper}
chartConfig={{ chartOptions: { height: 300 }, animationEnabled: true }}
chartConfig={{ chartOptions: { height: CHART_CONTAINER_HEIGHT }, animationEnabled: true }}
/>
</Col>
</Row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { getClientSideSenderInfo } from '@condo/domains/common/utils/userid.util

import { TicketHorizontalBarDataMapper } from './dataMappers'

import { CHART_CONTAINER_BIG_HEIGHT } from '../../CustomChartView'

import type { ITicketChartCard } from './dataMappers'

const mapperInstance = TicketHorizontalBarDataMapper([TicketGroupBy.Status, TicketGroupBy.Executor])
Expand Down Expand Up @@ -74,7 +76,7 @@ const TicketByExecutorChart: ITicketChartCard = ({ data, organizationId }) => {
viewMode='bar'
mapperInstance={mapperInstance}
mainGroup='status'
chartConfig={{ chartOptions: { height: 350 }, animationEnabled: true }}
chartConfig={{ chartOptions: { height: CHART_CONTAINER_BIG_HEIGHT }, animationEnabled: true }}
loading={loading}
/>
), [localData, loading])
Expand All @@ -93,7 +95,7 @@ const TicketByExecutorChart: ITicketChartCard = ({ data, organizationId }) => {
mainGroup='status'
mapperInstance={mapperInstance}
viewMode='bar'
chartConfig={{ chartOptions: { height: 350 }, animationEnabled: true }}
chartConfig={{ chartOptions: { height: CHART_CONTAINER_BIG_HEIGHT }, animationEnabled: true }}
/>
</Col>
</Row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useLazyQuery } from '@open-condo/next/apollo'
import { useIntl } from '@open-condo/next/intl'
import { Typography } from '@open-condo/ui'

import { CHART_CONTAINER_BIG_HEIGHT } from '@condo/domains/analytics/components/CustomChartView'
import { CustomListView } from '@condo/domains/analytics/components/CustomListView'
import TicketChartView from '@condo/domains/analytics/components/TicketChartView'
import { GET_OVERVIEW_DASHBOARD_MUTATION } from '@condo/domains/analytics/gql'
Expand Down Expand Up @@ -69,7 +70,7 @@ const TicketByPropertyChart: ITicketChartCard = ({ data, organizationId }) => {
mainGroup='status'
mapperInstance={mapperInstance}
viewMode='bar'
chartConfig={{ chartOptions: { height: 350 }, animationEnabled: true }}
chartConfig={{ chartOptions: { height: CHART_CONTAINER_BIG_HEIGHT }, animationEnabled: true }}
loading={loading}
/>
), [localData, loading])
Expand All @@ -88,7 +89,7 @@ const TicketByPropertyChart: ITicketChartCard = ({ data, organizationId }) => {
mainGroup='status'
mapperInstance={mapperInstance}
viewMode='bar'
chartConfig={{ chartOptions: { height: 350 }, animationEnabled: true }}
chartConfig={{ chartOptions: { height: CHART_CONTAINER_BIG_HEIGHT }, animationEnabled: true }}
/>
</Col>
</Row>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'

import { CHART_CONTAINER_HEIGHT } from '@condo/domains/analytics/components/CustomChartView'
import TicketChartView from '@condo/domains/analytics/components/TicketChartView'

import { TicketQualityControlDataMapper } from './dataMappers'
Expand All @@ -13,7 +14,7 @@ const TicketQualityControlChart: ITicketChartCard = ({ data, loading }) => {
loading={loading}
viewMode='bar'
mapperInstance={TicketQualityControlDataMapper}
chartConfig={{ chartOptions: { height: 300 }, animationEnabled: false }}
chartConfig={{ chartOptions: { height: CHART_CONTAINER_HEIGHT }, animationEnabled: false }}
/>
)
}
Expand Down

0 comments on commit 691e018

Please sign in to comment.