All Projects → benwinding → React Admin Import Csv

benwinding / React Admin Import Csv

Licence: mit
A csv file import button for react-admin

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React Admin Import Csv

Jsoncsv
a command tool easily convert json file to csv or xlsx
Stars: ✭ 43 (-31.75%)
Mutual labels:  csv
Fast Csv
CSV parser and formatter for node
Stars: ✭ 1,054 (+1573.02%)
Mutual labels:  csv
Q
q - Run SQL directly on CSV or TSV files
Stars: ✭ 8,809 (+13882.54%)
Mutual labels:  csv
Jl Sql
SQL for JSON and CSV streams
Stars: ✭ 44 (-30.16%)
Mutual labels:  csv
Azure Functions Billing
Azure Functions v2 with .NET Core - billing in serverless architecture.
Stars: ✭ 49 (-22.22%)
Mutual labels:  csv
Csv
Fast C# CSV parser
Stars: ✭ 53 (-15.87%)
Mutual labels:  csv
Ether sql
A python library to push ethereum blockchain data into an sql database.
Stars: ✭ 41 (-34.92%)
Mutual labels:  csv
Csv File Validator
🔧🔦 Validation of CSV file against user defined schema (returns back object with data and invalid messages)
Stars: ✭ 60 (-4.76%)
Mutual labels:  csv
Ra Jsonapi Client
JSON API data provider for react-admin.
Stars: ✭ 50 (-20.63%)
Mutual labels:  react-admin
Rumble
⛈️ Rumble 1.11.0 "Banyan Tree"🌳 for Apache Spark | Run queries on your large-scale, messy JSON-like data (JSON, text, CSV, Parquet, ROOT, AVRO, SVM...) | No install required (just a jar to download) | Declarative Machine Learning and more
Stars: ✭ 58 (-7.94%)
Mutual labels:  csv
Django Rest Pandas
📊📈 Serves up Pandas dataframes via the Django REST Framework for use in client-side (i.e. d3.js) visualizations and offline analysis (e.g. Excel)
Stars: ✭ 1,030 (+1534.92%)
Mutual labels:  csv
Joiner
A simple utility for SQL-like joins with Json, GeoJson or dbf data in Node, the browser and on the command line. Also creates join reports so you can know how successful a given join was. Try it in the browser -->
Stars: ✭ 47 (-25.4%)
Mutual labels:  csv
Fifa Fut Data
Web-scraping script that writes the data of all players from FutHead and FutBin to a CSV file or a DB
Stars: ✭ 55 (-12.7%)
Mutual labels:  csv
Excellentexport
Javascript export to Excel
Stars: ✭ 1,018 (+1515.87%)
Mutual labels:  csv
Re Txt
converts text-formats from one to another, it is very useful if you want to re-format a json file to yaml, toml to yaml, csv to yaml, ... etc
Stars: ✭ 59 (-6.35%)
Mutual labels:  csv
Goloc
A flexible tool for application localization using Google Sheets.
Stars: ✭ 42 (-33.33%)
Mutual labels:  csv
Faster Than Csv
Faster CSV on Python 3
Stars: ✭ 52 (-17.46%)
Mutual labels:  csv
Yacr
Yet another CSV Reader
Stars: ✭ 62 (-1.59%)
Mutual labels:  csv
Cesil
Modern CSV (De)Serializer
Stars: ✭ 59 (-6.35%)
Mutual labels:  csv
Parsrs
CSV, JSON, XML text parsers and generators written in pure POSIX shellscript
Stars: ✭ 56 (-11.11%)
Mutual labels:  csv

react-admin-import-csv

NPM Version Downloads/week License Github Issues Build and Publish Code Coverage

CSV import button for react-admin.

image

Usage

Simply import the button into a toolbar, like so:

Basic Import Action Only

import {
  Datagrid,
  List,
  TextField,
  RichTextField,
  TopToolbar
} from "react-admin";
import { ImportButton } from "react-admin-import-csv";
import { CreateButton } from "ra-ui-materialui";

const ListActions = props => {
  const { className, basePath } = props;
  return (
    <TopToolbar className={className}>
      <CreateButton basePath={basePath} />
      <ImportButton {...props} />
    </TopToolbar>
  );
};
export const PostList = props => (
  <List {...props} filters={<PostFilter />} actions={<ListActions />}>
    <Datagrid>
      <TextField source="title" />
      <RichTextField source="body" />
      ...
    </Datagrid>
  </List>
);

