diff --git a/src/components/PerspectiveView/index.js b/src/components/PerspectiveView/index.js index 72fbc053..0428cfba 100644 --- a/src/components/PerspectiveView/index.js +++ b/src/components/PerspectiveView/index.js @@ -16,6 +16,7 @@ import { openModal } from "ducks/modals"; import { addLexicalEntry, resetAddedLexes, + removeAddedLexes, resetEntriesSelection, resetSortByField, selectLexicalEntry, @@ -356,6 +357,7 @@ class P extends React.Component { mergeLexicalEntries, removeLexicalEntries, addLexicalEntry: addCreatedEntry, + removeAddedLexes: removeCreatedLexes, selectLexicalEntry: onEntrySelect, resetEntriesSelection: resetSelection, openModal: openNewModal, @@ -473,7 +475,7 @@ class P extends React.Component { const result = cloneDeep(data); const current_entries = result.perspective.perspective_page.lexical_entries; const selectedEntriesStr = selectedEntries.map(id => id.toString()); - + result.perspective.perspective_page.lexical_entries = ( current_entries.filter(({id}) => !selectedEntriesStr.includes(id.toString()))); @@ -482,6 +484,7 @@ class P extends React.Component { return undefined; } ); + removeCreatedLexes(selectedEntries); resetSelection(); this.setState({ entriesTotal: entriesTotal - 1 }); } @@ -751,6 +754,7 @@ P.propTypes = { resetSortByField: PropTypes.func.isRequired, addLexicalEntry: PropTypes.func.isRequired, resetAddedLexes: PropTypes.func.isRequired, + removeAddedLexes: PropTypes.func.isRequired, createLexicalEntry: PropTypes.func.isRequired, mergeLexicalEntries: PropTypes.func.isRequired, removeLexicalEntries: PropTypes.func.isRequired, @@ -784,6 +788,7 @@ const PerspectiveView = compose( { addLexicalEntry, resetAddedLexes, + removeAddedLexes, setSortByField, resetSortByField, selectLexicalEntry, diff --git a/src/ducks/perspective.js b/src/ducks/perspective.js index 0410c8fe..caaf4877 100644 --- a/src/ducks/perspective.js +++ b/src/ducks/perspective.js @@ -10,6 +10,7 @@ export const RESET_SORT_MODE = "@data/perspective/RESET_SORT_MODE"; export const SET_ORDERED_SORT_MODE = "@data/perspective/SET_ORDERED_SORT_MODE"; export const RESET_ORDERED_SORT_MODE = "@data/perspective/RESET_ORDERED_SORT_MODE"; export const ADD_LEXICAL_ENTRY = "@data/perspective/ADD_LEXICAL_ENTRY"; +export const REMOVE_ADDED_LEXES = "@data/perspective/REMOVE_ADDED_LEXES"; export const RESET_ADDED_LEXES = "@data/perspective/RESET_ADDED_LEXES"; export const SELECT_LEXICAL_ENTRY = "@data/perspective/SELECT_LEXICAL_ENTRY"; export const RESET_ENTRIES_SELECTION = "@data/perspective/RESET_ENTRIES_SELECTION"; @@ -59,6 +60,9 @@ function createdEntries(state = [], { type, payload }) { switch (type) { case ADD_LEXICAL_ENTRY: return [payload, ...state]; + case REMOVE_ADDED_LEXES: + const selected = payload.map(id => id.toString()); + return state.filter(({id}) => !selected.includes(id.toString())); case RESET_ADDED_LEXES: return []; default: @@ -126,6 +130,10 @@ export function addLexicalEntry(entry) { return { type: ADD_LEXICAL_ENTRY, payload: entry }; } +export function removeAddedLexes(ids) { + return { type: REMOVE_ADDED_LEXES, payload: ids }; +} + export function resetAddedLexes(entry) { return { type: RESET_ADDED_LEXES, payload: null }; }