Skip to content

Desktop: Support "select all" in the note list #2403

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

Merged
merged 3 commits into from
Feb 4, 2020
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
33 changes: 29 additions & 4 deletions CliClient/tests/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function createNTestFolders(n) {
async function createNTestNotes(n, folder) {
let notes = [];
for (let i = 0; i < n; i++) {
let note = await Note.save({ title: 'note', parent_id: folder.id });
let note = await Note.save({ title: 'note', parent_id: folder.id, is_conflict: 0 });
notes.push(note);
}
return notes;
Expand All @@ -36,12 +36,13 @@ async function createNTestTags(n) {

function initTestState(folders, selectedFolderIndex, notes, selectedIndexes, tags=null, selectedTagIndex=null) {
let state = defaultState;
if (folders != null) {
state = reducer(state, { type: 'FOLDER_UPDATE_ALL', items: folders });
}

if (selectedFolderIndex != null) {
state = reducer(state, { type: 'FOLDER_SELECT', id: folders[selectedFolderIndex].id });
}
if (folders != null) {
state = reducer(state, { type: 'FOLDER_UPDATE_ALL', items: folders });
}
if (notes != null) {
state = reducer(state, { type: 'NOTE_UPDATE_ALL', notes: notes, noteSource: 'test' });
}
Expand Down Expand Up @@ -347,4 +348,28 @@ describe('Reducer', function() {
expect(getIds(state.tags)).toEqual(getIds(expected.items));
expect(state.selectedTagId).toEqual(expected.selectedIds[0]);
}));

it('should select all notes', asyncTest(async () => {
let folders = await createNTestFolders(2);
let notes = [];
for (let i = 0; i < folders.length; i++) {
notes.push(...await createNTestNotes(3, folders[i]));
}

let state = initTestState(folders, 0, notes.slice(0,3), [0]);

let expected = createExpectedState(notes, [0,1,2], [0]);

expect(state.notes.length).toEqual(expected.items.length);
expect(getIds(state.notes.slice(0,4))).toEqual(getIds(expected.items));
expect(state.selectedNoteIds).toEqual(expected.selectedIds);

// test action
state = reducer(state, {type: 'NOTE_SELECT_ALL'});

expected = createExpectedState(notes.slice(0,3), [0,1,2], [0,1,2]);
expect(getIds(state.notes)).toEqual(getIds(expected.items));
expect(state.selectedNoteIds).toEqual(expected.selectedIds);
}));

});
9 changes: 9 additions & 0 deletions ElectronClient/app/gui/NoteList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,15 @@ class NoteListComponent extends React.Component {
});
}
}

if (event.keyCode === 65 && (event.ctrlKey || event.metaKey)) {
// Ctrl+A key
event.preventDefault();

this.props.dispatch({
type: 'NOTE_SELECT_ALL',
});
}
}

focusNoteId_(noteId) {
Expand Down
5 changes: 5 additions & 0 deletions ElectronClient/app/gui/SideBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,11 @@ class SideBarComponent extends React.Component {
id: selectedItem.id,
});
}

if (keyCode === 65 && (event.ctrlKey || event.metaKey)) {
// Ctrl+A key
event.preventDefault();
}
}

onHeaderClick_(key, event) {
Expand Down
5 changes: 5 additions & 0 deletions ReactNativeClient/lib/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ const reducer = (state = defaultState, action) => {
}
break;

case 'NOTE_SELECT_ALL':
newState = Object.assign({}, state);
newState.selectedNoteIds = newState.notes.map(n => n.id);
break;

case 'FOLDER_SELECT':
newState = changeSelectedFolder(state, action, { clearSelectedNoteIds: true });
break;
Expand Down