Export/Import Actions

import {
  Datagrid,
  List,
  TextField,
  RichTextField,
  TopToolbar
} from "react-admin";
import { ImportButton } from "react-admin-import-csv";
import { CreateButton, ExportButton } from "ra-ui-materialui";

const ListActions = props => {
  const { 
    className, 
    basePath, 
    total, 
    resource, 
    currentSort, 
    filterValues, 
    exporter 
  } = props;
  return (
    <TopToolbar className={className}>
      <CreateButton basePath={basePath} />
      <ExportButton
        disabled={total === 0}
        resource={resource}
        sort={currentSort}
        filter={filterValues}
        exporter={exporter}
      />
      <ImportButton {...props} />
    </TopToolbar>
  );
};
export const PostList = props => (
  <List {...props} filters={<PostFilter />} actions={<ListActions />}>
    <Datagrid>
      <TextField source="title" />
      <RichTextField source="body" />
      ...
    </Datagrid>
  </List>
);

Configuration Options

// All configuration options are optional
const config: ImportConfig = {
  // Enable logging
  logging?: boolean;
  // Disable "import new" button 
  disableImportNew?: boolean;
  // Disable "import overwrite" button 
  disableImportOverwrite?: boolean;
  // A function to translate the CSV rows on import 
  preCommitCallback?: (action: "create" | "overwrite", values: any[]) => Promise<any[]>;
  // A function to handle row errors after import
  postCommitCallback?: (error: any) => void;
  // Transform rows before anything is sent to dataprovider
  transformRows?: (csvRows: any[]) => Promise<any[]>;
  // Async function to Validate a row, reject the promise if it's not valid
  validateRow?: (csvRowItem: any) => Promise<void>;
  // Any option from the "papaparse" library 
  parseConfig?: {
    // For all options see: https://www.papaparse.com/docs#config
  }
}
<ImportButton {...props} {...config}/>

Handle id fields which might be numbers

Use the paparse configuration option dynamicTyping

const importOptions = {
  parseConfig?: {
    // For all options see: https://www.papaparse.com/docs#config
    dynamicTyping: true
  }
}

Reducing Requests

Your dataprovider will need to implement the .createMany() method in order to reduce requests to your backend. If it doesn't exist, it will fallback to calling .create() on all items, as shown below (same goes for .update()):

Name Special Method Fallback Method
Creating from CSV .createMany() .create()
Updating from CSV .updateManyArray() .update()

Interfaces

The dataprovider should accept these param interfaces for the bulk create/update methods.

export interface UpdateManyArrayParams {
  ids: Identifier[];
  data: any[];
}
export interface CreateManyParams {
  data: any[];
}

Translation i18n

This package uses react-admin's global i18n translation. Below is an example on how to set it up with this package.

Current supported languages (submit a PR if you'd like to add a language):

  • English (en)
  • Spanish (es)
  • Chinese (zh)
  • German (de)
  • French (fr)

Example (i18nProvider)

import { resolveBrowserLocale, useLocale } from "react-admin";
import polyglotI18nProvider from "ra-i18n-polyglot";
import englishMessages from "ra-language-english";
// This package's translations
import * as domainMessages from "react-admin-import-csv/lib/i18n";

// Select locale based on react-admin OR browser
const locale = useLocale() || resolveBrowserLocale();
// Create messages object
const messages = {
  // Delete languages you don't need
  en: { ...englishMessages, ...domainMessages.en },
  zh: { ...chineseMessages, ...domainMessages.zh },
  es: { ...spanishMessages, ...domainMessages.es },
};
// Create polyglot provider
const i18nProvider = polyglotI18nProvider(
  (locale) => (messages[locale] ? messages[locale] : messages.en),
  locale
);

// declare prop in Admin component
<Admin dataProvider={dataProvider} i18nProvider={i18nProvider}>

More information on this setup here

Development

If you'd like to develop on react-admin-import-csv do the following.

Local install

  • git clone https://github.com/benwinding/react-admin-import-csv/
  • cd react-admin-import-csv
  • yarn

Tests

  • yarn test # in root folder

Run demo

Open another terminal

  • yarn build-watch

Open another terminal and goto the demo folder

  • yarn start
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].