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

Fix(AC): Handle AC modal state for editionGroup entity #867

Merged
merged 1 commit into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
import {Button, Col, Form, InputGroup, OverlayTrigger, Row, Tooltip} from 'react-bootstrap';

import {SingleValueProps, components} from 'react-select';
import {map as _map, values as _values} from 'lodash';
import {map as _map, values as _values, camelCase} from 'lodash';

import {faPencilAlt, faQuestionCircle} from '@fortawesome/free-solid-svg-icons';
import AuthorCreditEditor from './author-credit-editor';
Expand Down Expand Up @@ -143,15 +143,16 @@ AuthorCreditSection.propTypes = {
showEditor: PropTypes.bool.isRequired
};

function mapStateToProps(rootState): StateProps {
function mapStateToProps(rootState, {type}): StateProps {
const firstRowKey = rootState.get('authorCreditEditor').keySeq().first();
const authorCreditRow = rootState.getIn(['authorCreditEditor', firstRowKey]);
const isEditable = !(rootState.get('authorCreditEditor').size > 1) &&
authorCreditRow.get('name') === authorCreditRow.getIn(['author', 'text'], '');
authorCreditRow.get('name') === authorCreditRow.getIn(['author', 'text'], '');
const entitySection = `${camelCase(type)}Section`;
return {
authorCreditEditor: convertMapToObject(rootState.get('authorCreditEditor')),
isEditable,
showEditor: rootState.getIn(['editionSection', 'authorCreditEditorVisible'])
showEditor: rootState.getIn([entitySection, 'authorCreditEditorVisible'])
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
*/

import * as React from 'react';
import AuthorCreditSection from '../author-credit-editor/author-credit-section';
import {Action, updateType} from './actions';
import {Col, Form, OverlayTrigger, Row, Tooltip} from 'react-bootstrap';
import AuthorCreditSection from '../author-credit-editor/author-credit-section';

import type {Dispatch} from 'redux';
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
import type {Map} from 'immutable';
import Select from 'react-select';
import {connect} from 'react-redux';
import {faQuestionCircle} from '@fortawesome/free-solid-svg-icons';
Expand All @@ -35,7 +34,7 @@ type EditionGroupType = {
};

type StateProps = {
typeValue: Map<string, any>
typeValue: number
};

type DispatchProps = {
Expand Down Expand Up @@ -80,7 +79,7 @@ function EditionGroupSection({
<h2>
What else do you know about the Edition Group?
</h2>
<AuthorCreditSection/>
<AuthorCreditSection type="editionGroup"/>
<p className="text-muted">
All fields optional — leave something blank if you don&rsquo;t
know it
Expand Down
6 changes: 6 additions & 0 deletions src/client/entity-editor/edition-group-section/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as Immutable from 'immutable';
import {
Action, UPDATE_TYPE
} from './actions';
import {HIDE_AUTHOR_CREDIT_EDITOR, SHOW_AUTHOR_CREDIT_EDITOR} from '../author-credit-editor/actions';


type State = Immutable.Map<string, any>;
Expand All @@ -35,6 +36,11 @@ function reducer(
switch (type) {
case UPDATE_TYPE:
return state.set('type', payload);
case SHOW_AUTHOR_CREDIT_EDITOR:
return state.set('authorCreditEditorVisible', true);
case HIDE_AUTHOR_CREDIT_EDITOR:
return state.set('authorCreditEditorVisible', false);

// no default
}
return state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ function EditionSection({
<h2>
What else do you know about the Edition?
</h2>
<AuthorCreditSection/>
<AuthorCreditSection type="edition"/>
<p className="text-muted">
Edition Group is required — this cannot be blank. You can search for and choose an existing Edition Group,
or choose to automatically create one instead.
Expand Down