[Components][s]: Update views components to include validation
This commit is contained in:
8
src/components/views/Chart.js
vendored
8
src/components/views/Chart.js
vendored
@@ -1,8 +1,9 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
import createPlotlyComponent from "react-plotly.js/factory";
|
import createPlotlyComponent from "react-plotly.js/factory";
|
||||||
let Plot;
|
let Plot;
|
||||||
|
|
||||||
const PlotlyChart = (props) => {
|
const PlotlyChart = ({spec}) => {
|
||||||
const [plotCreated, setPlotCreated] = useState(0) //0: false, 1: true
|
const [plotCreated, setPlotCreated] = useState(0) //0: false, 1: true
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -18,7 +19,7 @@ const PlotlyChart = (props) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div data-testid="plotlyChart">
|
<div data-testid="plotlyChart">
|
||||||
<Plot {...props.spec}
|
<Plot {...spec}
|
||||||
layout={{ autosize: true }}
|
layout={{ autosize: true }}
|
||||||
style={{ width: "100%", height: "100%" }}
|
style={{ width: "100%", height: "100%" }}
|
||||||
useResizeHandler={true}
|
useResizeHandler={true}
|
||||||
@@ -27,4 +28,7 @@ const PlotlyChart = (props) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PlotlyChart.propTypes = {
|
||||||
|
spec: PropTypes.object.isRequired
|
||||||
|
}
|
||||||
export { PlotlyChart }
|
export { PlotlyChart }
|
||||||
@@ -1,24 +1,13 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { DataGrid } from '@material-ui/data-grid';
|
import { DataGrid } from '@material-ui/data-grid';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays a table from a Frictionless dataset
|
* Displays dataset in tabular form using data grid
|
||||||
* @param schema: Frictionless Table Schema
|
* @param columns: An array of column names with properties: e.g [{field: "col1", headerName: "col1"}, {field: "col2", headerName: "col2"}]
|
||||||
* @param data: an array of data objects e.g. [ {a: 1, b: 2}, {a: 5, b: 7} ]
|
* @param data: an array of data objects e.g. [ {col1: 1, col2: 2}, {col1: 5, col2: 7} ]
|
||||||
*/
|
*/
|
||||||
const Table = ({ schema, data }) => {
|
const Table = ({ columns, data }) => {
|
||||||
const columns = schema.fields.map((field) => (
|
|
||||||
{
|
|
||||||
field: field.title || field.name,
|
|
||||||
headerName: field.name,
|
|
||||||
width: 300
|
|
||||||
}
|
|
||||||
))
|
|
||||||
data = data.map((item, index)=>{
|
|
||||||
item.id = index //Datagrid requires every row to have an ID
|
|
||||||
return item
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div data-testid="tableGrid" style={{ height: 400, width: '100%' }}>
|
<div data-testid="tableGrid" style={{ height: 400, width: '100%' }}>
|
||||||
<DataGrid rows={data} columns={columns} pageSize={5} />
|
<DataGrid rows={data} columns={columns} pageSize={5} />
|
||||||
@@ -26,4 +15,9 @@ const Table = ({ schema, data }) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Table.propTypes = {
|
||||||
|
columns: PropTypes.array.isRequired,
|
||||||
|
data: PropTypes.array.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
export default Table
|
export default Table
|
||||||
|
|||||||
Reference in New Issue
Block a user