Skip to content

Commit

Permalink
[#3] Rename taggable -> filterable
Browse files Browse the repository at this point in the history
Also rename:
  values -> filterValues,
  getValueTitle -> getFilterTitle,
  getValueLabel -> getFilterLabel,
  getValueClassName -> getFilterClassName
  • Loading branch information
amir-hadzic committed Nov 2, 2016
1 parent 803ddd7 commit 86b5d0d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ export const createTextFilter = (text) => ({
export const createValueFilter = (column, value) => {
const {
key,
getValueTitle = () => undefined,
getValueClassName = () => undefined,
getValueLabel = () => {
getFilterTitle = () => undefined,
getFilterClassName = () => undefined,
getFilterLabel = () => {
let labelValue = value;
if (_.isBoolean(value)) {
labelValue = value ? 'Yes' : 'No';
}
return `${column.header}:${labelValue}`;
},
} = column;
const title = getValueTitle(value);
const label = getValueLabel(value);
const className = getValueClassName(value);
const title = getFilterTitle(value);
const label = getFilterLabel(value);
const className = getFilterClassName(value);
return {
key,
label,
Expand Down
10 changes: 5 additions & 5 deletions src/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ function filter(rows = [], filters = [], filterText, columns) {
}

if (valueFilters.length > 0) {
// apply value filters on taggable columns
// apply value filters on filterable columns
filteredRows = _.filter(filteredRows, row => _.every(columns, column => {
if (!column.taggable) {
if (!column.filterable) {
return true;
}
const value = _.get(row, column.key);
Expand Down Expand Up @@ -117,15 +117,15 @@ export default (tableName) => {

// set predefined values
columns.forEach(column => {
if (column.taggable && column.values) {
values[column.key] = column.values;
if (column.filterable && column.filterValues) {
values[column.key] = column.filterValues;
}
});

// collect values for columns that don't have predefined values
initialData.forEach(row => {
columns.forEach(column => {
if (!column.taggable || column.values) {
if (!column.filterable || column.filterValues) {
return;
}
if (!values[column.key]) {
Expand Down
12 changes: 6 additions & 6 deletions stories/UsersTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ const columns = [
{
key: 'status',
header: 'Status',
taggable: true,
values: [
filterable: true,
filterValues: [
'UNKNOWN',
'ACTIVE',
'DISABLED',
],
getValueTitle: (value) => ({
getFilterTitle: (value) => ({
UNKNOWN: 'Gone missing users',
ACTIVE: 'Active users',
}[value]),
getValueClassName: (value) => `col-${value.toLowerCase()}`,
getFilterClassName: (value) => `col-${value.toLowerCase()}`,
},
{
key: 'confirmed',
header: 'Confirmed',
Component: YesNo,
taggable: true,
getValueTitle: (value) => value ? 'Confirmed' : 'Not confirmed',
filterable: true,
getFilterTitle: (value) => value ? 'Confirmed' : 'Not confirmed',
},
];

Expand Down

0 comments on commit 86b5d0d

Please sign in to comment.