-
Notifications
You must be signed in to change notification settings - Fork 16
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
[WIP] Add filters to course search #2378
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
9256814
preliminary work on filter view
hannesmcman d2fdcdb
filtering working for gereqs
hannesmcman c22190f
Merge branch 'add-course-search' into add-filters
hannesmcman 7cede82
add menu icon
hannesmcman ba48a7f
Merge branch 'add-course-search' into add-filters
hannesmcman 4a44d45
Updated filter toolbar to match menu filters style
hannesmcman a103012
got rid of menu icon
hannesmcman da79336
Merge branch 'master' into add-filters
hannesmcman 8b3dc76
put header component in
hannesmcman 562281b
Merge branch 'master' into add-filters
hannesmcman b6e8ad4
added courseSearch to flux, ability to store term filters in redux
hannesmcman b361977
term filters working
hannesmcman 70881bc
removed unused files and dependency
hannesmcman 621d6e5
terms filter functional
hannesmcman 3eded99
prettier
hannesmcman 02850ac
added status and lab only filters
hannesmcman 9c16fd0
prettier
hannesmcman 135a015
add ge filter
hannesmcman 233825a
generalize data loading for filters
hannesmcman 377c22e
add department filter
hannesmcman 4dc9f04
switch from bluebird to pProps dependency
hannesmcman 2fdeac6
prettier
hannesmcman 57020a9
formatted terms for toolbar..pissed off flow
hannesmcman f00bb60
Merge branch 'master' into add-filters
hawkrives 38ded64
add functions to filter lists of specs
hawkrives e165bba
fix up flow types in SIS/filter-toolbar
hawkrives File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// @flow | ||
|
||
import {type FilterType} from '../../views/components/filter/types' | ||
|
||
const UPDATE_COURSE_FILTERS = 'courseSearch/UPDATE_COURSE_FILTERS' | ||
|
||
type UpdateCourseFiltersAction = {| | ||
type: 'courseSearch/UPDATE_COURSE_FILTERS', | ||
payload: Array<FilterType>, | ||
|} | ||
export function updateCourseFilters( | ||
filters: FilterType[], | ||
): UpdateCourseFiltersAction { | ||
return {type: UPDATE_COURSE_FILTERS, payload: filters} | ||
} | ||
|
||
type Action = UpdateCourseFiltersAction | ||
|
||
export type State = {| | ||
filters: Array<FilterType>, | ||
|} | ||
|
||
const initialState = { | ||
filters: [], | ||
} | ||
|
||
export function courseSearch(state: State = initialState, action: Action) { | ||
switch (action.type) { | ||
case UPDATE_COURSE_FILTERS: | ||
return {...state, filters: action.payload} | ||
|
||
default: | ||
return state | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// @flow | ||
|
||
import {GE_DATA, DEPT_DATA} from './urls' | ||
import * as storage from '../storage' | ||
import mapValues from 'lodash/mapValues' | ||
import isEqual from 'lodash/isEqual' | ||
import pProps from 'p-props' | ||
|
||
const filterCategories = { | ||
ges: {name: 'ges', url: GE_DATA}, | ||
departments: {name: 'departments', url: DEPT_DATA}, | ||
} | ||
|
||
type FilterCategory = {name: string, url: string} | ||
|
||
type AllFilterCategories = { | ||
ges: string[], | ||
departments: string[], | ||
} | ||
|
||
export async function loadCourseFilterOption( | ||
category: FilterCategory, | ||
): Promise<Array<string>> { | ||
const remoteData = await fetchJson(category.url).catch(() => []) | ||
const storedData = await storage.getCourseFilterOption(category.name) | ||
if (!isEqual(remoteData, storedData) || storedData.length === 0) { | ||
storage.setCourseFilterOption(category.name, remoteData) | ||
return remoteData | ||
} else { | ||
return storedData | ||
} | ||
} | ||
|
||
export function loadAllCourseFilterOptions(): Promise<AllFilterCategories> { | ||
return pProps( | ||
mapValues(filterCategories, category => loadCourseFilterOption(category)), | ||
).then(result => result) | ||
} |
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
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
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
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// @flow | ||
|
||
import type {FilterType, ListType, PickerType, ToggleType} from './types' | ||
|
||
export function filterListSpecs(specs: Array<FilterType>): Array<ListType> { | ||
const retval = specs.filter(f => f.type === 'list') | ||
return ((retval: any): Array<ListType>) | ||
} | ||
|
||
export function filterPickerSpecs(specs: Array<FilterType>): Array<PickerType> { | ||
const retval = specs.filter(f => f.type === 'picker') | ||
return ((retval: any): Array<PickerType>) | ||
} | ||
|
||
export function filterToggleSpecs(specs: Array<FilterType>): Array<ToggleType> { | ||
const retval = specs.filter(f => f.type === 'toggle') | ||
return ((retval: any): Array<ToggleType>) | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// @flow | ||
import * as React from 'react' | ||
import {type FilterType, filterListSpecs} from '../../components/filter' | ||
import {StyleSheet, Text, View, Platform} from 'react-native' | ||
import {Toolbar, ToolbarButton} from '../../components/toolbar' | ||
import {formatTerms} from '../course-search/lib/format-terms' | ||
|
||
const styles = StyleSheet.create({ | ||
today: { | ||
flex: 1, | ||
paddingLeft: 12, | ||
paddingVertical: 14, | ||
}, | ||
toolbarSection: { | ||
flexDirection: 'row', | ||
}, | ||
}) | ||
|
||
type Props = { | ||
filters: Array<FilterType>, | ||
onPress: () => any, | ||
} | ||
|
||
export function FilterToolbar({filters, onPress}: Props) { | ||
const appliedFilterCount = filters.filter(f => f.enabled).length | ||
const isFiltered = appliedFilterCount > 0 | ||
const filterWord = appliedFilterCount === 1 ? 'Filter' : 'Filters' | ||
|
||
const termFilter = filterListSpecs(filters).find(f => f.key === 'term') | ||
|
||
let toolbarTitle = 'All Terms' | ||
if (termFilter) { | ||
const selectedTerms = termFilter ? termFilter.spec.selected : [] | ||
const terms = selectedTerms.map(t => parseInt(t.title)) | ||
toolbarTitle = terms.length ? formatTerms(terms) : 'No Terms' | ||
} | ||
|
||
const buttonTitle = isFiltered | ||
? `${appliedFilterCount} ${filterWord}` | ||
: 'No Filters' | ||
|
||
return ( | ||
<Toolbar onPress={onPress}> | ||
<View style={[styles.toolbarSection, styles.today]}> | ||
<Text ellipsizeMode="tail" numberOfLines={1}> | ||
{toolbarTitle} | ||
</Text> | ||
</View> | ||
|
||
<ToolbarButton | ||
iconName={Platform.OS === 'ios' ? 'ios-funnel' : 'md-funnel'} | ||
isActive={isFiltered} | ||
title={buttonTitle} | ||
/> | ||
</Toolbar> | ||
) | ||
} |
Oops, something went wrong.
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.
I'm not entirely clear on the difference between these two – can you summarize for me, please?
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.
Looks like it comes down to:
term
would be a string or a numberlabel
is data massaged out ofparseTerm
which lives in lib/course-search/parse-term.js where it returns the human readable term name (Abroad current / next year, Fall current / next year, etc)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.
Yep! I changed the spec type so that the applyFilters() function would work when the value of the key item specified isn't a string. The label allows the filter options to be displayed as "Fall 2016/17" instead of 20171, for example.