mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-29 00:16:39 +01:00
feat(csv-import): add geopoint parser
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user