fix(build): Fix lint issues and specs

This commit is contained in:
Juan Tejada 2016-05-11 15:33:52 -07:00
parent 72e86dde36
commit eacf54b4eb
8 changed files with 74 additions and 76 deletions

View file

@ -34,7 +34,7 @@
"quote-props": ["error", "consistent-as-needed", { "keywords": true }], "quote-props": ["error", "consistent-as-needed", { "keywords": true }],
"no-param-reassign": ["error", { "props": false }], "no-param-reassign": ["error", { "props": false }],
"semi": "off", "semi": "off",
"import/no-unresolved": ["error", {"ignore": ["nylas-exports", "nylas-component-kit", "electron", "nylas-store", "react-dom/server", "nylas-observables", "windows-shortcuts", "moment-round", "chrono-node", "event-kit"]}], "import/no-unresolved": ["error", {"ignore": ["nylas-exports", "nylas-component-kit", "electron", "nylas-store", "react-dom/server", "nylas-observables", "windows-shortcuts", "moment-round", "chrono-node", "event-kit", "enzyme"]}],
"react/no-multi-comp": "off", "react/no-multi-comp": "off",
"react/prop-types": ["error", {"ignore": ["children"]}], "react/prop-types": ["error", {"ignore": ["children"]}],
"react/sort-comp": "error" "react/sort-comp": "error"

View file

