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

create unhide all redux setup #2517

Merged
merged 2 commits into from
Feb 10, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 8 additions & 10 deletions applications/desktop/__tests__/renderer/menu-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,21 +261,19 @@ describe("menu", () => {
});

describe("dispatchUnhideAll", () => {
test("dispatches toggleCellInputVisibility for hidden code cells", () => {
test("", () => {
const store = dummyStore({ hideAll: true });
store.dispatch = jest.fn();

menu.dispatchUnhideAll(store);

const first = store
.getState()
.document.getIn(["notebook", "cellOrder"])
.first();
const expectedAction = {
type: "TOGGLE_CELL_INPUT_VISIBILITY",
id: first
};
expect(store.dispatch).toHaveBeenCalledWith(expectedAction);
expect(store.dispatch).toHaveBeenCalledWith({
type: "UNHIDE_ALL",
payload: {
outputs: true,
input: true
}
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion applications/desktop/src/main/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ export function loadFullMenu(store: * = global.store) {
click: createSender("menu:clear-all")
},
{
label: "Unhide All Outputs",
label: "Unhide Input and Output in all Cells",
enabled: BrowserWindow.getAllWindows().length > 0,
click: createSender("menu:unhide-all")
}
Expand Down
5 changes: 1 addition & 4 deletions applications/desktop/src/notebook/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,7 @@ export function dispatchClearAll(store: *) {
}

export function dispatchUnhideAll(store: *) {
const hiddenCellIds = selectors.currentHiddenCellIds(store.getState());
hiddenCellIds.forEach(id =>
store.dispatch(actions.toggleCellInputVisibility(id))
);
store.dispatch(actions.unhideAll());
}

export function dispatchKillKernel(store: *) {
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/actionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ export type UpdateDisplayAction = {
}
};

export const UNHIDE_ALL = "UNHIDE_ALL";
export type UnhideAll = {
type: "UNHIDE_ALL",
payload: {
input: boolean,
outputs: boolean
}
};

export const TOGGLE_CELL_OUTPUT_VISIBILITY = "TOGGLE_CELL_OUTPUT_VISIBILITY";
export type ToggleCellOutputVisibilityAction = {
type: "TOGGLE_CELL_OUTPUT_VISIBILITY",
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import type {
import type { Output, StreamOutput } from "@nteract/commutable/src/v4";

import type {
UnhideAll,
RestartKernel,
RestartKernelFailed,
RestartKernelSuccessful,
Expand Down Expand Up @@ -331,6 +332,18 @@ export function updateCellExecutionCount(
return setInCell(id, ["execution_count"], count);
}

export function unhideAll(
payload: { outputs: boolean, input: boolean } = {
outputs: true,
input: true
}
): UnhideAll {
return {
type: "UNHIDE_ALL",
payload
};
}

export function toggleCellOutputVisibility(
id: string
): ToggleCellOutputVisibilityAction {
Expand Down
19 changes: 19 additions & 0 deletions packages/core/src/reducers/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as actionTypes from "../actionTypes";
// TODO: With the new document plan, I think it starts to make sense to decouple
// the document view actions and the underlying document format
import type {
UnhideAll,
RestartKernel,
ClearAllOutputs,
PasteCellAction,
Expand Down Expand Up @@ -576,6 +577,21 @@ function toggleCellOutputVisibility(
);
}

function unhideAll(state: DocumentRecord, action: UnhideAll) {
return state.updateIn(["notebook", "cellMap"], cellMap =>
cellMap.map(cell => {
if (cell.get("cell_type") === "code") {
return cell.mergeIn(["metadata"], {
// TODO: Verify that we convert to one namespace for hidden input/output
outputHidden: !action.payload.outputs,
inputHidden: !action.payload.input
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me wonder if I should change the nomenclature and pattern to action.payload.outputHidden.

});
}
return cell;
})
);
}

function toggleCellInputVisibility(
state: DocumentRecord,
action: ToggleCellInputVisibilityAction
Expand All @@ -586,6 +602,7 @@ function toggleCellInputVisibility(
!state.getIn(["notebook", "cellMap", id, "metadata", "inputHidden"])
);
}

function updateCellStatus(
state: DocumentRecord,
action: UpdateCellStatusAction
Expand Down Expand Up @@ -824,6 +841,8 @@ function handleDocument(
return changeCellType(state, action);
case actionTypes.TOGGLE_OUTPUT_EXPANSION:
return toggleOutputExpansion(state, action);
case actionTypes.UNHIDE_ALL:
return unhideAll(state, action);
case actionTypes.CHANGE_FILENAME:
return changeFilename(state, action);
default:
Expand Down