mirror of
https://github.com/rowyio/rowy.git
synced 2026-07-13 22:08:55 +02:00
@@ -259,19 +259,23 @@ export default function DraggableHeaderRenderer<R>({
|
||||
</Grid>
|
||||
)}
|
||||
|
||||
{userClaims?.roles?.includes("ADMIN") && (
|
||||
<Grid item>
|
||||
<IconButton
|
||||
size="small"
|
||||
className={classes.dropdownButton}
|
||||
aria-label={`Show ${column.name} column dropdown`}
|
||||
color="inherit"
|
||||
onClick={handleClick}
|
||||
>
|
||||
<DropdownIcon />
|
||||
</IconButton>
|
||||
</Grid>
|
||||
)}
|
||||
{userClaims?.roles?.includes("ADMIN") ||
|
||||
(userClaims?.roles?.includes("OPS") &&
|
||||
[FieldType.multiSelect, FieldType.singleSelect].includes(
|
||||
(column as any).type
|
||||
) && (
|
||||
<Grid item>
|
||||
<IconButton
|
||||
size="small"
|
||||
className={classes.dropdownButton}
|
||||
aria-label={`Show ${column.name} column dropdown`}
|
||||
color="inherit"
|
||||
onClick={handleClick}
|
||||
>
|
||||
<DropdownIcon />
|
||||
</IconButton>
|
||||
</Grid>
|
||||
))}
|
||||
</Grid>
|
||||
);
|
||||
// return (
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import React from "react";
|
||||
import { ScrollSync, ScrollSyncPane } from "react-scroll-sync";
|
||||
import _find from "lodash/find";
|
||||
import { parseJSON } from "date-fns";
|
||||
|
||||
import { makeStyles, createStyles, Grid } from "@material-ui/core";
|
||||
|
||||
@@ -83,6 +82,7 @@ export default function Step4Preview({ csvData, config }: IStepProps) {
|
||||
|
||||
const columns = config.pairs.map(({ csvKey, columnKey }) => ({
|
||||
csvKey,
|
||||
columnKey,
|
||||
...(tableState!.columns[columnKey] ??
|
||||
_find(config.newColumns, { key: columnKey }) ??
|
||||
{}),
|
||||
@@ -105,17 +105,13 @@ export default function Step4Preview({ csvData, config }: IStepProps) {
|
||||
|
||||
<ScrollSyncPane>
|
||||
<Grid container wrap="nowrap" className={classes.data}>
|
||||
{columns.map(({ csvKey, name, type }) => (
|
||||
{columns.map(({ csvKey, name, columnKey, type }) => (
|
||||
<Grid item key={csvKey} className={classes.column}>
|
||||
{csvData.rows.map((row, i) => (
|
||||
<Cell
|
||||
key={csvKey + i}
|
||||
field={csvKey}
|
||||
value={
|
||||
type === FieldType.date || type === FieldType.dateTime
|
||||
? parseJSON(row[csvKey]).getTime()
|
||||
: row[csvKey]
|
||||
}
|
||||
field={columnKey}
|
||||
value={row[columnKey]}
|
||||
type={type}
|
||||
name={name}
|
||||
/>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import React, { useState, useMemo } from "react";
|
||||
import _mergeWith from "lodash/mergeWith";
|
||||
import _find from "lodash/find";
|
||||
import { parseJSON } from "date-fns";
|
||||
@@ -21,6 +21,7 @@ import { ColumnConfig } from "hooks/useFiretable/useTableConfig";
|
||||
import { useFiretableContext } from "contexts/FiretableContext";
|
||||
import { FieldType } from "constants/fields";
|
||||
import { useSnackContext } from "contexts/SnackContext";
|
||||
import { getFieldProp } from "components/fields";
|
||||
|
||||
export type CsvConfig = {
|
||||
pairs: { csvKey: string; columnKey: string }[];
|
||||
@@ -67,24 +68,32 @@ export default function ImportCsvWizard({
|
||||
}));
|
||||
};
|
||||
|
||||
const handleFinish = () => {
|
||||
if (!tableState || !tableActions || !csvData) return;
|
||||
openSnackbar({ message: "Importing data…" });
|
||||
// Add all new rows — synchronous
|
||||
for (const row of csvData.rows) {
|
||||
const newRow = config.pairs.reduce((a, pair) => {
|
||||
const parsedRows: any[] = useMemo(() => {
|
||||
if (!tableState || !tableActions || !csvData) return [];
|
||||
return csvData.rows.map((row) =>
|
||||
config.pairs.reduce((a, pair) => {
|
||||
const matchingColumn =
|
||||
tableState.columns[pair.columnKey] ??
|
||||
_find(config.newColumns, { key: pair.columnKey });
|
||||
const value =
|
||||
matchingColumn.type === FieldType.date ||
|
||||
matchingColumn.type === FieldType.dateTime
|
||||
? parseJSON(row[pair.csvKey])
|
||||
: row[pair.csvKey];
|
||||
console.log({ type: matchingColumn.type });
|
||||
const csvFieldParser = getFieldProp(
|
||||
"csvImportParser",
|
||||
matchingColumn.type
|
||||
);
|
||||
const value = csvFieldParser
|
||||
? csvFieldParser(row[pair.csvKey])
|
||||
: row[pair.csvKey];
|
||||
return { ...a, [pair.columnKey]: value };
|
||||
}, {});
|
||||
tableActions.row.add(newRow);
|
||||
}
|
||||
}, {})
|
||||
);
|
||||
}, [csvData, tableState, tableActions, config]);
|
||||
|
||||
const handleFinish = () => {
|
||||
if (!tableState || !tableActions || !parsedRows) return;
|
||||
openSnackbar({ message: "Importing data…" });
|
||||
// Add all new rows — synchronous
|
||||
parsedRows?.forEach((newRow) => 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);
|
||||
@@ -172,7 +181,7 @@ export default function ImportCsvWizard({
|
||||
"Preview your data with your configured columns. You can change column types by clicking “Edit Type” from the column menu at any time.",
|
||||
content: (
|
||||
<Step3Preview
|
||||
csvData={csvData}
|
||||
csvData={{ ...csvData, rows: parsedRows }}
|
||||
config={config}
|
||||
setConfig={setConfig}
|
||||
updateConfig={updateConfig}
|
||||
|
||||
@@ -26,6 +26,11 @@ export const config: IFieldConfig = {
|
||||
description: "Either checked or unchecked. Unchecked by default.",
|
||||
TableCell: withHeavyCell(BasicCell, TableCell),
|
||||
TableEditor: NullEditor,
|
||||
csvImportParser: (value: string) => {
|
||||
if (["YES", "TRUE", "1"].includes(value.toUpperCase())) return true;
|
||||
else if (["NO", "FALSE", "0"].includes(value.toUpperCase())) return false;
|
||||
else return null;
|
||||
},
|
||||
SideDrawerField,
|
||||
};
|
||||
export default config;
|
||||
|
||||
Reference in New Issue
Block a user