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

Fix: collections pagination and other admin UX improvements #156

Merged
merged 2 commits into from
Apr 22, 2024
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
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).


## [Unreleased]

### Fixed

- Pagination bug on admin organization details collections assignment UI

### Added

- Loading indicators for admin organization details: cost centers, collections, payment terms, price tables, and sellers

## [1.31.2] - 2024-03-14

### Changed
Expand All @@ -23,6 +30,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [1.31.0] - 2024-02-27

### Added

- Add help footer on bulk import upload modal

## [1.30.2] - 2024-01-31
Expand Down Expand Up @@ -70,7 +78,8 @@ Arabic, Bulgarian, Catalan, Czech, Danish, German, Greek, English, Spanish, Finn
## [1.28.1] - 2023-11-06

### Fixed
- Arabic, Bulgarian, Catalan, Czech, Danish, German, Greek, English, Spanish, Finnish, French, Indonesian, Italian, Japanese, Korean, Dutch, Norwegian, Polish, Portuguese, Romanian, Russian, Slovakian, Slovenian, Swedish, Thai and Ukrainian translations.

- Arabic, Bulgarian, Catalan, Czech, Danish, German, Greek, English, Spanish, Finnish, French, Indonesian, Italian, Japanese, Korean, Dutch, Norwegian, Polish, Portuguese, Romanian, Russian, Slovakian, Slovenian, Swedish, Thai and Ukrainian translations.

## [1.28.0] - 2023-10-18

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
collectionsState,
setCollectionsState,
}: {
getSchema: (argument?: any) => any

Check warning on line 21 in react/admin/OrganizationDetails/OrganizationDetailsCollections.tsx

View workflow job for this annotation

GitHub Actions / QE / Lint Node.js

Unexpected any. Specify a different type

Check warning on line 21 in react/admin/OrganizationDetails/OrganizationDetailsCollections.tsx

View workflow job for this annotation

GitHub Actions / QE / Lint Node.js

Unexpected any. Specify a different type
collectionsState: Collection[]
setCollectionsState: (value: any) => void

Check warning on line 23 in react/admin/OrganizationDetails/OrganizationDetailsCollections.tsx

View workflow job for this annotation

GitHub Actions / QE / Lint Node.js

Unexpected any. Specify a different type
}) => {
/**
* Hooks
Expand All @@ -42,17 +42,19 @@
const {
data: collectionsData,
refetch: refetchCollections,
} = useQuery(GET_COLLECTIONS, { ssr: false })
loading,
} = useQuery(GET_COLLECTIONS, {
variables: collectionPaginationState,
notifyOnNetworkStatusChange: true,
ssr: false,
})

/**
* Effects
*/

useEffect(() => {
if (
!collectionsData?.collections?.items?.length ||
collectionOptions.length
) {
if (!collectionsData?.collections?.items?.length) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: could you explain why this line was changed? Why the check on collectionOptions.lenght was removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The effect of this check is that it's impossible to advance to the next page of available collections. The code sees that collectionOptions already has length (the first page of results) and therefore skips setting the second page of results to state.

return
}

Expand Down Expand Up @@ -171,6 +173,7 @@
fullWidth
schema={getSchema('availableCollections')}
items={collectionOptions}
loading={loading}
pagination={{
onNextClick: handleCollectionsNextClick,
onPrevClick: handleCollectionsPrevClick,
Expand All @@ -189,7 +192,7 @@
textShowRows: formatMessage(messages.showRows),
textOf: formatMessage(messages.of),
totalItems: collectionsData?.collections?.paging?.total ?? 0,
rowsOptions: [25, 50, 100],
rowsOptions: [25, 50],
}}
bulkActions={organizationBulkAction(
handleAddCollections,
Expand Down
21 changes: 12 additions & 9 deletions react/admin/OrganizationDetails/OrganizationDetailsCostCenters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,17 @@ const OrganizationDetailsCostCenters = ({
* Mutations
*/
const [createCostCenter] = useMutation(CREATE_COST_CENTER)
const { data: costCentersData, refetch: refetchCostCenters } = useQuery(
GET_COST_CENTERS,
{
variables: { ...costCenterPaginationState, id: params?.id },
fetchPolicy: 'network-only',
skip: !params?.id,
ssr: false,
}
)
const {
data: costCentersData,
refetch: refetchCostCenters,
loading,
} = useQuery(GET_COST_CENTERS, {
variables: { ...costCenterPaginationState, id: params?.id },
fetchPolicy: 'network-only',
notifyOnNetworkStatusChange: true,
skip: !params?.id,
ssr: false,
})

//! CUSTOM FIELDS
const {
Expand Down Expand Up @@ -286,6 +288,7 @@ const OrganizationDetailsCostCenters = ({
<Table
fullWidth
schema={getCostCenterSchema()}
loading={loading}
items={costCentersData?.getCostCentersByOrganizationId?.data}
onRowClick={({
rowData: { id },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const OrganizationDetailsPayTerms = ({
* Queries
*/

const { data: paymentTermsData } = useQuery<{
const { data: paymentTermsData, loading } = useQuery<{
getPaymentTerms: PaymentTerm[]
}>(GET_PAYMENT_TERMS, { ssr: false })

Expand All @@ -47,10 +47,7 @@ const OrganizationDetailsPayTerms = ({
*/

useEffect(() => {
if (
!paymentTermsData?.getPaymentTerms?.length ||
paymentTermsOptions.length
) {
if (!paymentTermsData?.getPaymentTerms?.length) {
return
}

Expand Down Expand Up @@ -131,6 +128,7 @@ const OrganizationDetailsPayTerms = ({
fullWidth
schema={getSchema('availablePayments')}
items={paymentTermsOptions}
loading={loading}
bulkActions={organizationBulkAction(
handleAddPaymentTerms,
messages.addToOrg,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ const OrganizationDetailsPriceTables = ({
/**
* Queries
*/
const { data: priceTablesData } = useQuery(GET_PRICE_TABLES, { ssr: false })
const { data: priceTablesData, loading } = useQuery(GET_PRICE_TABLES, {
ssr: false,
})

/**
* Effects
Expand Down Expand Up @@ -120,6 +122,7 @@ const OrganizationDetailsPriceTables = ({
fullWidth
schema={getSchema('availablePriceTables')}
items={priceTableOptions}
loading={loading}
bulkActions={organizationBulkAction(
handleAddPriceTables,
messages.addToOrg,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const OrganizationDetailsSellers = ({
/**
* Queries
*/
const { data: sellersData } = useQuery(GET_SELLERS)
const { data: sellersData, loading } = useQuery(GET_SELLERS)

/**
* Effects
Expand Down Expand Up @@ -107,6 +107,7 @@ const OrganizationDetailsSellers = ({
fullWidth
schema={getSchema()}
items={sellersState}
loading={loading}
bulkActions={organizationBulkAction(
handleRemoveSellers,
messages.removeFromOrg,
Expand Down
Loading