Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 5 additions & 5 deletions assets/js/src/core/modules/data-object/unit-slice-enhanced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @license Pimcore Open Core License (POCL)
*/

import { providingTags, tagNames } from '@Pimcore/app/api/pimcore/tags'
import { invalidatingTags, providingTags, tagNames } from '@Pimcore/app/api/pimcore/tags'

Check warning on line 11 in assets/js/src/core/modules/data-object/unit-slice-enhanced.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import of 'invalidatingTags'.

See more on https://sonarcloud.io/project/issues?id=pimcore_studio-ui-bundle&issues=AZ1xa3UOTHYJ6n2aoFaF&open=AZ1xa3UOTHYJ6n2aoFaF&pullRequest=3324
import { api as baseApi } from './unit-slice.gen'

const api = baseApi.enhanceEndpoints({
Expand All @@ -20,19 +20,19 @@
},

unitQuantityValueUnitsUpdate: {
invalidatesTags: () => []
invalidatesTags: () => [tagNames.QUANTITY_VALUE_UNITS]
},

unitQuantityValueUnitsDelete: {
invalidatesTags: () => []
invalidatesTags: () => [tagNames.QUANTITY_VALUE_UNITS]
},

unitQuantityValueUnitsCreate: {
invalidatesTags: () => []
invalidatesTags: () => [tagNames.QUANTITY_VALUE_UNITS]
},

unitQuantityValueList: {
providesTags: () => []
providesTags: () => providingTags.QUANTITY_VALUE_UNITS()
},

unitQuantityValueUnitsExport: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,58 @@
import { ModalTitle } from '@Pimcore/components/modal/modal-title/modal-title'
import { Title } from '@Pimcore/components/title/title'
import { Toolbar } from '@Pimcore/components/toolbar/toolbar'
import { Box, IconTextButton, Pagination, Split } from '@sdk/components'
import { Box, IconTextButton, Pagination, SearchInput, Split } from '@sdk/components'
import { uuid } from '@sdk/utils'
import { isUndefined } from 'lodash'
import React, { useEffect, useState } from 'react'
import React, { useEffect, useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { type SortingState } from '@tanstack/react-table'
import trackError, { ApiError, GeneralError } from '../app/error-handler'
import { downloadFile } from '../app/utils/download'
import { useLazyUnitQuantityValueUnitsExportQuery, useUnitQuantityValueUnitsCollectionQuery } from '../data-object/unit-slice-enhanced'
import { type QuantityValueUnitRow, useQuantityValueUnit } from './hooks/use-quantity-value-unit'
import { Table } from './table/table'

/**
* Maps camelCase column IDs from the TypeScript QuantityValueUnit type
* to the actual database column names expected by the backend sort filter.
*/
const SORT_KEY_MAP: Record<string, string> = {
longName: 'longname',
baseUnit: 'baseunit'
}

function toSortKey (columnId: string): string {
return SORT_KEY_MAP[columnId] ?? columnId
}

export const QuantityValueContainer = (): React.JSX.Element => {
const { t } = useTranslation()
const { createUnit, createLoading } = useQuantityValueUnit()
const modal = useFormModal()

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

const { data, isLoading, isFetching, error, refetch } = useUnitQuantityValueUnitsCollectionQuery({ body: { filters: { page: currentPage, pageSize } } })
const queryArgs = useMemo(() => ({
body: {
filters: {
page: currentPage,
pageSize,
columnFilters: filter !== '' ? [{ type: 'search', filterValue: filter }] : [],

Check warning on line 61 in assets/js/src/core/modules/quantity-value/quantity-value-container.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected negated condition.

See more on https://sonarcloud.io/project/issues?id=pimcore_studio-ui-bundle&issues=AZ1xa3XvTHYJ6n2aoFaG&open=AZ1xa3XvTHYJ6n2aoFaG&pullRequest=3324
sortFilter: sorting.length > 0
? {
key: toSortKey(sorting[0].id),
direction: sorting[0].desc ? 'DESC' : 'ASC'
}
: {}
}
}
}), [currentPage, pageSize, filter, sorting])

const { data, isLoading, isFetching, error, refetch } = useUnitQuantityValueUnitsCollectionQuery(queryArgs)

const handleRefetch = (): void => {
void refetch().catch(() => {
Expand Down Expand Up @@ -94,6 +126,11 @@
return { success }
}

const handleSortingChange = (newSorting: SortingState): void => {
setSorting(newSorting)
setCurrentPage(1)
}

const handleImportSuccess = (): void => {
setIsImportModalOpen(false)
handleRefetch()
Expand Down Expand Up @@ -189,16 +226,26 @@
onClick={ openCreateModal }
>{t('quantity-values.new')}</IconTextButton>
</Flex>
<SearchInput
loading={ isFetching }
onSearch={ (value) => {
setFilter(value)
setCurrentPage(1)
} }
placeholder="Search"
withPrefix={ false }
withoutAddon={ false }
/>
</Toolbar>
}
>
<Content
loading={ isLoading || isFetching }
loading={ isLoading }
margin={ {
x: 'extra-small',
y: 'none'
} }
none={ isUndefined(items) || items.length === 0 }
none={ !isLoading && (isUndefined(items) || items.length === 0) }
>
<Box
margin={ {
Expand All @@ -207,8 +254,10 @@
} }
>
<Table
onSortingChange={ handleSortingChange }
quantityValueUnitRows={ quantityValueUnitRows }
setQuantityValueUnitRows={ setQuantityValueUnitRows }
sorting={ sorting }
/>
</Box>
</Content>
Expand Down
11 changes: 9 additions & 2 deletions assets/js/src/core/modules/quantity-value/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

export const Table = ({ quantityValueUnitRows, setQuantityValueUnitRows }: TableProps): React.JSX.Element => {
export const Table = ({ quantityValueUnitRows, setQuantityValueUnitRows, sorting, onSortingChange }: TableProps): React.JSX.Element => {
const { t } = useTranslation()
const { updateUnitById } = useQuantityValueUnit()
const [modifiedCells, setModifiedCells] = useState<ModifiedCells>([])
Expand Down Expand Up @@ -68,11 +70,13 @@ export const Table = ({ quantityValueUnitRows, setQuantityValueUnitRows }: Table
columnHelper.accessor('conversionOffset', {
header: t('quantity-values.columns.conversion-offset'),
meta: { type: 'number', editable: true },
enableSorting: false,
size: 150
}),
columnHelper.accessor('converter', {
header: t('quantity-values.columns.converter'),
meta: { editable: true },
enableSorting: false,
size: 150
}),
columnHelper.accessor('actions', {
Expand Down Expand Up @@ -127,10 +131,13 @@ export const Table = ({ quantityValueUnitRows, setQuantityValueUnitRows }: Table
columns={ tableColumns }
data={ quantityValueUnitRows }
enableSorting
manualSorting
modifiedCells={ modifiedCells }
onSortingChange={ onSortingChange }
onUpdateCellData={ onUpdateCellData }
resizable
setRowId={ (row: QuantityValueUnitRow) => row.rowId }
sorting={ sorting }
/>
)
}
22 changes: 0 additions & 22 deletions public/build/1bbc463c-5b2c-499b-ac61-f4eeb3381bdf/entrypoints.json

This file was deleted.

33 changes: 0 additions & 33 deletions public/build/1bbc463c-5b2c-499b-ac61-f4eeb3381bdf/manifest.json

This file was deleted.

23 changes: 0 additions & 23 deletions public/build/303cdcf1-58ee-4ae4-8040-42836066132b/entrypoints.json

This file was deleted.

Loading