Skip to content

Commit c95c10f

Browse files
authored
feat(condo): DOMA-12533, DOMA-11058, DOMA-11673, DOMA-10972 add table on contact page (#6917)
* feat(condo): DOMA-12250 add new compoent * feat(condo): DOMA-12533 add new contact table * feat(condo): DOMA-12533 add table to contact page * feat(condo): DOMA-12533 add new table in callcenter on /contact page * feat(condo): DOMA-12533 sync state with ui kit * feat(condo): DOMA-12533 update yarn.lock to include local domain link for pos-integration * feat(condo): DOMA-12533 remove TanStackTable component and lodash dependency * feat(condo): DOMA-12533 add default settings label to contact table * feat(condo): DOMA-12533 update after testing * feat(condo): DOMA-12533 update table components and enhance search functionality * feat(condo): DOMA-12533 refactor table rendering and search handling in contact components * feat(condo): DOMA-12533 enhance table component with improved state management and style adjustments * feat(callcenter): DOMA-12533 update subproject commit reference * feat(condo): DOMA-12533 implement table URL query management and enhance contact table functionality * feat(condo): DOMA-12533 add CSS styles for filter components and refactor filter handling in table * feat(condo): DOMA-12533 improve filter component styles and update type handling in filters * feat(condo): DOMA-12533 update filter component styles, improve type handling, and enhance table functionality * feat(condo): DOMA-12533 update subproject commit references and enhance contact table functionality with improved row selection handling * feat(condo): DOMA-12533 remove community fee column and filter from contact table
1 parent 7e072ee commit c95c10f

File tree

28 files changed

+1457
-411
lines changed

28 files changed

+1457
-411
lines changed

apps/callcenter

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.filter-component-checkbox-group-container {
2+
display: flex;
3+
flex-direction: column;
4+
}
5+
6+
.filter-component-select-container {
7+
display: flex;
8+
flex-direction: column;
9+
}
10+
11+
.filter-component-gql-select-container {
12+
display: flex;
13+
flex-direction: column;
14+
width: 400px;
15+
}

apps/condo/domains/common/components/Table/Filters.tsx

Lines changed: 257 additions & 17 deletions
Large diffs are not rendered by default.

apps/condo/domains/common/components/Table/Renders.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { TTextHighlighterRenderPartFN } from '@condo/domains/common/components/T
2222
import { TextHighlighter, TTextHighlighterProps } from '@condo/domains/common/components/TextHighlighter'
2323
import { LOCALES } from '@condo/domains/common/constants/locale'
2424
import { ELLIPSIS_ROWS } from '@condo/domains/common/constants/style'
25-
import { getAddressDetails } from '@condo/domains/common/utils/helpers'
25+
import { getAddressDetails, ObjectWithAddressInfo } from '@condo/domains/common/utils/helpers'
2626
import { renderLink } from '@condo/domains/common/utils/Renders'
2727
import { ELECTRICITY_METER_RESOURCE_ID } from '@condo/domains/meter/constants/constants'
2828

@@ -223,7 +223,7 @@ const POSTFIX_PROPS: TextProps = { type: 'secondary' }
223223
const NEW_LINE_POSTFIX_STYLE: TextProps = { style: { whiteSpace: 'pre-line' } }
224224
const ONE_LINE_POSTFIX_STYLE: TextProps = { style: { whiteSpace: 'nowrap' } }
225225

226-
export const getAddressRender = (property: Pick<Property, 'addressMeta' | 'address' | 'deletedAt'>, DeletedMessage?: string, search?: FilterValue | string, oneLinePostfix?: boolean) => {
226+
export const getAddressRender = (property: ObjectWithAddressInfo, DeletedMessage?: string, search?: FilterValue | string, oneLinePostfix?: boolean) => {
227227

228228
if (!property) {
229229
return getTableCellRenderer({
@@ -265,6 +265,12 @@ export const getUnitNameRender = <T extends Record<string, unknown>>(intl, text:
265265
return getTableCellRenderer({ search, extraTitle })(unitName)
266266
}
267267

268+
export const getUnitTypeRender = <T extends Record<string, unknown>>(intl, text: string, record: T, search?: FilterValue | string) => {
269+
const unitType = get(record, 'unitType', BuildingUnitSubType.Flat)
270+
const renderUnitType = unitType ? intl.formatMessage({ id: `pages.condo.ticket.field.unitType.${unitType}` }) : null
271+
return getTableCellRenderer({ search, extraTitle: renderUnitType })(renderUnitType)
272+
}
273+
268274
export const getDateRender = (intl, search?: FilterValue | string, prefix = '\n') => {
269275
return function render (stringDate: string): RenderReturnType {
270276
if (!stringDate) return '—'

apps/condo/domains/common/hooks/useQueryMappers.ts

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@ import get from 'lodash/get'
22
import isFunction from 'lodash/isFunction'
33
import { useMemo } from 'react'
44

5+
import type { SortState } from '@open-condo/ui'
6+
57
import { QueryMeta, SorterColumn, convertSortersToSortBy } from '../utils/tables.utils'
68

79
const DEFAULT_SORT_BY = ['createdAt_DESC']
810

9-
export const useQueryMappers = <F>(queryMetas: Array<QueryMeta<F>>, sortableColumns: Array<string>) => {
11+
export const useQueryMappers = <F>(queryMetas: Array<QueryMeta<F>>, sortableColumns: Array<string> | null) => {
1012
return useMemo(() => {
11-
const validSorts = sortableColumns.reduce((acc, cur) => {
12-
return [...acc, `${cur}_ASC`, `${cur}_DESC`]
13-
}, [])
13+
const validSorts = Array.isArray(sortableColumns)
14+
? sortableColumns.reduce((acc, cur) => [...acc, `${cur}_ASC`, `${cur}_DESC`], [])
15+
: null
1416

1517
const validMetas = queryMetas
16-
.filter((meta) => meta && meta.keyword && meta.filters && (isFunction(meta.filters) || meta.filters.length > 0))
18+
.filter((meta) => meta?.keyword && meta.filters && (isFunction(meta.filters) || meta.filters.length > 0))
1719

1820
const filtersToWhere = (queryFilters) => {
1921
const whereQueries = []
@@ -45,12 +47,26 @@ export const useQueryMappers = <F>(queryMetas: Array<QueryMeta<F>>, sortableColu
4547
}
4648
}
4749

48-
const sortersToSortBy = (querySorts: SorterColumn | Array<SorterColumn>, defaultSortBy?: string[]) => {
49-
const sortBy = defaultSortBy ? defaultSortBy : DEFAULT_SORT_BY
50-
const sorters = convertSortersToSortBy(querySorts)
51-
.filter((sortLine) => validSorts.includes(sortLine))
50+
const sortersToSortBy = (
51+
querySorts: SorterColumn | Array<SorterColumn> | SortState,
52+
defaultSortBy?: Array<string>,
53+
) => {
54+
const defaultSorters = defaultSortBy ?? DEFAULT_SORT_BY
55+
if (!querySorts || (Array.isArray(querySorts) && querySorts.length === 0)) return defaultSorters
56+
57+
if (Array.isArray(querySorts) && querySorts.every((s) => 'id' in s)) {
58+
return querySorts
59+
.map((s) => `${s.id}_${s.desc ? 'DESC' : 'ASC'}`)
60+
.filter(Boolean)
61+
}
62+
63+
const sorters = validSorts
64+
?
65+
convertSortersToSortBy(querySorts).filter((sortLine) => validSorts.includes(sortLine))
66+
:
67+
[]
5268

53-
return sorters.length ? sorters : sortBy
69+
return sorters.length ? sorters : defaultSorters
5470
}
5571

5672
return {
@@ -59,4 +75,4 @@ export const useQueryMappers = <F>(queryMetas: Array<QueryMeta<F>>, sortableColu
5975
}
6076

6177
}, [queryMetas, sortableColumns])
62-
}
78+
}

apps/condo/domains/common/hooks/useSearch.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ import isEqual from 'lodash/isEqual'
44
import { useRouter } from 'next/router'
55
import { useCallback, useEffect, useMemo, useState } from 'react'
66

7+
import { TableRef } from '@open-condo/ui/src'
8+
79
import { getFiltersQueryData } from '@condo/domains/common/utils/filters.utils'
810
import { getFiltersFromQuery, updateQuery } from '@condo/domains/common/utils/helpers'
911

1012

1113
type UseSearchOutputType = [string, (search: string) => void, () => void]
1214

15+
/**
16+
* @deprecated use useTableSearch
17+
*/
1318
export const useSearch = <F> (debounceTime: number = 400): UseSearchOutputType => {
1419
const router = useRouter()
1520
const filtersFromQuery = useMemo(() => getFiltersFromQuery<F>(router.query), [router.query])
@@ -38,3 +43,23 @@ export const useSearch = <F> (debounceTime: number = 400): UseSearchOutputType =
3843

3944
return [search, handleSearchChange, handleResetSearch]
4045
}
46+
47+
export const useTableSearch = (tableRef: TableRef, debounceTime: number = 400): UseSearchOutputType => {
48+
const [search, setSearch] = useState<string>('')
49+
50+
const searchChange = useMemo(() => debounce((value: string) => {
51+
tableRef?.api?.setGlobalFilter(value)
52+
}, debounceTime), [tableRef?.api, debounceTime])
53+
54+
const handleSearchChange = useCallback((value: string): void => {
55+
setSearch(value)
56+
searchChange(value)
57+
}, [searchChange])
58+
59+
const handleResetSearch = useCallback(() => {
60+
setSearch('')
61+
searchChange('')
62+
}, [searchChange])
63+
64+
return [search, handleSearchChange, handleResetSearch]
65+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { useMemo } from 'react'
2+
3+
import { useIntl } from '@open-condo/next/intl'
4+
5+
export const useTableTranslations = () => {
6+
const intl = useIntl()
7+
8+
const menuLabels = useMemo(() => ({
9+
sortDescLabel: intl.formatMessage({ id: 'Table.Sort' }),
10+
sortAscLabel: intl.formatMessage({ id: 'Table.Sort' }),
11+
filterLabel: intl.formatMessage({ id: 'Table.Filter' }),
12+
settingsLabel: intl.formatMessage({ id: 'Table.Settings' }),
13+
sortedDescLabel: intl.formatMessage({ id: 'Table.Sorted' }),
14+
sortedAscLabel: intl.formatMessage({ id: 'Table.Sorted' }),
15+
filteredLabel: intl.formatMessage({ id: 'Table.Filtered' }),
16+
noDataLabel: intl.formatMessage({ id: 'Table.NoData' }),
17+
defaultSettingsLabel: intl.formatMessage({ id: 'Table.DefaultSettingsLabel' }),
18+
resetFilterLabel: intl.formatMessage({ id: 'Table.ResetFilter' }),
19+
}), [intl])
20+
21+
return menuLabels
22+
}

0 commit comments

Comments
 (0)