Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

799 admin campaign list loading #816

Merged
merged 11 commits into from
Sep 10, 2018
2 changes: 2 additions & 0 deletions src/api/campaign.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export const schema = `
input CampaignsFilter {
isArchived: Boolean
campaignId: Int
listSize: Int
pageSize: Int
}

type CampaignStats {
Expand Down
29 changes: 26 additions & 3 deletions src/containers/AdminCampaignList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import CampaignList from './CampaignList'
import FloatingActionButton from 'material-ui/FloatingActionButton'
import ContentAdd from 'material-ui/svg-icons/content/add'
import loadData from './hoc/load-data'
import { hasRole } from '../lib'
import { withRouter } from 'react-router'
import gql from 'graphql-tag'
import theme from '../styles/theme'
Expand All @@ -18,7 +17,8 @@ class AdminCampaignList extends React.Component {
state = {
isCreating: false,
campaignsFilter: {
isArchived: false
isArchived: false,
listSize: 25
}
}

Expand Down Expand Up @@ -48,11 +48,33 @@ class AdminCampaignList extends React.Component {
handleFilterChange = (event, index, value) => {
this.setState({
campaignsFilter: {
isArchived: value
isArchived: value,
listSize: this.state.campaignsFilter.listSize
}
})
}

handleListSizeChange = (event, index, value) => {
this.setState({
campaignsFilter: {
isArchived: this.state.campaignsFilter.isArchived,
listSize: value
}
})
}

renderListSizeOptions() {
return (
<DropDownMenu value={this.state.campaignsFilter.listSize} onChange={this.handleListSizeChange} >
<MenuItem value={10} primaryText='10' />
<MenuItem value={25} primaryText='25' />
<MenuItem value={50} primaryText='50' />
<MenuItem value={100} primaryText='100' />
<MenuItem value={0} primaryText='All' />
</DropDownMenu>
)
}

renderFilters() {
return (
<DropDownMenu value={this.state.campaignsFilter.isArchived} onChange={this.handleFilterChange}>
Expand All @@ -66,6 +88,7 @@ class AdminCampaignList extends React.Component {
return (
<div>
{this.renderFilters()}
{this.renderListSizeOptions()}
{this.state.isCreating ? <LoadingIndicator /> : (
<CampaignList
campaignsFilter={this.state.campaignsFilter}
Expand Down
8 changes: 8 additions & 0 deletions src/server/api/campaign.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Campaign, JobRequest, r } from '../models'

export function buildCampaignQuery(queryParam, organizationId, campaignsFilter, addFromClause = true) {
let query = queryParam
const resultSize = (campaignsFilter.listSize ? campaignsFilter.listSize : 0)
const pageSize = (campaignsFilter.pageSize ? campaignsFilter.pageSize : 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's default pagesize to something other than 0 -- maybe 10?
If pageSize is offset' -- then maybe rename to pageOffset` -- 'pagesize' sounds like it would mean the same thing as listsize/resultsize


if (addFromClause) {
query = query.from('campaign')
Expand All @@ -17,6 +19,12 @@ export function buildCampaignQuery(queryParam, organizationId, campaignsFilter,
if ('campaignId' in campaignsFilter) {
query = query.where('campaign.id', parseInt(campaignsFilter.campaignId, 10))
}
if (resultSize && !pageSize) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's have cleaner conditionals

if (resultSize) {
   query = query.limit(resultSize)
}
if (pageSize) {
   query = query.offset(pageSize)
}

query = query.limit(resultSize)
}
if (resultSize && pageSize) {
query = query.limit(resultSize).offSet(pageSize)
}
}

return query
Expand Down