This repository has been archived by the owner on May 27, 2021. It is now read-only.
ability to sort and filter on actions #497
Merged
bors
merged 3 commits into
mozilla:master
from
peterbe:151-ability-to-sort-and-filter-on-actions
Oct 10, 2018
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import { Pagination, Table } from 'antd'; | |
import autobind from 'autobind-decorator'; | ||
import { push } from 'connected-react-router'; | ||
import dateFns from 'date-fns'; | ||
import { List } from 'immutable'; | ||
import { Map, List } from 'immutable'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
|
@@ -28,9 +28,11 @@ import { | |
getQueryParam, | ||
getQueryParamAsInt, | ||
} from 'console/state/router/selectors'; | ||
import { getAllActions } from 'console/state/actions/selectors'; | ||
|
||
@connect( | ||
(state, props) => ({ | ||
actions: getAllActions(state, new Map()), | ||
columns: getRecipeListingColumns(state), | ||
count: getRecipeListingCount(state), | ||
getCurrentUrlAsObject: queryParams => getCurrentUrlAsObjectSelector(state, queryParams), | ||
|
@@ -39,6 +41,7 @@ import { | |
recipes: getRecipeListingFlattenedAction(state), | ||
searchText: getQueryParam(state, 'searchText'), | ||
status: getQueryParam(state, 'status'), | ||
action: getQueryParam(state, 'action'), | ||
}), | ||
{ | ||
push, | ||
|
@@ -47,6 +50,7 @@ import { | |
@autobind | ||
class RecipeListingPage extends React.PureComponent { | ||
static propTypes = { | ||
actions: PropTypes.instanceOf(Map).isRequired, | ||
columns: PropTypes.instanceOf(List).isRequired, | ||
count: PropTypes.number, | ||
getCurrentUrlAsObject: PropTypes.func.isRequired, | ||
|
@@ -56,6 +60,7 @@ class RecipeListingPage extends React.PureComponent { | |
recipes: PropTypes.instanceOf(List).isRequired, | ||
searchText: PropTypes.string, | ||
status: PropTypes.string, | ||
action: PropTypes.string, | ||
}; | ||
|
||
static defaultProps = { | ||
|
@@ -64,99 +69,21 @@ class RecipeListingPage extends React.PureComponent { | |
pageNumber: null, | ||
searchText: null, | ||
status: null, | ||
}; | ||
|
||
static columnRenderers = { | ||
name({ ordering }) { | ||
return ( | ||
<Table.Column | ||
title="Name" | ||
dataIndex="name" | ||
key="name" | ||
render={(text, record) => ( | ||
<div className="recipe-listing-name"> | ||
<ShieldIdenticon className="shieldicon" seed={record.identicon_seed} size={24} /> | ||
{RecipeListingPage.renderLinkedText(text, record)} | ||
</div> | ||
)} | ||
sortOrder={DataList.getSortOrder('name', ordering)} | ||
sorter | ||
/> | ||
); | ||
}, | ||
|
||
action() { | ||
return ( | ||
<Table.Column | ||
title="Action" | ||
dataIndex="action" | ||
key="action" | ||
render={RecipeListingPage.renderLinkedText} | ||
/> | ||
); | ||
}, | ||
|
||
enabled({ status }) { | ||
return ( | ||
<Table.Column | ||
title="Enabled" | ||
key="status" | ||
render={(text, record) => <BooleanIcon value={record.enabled} />} | ||
filters={[ | ||
{ text: 'Enabled', value: 'enabled' }, | ||
{ text: 'Disabled', value: 'disabled' }, | ||
]} | ||
filteredValue={status} | ||
filterMultiple={false} | ||
/> | ||
); | ||
}, | ||
|
||
paused() { | ||
return ( | ||
<Table.Column | ||
title="Enrollment Active" | ||
key="paused" | ||
render={(text, record) => <EnrollmentStatus recipe={record} />} | ||
/> | ||
); | ||
}, | ||
|
||
lastUpdated({ ordering }) { | ||
return ( | ||
<Table.Column | ||
title="Last Updated" | ||
key="last_updated" | ||
dataIndex="last_updated" | ||
render={(text, record) => { | ||
const lastUpdated = dateFns.parse(record.last_updated); | ||
return ( | ||
<Link | ||
to={reverse('recipes.details', { recipeId: record.id })} | ||
title={dateFns.format(lastUpdated, 'dddd, MMMM M, YYYY h:mm A')} | ||
> | ||
{dateFns.distanceInWordsToNow(lastUpdated)} | ||
</Link> | ||
); | ||
}} | ||
sortOrder={DataList.getSortOrder('last_updated', ordering)} | ||
sorter | ||
/> | ||
); | ||
}, | ||
action: null, | ||
}; | ||
|
||
static renderLinkedText(text, { id: recipeId }) { | ||
return <Link to={reverse('recipes.details', { recipeId })}>{text}</Link>; | ||
} | ||
|
||
getFilters() { | ||
const { ordering, searchText, status } = this.props; | ||
const { ordering, searchText, status, action } = this.props; | ||
|
||
const filters = { | ||
text: searchText, | ||
ordering, | ||
status, | ||
action, | ||
}; | ||
|
||
Object.keys(filters).forEach(key => { | ||
|
@@ -178,12 +105,100 @@ class RecipeListingPage extends React.PureComponent { | |
} | ||
|
||
render() { | ||
const { columns, count, ordering, pageNumber, recipes, status } = this.props; | ||
const { columns, count, ordering, pageNumber, recipes, status, action, actions } = this.props; | ||
const actionNames = Object.values(actions.toJS()).map(action => action.name); | ||
actionNames.sort(); | ||
|
||
const filters = this.getFilters(); | ||
|
||
const filterIds = Object.keys(filters).map(key => `${key}-${filters[key]}`); | ||
const requestId = `fetch-filtered-recipes-page-${pageNumber}-${filterIds.join('-')}`; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change here is that I moved it from being a static object of functions to instead being defined inside the |
||
const columnRenderers = { | ||
name: ({ ordering }) => { | ||
return ( | ||
<Table.Column | ||
title="Name" | ||
dataIndex="name" | ||
key="name" | ||
render={(text, record) => ( | ||
<div className="recipe-listing-name"> | ||
<ShieldIdenticon className="shieldicon" seed={record.identicon_seed} size={24} /> | ||
{RecipeListingPage.renderLinkedText(text, record)} | ||
</div> | ||
)} | ||
sortOrder={DataList.getSortOrder('name', ordering)} | ||
sorter | ||
/> | ||
); | ||
}, | ||
|
||
action: ({ action, ordering }) => { | ||
return ( | ||
<Table.Column | ||
title="Action" | ||
dataIndex="action" | ||
key="action" | ||
render={RecipeListingPage.renderLinkedText} | ||
filters={actionNames.map(name => ({ text: name, value: name }))} | ||
filteredValue={[action]} | ||
filterMultiple={false} | ||
sortOrder={DataList.getSortOrder('action', ordering)} | ||
sorter | ||
/> | ||
); | ||
}, | ||
|
||
enabled: ({ status }) => { | ||
return ( | ||
<Table.Column | ||
title="Enabled" | ||
key="status" | ||
render={(text, record) => <BooleanIcon value={record.enabled} />} | ||
filters={[ | ||
{ text: 'Enabled', value: 'enabled' }, | ||
{ text: 'Disabled', value: 'disabled' }, | ||
]} | ||
filteredValue={status} | ||
filterMultiple={false} | ||
/> | ||
); | ||
}, | ||
|
||
paused: () => { | ||
return ( | ||
<Table.Column | ||
title="Enrollment Active" | ||
key="paused" | ||
render={(text, record) => <EnrollmentStatus recipe={record} />} | ||
/> | ||
); | ||
}, | ||
|
||
lastUpdated: ({ ordering }) => { | ||
return ( | ||
<Table.Column | ||
title="Last Updated" | ||
key="last_updated" | ||
dataIndex="last_updated" | ||
render={(text, record) => { | ||
const lastUpdated = dateFns.parse(record.last_updated); | ||
return ( | ||
<Link | ||
to={reverse('recipes.details', { recipeId: record.id })} | ||
title={dateFns.format(lastUpdated, 'dddd, MMMM M, YYYY h:mm A')} | ||
> | ||
{dateFns.distanceInWordsToNow(lastUpdated)} | ||
</Link> | ||
); | ||
}} | ||
sortOrder={DataList.getSortOrder('last_updated', ordering)} | ||
sorter | ||
/> | ||
); | ||
}, | ||
}; | ||
|
||
return ( | ||
<div className="content-wrapper"> | ||
<QueryRecipeListingColumns /> | ||
|
@@ -194,11 +209,12 @@ class RecipeListingPage extends React.PureComponent { | |
<LoadingOverlay requestIds={requestId}> | ||
<DataList | ||
columns={columns} | ||
columnRenderers={RecipeListingPage.columnRenderers} | ||
columnRenderers={columnRenderers} | ||
dataSource={recipes.toJS()} | ||
ordering={ordering} | ||
getUrlFromRecord={this.getUrlFromRecord} | ||
status={status} | ||
action={action} | ||
/> | ||
</LoadingOverlay> | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can/should this be
actions: getAllActions(state) || new Map()
instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it could be that too.