Skip to content

Commit

Permalink
feat: add ability to show/hide the header in a table (elastic#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasolson authored Jun 26, 2018
1 parent 9142458 commit d3c7526
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 15 deletions.
12 changes: 12 additions & 0 deletions common/functions/__tests__/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,17 @@ describe('table', () => {
expect(result).to.have.property('perPage', 10);
});
});

describe('showHeader', () => {
it('sets the showHeader property', () => {
const result = fn(testTable, { showHeader: false }).value;
expect(result).to.have.property('showHeader', false);
});

it('defaults to true', () => {
const result = fn(testTable).value;
expect(result).to.have.property('showHeader', true);
});
});
});
});
8 changes: 7 additions & 1 deletion common/functions/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ export const table = () => ({
default: 10,
help: 'Show this many rows per page. You probably want to raise this is disabling pagination',
},
showHeader: {
types: ['boolean'],
default: true,
help: 'Show or hide the header row with titles for each column.',
},
},
fn: (context, args) => {
const { font, paginate, perPage } = args;
const { font, paginate, perPage, showHeader } = args;

return {
type: 'render',
Expand All @@ -34,6 +39,7 @@ export const table = () => ({
font,
paginate,
perPage,
showHeader,
},
};
},
Expand Down
1 change: 1 addition & 0 deletions common/types/datatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const datatable = () => ({
datatable,
paginate: true,
perPage: 10,
showHeader: true,
},
};
},
Expand Down
5 changes: 4 additions & 1 deletion common/types/pointseries.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export const pointseries = () => ({
return {
type: 'render',
as: 'table',
value: { datatable },
value: {
datatable,
showHeader: true,
},
};
},
},
Expand Down
25 changes: 14 additions & 11 deletions public/components/datatable/datatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const getFormattedValue = (val, type) => {
return String(val);
};

export const Datatable = ({ datatable, perPage, paginate }) => (
export const Datatable = ({ datatable, perPage, paginate, showHeader }) => (
<Paginate rows={datatable.rows} perPage={perPage || 10}>
{({
rows,
Expand All @@ -46,16 +46,18 @@ export const Datatable = ({ datatable, perPage, paginate }) => (
<div className="canvas__datatable">
<div style={{ flexGrow: 1 }}>
<Table condensed>
<thead>
<tr>
{datatable.columns.map(col => (
<th key={`header-${getColumnName(col)}`}>
{getColumnName(col)}{' '}
<small className="muted">{getIcon(getColumnType(col))}</small>
</th>
))}
</tr>
</thead>
{!showHeader ? null : (
<thead>
<tr>
{datatable.columns.map(col => (
<th key={`header-${getColumnName(col)}`}>
{getColumnName(col)}{' '}
<small className="muted">{getIcon(getColumnType(col))}</small>
</th>
))}
</tr>
</thead>
)}
<tbody>
{rows.map((row, i) => (
<tr key={i}>
Expand Down Expand Up @@ -90,4 +92,5 @@ Datatable.propTypes = {
datatable: PropTypes.object.isRequired,
perPage: PropTypes.number,
paginate: PropTypes.bool,
showHeader: PropTypes.bool,
};
7 changes: 7 additions & 0 deletions public/expression_types/views/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,12 @@ export const table = () => ({
argType: 'toggle',
default: true,
},
{
name: 'showHeader',
displayName: 'Header',
help: 'Show or hide the header row with titles for each column.',
argType: 'toggle',
default: true,
},
],
});
9 changes: 7 additions & 2 deletions public/render_functions/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ export const table = () => ({
help: 'Render tabular data as HTML',
reuseDomNode: true,
render(domNode, config, handlers) {
const { datatable, paginate, perPage, font } = config;
const { datatable, paginate, perPage, font, showHeader } = config;
ReactDOM.render(
<div style={{ ...get(font, 'spec'), height: '100%' }}>
<Datatable datatable={datatable} perPage={perPage} paginate={paginate} />
<Datatable
datatable={datatable}
perPage={perPage}
paginate={paginate}
showHeader={showHeader}
/>
</div>,
domNode,
() => handlers.done()
Expand Down

0 comments on commit d3c7526

Please sign in to comment.