Skip to content

Commit

Permalink
#1 add a limit to rows number in static mode
Browse files Browse the repository at this point in the history
  • Loading branch information
robindemourat committed Oct 31, 2017
1 parent ba5ac16 commit fc592fa
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
36 changes: 23 additions & 13 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,17 @@ exports.default = {
acceptedResourceTypes: [{ type: 'table' }],
block: {
expandable: false,
options: []
options: [{
id: 'pageRowsLimit',
title: {
fr: 'Nombre de lignes à afficher dans les rendus "page"',
en: 'Number of rows to display in "page" outputs'
},
type: 'number',
default: 50,
minimum: 1,
maximum: 100000
}]
}
}
};
Expand Down Expand Up @@ -218,50 +228,50 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de

exports.default = function (_ref) {
var resource = _ref.resource,
contextualizer = _ref.contextualizer,
pageRowsLimit = _ref.contextualizer.pageRowsLimit,
contextualization = _ref.contextualization;

var data = resource.data;
// this is weak
var data = pageRowsLimit && typeof pageRowsLimit === 'number' ? resource.data.slice(0, pageRowsLimit) : resource.data;
// @todo: handle columns definition in a better way than inspecting the keys of the first object
var columns = (0, _keys2.default)(data[0]).map(function (key) {
return {
Header: key,
accessor: key
};
});
return _react2.default.createElement(
"figure",
'figure',
{
className: "peritext-contextualization peritext-contextualization-block peritext-contextualization-codex peritext-contextualizer-table"
className: 'peritext-contextualization peritext-contextualization-block peritext-contextualization-codex peritext-contextualizer-table'
},
_react2.default.createElement(
"table",
'table',
null,
_react2.default.createElement(
"thead",
'thead',
null,
_react2.default.createElement(
"tr",
'tr',
null,
columns.map(function (column, index) {
return _react2.default.createElement(
"th",
'th',
{ key: index },
column.Header
);
})
)
),
_react2.default.createElement(
"tbody",
'tbody',
null,
data.map(function (row, rowIndex) {
return _react2.default.createElement(
"tr",
'tr',
{ key: rowIndex },
columns.map(function (column, index) {
return _react2.default.createElement(
"th",
'th',
{ key: index },
row[column.accessor]
);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "peritext-contextualizer-table",
"version": "0.0.4",
"version": "0.0.5",
"description": "Peritext default table contextualizer",
"main": "dist/index.js",
"scripts": {
Expand Down
8 changes: 5 additions & 3 deletions src/BlockStatic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import React from 'react';

export default ({
resource,
contextualizer,
contextualizer: {
pageRowsLimit
},
contextualization
}) => {
const data = resource.data;
// this is weak
const data = pageRowsLimit && typeof pageRowsLimit === 'number' ? resource.data.slice(0, pageRowsLimit) : resource.data;
// @todo: handle columns definition in a better way than inspecting the keys of the first object
const columns = Object.keys(data[0]).map(key => ({
Header: key,
accessor: key
Expand Down
14 changes: 13 additions & 1 deletion src/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,19 @@ export default {
acceptedResourceTypes: [{type: 'table'}],
block: {
expandable: false,
options: []
options: [
{
id: 'pageRowsLimit',
title: {
fr: 'Nombre de lignes à afficher dans les rendus "page"',
en: 'Number of rows to display in "page" outputs',
},
type: 'number',
default: 50,
minimum: 1,
maximum: 100000
},
]
}
}
}

0 comments on commit fc592fa

Please sign in to comment.