<commit_before>/* @flow */
import { Map, fromJS } from 'immutable';

import * as actionTypes from './PermissionsActionTypes';
import { ASYNC_STATUS } from '../../components/asynccontent/AsyncContent'

export const LOADING_ERROR = Symbol('loading error');


const INITIAL_STATE:Map<*, *> = fromJS({
  authorizations: {},
  requestPermissionsModal: {
    show: false,
    entitySetId: null,
    asyncStatus: ASYNC_STATUS.PENDING
  }
});

export default function reducer(state:Map<*, *> = INITIAL_STATE, action:Object) {
  let authorizations;

  switch (action.type) {
    case actionTypes.CHECK_AUTHORIZATION_REJECT:
      authorizations = state.get('authorizations');
      action.accessChecks.forEach(accessCheck => {
        authorizations = authorizations.setIn(accessCheck.aclKey.concat(['permissions']), LOADING_ERROR)
      });
      return state.set('authorizations', authorizations);

    case actionTypes.CHECK_AUTHORIZATION_RESOLVE:
      authorizations = state.get('authorizations');
      action.authorizations.forEach(authorization => {
        authorizations = authorizations.setIn(authorization.aclKey.concat(['permissions']), Map(authorization.permissions))
      });
      return state.set('authorizations', authorizations);

    case actionTypes.REQUEST_PERMISSIONS_MODAL_SHOW:
      return state.mergeIn(['requestPermissionsModal'], {
        show: true,
        entitySetId: action.entitySetId,
        saveState: ASYNC_STATUS.PENDING
      });

    case actionTypes.REQUEST_PERMISSIONS_MODAL_HIDE:
      return state.mergeIn(['requestPermissionsModal'], {
        show: false
        // Don't set entitySetId to false. Allows modal to fade away with content
      });

    case actionTypes.SUBMIT_AUTHN_REQUEST:
      return state.mergeIn(['requestPermissionsModal'], {
        asyncStatus: ASYNC_STATUS.LOADING
      });

    case actionTypes.REQUEST_PERMISSIONS_MODAL_SUCCESS:
      return state.mergeIn(['requestPermissionsModal'], {
        asyncStatus: ASYNC_STATUS.SUCCESS
      });

    case actionTypes.REQUEST_PERMISSIONS_MODAL_FAILURE:
      return state.mergeIn(['requestPermissionsModal'], {
        asyncStatus: ASYNC_STATUS.ERROR
      });

    default:
      return state;
  }
}<commit_msg>Fix: show request permissions modal on subsequent attempts after initial request<commit_after>/* @flow */
import { Map, fromJS } from 'immutable';

import * as actionTypes from './PermissionsActionTypes';
import { ASYNC_STATUS } from '../../components/asynccontent/AsyncContent'

export const LOADING_ERROR = Symbol('loading error');


const INITIAL_STATE:Map<*, *> = fromJS({
  authorizations: {},
  requestPermissionsModal: {
    show: false,
    entitySetId: null,
    asyncStatus: ASYNC_STATUS.PENDING
  }
});

export default function reducer(state:Map<*, *> = INITIAL_STATE, action:Object) {
  let authorizations;

  switch (action.type) {
    case actionTypes.CHECK_AUTHORIZATION_REJECT:
      authorizations = state.get('authorizations');
      action.accessChecks.forEach(accessCheck => {
        authorizations = authorizations.setIn(accessCheck.aclKey.concat(['permissions']), LOADING_ERROR)
      });
      return state.set('authorizations', authorizations);

    case actionTypes.CHECK_AUTHORIZATION_RESOLVE:
      authorizations = state.get('authorizations');
      action.authorizations.forEach(authorization => {
        authorizations = authorizations.setIn(authorization.aclKey.concat(['permissions']), Map(authorization.permissions))
      });
      return state.set('authorizations', authorizations);

    case actionTypes.REQUEST_PERMISSIONS_MODAL_SHOW:
      return state.mergeIn(['requestPermissionsModal'], {
        show: true,
        entitySetId: action.entitySetId,
        asyncStatus: ASYNC_STATUS.PENDING
      });

    case actionTypes.REQUEST_PERMISSIONS_MODAL_HIDE:
      return state.mergeIn(['requestPermissionsModal'], {
        show: false
        // Don't set entitySetId to false. Allows modal to fade away with content
      });

    case actionTypes.SUBMIT_AUTHN_REQUEST:
      return state.mergeIn(['requestPermissionsModal'], {
        asyncStatus: ASYNC_STATUS.LOADING
      });

    case actionTypes.REQUEST_PERMISSIONS_MODAL_SUCCESS:
      return state.mergeIn(['requestPermissionsModal'], {
        asyncStatus: ASYNC_STATUS.SUCCESS
      });

    case actionTypes.REQUEST_PERMISSIONS_MODAL_FAILURE:
      return state.mergeIn(['requestPermissionsModal'], {
        asyncStatus: ASYNC_STATUS.ERROR
      });

    default:
      return state;
  }
}
{'fraction_non_alphanumeric': 0.10909493250719186, 'fraction_numerical': 0.0, 'mean_word_length': 3.813631522896699, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5519583', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1290, 'n_words': 236}