Skip to content

Commit

Permalink
Merge branch 'hspitzley/additional_ingress_rules' of github.com:chanz…
Browse files Browse the repository at this point in the history
…uckerberg/single-cell-explorer into hspitzley/additional_ingress_rules
  • Loading branch information
hspitzley-czi committed Jun 27, 2024
2 parents 0b44cc2 + ec0e9b4 commit a1c628c
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 11 deletions.
32 changes: 32 additions & 0 deletions client/__tests__/e2e/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import {
toggleSidePanel,
} from "../util/helpers";
import { SCALE_MAX } from "../../src/util/constants";
import { PANEL_EMBEDDING_MINIMIZE_TOGGLE_TEST_ID } from "../../src/components/PanelEmbedding/constants";

const { describe, skip } = test;

Expand Down Expand Up @@ -1467,7 +1468,38 @@ for (const testDataset of testDatasets) {

await downloadAndSnapshotImage(page, testInfo);
});

test("with side panel", async ({ page }) => {
await goToPage(page, url);

await toggleSidePanel(page);

const downloads: Download[] = [];

page.on("download", (downloadData) => {
downloads.push(downloadData);
});

await page.getByTestId("download-graph-button").click();

expect(downloads.length).toBe(2);

const afterMinimizeDownloads: Download[] = [];

await page
.getByTestId(PANEL_EMBEDDING_MINIMIZE_TOGGLE_TEST_ID)
.click();

page.on("download", (downloadData) => {
afterMinimizeDownloads.push(downloadData);
});

await page.getByTestId("download-graph-button").click();

expect(afterMinimizeDownloads.length).toBe(1);
});
});

