Codebase Overview
Project structure
The repository is designed in a way to easily add extra features without adding bloat to the main react-data-grid package. As such, we have decided to adopt a monorepository structure, allowing us to publish individual npm packages within the same repository. Each publishable package lives as a separate folder in the packages
folder.
Currently there are three packages:
- react-data-grid the core package of the grid, contains all the core functionality of the project
- react-data-grid-addons a set of addons for the base grid, containing things like toolbars, custom editors...
- react-data-grid-examples a playground for the project, this is where you can check your changes for real.
There is also a common folder which contains common code between all packages.
To manage the multiple packages in the project we use lerna, It allows us to have an independent release process for each package,
individual and shared dependencies between packages and an automated bootstrap system to link packages together during development time.
This also means that you must not add any path reference between packages, when you need to use something in a different package you just need to import it as if
it was a standard npm package. (for example you if need something from react-data-grid package when developing in react-data-grid-addons you need to import { something } from 'react-data-grid';
).
Top-Level Folders
After cloning the ReactDataGrid repository, you will see a few top-level folders in it:
- ci - Contains scripts for continuous integration processes like building and publishing
- config - Contains Webpack config files for building the project, and Karma config files for configuring testing.
- gulp - There are some legacy build processes using Gulp that are still in use such as a gulp task to autogenerate documentation.
- packages - Contains metadata (such as package.json) and the source code (src subdirectory) for all packages in the ReactDataGrid repository. If your change is related to the code, the src subdirectory of each package is where you’ll spend most of your time.
- themes - Contains styles that are imported to the various component using CSS loader.
- website - Our public documentation site built with Docusaurus
Colocated Tests
We don’t have a top-level directory for unit tests. Instead, we put them into a directory called tests relative to the files that they test.
For example, a test for Cell.js is located in __tests__/Cell.spec.js right next to it.
This is just a convention however and is not necessary to automatically detect a test. Test running is implemented using Karma Any files with an extension of .spec.js
will be picked up by Karma when the test command npm run test
is run.
Packages
react-data-grid
This is main npm package that contains the ReactDataGrid component. Here is the basic top down component heirarchy of the grid
ReactDataGrid 'Root API Component to render a data grid'
└─┬ BaseGrid 'Renders the Header and Viewport'
├─┬ Header 'Renders HeaderRow and Cells based on a list of columns'
│ └─┬ HeaderRow
│ └── HeaderCell
└─┬ Viewport 'Calculates the visible rows and columns to show as well as a buffer of overflow rows and columns'
└─┬ Canvas 'Renders the visible rows and columns'
└── InteractionMasks 'A layer that sits above the grid which is used for interaction such as keyboard navigation'
│ └── SelectionMask 'A component used to track the selected cell. It can be moved by using the keyboard or the mouse'
│ └── EditorContainer 'When a cell is being edited, this component renders the editor specified in column.editor'
│ └── Editor 'Component used to update the data of a cell'
└── Row 'Component that renders a list of Cell components for each column'
└── Cell 'Renders the cell content'
└── Formatter 'The component to display the cell content as specified by column.formatter'
react-data-grid-addons
Below are the current addons available in the addons package. It is a future goal of the project to deprecate this package and move each folder to its own separate package
- Editors - Contains a range of cell editors for the grid
- Formatters - Contains a selection of formatters for the grid
- Toolbar
- Menu - A context menu that can be used on the grid
- Data - Functional utilities for row filtering, grouping, sorting, expanding etc that can be used to modify grid rows based on certain input paramaters
- ToolsPanel - UI components used for a tool panel above the grid.
- Draggable - Utilities to add drag and drop capability to the grid
- Filters - Custom Filters that can be added to the header of the grid