Skip to content

Commit

Permalink
remove created lexes
Browse files Browse the repository at this point in the history
  • Loading branch information
vmonakhov committed Oct 17, 2024
1 parent ddb4bcd commit ec2abf6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/PerspectiveView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { openModal } from "ducks/modals";
import {
addLexicalEntry,
resetAddedLexes,
removeAddedLexes,
resetEntriesSelection,
resetSortByField,
selectLexicalEntry,
Expand Down Expand Up @@ -356,6 +357,7 @@ class P extends React.Component {
mergeLexicalEntries,
removeLexicalEntries,
addLexicalEntry: addCreatedEntry,
removeAddedLexes: removeCreatedLexes,
selectLexicalEntry: onEntrySelect,
resetEntriesSelection: resetSelection,
openModal: openNewModal,
Expand Down Expand Up @@ -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())));

Expand All @@ -482,6 +484,7 @@ class P extends React.Component {
return undefined;
}
);
removeCreatedLexes(selectedEntries);
resetSelection();
this.setState({ entriesTotal: entriesTotal - 1 });
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -784,6 +788,7 @@ const PerspectiveView = compose(
{
addLexicalEntry,
resetAddedLexes,
removeAddedLexes,
setSortByField,
resetSortByField,
selectLexicalEntry,
Expand Down
8 changes: 8 additions & 0 deletions src/ducks/perspective.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 };
}
Expand Down

0 comments on commit ec2abf6

Please sign in to comment.