describeFn("Side Panel", () => {
test("open and close side panel", async ({ page }, testInfo) => {
await goToPage(page, url);
Expand Down
5 changes: 1 addition & 4 deletions client/__tests__/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,7 @@ export async function conditionallyToggleSidePanel(
}

export function skipIfSidePanel(graphTestId: string, MAIN_PANEL: string) {
const message = "This test is only for the main panel";
if (graphTestId !== MAIN_PANEL) {
skip(true, message);
}
skip(graphTestId !== MAIN_PANEL, "This test is only for the main panel");
}

export function shouldSkipTests(
Expand Down
2 changes: 2 additions & 0 deletions client/src/components/PanelEmbedding/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const PANEL_EMBEDDING_MINIMIZE_TOGGLE_TEST_ID =
"panel-embedding-minimize-toggle";
2 changes: 2 additions & 0 deletions client/src/components/PanelEmbedding/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Controls from "../controls";
import Embedding from "../embedding";
import { AppDispatch, RootState } from "../../reducers";
import actions from "../../actions";
import { PANEL_EMBEDDING_MINIMIZE_TOGGLE_TEST_ID } from "./constants";

interface StateProps {
isMinimized: boolean;
Expand Down Expand Up @@ -94,6 +95,7 @@ const PanelEmbedding = (props: StateProps & DispatchProps) => {
>
<Button
type="button"
data-testid={PANEL_EMBEDDING_MINIMIZE_TOGGLE_TEST_ID}
icon={isMinimized ? IconNames.MAXIMIZE : IconNames.MINIMIZE}
onClick={() => {
dispatch({
Expand Down
31 changes: 25 additions & 6 deletions client/src/components/graph/graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
getSpatialPrefixUrl,
getSpatialTileSources,
loadImage,
shouldSkipSidePanelImage,
sidePanelAttributeNameChange,
} from "./util";

Expand Down Expand Up @@ -85,6 +86,7 @@ const mapStateToProps = (state: RootState, ownProps: OwnProps): StateProps => ({
imageUnderlay: state.controls.imageUnderlay,
config: state.config,
isSidePanelOpen: state.panelEmbedding.open,
isSidePanelMinimized: state.panelEmbedding.minimized,
sidePanelLayoutChoice: state.panelEmbedding.layoutChoice,
});

Expand Down Expand Up @@ -302,6 +304,8 @@ class Graph extends React.Component<GraphProps, GraphState> {
screenCap,
imageUnderlay,
layoutChoice,
isHidden,
isSidePanel,
} = this.props;

const { toolSVG, viewport } = this.state;
Expand Down Expand Up @@ -342,7 +346,7 @@ class Graph extends React.Component<GraphProps, GraphState> {
stateChanges.toolSVG
) {
const { tool } = this.state;
this.selectionToolUpdate(stateChanges.tool ? stateChanges.tool : tool!);
this.selectionToolUpdate(stateChanges.tool ? stateChanges.tool : tool);
}

if (Object.keys(stateChanges).length > 0) {
Expand All @@ -368,6 +372,14 @@ class Graph extends React.Component<GraphProps, GraphState> {
if (prevProps.layoutChoice.current !== layoutChoice.current) {
this.handleResize();
}

/**
* (thuang): We need to resize the graph when the side panel is expanded
* from minimized state to prevent squished graph.
*/
if (isSidePanel && prevProps.isHidden && !isHidden) {
this.handleResize();
}
}

componentWillUnmount(): void {
Expand Down Expand Up @@ -561,9 +573,16 @@ class Graph extends React.Component<GraphProps, GraphState> {
isSidePanelOpen,
sidePanelLayoutChoice,
isSidePanel,
isSidePanelMinimized,
} = this.props;

if (!this.reglCanvas || !screenCap || !regl || this.isDownloadingImage) {
if (
!this.reglCanvas ||
!screenCap ||
!regl ||
this.isDownloadingImage ||
shouldSkipSidePanelImage(this.props)
) {
return;
}

Expand Down Expand Up @@ -655,7 +674,7 @@ class Graph extends React.Component<GraphProps, GraphState> {
if (!isSidePanel) {
track(
EVENTS.EXPLORER_DOWNLOAD_COMPLETE,
isSidePanelOpen
isSidePanelOpen && !isSidePanelMinimized
? {
embedding: layoutChoice.current,
side_by_side: sidePanelLayoutChoice?.current,
Expand Down Expand Up @@ -910,7 +929,7 @@ class Graph extends React.Component<GraphProps, GraphState> {
return Promise.all(promises);
}

lassoToolUpdate(tool: LassoFunctionWithAttributes): void {
lassoToolUpdate(tool: LassoFunctionWithAttributes | null): void {
/*
this is called from componentDidUpdate(), so be very careful using
anything from this.state, which may be updated asynchronously.
Expand All @@ -923,9 +942,9 @@ class Graph extends React.Component<GraphProps, GraphState> {
const polygon = currentSelection.polygon.map((p: [number, number]) =>
this.mapPointToScreen(p)
);
tool.move(polygon);
tool?.move(polygon);
} else {
tool.reset();
tool?.reset();
}
}

Expand Down
3 changes: 2 additions & 1 deletion client/src/components/graph/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Camera } from "../../util/camera";

import { Dataframe } from "../../util/dataframe";

import { LassoFunctionWithAttributes } from "./setupLasso";
import { type LassoFunctionWithAttributes } from "./setupLasso";

import { AppDispatch, RootState } from "../../reducers";

Expand Down Expand Up @@ -60,6 +60,7 @@ export interface StateProps {
imageUnderlay: RootState["controls"]["imageUnderlay"];
config: RootState["config"];
isSidePanelOpen: RootState["panelEmbedding"]["open"];
isSidePanelMinimized: RootState["panelEmbedding"]["minimized"];
sidePanelLayoutChoice: RootState["panelEmbedding"]["layoutChoice"];
}

Expand Down
12 changes: 12 additions & 0 deletions client/src/components/graph/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { mat3 } from "gl-matrix";
import { toPng } from "html-to-image";
import { LayoutChoiceState } from "../../reducers/layoutChoice";
import { GraphProps } from "./types";

export function sidePanelAttributeNameChange(
name: string,
Expand Down Expand Up @@ -208,3 +209,14 @@ export function downloadImage(
a.remove();
}, 1000);
}

/**
* (thuang): Product requirement that the side panel should NOT be included
* in the download when it's minimized
*/
export function shouldSkipSidePanelImage({
isSidePanel,
isSidePanelMinimized,
}: GraphProps) {
return isSidePanel && isSidePanelMinimized;
}

0 comments on commit a1c628c

Please sign in to comment.