@ -94,7 +94,7 @@ function InflatesDraftClientId(ComposedComponent) {
render() { render() {
if (!this.state.draft) { if (!this.state.draft) {
return <span/>; return <span />;
} }
return <ComposedComponent ref="composed" {...this.props} {...this.state} />; return <ComposedComponent ref="composed" {...this.props} {...this.state} />;
} }

View file

@ -231,8 +231,8 @@ describe('SelectableTable Components', () => {
}); });
it('renders with the correct props', () => { it('renders with the correct props', () => {
const RowRenderer = () => <tr/> const RowRenderer = () => <tr />
const CellRenderer = () => <td/> const CellRenderer = () => <td />
const onSetSelection = () => {} const onSetSelection = () => {}
const onShiftSelection = () => {} const onShiftSelection = () => {}
const extraProps = {p1: 'p1'} const extraProps = {p1: 'p1'}

View file

@ -12,23 +12,23 @@ describe('Table Components', () => {
}); });
it('renders a th when is header', () => { it('renders a th when is header', () => {
const element = shallow(<TableCell isHeader/>) const element = shallow(<TableCell isHeader />)
expect(element.type()).toEqual('th') expect(element.type()).toEqual('th')
}); });
it('renders a td when is not header', () => { it('renders a td when is not header', () => {
const element = shallow(<TableCell isHeader={false}/>) const element = shallow(<TableCell isHeader={false} />)
expect(element.type()).toEqual('td') expect(element.type()).toEqual('td')
}); });
it('renders extra classNames', () => { it('renders extra classNames', () => {
const element = shallow(<TableCell className="my-cell"/>) const element = shallow(<TableCell className="my-cell" />)
expect(element.hasClass('my-cell')).toBe(true) expect(element.hasClass('my-cell')).toBe(true)
}); });
it('passes additional props to cell', () => { it('passes additional props to cell', () => {
const handler = () => {} const handler = () => {}
const element = shallow(<TableCell className="my-cell" onClick={handler}/>) const element = shallow(<TableCell className="my-cell" onClick={handler} />)
expect(element.prop('onClick')).toBe(handler) expect(element.prop('onClick')).toBe(handler)
}); });
}); });
@ -116,7 +116,7 @@ describe('Table Components', () => {
describe('Table', () => { describe('Table', () => {
function renderTable(props = {}) { function renderTable(props = {}) {
return shallow(<Table {...props} tableDataSource={testDataSource}/>) return shallow(<Table {...props} tableDataSource={testDataSource} />)
} }
it('renders extra classNames', () => { it('renders extra classNames', () => {
@ -163,7 +163,7 @@ describe('Table Components', () => {
describe('renderRow', () => { describe('renderRow', () => {
it('renders row with the given RowRenderer', () => { it('renders row with the given RowRenderer', () => {
const RowRenderer = (props) => <div {...props}/> const RowRenderer = (props) => <div {...props} />
const table = renderTable({RowRenderer}) const table = renderTable({RowRenderer})
const Renderer = table.instance().renderRow const Renderer = table.instance().renderRow
const row = shallow(<Renderer idx={5} />) const row = shallow(<Renderer idx={5} />)
@ -171,7 +171,7 @@ describe('Table Components', () => {
}); });
it('passes the correct props to the row when displayHeader is true', () => { it('passes the correct props to the row when displayHeader is true', () => {
const CellRenderer = (props) => <div {...props}/> const CellRenderer = (props) => <div {...props} />
const extraProps = {p1: 'p1'} const extraProps = {p1: 'p1'}
const table = renderTable({displayHeader: true, displayNumbers: true, extraProps, CellRenderer}) const table = renderTable({displayHeader: true, displayNumbers: true, extraProps, CellRenderer})
const Renderer = table.instance().renderRow const Renderer = table.instance().renderRow

View file

@ -148,66 +148,66 @@ export class EditableTableCell extends Component {
} }
} }
export default class EditableTable extends Component { function EditableTable(props) {
static displayName = 'EditableTable' const {
inputProps,
InputRenderer,
onCellEdited,
onAddRow,
onRemoveRow,
onAddColumn,
onRemoveColumn,
...otherProps,
} = props
static propTypes = { const tableProps = {
tableDataSource: SelectableTable.propTypes.tableDataSource, ...otherProps,
inputProps: PropTypes.object, className: "editable-table",
InputRenderer: PropTypes.any, extraProps: {
onCellEdited: PropTypes.func.isRequired,
onAddColumn: PropTypes.func,
onRemoveColumn: PropTypes.func,
onAddRow: PropTypes.func,
onRemoveRow: PropTypes.func,
}
render() {
const {
inputProps,
InputRenderer,
onCellEdited,
onAddRow, onAddRow,
onRemoveRow, onRemoveRow,
onAddColumn, onCellEdited,
onRemoveColumn, inputProps,
...otherProps, InputRenderer,
} = this.props },
CellRenderer: EditableTableCell,
}
const tableProps = { if (!onAddColumn || !onRemoveColumn) {
...otherProps, return <SelectableTable {...tableProps} />
className: "editable-table", }
extraProps: { return (
onAddRow, <div className="editable-table-container">
onRemoveRow, <SelectableTable {...tableProps} />
onCellEdited, <div className="column-actions">
inputProps, <div className="btn btn-small" onClick={onAddColumn}>
InputRenderer, <RetinaImg
}, name="icon-column-plus.png"
CellRenderer: EditableTableCell, mode={RetinaImg.Mode.ContentPreserve}
} />
</div>
if (!onAddColumn || !onRemoveColumn) { <div className="btn btn-small" onClick={onRemoveColumn}>
return <SelectableTable {...tableProps} /> <RetinaImg
} name="icon-column-minus.png"
return ( mode={RetinaImg.Mode.ContentPreserve}
<div className="editable-table-container"> />
<SelectableTable {...tableProps} />
<div className="column-actions">
<div className="btn btn-small" onClick={onAddColumn}>
<RetinaImg
name="icon-column-plus.png"
mode={RetinaImg.Mode.ContentPreserve}
/>
</div>
<div className="btn btn-small" onClick={onRemoveColumn}>
<RetinaImg
name="icon-column-minus.png"
mode={RetinaImg.Mode.ContentPreserve}
/>
</div>
</div> </div>
</div> </div>
) </div>
} )
} }
EditableTable.displayName = 'EditableTable'
EditableTable.propTypes = {
tableDataSource: SelectableTable.propTypes.tableDataSource,
inputProps: PropTypes.object,
InputRenderer: PropTypes.any,
onCellEdited: PropTypes.func.isRequired,
onAddColumn: PropTypes.func,
onRemoveColumn: PropTypes.func,
onAddRow: PropTypes.func,
onRemoveRow: PropTypes.func,
}
export default EditableTable

View file

@ -60,11 +60,10 @@ const TablePropTypes = {
} }
export function TableCell(props) { export function TableCell(props) {
const {className, isHeader, children} = props; const {className, isHeader, children, ...extraProps} = props;
const continuedProps = _.omit(props, "className", "isHeader", "children")
const CellTag = isHeader ? 'th' : 'td' const CellTag = isHeader ? 'th' : 'td'
return ( return (
<CellTag {...continuedProps} className={`table-cell ${className}`} > <CellTag {...extraProps} className={`table-cell ${className}`} >
{children} {children}
</CellTag> </CellTag>
) )
@ -73,7 +72,6 @@ export function TableCell(props) {
TableCell.propTypes = { TableCell.propTypes = {
isHeader: PropTypes.bool, isHeader: PropTypes.bool,
className: PropTypes.string, className: PropTypes.string,
children: PropTypes.children,
}; };
export class TableRow extends Component { export class TableRow extends Component {

View file

@ -11,7 +11,7 @@ class NylasComponentKit
@loadFrom = (prop, path) -> @loadFrom = (prop, path) ->
Object.defineProperty @prototype, prop, Object.defineProperty @prototype, prop,
get: -> get: ->
exported = NylasComponentKit.default(require "../components/#{path}") exported = require "../components/#{path}"
return exported[prop] return exported[prop]
@loadDeprecated = (prop, path, {instead} = {}) -> @loadDeprecated = (prop, path, {instead} = {}) ->
@ -60,13 +60,13 @@ class NylasComponentKit
@load "DateInput", "date-input" @load "DateInput", "date-input"
@load "DatePicker", "date-picker" @load "DatePicker", "date-picker"
@load "TimePicker", "time-picker" @load "TimePicker", "time-picker"
@loadFrom "Table", "table/table" @load "Table", "table/table"
@loadFrom "TableRow", "table/table" @loadFrom "TableRow", "table/table"
@loadFrom "TableCell", "table/table" @loadFrom "TableCell", "table/table"
@loadFrom "SelectableTable", "selectable-table" @load "SelectableTable", "selectable-table"
@loadFrom "SelectableTableRow", "selectable-table" @loadFrom "SelectableTableRow", "selectable-table"
@loadFrom "SelectableTableCell", "selectable-table" @loadFrom "SelectableTableCell", "selectable-table"
@loadFrom "EditableTable", "editable-table" @load "EditableTable", "editable-table"
@loadFrom "EditableTableCell", "editable-table" @loadFrom "EditableTableCell", "editable-table"
@load "LazyRenderedList", "lazy-rendered-list" @load "LazyRenderedList", "lazy-rendered-list"

@ -1 +1 @@
Subproject commit 5ea51b035478ea2912257f3a57d876d3e0c335b9 Subproject commit 6e7135d50ed005e4b0e9a5ac54b8323ef031e0bd