Skip to content

Commit c6e2d7b

Browse files
authored
Added api filter to table (#3324)
* added api filter to table * Automatic frontend build * added sonar fixes * Apply eslint-fixer changes * Automatic frontend build --------- Co-authored-by: Corepex <16717695+Corepex@users.noreply.github.com>
1 parent 1627874 commit c6e2d7b

749 files changed

Lines changed: 30059 additions & 11 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

assets/js/src/core/modules/data-object/unit-slice-enhanced.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ const api = baseApi.enhanceEndpoints({
2020
},
2121

2222
unitQuantityValueUnitsUpdate: {
23-
invalidatesTags: () => []
23+
invalidatesTags: () => [tagNames.QUANTITY_VALUE_UNITS]
2424
},
2525

2626
unitQuantityValueUnitsDelete: {
27-
invalidatesTags: () => []
27+
invalidatesTags: () => [tagNames.QUANTITY_VALUE_UNITS]
2828
},
2929

3030
unitQuantityValueUnitsCreate: {
3131
invalidatesTags: () => [tagNames.QUANTITY_VALUE_UNITS]
3232
},
3333

3434
unitQuantityValueList: {
35-
providesTags: () => []
35+
providesTags: () => providingTags.QUANTITY_VALUE_UNITS()
3636
},
3737

3838
unitQuantityValueUnitsExport: {

assets/js/src/core/modules/quantity-value/quantity-value-container.tsx

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,58 @@ import { useFormModal } from '@Pimcore/components/modal/form-modal/hooks/use-for
1818
import { ModalTitle } from '@Pimcore/components/modal/modal-title/modal-title'
1919
import { Title } from '@Pimcore/components/title/title'
2020
import { Toolbar } from '@Pimcore/components/toolbar/toolbar'
21-
import { Box, IconTextButton, Pagination, Split } from '@sdk/components'
21+
import { Box, IconTextButton, Pagination, SearchInput, Split } from '@sdk/components'
2222
import { uuid } from '@sdk/utils'
23-
import { isUndefined } from 'lodash'
24-
import React, { useEffect, useState } from 'react'
23+
import { isNil, isUndefined } from 'lodash'
24+
import React, { useEffect, useMemo, useState } from 'react'
2525
import { useTranslation } from 'react-i18next'
26+
import { type SortingState } from '@tanstack/react-table'
2627
import trackError, { ApiError, GeneralError } from '../app/error-handler'
2728
import { downloadFile } from '../app/utils/download'
2829
import { useLazyUnitQuantityValueUnitsExportQuery, useUnitQuantityValueUnitsCollectionQuery } from '../data-object/unit-slice-enhanced'
2930
import { type QuantityValueUnitRow, useQuantityValueUnit } from './hooks/use-quantity-value-unit'
3031
import { Table } from './table/table'
3132

33+
/**
34+
* Maps camelCase column IDs from the TypeScript QuantityValueUnit type
35+
* to the actual database column names expected by the backend sort filter.
36+
*/
37+
const SORT_KEY_MAP: Record<string, string> = {
38+
longName: 'longname',
39+
baseUnit: 'baseunit'
40+
}
41+
42+
function toSortKey (columnId: string): string {
43+
return SORT_KEY_MAP[columnId] ?? columnId
44+
}
45+
3246
export const QuantityValueContainer = (): React.JSX.Element => {
3347
const { t } = useTranslation()
3448
const { createUnit, createLoading } = useQuantityValueUnit()
3549
const modal = useFormModal()
3650

3751
const [currentPage, setCurrentPage] = useState<number>(1)
3852
const [pageSize, setPageSize] = useState<number>(20)
53+
const [sorting, setSorting] = useState<SortingState>([])
54+
const [filter, setFilter] = useState<string>('')
3955

40-
const { data, isLoading, isFetching, error, refetch } = useUnitQuantityValueUnitsCollectionQuery({ body: { filters: { page: currentPage, pageSize } } })
56+
const queryArgs = useMemo(() => ({
57+
body: {
58+
filters: {
59+
page: currentPage,
60+
pageSize,
61+
columnFilters: isNil(filter) ? [] : [{ type: 'search', filterValue: filter }],
62+
sortFilter: sorting.length > 0
63+
? {
64+
key: toSortKey(sorting[0].id),
65+
direction: sorting[0].desc ? 'DESC' : 'ASC'
66+
}
67+
: {}
68+
}
69+
}
70+
}), [currentPage, pageSize, filter, sorting])
71+
72+
const { data, isLoading, isFetching, error, refetch } = useUnitQuantityValueUnitsCollectionQuery(queryArgs)
4173

4274
const handleRefetch = (): void => {
4375
void refetch().catch(() => {
@@ -94,6 +126,11 @@ export const QuantityValueContainer = (): React.JSX.Element => {
94126
return { success }
95127
}
96128

129+
const handleSortingChange = (newSorting: SortingState): void => {
130+
setSorting(newSorting)
131+
setCurrentPage(1)
132+
}
133+
97134
const handleImportSuccess = (): void => {
98135
setIsImportModalOpen(false)
99136
handleRefetch()
@@ -189,16 +226,26 @@ export const QuantityValueContainer = (): React.JSX.Element => {
189226
onClick={ openCreateModal }
190227
>{t('quantity-values.new')}</IconTextButton>
191228
</Flex>
229+
<SearchInput
230+
loading={ isFetching }
231+
onSearch={ (value) => {
232+
setFilter(value)
233+
setCurrentPage(1)
234+
} }
235+
placeholder="Search"
236+
withPrefix={ false }
237+
withoutAddon={ false }
238+
/>
192239
</Toolbar>
193240
}
194241
>
195242
<Content
196-
loading={ isLoading || isFetching }
243+
loading={ isLoading }
197244
margin={ {
198245
x: 'extra-small',
199246
y: 'none'
200247
} }
201-
none={ isUndefined(items) || items.length === 0 }
248+
none={ !isLoading && (isUndefined(items) || items.length === 0) }
202249
>
203250
<Box
204251
margin={ {
@@ -207,8 +254,10 @@ export const QuantityValueContainer = (): React.JSX.Element => {
207254
} }
208255
>
209256
<Table
257+
onSortingChange={ handleSortingChange }
210258
quantityValueUnitRows={ quantityValueUnitRows }
211259
setQuantityValueUnitRows={ setQuantityValueUnitRows }
260+
sorting={ sorting }
212261
/>
213262
</Box>
214263
</Content>

assets/js/src/core/modules/quantity-value/table/table.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import React, { useMemo, useState } from 'react'
1212
import { Grid } from '@Pimcore/components/grid/grid'
13-
import { createColumnHelper } from '@tanstack/react-table'
13+
import { createColumnHelper, type SortingState } from '@tanstack/react-table'
1414
import { useTranslation } from 'react-i18next'
1515
import { type QuantityValueUnit } from '@Pimcore/modules/data-object/unit-slice-enhanced'
1616
import { type QuantityValueUnitRow, useQuantityValueUnit } from '../hooks/use-quantity-value-unit'
@@ -23,9 +23,11 @@ type QuantityValueUnitWithActions = QuantityValueUnit & { actions: React.ReactNo
2323
interface TableProps {
2424
quantityValueUnitRows: QuantityValueUnitRow[]
2525
setQuantityValueUnitRows: React.Dispatch<React.SetStateAction<QuantityValueUnitRow[]>>
26+
sorting?: SortingState
27+
onSortingChange?: (sorting: SortingState) => void
2628
}
2729

28-
export const Table = ({ quantityValueUnitRows, setQuantityValueUnitRows }: TableProps): React.JSX.Element => {
30+
export const Table = ({ quantityValueUnitRows, setQuantityValueUnitRows, sorting, onSortingChange }: TableProps): React.JSX.Element => {
2931
const { t } = useTranslation()
3032
const { updateUnitById } = useQuantityValueUnit()
3133
const [modifiedCells, setModifiedCells] = useState<ModifiedCells>([])
@@ -68,11 +70,13 @@ export const Table = ({ quantityValueUnitRows, setQuantityValueUnitRows }: Table
6870
columnHelper.accessor('conversionOffset', {
6971
header: t('quantity-values.columns.conversion-offset'),
7072
meta: { type: 'number', editable: true },
73+
enableSorting: false,
7174
size: 150
7275
}),
7376
columnHelper.accessor('converter', {
7477
header: t('quantity-values.columns.converter'),
7578
meta: { editable: true },
79+
enableSorting: false,
7680
size: 150
7781
}),
7882
columnHelper.accessor('actions', {
@@ -127,10 +131,13 @@ export const Table = ({ quantityValueUnitRows, setQuantityValueUnitRows }: Table
127131
columns={ tableColumns }
128132
data={ quantityValueUnitRows }
129133
enableSorting
134+
manualSorting
130135
modifiedCells={ modifiedCells }
136+
onSortingChange={ onSortingChange }
131137
onUpdateCellData={ onUpdateCellData }
132138
resizable
133139
setRowId={ (row: QuantityValueUnitRow) => row.rowId }
140+
sorting={ sorting }
134141
/>
135142
)
136143
}

public/build/3f2ada02-d836-446e-b354-65774232ce0b/entrypoints.json

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/3f2ada02-d836-446e-b354-65774232ce0b/exposeRemote.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/3f2ada02-d836-446e-b354-65774232ce0b/index.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)