From c67b80567b2ac42834564fa839b49c82bed69a86 Mon Sep 17 00:00:00 2001 From: francesco Date: Fri, 25 Aug 2023 18:07:38 +0200 Subject: [PATCH] Fix for csv export with incorrect data --- CHANGELOG.md | 25 ++++++++++++++----- .../collections/products_collection.tsx | 3 +-- lib/src/core/util/csv.ts | 16 ++++++------ lib/src/hooks/data/useCollectionFetch.tsx | 13 ++++------ lib/src/hooks/data/useEntityFetch.tsx | 3 ++- website/docs/CHANGELOG.md | 19 ++++++++++---- website/docs/{roles.md => _roles.md} | 0 7 files changed, 49 insertions(+), 30 deletions(-) rename website/docs/{roles.md => _roles.md} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 422849f12..3a6614776 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,25 @@ +## [2.1.0] - 2023-08- + +### Changed + +- [BREAKING] The logic to verify valid filter combinations has been moved to the `DataSource` interface. + This improves the ability to customize the data source and allows for more complex filters. + This change will only affect you if you have implemented a custom data source. You will need to + add a `isFilterCombinationValid` method to your data source. +- You can now use nested `spreadChildren` in map properties, allowing to show arbitrary + nested structures as single columns in the collection view. +- The collection count value is now updated with filters applied. +- Fix for csv export not working when underlying data is invalid. + ## [2.0.5] - 2023-07-11 ### Changed -- Default value for string properties is now `null` instead of `"""`. +- Default value for string properties is now `null` instead of `""`. - Fix for changing text search controller not updating as a dependency. -- Fix for setting a unique field using a reference, which was -generating an invalid query in Firestore. - +- Fix for setting a unique field using a reference, which was + generating an invalid query in Firestore. + ## [2.0.4] - 2023-06-15 ### Changed @@ -20,14 +33,14 @@ generating an invalid query in Firestore. - Fix for form resetting values when saving. - ## [2.0.2] - 2023-06-14 ### Changed - Replaced `flexsearch` with `js-search`. Their imports are too messed up. - Fix for form assigning wrong ids -- +- + ## [2.0.1] - 2023-06-12 ### Changed diff --git a/example/src/SampleApp/collections/products_collection.tsx b/example/src/SampleApp/collections/products_collection.tsx index 4172dfdd4..b1ebf18a3 100644 --- a/example/src/SampleApp/collections/products_collection.tsx +++ b/example/src/SampleApp/collections/products_collection.tsx @@ -273,8 +273,7 @@ export const productsCollection = buildCollection({ name: "External id", dataType: "string" } - }, - expanded: true + } }, available_locales: { name: "Available locales", diff --git a/lib/src/core/util/csv.ts b/lib/src/core/util/csv.ts index 211f7a388..f1bd3460b 100644 --- a/lib/src/core/util/csv.ts +++ b/lib/src/core/util/csv.ts @@ -15,10 +15,10 @@ interface Header { } export function downloadCSV>(data: Entity[], - additionalData: Record[] | undefined, - collection: ResolvedEntityCollection, - path: string, - exportConfig: ExportConfig | undefined) { + additionalData: Record[] | undefined, + collection: ResolvedEntityCollection, + path: string, + exportConfig: ExportConfig | undefined) { const properties = collection.properties; const headers = getExportHeaders(properties, path, exportConfig); const exportableData = getExportableData(data, additionalData, properties, headers); @@ -45,8 +45,8 @@ export function getExportableData(data: any[], } function getExportHeaders, UserType extends User>(properties: ResolvedProperties, - path: string, - exportConfig?: ExportConfig): Header[] { + path: string, + exportConfig?: ExportConfig): Header[] { const headers = [ { label: "id", key: "id" }, ...Object.entries(properties) @@ -99,10 +99,10 @@ function processCSVValue(inputValue: any, } else { value = inputValue; } - } else if (property.dataType === "reference") { + } else if (property.dataType === "reference" && inputValue instanceof EntityReference) { const ref = inputValue ? inputValue as EntityReference : undefined; value = ref ? ref.pathWithId : null; - } else if (property.dataType === "date") { + } else if (property.dataType === "date" && inputValue instanceof Date) { value = inputValue ? inputValue.getTime() : null; } else { value = inputValue; diff --git a/lib/src/hooks/data/useCollectionFetch.tsx b/lib/src/hooks/data/useCollectionFetch.tsx index b9bcb7855..92c2dd206 100644 --- a/lib/src/hooks/data/useCollectionFetch.tsx +++ b/lib/src/hooks/data/useCollectionFetch.tsx @@ -1,11 +1,5 @@ import { useEffect, useState } from "react"; -import { - Entity, - EntityCollection, - FilterValues, - FireCMSContext, - User -} from "../../types"; +import { Entity, EntityCollection, FilterValues, FireCMSContext, User } from "../../types"; import { useDataSource } from "./useDataSource"; import { useNavigationContext } from "../useNavigationContext"; import { useFireCMSContext } from "../useFireCMSContext"; @@ -113,7 +107,10 @@ export function useCollectionFetch, UserType exten } setDataLoading(false); setDataLoadingError(undefined); - setData(entities); + setData(entities.map(e => ({ + ...e, + // values: sanitizeData(e.values, resolvedCollection.properties) + }))); setNoMoreToLoad(!itemCount || entities.length < itemCount); }; diff --git a/lib/src/hooks/data/useEntityFetch.tsx b/lib/src/hooks/data/useEntityFetch.tsx index 1611b9d2e..282160773 100644 --- a/lib/src/hooks/data/useEntityFetch.tsx +++ b/lib/src/hooks/data/useEntityFetch.tsx @@ -3,6 +3,7 @@ import { Entity, EntityCollection, FireCMSContext, User } from "../../types"; import { useDataSource } from "./useDataSource"; import { useNavigationContext } from "../useNavigationContext"; import { useFireCMSContext } from "../useFireCMSContext"; +import { resolveCollection } from "../../core"; /** * @category Hooks and utilities @@ -23,7 +24,7 @@ export interface EntityFetchResult> { dataLoadingError?: Error } -const CACHE:Record| undefined> = {}; +const CACHE: Record | undefined> = {}; /** * This hook is used to fetch an entity. diff --git a/website/docs/CHANGELOG.md b/website/docs/CHANGELOG.md index eed278a93..4f0f03405 100644 --- a/website/docs/CHANGELOG.md +++ b/website/docs/CHANGELOG.md @@ -2,15 +2,24 @@ id: changelog title: Changelog --- +## [2.1.0] - 2023-08- + +### Changed + +- [BREAKING] The logic to verify valid filter combinations has been moved to the `DataSource` interface. + This improves the ability to customize the data source and allows for more complex filters. + This change will only affect you if you have implemented a custom data source. You will need to + add a `isFilterCombinationValid` method to your data source. + ## [2.0.5] - 2023-07-11 ### Changed - Default value for string properties is now `null` instead of `"""`. - Fix for changing text search controller not updating as a dependency. -- Fix for setting a unique field using a reference, which was -generating an invalid query in Firestore. - +- Fix for setting a unique field using a reference, which was + generating an invalid query in Firestore. + ## [2.0.4] - 2023-06-15 ### Changed @@ -24,14 +33,14 @@ generating an invalid query in Firestore. - Fix for form resetting values when saving. - ## [2.0.2] - 2023-06-14 ### Changed - Replaced `flexsearch` with `js-search`. Their imports are too messed up. - Fix for form assigning wrong ids -- +- + ## [2.0.1] - 2023-06-12 ### Changed diff --git a/website/docs/roles.md b/website/docs/_roles.md similarity index 100% rename from website/docs/roles.md rename to website/docs/_roles.md