Skip to content

Commit

Permalink
Fix for csv export with incorrect data
Browse files Browse the repository at this point in the history
  • Loading branch information
fgatti675 committed Aug 25, 2023
1 parent e600ba9 commit c67b805
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 30 deletions.
25 changes: 19 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions example/src/SampleApp/collections/products_collection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,7 @@ export const productsCollection = buildCollection<Product>({
name: "External id",
dataType: "string"
}
},
expanded: true
}
},
available_locales: {
name: "Available locales",
Expand Down
16 changes: 8 additions & 8 deletions lib/src/core/util/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ interface Header {
}

export function downloadCSV<M extends Record<string, any>>(data: Entity<M>[],
additionalData: Record<string, any>[] | undefined,
collection: ResolvedEntityCollection<M>,
path: string,
exportConfig: ExportConfig | undefined) {
additionalData: Record<string, any>[] | undefined,
collection: ResolvedEntityCollection<M>,
path: string,
exportConfig: ExportConfig | undefined) {
const properties = collection.properties;
const headers = getExportHeaders(properties, path, exportConfig);
const exportableData = getExportableData(data, additionalData, properties, headers);
Expand All @@ -45,8 +45,8 @@ export function getExportableData(data: any[],
}

function getExportHeaders<M extends Record<string, any>, UserType extends User>(properties: ResolvedProperties<M>,
path: string,
exportConfig?: ExportConfig<UserType>): Header[] {
path: string,
exportConfig?: ExportConfig<UserType>): Header[] {
const headers = [
{ label: "id", key: "id" },
...Object.entries(properties)
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 5 additions & 8 deletions lib/src/hooks/data/useCollectionFetch.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -113,7 +107,10 @@ export function useCollectionFetch<M extends Record<string, any>, UserType exten
}
setDataLoading(false);
setDataLoadingError(undefined);
setData(entities);
setData(entities.map(e => ({
...e,
// values: sanitizeData(e.values, resolvedCollection.properties)
})));
setNoMoreToLoad(!itemCount || entities.length < itemCount);
};

Expand Down
3 changes: 2 additions & 1 deletion lib/src/hooks/data/useEntityFetch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,7 +24,7 @@ export interface EntityFetchResult<M extends Record<string, any>> {
dataLoadingError?: Error
}

const CACHE:Record<string, Entity<any>| undefined> = {};
const CACHE: Record<string, Entity<any> | undefined> = {};

/**
* This hook is used to fetch an entity.
Expand Down
19 changes: 14 additions & 5 deletions website/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
File renamed without changes.

0 comments on commit c67b805

Please sign in to comment.