• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bookbrainz / bookbrainz-site / 3654

pending completion
3654

Pull #463

travis-ci

web-flow
Merge bd882516c into 46b7412ac
Pull Request #463: Add author credit display and edit for Editions

1476 of 3761 branches covered (39.24%)

221 of 221 new or added lines in 23 files covered. (100.0%)

4326 of 7133 relevant lines covered (60.65%)

39.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

21.82
/src/client/entity-editor/author-credit-editor/reducer.js
1
/*
2
 * Copyright (C) 2020  Sean Burke
3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 2 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License along
15
 * with this program; if not, write to the Free Software Foundation, Inc.,
16
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
 */
18

19
import {
3✔
20
        ADD_AUTHOR_CREDIT_ROW,
21
        REMOVE_AUTHOR_CREDIT_ROW,
22
        REMOVE_EMPTY_CREDIT_ROWS,
23
        UPDATE_CREDIT_AUTHOR_VALUE,
24
        UPDATE_CREDIT_DISPLAY_VALUE,
25
        UPDATE_CREDIT_JOIN_PHRASE_VALUE
26
} from './actions';
27

28
import Immutable from 'immutable';
3✔
29

30

31
const EMPTY_CREDIT_ROW = Immutable.Map({
3✔
32
        author: null,
33
        joinPhrase: '',
34
        name: ''
35
});
36

37
function addAuthorCreditRow(state, payload) {
38
        let stateToModify = state;
×
39

40
        // If there are already names in the author credit and the previous name
41
        // has no join phrase set, set a default.
42
        const lastKey = stateToModify.keySeq().last();
×
43
        if (lastKey && stateToModify.getIn([lastKey, 'joinPhrase'], '') === '') {
×
44
                stateToModify = stateToModify.setIn([lastKey, 'joinPhrase'], ' & ');
×
45
        }
46

47
        return stateToModify.set(payload, EMPTY_CREDIT_ROW);
×
48
}
49

50
function setNewAuthorAndDisplay(state, payload) {
51
        let returnState = state.setIn([payload.rowId, 'author'], Immutable.fromJS(payload));
×
52

53
        if (!payload.id) {
×
54
                // If the user has emptied the author field, also empty the display
55
                // name.
56
                returnState = returnState.setIn([payload.rowId, 'name'], '');
×
57
        }
58
        else if (returnState.getIn([payload.rowId, 'name'], '') === '') {
×
59
                // When the display name is empty and the user sets a new author, copy
60
                // the author's name to the display name field.
61
                returnState = returnState.setIn([payload.rowId, 'name'], payload.text);
×
62
        }
63

64
        return returnState;
×
65
}
66

67
function deleteAuthorCreditRow(state, payload) {
68
        let returnState = state.delete(payload);
×
69

70
        // If names remain in the author credit, empty the join phrase for the last
71
        // name.
72
        const lastKey = returnState.keySeq().last();
×
73
        if (lastKey) {
×
74
                returnState = returnState.setIn([lastKey, 'joinPhrase'], '');
×
75
        }
76

77
        return returnState;
×
78
}
79
function deleteEmptyRows(state) {
80
        const returnState = state.filterNot(row =>
×
81
                row.get('author') === null && row.get('joinPhrase') === '' && row.get('name') === '');
×
82

83
        return returnState;
×
84
}
85

86
function reducer(
87
        state = Immutable.OrderedMap(),
88
        action
89
) {
12✔
90
        const {type, payload} = action;
12✔
91
        switch (type) {
12✔
92
                case ADD_AUTHOR_CREDIT_ROW:
×
93
                        return addAuthorCreditRow(state, payload);
×
94
                case UPDATE_CREDIT_AUTHOR_VALUE:
95
                        return setNewAuthorAndDisplay(state, payload);
×
96
                case UPDATE_CREDIT_DISPLAY_VALUE:
97
                        return state.setIn([payload.rowId, 'name'], payload.value);
×
98
                case UPDATE_CREDIT_JOIN_PHRASE_VALUE:
99
                        return state.setIn([payload.rowId, 'joinPhrase'], payload.value);
×
100
                case REMOVE_AUTHOR_CREDIT_ROW:
101
                        return deleteAuthorCreditRow(state, payload);
×
102
                case REMOVE_EMPTY_CREDIT_ROWS:
103
                        return deleteEmptyRows(state);
×
104
                // no default
105
        }
106
        return state;
12✔
107
}
108

109
export default reducer;
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc