mirror of
https://github.com/rowyio/rowy.git
synced 2026-07-12 13:28:48 +02:00
Merge branch 'fields-refactor' of https://github.com/AntlerVC/firetable into fields-refactor
This commit is contained in:
@@ -3,7 +3,7 @@ import React from "react";
|
||||
import { makeStyles, createStyles } from "@material-ui/core";
|
||||
|
||||
import { FieldType } from "constants/fields";
|
||||
//import { getFormatter } from "components/Table/formatters";
|
||||
import { getFieldProp } from "components/fields";
|
||||
import EmptyState from "components/EmptyState";
|
||||
|
||||
const useStyles = makeStyles((theme) =>
|
||||
@@ -68,8 +68,7 @@ export default function Cell({
|
||||
...props
|
||||
}: ICellProps) {
|
||||
const classes = useStyles();
|
||||
const formatter = null;
|
||||
//const formatter = type ? getFormatter({ type: type }, true) : null;
|
||||
const formatter = type ? getFieldProp("TableCell", type) : null;
|
||||
|
||||
return (
|
||||
<div className={classes.root} {...props}>
|
||||
@@ -83,6 +82,7 @@ export default function Cell({
|
||||
key: field,
|
||||
name,
|
||||
config: { options: [] },
|
||||
editable: false,
|
||||
} as any,
|
||||
row: { [field]: value },
|
||||
isRowSelected: false,
|
||||
|
||||
@@ -20,6 +20,7 @@ import Step3Preview from "./Step3Preview";
|
||||
import { ColumnConfig } from "hooks/useFiretable/useTableConfig";
|
||||
import { useFiretableContext } from "contexts/FiretableContext";
|
||||
import { FieldType } from "constants/fields";
|
||||
import { useSnackContext } from "contexts/SnackContext";
|
||||
|
||||
export type CsvConfig = {
|
||||
pairs: { csvKey: string; columnKey: string }[];
|
||||
@@ -52,6 +53,7 @@ export default function ImportCsvWizard({
|
||||
const [open, setOpen] = useState(true);
|
||||
|
||||
const { tableState, tableActions } = useFiretableContext();
|
||||
const { open: openSnackbar } = useSnackContext();
|
||||
|
||||
const [config, setConfig] = useState<CsvConfig>({
|
||||
pairs: [],
|
||||
@@ -67,14 +69,9 @@ export default function ImportCsvWizard({
|
||||
|
||||
const handleFinish = () => {
|
||||
if (!tableState || !tableActions || !csvData) return;
|
||||
// Add any new columns to the end
|
||||
config.newColumns.forEach((col) =>
|
||||
setTimeout(() => {
|
||||
tableActions.column.add(col.name, col.type, col);
|
||||
})
|
||||
);
|
||||
// Add all new rows
|
||||
csvData.rows.forEach((row) => {
|
||||
openSnackbar({ message: "Importing data…" });
|
||||
// Add all new rows — synchronous
|
||||
for (const row of csvData.rows) {
|
||||
const newRow = config.pairs.reduce((a, pair) => {
|
||||
const matchingColumn =
|
||||
tableState.columns[pair.columnKey] ??
|
||||
@@ -87,7 +84,11 @@ export default function ImportCsvWizard({
|
||||
return { ...a, [pair.columnKey]: value };
|
||||
}, {});
|
||||
tableActions.row.add(newRow);
|
||||
});
|
||||
}
|
||||
// Add any new columns to the end
|
||||
for (const col of config.newColumns) {
|
||||
tableActions.column.add(col.name, col.type, col);
|
||||
}
|
||||
// Close wizard
|
||||
setOpen(false);
|
||||
setTimeout(handleClose, 300);
|
||||
|
||||
@@ -18,7 +18,7 @@ const SideDrawerField = lazy(
|
||||
|
||||
export const config: IFieldConfig = {
|
||||
type: FieldType.longText,
|
||||
name: "Short Text",
|
||||
name: "Long Text",
|
||||
dataType: "string",
|
||||
initialValue: "",
|
||||
initializable: true,
|
||||
|
||||
@@ -238,8 +238,8 @@ const useTable = (initialOverrides: any) => {
|
||||
|
||||
const docData = {
|
||||
...valuesFromFilter,
|
||||
createdAt: serverTimestamp(),
|
||||
updatedAt: serverTimestamp(),
|
||||
_ft_createdAt: serverTimestamp(),
|
||||
_ft_updatedAt: serverTimestamp(),
|
||||
...data,
|
||||
};
|
||||
try {
|
||||
|
||||
@@ -54,10 +54,11 @@ const useTableConfig = (tablePath?: string) => {
|
||||
const addColumn = (name: string, type: FieldType, data?: any) => {
|
||||
//TODO: validation
|
||||
const { columns } = tableConfigState;
|
||||
const newIndex = Object.keys(columns).length;
|
||||
let updatedColumns = columns;
|
||||
const newIndex = Object.keys(columns).length ?? 0;
|
||||
let updatedColumns = { ...columns };
|
||||
const key = _camelCase(name);
|
||||
updatedColumns[key] = { name, key, type, ...data, index: newIndex ?? 0 };
|
||||
console.log(name, type, data, updatedColumns);
|
||||
documentDispatch({
|
||||
action: DocActions.update,
|
||||
data: { columns: updatedColumns },
|
||||
|
||||
Reference in New Issue
Block a user