import React from 'react';
import {storiesOf} from '@storybook/react';
import {withInfo} from '@storybook/addon-info';
import styled from '@emotion/styled';
import Button from 'app/components/button';
import GlobalModal from 'app/components/globalModal';
import GridEditable from 'app/components/gridEditable';
const Section = styled('div')`
margin-bottom: 32px;
`;
const COLUMN_ORDER = [
{
key: 'farm',
name: 'farm',
},
{
key: 'count(apple)',
name: 'apples sold',
},
{
key: 'count(banana)',
name: 'banana sold',
},
];
const COLUMN_SORT_BY = [
{
key: 'count(apple)',
order: -1,
},
];
const DATA = [
{
farm: 'Old McDonalds',
'count(apple)': 100,
'count(banana)': 500,
'count(cherry)': 200,
'count(date)': 400,
'count(eggplant)': 600,
},
{
farm: 'Animal Farm',
'count(apple)': 900,
'count(banana)': 600,
'count(cherry)': 200,
'count(date)': 500,
'count(eggplant)': 700,
},
{
farm: 'Avocado Toast Farm',
'count(apple)': 700,
'count(banana)': 600,
'count(cherry)': 500,
'count(date)': 400,
'count(eggplant)': 500,
},
];
class GridParent extends React.Component {
state = {
columnOrder: [...COLUMN_ORDER],
columnSortBy: [...COLUMN_SORT_BY],
};
createColumn = () => {
const dataRow = DATA[0];
const keys = Object.keys(dataRow);
const randomKey = keys[Math.floor(Math.random() * keys.length)];
this.setState({
columnOrder: [
...this.state.columnOrder,
{
key: randomKey,
name: randomKey,
},
],
});
};
updateColumn = (i, nextColumn) => {
const {columnOrder} = this.state;
this.setState({
columnOrder: [...columnOrder.slice(0, i), nextColumn, ...columnOrder.slice(i + 1)],
});
};
deleteColumn = i => {
const {columnOrder} = this.state;
this.setState({
columnOrder: [...columnOrder.slice(0, i), ...columnOrder.slice(i + 1)],
});
};
renderModalBodyWithForm = (i, column) => {
return (