Example #1
0
`;

type Props = {
  sandbox: Sandbox,
  sandboxActions: typeof sandboxActionCreators,
  preventTransition: boolean,
  user: User,
  isPatron: boolean,
};

const mapStateToProps = createSelector(
  modulesFromSandboxNotSavedSelector,
  usersSelector,
  (_, props) => props.sandbox && props.sandbox.author,
  isPatronSelector,
  (preventTransition, users, author, isPatron) => ({
    preventTransition,
    user: users[author],
    isPatron,
  }),
);

const mapDispatchToProps = dispatch => ({
  sandboxActions: bindActionCreators(sandboxActionCreators, dispatch),
});

const Workspace = ({
  sandbox,
  user,
  preventTransition,
  sandboxActions,
Example #2
0
const usersOfGroup = (type, groupId) =>
  createSelector(
    groupSelectorCreator(groupId),
    group => (group && isReady(group) ? group.getIn(['data', 'privateData', type], EMPTY_LIST) : EMPTY_LIST)
  );
Example #3
0
export const groupOrganizationalPendingChange = id =>
  createSelector(
    groupsSelector,
    groups => groups && groups.getIn([id, 'pending-organizational'], false)
  );
Example #4
0
function computeTotalPlaceFrequency(places) {
  return places.reduce(function(frequency, place) {
    if (!place.visible)
      return frequency;

    return frequency + place.frequency;
  }, 0);
}

export const placeLimitSelector = function() {
  return ENV.place_limit;
};

export const totalConnectionsSelector = createSelector(
  [
    filteredConnectionsSelector
  ],
  connections => connections.filter(connection => connection.visible).size
);

export const totalPlacesSelector = createSelector(
  [
    filteredPlacesSelector
  ],
  places => places.filter(place => place.visible).size
);

export const totalConnectionDistanceSelector = createSelector(
  [
    filteredConnectionsSelector
  ],
  computeTotalConnectionDistance
Example #5
0
        return p;
    }, playList);
}

const includedMoviesSelector = createSelector(
    (state) => state.common.movies,
    filtersSelector,
    (movies, filters) => {
        const filteredTags = filters.reduce((playList, tag) => {
            reduceTagMovieTimes(tag, playList);

            return playList;
        }, {});

        if (_.isEmpty(filteredTags)) {
            return movies.reduce((playList, movie) => {
                playList[movie.movieNumber] = [0, movie.length];

                return playList;
            }, {});
        }

        return filteredTags;
    }
);

export const playListSelector = createSelector(
    includedMoviesSelector,
    moviesByNumberSelector,
    (includedMovies, moviesByNumber) => (
export const createTorchIdSelector = (state: State): string => state.create.config.torchId;
export const createConfigSelector = (state: State): Config => state.create.config;

export const createIsOrgSelector = (state: State): boolean => (
  state.create.parent.indexOf('chat') === -1
);

export const createMembersSelector = (state: State): Array<Member> => (
  state.create.groups[state.create.activeGroup] || []
);
export const createGroupChatMembersSelector = (state: State): Array<Member> => (
  state.create.groups.chat || []
);

export const createBreadcrumbSelector = createSelector(
  [createParentSelector, createSportSelector, createCardActionSelector],
  (parent, sportId, cardAction) => ({ parent, sportId, cardAction }),
);

export const createSagasSelector = createSelector(
  [createParentSelector, createMembersSelector],
  (parent, members) => ({ parent, members }),
);

export const createDeckIdSelector = createSelector(
  createSportSelector,
  (sport): number => (sport ? sport.deck_id || 0 : 0),
);

export const createRandomCardSelector = (state: State): number => (
  stockCardsRandomFromDeckSelector(state, createDeckIdSelector(state))
);
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { createOrder } from '../actions';
import OrderCreatePanel from '../components/OrderCreatePanel';

const actionStateSelector = state => state.appState.running;

const mapStateToProps = createSelector(
	actionStateSelector,
	(running) => ({
		running,
		steps: ['Add Items', 'Add Address', 'Delivery Fee']
	})
);

const mapActionToProps = (dispatch) => ({
	makeOrder: ({items, address, fees}) => {
		dispatch(createOrder(items, address, fees));
	}
});

export default connect(mapStateToProps, mapActionToProps)(OrderCreatePanel);
Example #8
0
export const createDiscoveriesSelector = pageSelector =>
  createSelector(
    [createPageContentSelector(DISCOVERIES_PAGINATOR, selector, pageSelector)],
    discoveries => discoveries.filter(discovery => discovery != null) // skip deleted
  );
Example #9
0
    }
}

export const getDashboardId       = state => state.dashboard.dashboardId;
export const getIsEditing         = state => state.dashboard.isEditing;
export const getCards             = state => state.dashboard.cards;
export const getDashboards        = state => state.dashboard.dashboards;
export const getDashcards         = state => state.dashboard.dashcards;
export const getCardData          = state => state.dashboard.dashcardData;
export const getSlowCards         = state => state.dashboard.slowCards;
export const getCardIdList        = state => state.dashboard.cardList;
export const getRevisions         = state => state.dashboard.revisions;
export const getParameterValues   = state => state.dashboard.parameterValues;

export const getDashboard = createSelector(
    [getDashboardId, getDashboards],
    (dashboardId, dashboards) => dashboards[dashboardId]
);

export const getDashboardComplete = createSelector(
    [getDashboard, getDashcards],
    (dashboard, dashcards) => (dashboard && {
        ...dashboard,
        ordered_cards: dashboard.ordered_cards.map(id => dashcards[id]).filter(dc => !dc.isRemoved)
    })
);

export const getIsDirty = createSelector(
    [getDashboard, getDashcards],
    (dashboard, dashcards) => !!(
        dashboard && (
            dashboard.isDirty ||
import { createSelector }  from 'reselect';

const userProfileTabSelector = createSelector(
  state => state.userProfileTabs,
  userProfileTabs => ({ userProfileTabs })
);

export { userProfileTabSelector };
Example #11
0
    case GET_DISCOVERY_SUCCESS:
      return state.set(action.payload.id, new Discovery(action.payload));

    case GET_DISCOVERIES_RESET:
      return initialState;
  }

  return state;
}

export default createPaginatedReducer(
  DISCOVERIES_PAGINATOR,
  GET_DISCOVERIES_SUCCESS,
  discoveriesReducer);

// Selectors

const selector = createSelector([moduleSelector], state => state.discoveries);

export const createDiscoveriesSelector = pageSelector =>
  createSelector(
    [createPageContentSelector(DISCOVERIES_PAGINATOR, selector, pageSelector)],
    discoveries => discoveries.filter(discovery => discovery != null) // skip deleted
  );

export const createDiscoveriesStatusSelector = pageSelector =>
  createPagePromiseStatusSelector(GET_DISCOVERIES, DISCOVERIES_PAGINATOR, pageSelector);

export const createDeleteDiscoveryStatusSelector = idSelector =>
  createPromiseStatusSelector(DELETE_DISCOVERY, idSelector);
import { createSelector } from 'reselect';

const userSelector = state => state.user;
const taskSelector = state => state.tasks;

export const selector = createSelector(
	userSelector,
	taskSelector,
	(user, tasks)=>{
		return {
			user, 
			tasks
		}
	}
)
    if (TAG_TYPES.includes(key)) {
      return dereferenceList(value, tags);
    }
    if (THING_TYPES.includes(key)) {
      return dereferenceList(value, things);
    }
    return value;
  });
};

// getEvents (state: Map) => List
export const getEvents = (state) => state.get('events') || initialState;

// getLatestEvent (state: Map) => Map
export const getLatestEvent = createSelector(
  getEvents,
  (events) => events.last()
);

// getOldestEvent (state: Map) => Map
export const getOldestEvent = createSelector(
  getEvents,
  (events) => events.first()
);

// getDereferencedEvents (state: Map) => Map
export const getDereferencedEvents = createSelector(
  [getEvents, getTags, getThings],
  (events, tags, things) => events.map(
    (event) => dereferenceEvent(event, tags, things)
  )
);
Example #14
0
import { createSelector } from 'reselect';
import { REDUCER_KEY } from '../reducers';
import transformPlayerHeroes from './transformPlayerHeroes';

const getSortState = (state) => state[REDUCER_KEY].gotPlayer.heroes.sortState;
const getSortField = (state) => state[REDUCER_KEY].gotPlayer.heroes.sortField;
const getSortFn = (state) => state[REDUCER_KEY].gotPlayer.heroes.sortFn;

const sortPlayerHeroes = createSelector(
  [transformPlayerHeroes, getSortState, getSortField, getSortFn],
  (heroes, sortState, sortField, sortFn) =>
    (sortState === 'desc' ? sortFn(heroes, sortField).reverse() : sortFn(heroes, sortField))
);

export default sortPlayerHeroes;
// Currently Unused
import { createSelector } from 'reselect';

export const nameSelector = state => state.get('name');
export const slugSelector = state => state.get('slug');
export const fundsSelector = state => state.get('funds');
export const itemsSelector = state => state.get('items');

export const spentSelector = createSelector(
  itemsSelector,
  items => items.reduce((memo, item => memo + item.value), 0)
);

export const availableSelector = createSelector(
  spentSelector,
  fundsSelector,
  (spent, funds) => funds - spent
);

export const categoriesListSelector = createSelector(
  nameSelector,
  fundsSelector,
  spentSelector,
  availableSelector,
  (name, funds, spent, available) => ({
    name, funds, spent, available
  })
)
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE
 *
 * @flow
 */
"use strict";

import allNotifications from "./allNotifications";
import { createSelector } from "reselect";

import type {
  Notification,
  SeenNotifications
} from "../../reducers/notifications";

function unseenNotificationsCount(
  notifications: Array<Notification>,
  seen: SeenNotifications
): number {
  return notifications.filter(notification => !seen[notification.id]).length;
}

module.exports = createSelector(
  allNotifications,
  store => store.notifications.seen,
  unseenNotificationsCount
);
Example #17
0
    React.PropTypes.object,
    React.PropTypes.bool,
  ]),
  products: React.PropTypes.oneOfType([
    React.PropTypes.array,
    React.PropTypes.bool,
  ]),
  onComponentWillMount: React.PropTypes.func,
  keyword: React.PropTypes.string,
  onChangeKeyword: React.PropTypes.func,
};

function mapDispatchToProps(dispatch) {
  return {
    onChangeKeyword: (evt) => dispatch(changeKeyword(evt.target.value)),
    changeRoute: (url) => dispatch(push(url)),
    onComponentWillMount: () => dispatch(loadProducts()),

    dispatch,
  };
}

// Wrap the component to inject dispatch and state into it
export default connect(createSelector(
  selectProducts(),
  selectKeyword(),
  selectLoading(),
  selectError(),
  (products, keyword, loading, error) => ({ products, keyword, loading, error })
), mapDispatchToProps)(HomePage);
Example #18
0
import { createSelector } from 'reselect'

export const articlesMapSelector = (state) => state.articles.entities
export const articleListSelector = createSelector(
  articlesMapSelector,
  (articlesMap) => articlesMap.valueSeq().toArray()
)

export const articlesLoadingSelector = (state) => state.articles.loading
export const articlesLoadedSelector = (state) => state.articles.loaded

export const commentsMapSelector = (state) => state.comments.entities

export const selectedArticlesSelector = (state) => state.filters.selected
export const dateRangeSelector = (state) => state.filters.dateRange

export const idSelector = (_, props) => props.id

export const articleSelector = createSelector(
  articlesMapSelector,
  idSelector,
  (articles, id) => articles.get(id)
)

export const createCommentSelector = () =>
  createSelector(
    commentsMapSelector,
    idSelector,
    (comments, id) => {
      console.log('---', 'comment selector', id)
      return comments.get(id)
Example #19
0
import {createSelector} from 'reselect'
import {fromJS} from 'immutable'
import slug from 'slug'

export const OpenAPISelector = () => fromJS(window.openapi)

export const definitionsSelector = createSelector(
    OpenAPISelector,
    openapi => openapi.get('definitions') || fromJS({})
)

export const tagsSelector = createSelector(
    OpenAPISelector,
    openapi => openapi.get('tags') || fromJS([])
)

export const pathsSelector = createSelector(
    OpenAPISelector,
    openapi => openapi.get('paths') || fromJS([])
)

export const orderedDefinitionsSelector = createSelector(
    definitionsSelector,
    definitions => definitions.sortBy((d, name) => name)
)

export const orderedTagsSelector = createSelector(
    tagsSelector,
    tags => tags.sortBy((t) => t.get('name'))
)
Example #20
0
import { createSelector } from 'reselect';

const getNotifications = state => state.notifications;

export const newNotificationsSelector = createSelector(
  getNotifications,
  notifications => notifications.get('visible')
);
export const oldNotificationsSelector = createSelector(
  getNotifications,
  notifications => notifications.get('hidden')
);
Example #21
0

import { APP_STORAGE_KEY } from '../../env';
const cityKey = `${APP_STORAGE_KEY}:city`;


// # Selectors
export const getCityList = state => state.city.get('list', List()) || List();
export const getCityId = state => state.city.get('id');
export const getCityPanelShowState = state => state.city.get('showCityPanel');
export const getCurrentCityName = createSelector(
   getCityId, getCityList,
   (cityId, cityList) => {
      if (isNil(cityId) || cityId === 1) {
        return '';
      }

      const currentCity = cityList.find(c => c.get('id') === cityId) || List()

      return currentCity.get('name');
    }
);

export const getCityIdByTeam = createSelector(
  getUserTeamId, getTeams,
  (teamId, teams) => {
    const usersTeamInfo = teams.find(team => team.get('id') === teamId);

    if (!usersTeamInfo) {
      return null;
    }
Example #22
0
import {createSelector} from 'reselect';
import {FILTERS} from './actions';


export const filterTodos = createSelector(
    [
        state => state.todos,
        state => state.filter
    ],
    (todos, filter) => {
        switch (filter) {
            case FILTERS.SHOW_ALL:
                return todos;
            case FILTERS.SHOW_COMPLETED:
                return todos.filter(todo => todo.completed);
            case FILTERS.SHOW_ACTIVE:
                return todos.filter(todo => !todo.completed);
        }
    }
);
Example #23
0
import { connect } from 'react-redux';
import addVideo from '../components/AddVideo';
import { update, remove }  from '../actions';
import { getAllVideos, getAllCategories } from '../reducers';
import { createSelector } from 'reselect'

const getId = (state, ownProps) =>  ownProps.params.id;

const getVideo = createSelector(
	[ getAllVideos, getId ],
	(videos, id) => {
		return videos.find((video) => video.get('id') == id);
	}
);

const mapStateToProps = (state, ownProps) => {
	let id = ownProps.params.id;

	return {
		title: 'Edit video data',
		editMode: true,
		id: id,
		initialValues: getVideo(state, ownProps),
		categories: getAllCategories(state)
	}
};

const mapDispatchToProps = (dispatch, ownProps) => {
	let id = ownProps.routeParams.id;
	return {
		update: (data) => {
import { createSelector, createStructuredSelector } from 'reselect';

const selectOpen = ({ modalMetadata }) => modalMetadata.isOpen;
const selectTitle = ({ modalMetadata }) => modalMetadata.title;
const selectLoading = ({ modalMetadata }) => modalMetadata.loading;
const selectSlug = ({ modalMetadata }) => modalMetadata.slug;
const selectData = ({ modalMetadata }) => modalMetadata.data;

export const getMetadata = createSelector([ selectSlug, selectData ], (slug, data) => {
  if (!slug || !data) return null;
  return data[slug];
});

export const mapStateToProps = createStructuredSelector({
  isOpen: selectOpen,
  loading: selectLoading,
  metadata: getMetadata,
  title: selectTitle
});
Example #25
0
const getGroups = state => state.groups;
export const groupsSelector = state => state.groups.get('resources');

export const notArchivedGroupsSelector = state =>
  state.groups
    .get('resources')
    .filter(isReady)
    .filter(group => group.getIn(['data', 'archived']) === false);

export const filterGroups = (ids, groups) => groups.filter(isReady).filter(group => ids.contains(getId(group)));

export const filterNonOrganizationalActiveGroups = groups =>
  groups.filter(group => !group.getIn(['data', 'organizational'], false) && !group.getIn(['data', 'archived'], false));

export const groupSelector = createSelector(
  [groupsSelector, getParam],
  (groups, id) => groups.get(id)
);

export const groupSelectorCreator = id =>
  createSelector(
    groupsSelector,
    groups => groups.get(id)
  );

// This is perhaps the best way how to create simple accessor (selector with parameter).
export const groupDataAccessorSelector = createSelector(
  groupsSelector,
  groups => groupId => groups.getIn([groupId, 'data'], EMPTY_MAP)
);

export const studentOfSelector = userId =>
Example #26
0
import { connect } from 'react-redux';
import grid from '../components/Grid';
import { BlockRecord } from '../minesweeper';
import { handleClick, handleFlag, setGame } from '../actions';
import { createSelector } from 'reselect';

const blockSelector = createSelector(
	state => state.mw.blocks,
	(state, ownProps) => ownProps,
	(blocks, ownProps) => blocks.get(new BlockRecord({
		row: ownProps.row,
		col: ownProps.col
	}))
);

const mapStateToProps = (state, ownProps) => ({
	block: blockSelector(state, ownProps)
});

const mapDispatchToProps = (dispatch, ownProps) => ({
	handleClick: (row, col) => {
		dispatch(handleClick(row, col));
	},

	handleFlag: (row, col) => {
		dispatch(handleFlag(row, col));
	}
});

const Grid = connect(mapStateToProps, mapDispatchToProps)(grid);
Example #27
0
export const allParentIdsForGroup = id =>
  createSelector(
    groupsSelector,
    groups => getGroupParentIds(id, groups)
  );
const getQuery = (state) => state.ui.query;
const getSortField = (state) => state.ui.sortField;
const getSortDirection = (state) => state.ui.sortDirection;
const getShowMatureThumbs = (state) => state.settings.showMatureThumbs;
const getShowExtras = (state) => state.settings.extras;
const getStyle = (state) => state.settings.style;
const getCurrentTab = (state) => state.ui.tab;
const getChannels = (state) => state.channels;
const getFeatured = (state) => state.featured;
const getShowBadges = (state) => state.ui.badges;
const getContextChannelID = (state) => state.ui.contextChannel;
const getQueueContext = (state) => state.ui.queueContext;

const getMergedFeatured = createSelector(
    getFeatured,
    getChannels,
    (featured, channels) => mergeFeatured(featured, channels)
);

const makeChannelsSelector = (tabGetter) => createSelector(
    getChannels,
    getMergedFeatured,
    getNonliveDisplay,
    tabGetter,
    (channels, featured, nonLiveDisplay, tab) => {
        if(tab === EXPLORE_TAB) {
            return {
                channels: featured,
                redirects: []
            };
        }
Example #29
0
export const groupArchivedPendingChange = id =>
  createSelector(
    groupsSelector,
    groups => groups && groups.getIn([id, 'pending-archived'], false)
  );
Example #30
0
import {RequestState} from 'indico/utils/redux';
import {selectors as configSelectors} from '../config';


const isFetching = ({map}) => map.request === RequestState.STARTED;

export const getMapAreas = ({map}) => map.areas;

export const isMapEnabled = state => !!configSelectors.getTileServerURL(state);

// the map is visible if it's enabled and we are fetching areas OR actually have areas
// that way we don't have a larger room list for a moment while loading areas, and the
// map has its own loading indicator anyway while there are no areas
export const isMapVisible = createSelector(
    isMapEnabled,
    isFetching,
    getMapAreas,
    (mapEnabled, areasFetching, mapAreas) => mapEnabled && (areasFetching || !!mapAreas.length)
);


export const makeGetMapData = (namespace) => ({[namespace]: stateSlice}) => ({
    bounds: stateSlice.map.bounds,
    search: stateSlice.map.search,
    filterBounds: stateSlice.filters.bounds,
});

export const makeIsMapSearchEnabled = (namespace) => ({[namespace]: stateSlice}) => stateSlice.map.search;

export const getHoveredRoom = ({map}) => map.ui.hoveredRoom;