feat(csv-import): add geopoint parser

This commit is contained in:
Han Tuerker
2022-08-17 16:53:10 +03:00
parent c56fdc0567
commit 67e6fc5e71
3 changed files with 15 additions and 1 deletions

View File

@@ -46,6 +46,7 @@ const inferTypeFromValue = (value: any) => {
if (typeof value === "object") {
if ("hex" in value && "rgb" in value) return FieldType.color;
if ("latitude" in value && "longitude" in value) return FieldType.geoPoint;
if ("toDate" in value) return FieldType.dateTime;
return FieldType.json;
}

View File

@@ -2,7 +2,7 @@ import { IBasicCellProps } from "@src/components/fields/types";
import { Typography } from "@mui/material";
export default function GeoPoint({ value }: IBasicCellProps) {
if (value === undefined) return null;
if (!value) return null;
const { latitude, longitude } = value;
if (latitude === undefined || longitude === undefined)

View File

@@ -1,4 +1,5 @@
import { lazy } from "react";
import { GeoPoint } from "firebase/firestore";
import { IFieldConfig, FieldType } from "@src/components/fields/types";
import withBasicCell from "@src/components/fields/_withTableCell/withBasicCell";
@@ -26,5 +27,17 @@ export const config: IFieldConfig = {
TableCell: withBasicCell(TableCell),
TableEditor: withSideDrawerEditor(TableCell),
SideDrawerField,
csvImportParser: (value: string) => {
try {
const { latitude, longitude } = JSON.parse(value);
if (latitude && longitude) {
return new GeoPoint(latitude, longitude);
}
throw new Error();
} catch (e) {
console.error("Invalid Geopoint value");
return null;
}
},
};
export default config;