Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

fix: Revert horizontal asset bar #881

Merged
merged 1 commit into from
Aug 26, 2019
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
4 changes: 1 addition & 3 deletions src/react/components/pages/editorPage/editorPage.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
overflow: hidden;
position: relative;

&-bottombar {
&-sidebar {
display: flex;
flex-grow: 1;
flex-direction: row;

&-nav {
height: 100%;
width: 100%;

.asset-list {
Expand Down
24 changes: 12 additions & 12 deletions src/react/components/pages/editorPage/editorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,22 @@ export default class EditorPage extends React.Component<IEditorPageProps, IEdito
icon={"fa-lock"}
handler={this.handleCtrlTagHotKey} />);
})}
<SplitPane split="horizontal"
<SplitPane split="vertical"
defaultSize={this.state.thumbnailSize.width}
minSize={100}
maxSize={400}
paneStyle={{ display: "flex" }}
onChange={this.onSideBarResize}
onDragFinished={this.onSideBarResizeComplete}
primary={"second"}>
onDragFinished={this.onSideBarResizeComplete}>
<div className="editor-page-sidebar bg-lighter-1">
<EditorSideBar
assets={rootAssets}
selectedAsset={selectedAsset ? selectedAsset.asset : null}
onBeforeAssetSelected={this.onBeforeAssetSelected}
onAssetSelected={this.selectAsset}
thumbnailSize={this.state.thumbnailSize}
/>
</div>
<div className="editor-page-content" onClick={this.onPageClick}>
<div className="editor-page-content-main">
<div className="editor-page-content-main-header">
Expand Down Expand Up @@ -250,15 +259,6 @@ export default class EditorPage extends React.Component<IEditorPageProps, IEdito
confirmButtonColor="danger"
onConfirm={this.onTagDeleted} />
</div>
<div className="editor-page-bottombar bg-lighter-1">
<EditorSideBar
assets={rootAssets}
selectedAsset={selectedAsset ? selectedAsset.asset : null}
onBeforeAssetSelected={this.onBeforeAssetSelected}
onAssetSelected={this.selectAsset}
thumbnailSize={this.state.thumbnailSize}
/>
</div>
</SplitPane>
<Alert show={this.state.showInvalidRegionWarning}
title={strings.editorPage.messages.enforceTaggedRegions.title}
Expand Down
31 changes: 5 additions & 26 deletions src/react/components/pages/editorPage/editorSideBar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import EditorSideBar, { IEditorSideBarProps, IEditorSideBarState } from "./editorSideBar";
import { ReactWrapper, mount } from "enzyme";
import { AutoSizer, Grid } from "react-virtualized";
import { AutoSizer, List } from "react-virtualized";
import MockFactory from "../../../../common/mockFactory";

describe("Editor SideBar", () => {
Expand All @@ -21,7 +21,7 @@ describe("Editor SideBar", () => {
const wrapper = createComponent(props);
expect(wrapper.exists()).toBe(true);
expect(wrapper.find(AutoSizer).exists()).toBe(true);
expect(wrapper.find(Grid).exists()).toBe(true);
expect(wrapper.find(List).exists()).toBe(true);
});

it("Initializes state without asset selected", () => {
Expand Down Expand Up @@ -117,8 +117,8 @@ describe("Editor SideBar", () => {
};

const wrapper = createComponent(props);
const grid = wrapper.find(Grid).instance() as Grid;
const recomputeGridSizeSpy = jest.spyOn(grid, "recomputeGridSize");
const list = wrapper.find(List).instance() as List;
const recomputeRowHeightsSpy = jest.spyOn(list, "recomputeRowHeights");

wrapper.setProps({
thumbnailSize: {
Expand All @@ -127,27 +127,6 @@ describe("Editor SideBar", () => {
},
});

expect(recomputeGridSizeSpy).toBeCalled();
});

it("Correctly computes Grid column size", () => {
const props: IEditorSideBarProps = {
assets: testAssets,
onAssetSelected: onSelectAssetHandler,
thumbnailSize: {
width: 175,
height: 155,
},
};

const wrapper = createComponent(props);
const grid = wrapper.find(Grid).instance() as Grid;
const autoSizer = wrapper.find(AutoSizer).instance() as AutoSizer;
autoSizer.setState({
width: 150,
height: 91,
});

expect(grid.props.columnWidth()).toBe(100);
expect(recomputeRowHeightsSpy).toBeCalled();
});
});
30 changes: 13 additions & 17 deletions src/react/components/pages/editorPage/editorSideBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { AutoSizer, Grid } from "react-virtualized";
import { AutoSizer, List } from "react-virtualized";
import { IAsset, AssetState, ISize } from "../../../../models/applicationState";
import { AssetPreview } from "../../common/assetPreview/assetPreview";
import { strings } from "../../../../common/strings";
Expand Down Expand Up @@ -38,24 +38,23 @@ export default class EditorSideBar extends React.Component<IEditorSideBarProps,
: 0,
};

private listRef: React.RefObject<Grid> = React.createRef();
private listRef: React.RefObject<List> = React.createRef();

public render() {
return (
<div className="editor-page-bottombar-nav">
<AutoSizer>
{({ height, width }) => (
<Grid
<List
ref={this.listRef}
className="asset-list"
cellRenderer={this.rowRenderer}
columnCount={this.props.assets.length}
columnWidth={() => this.getColumnWidth(height)}
height={height}
width={width}
rowCount={1}
rowHeight={height}
rowCount={this.props.assets.length}
rowHeight={() => this.getRowHeight(width)}
rowRenderer={this.rowRenderer}
overscanRowCount={2}
scrollToIndex={this.state.scrollToIndex}
/>
)}
</AutoSizer>
Expand All @@ -65,7 +64,7 @@ export default class EditorSideBar extends React.Component<IEditorSideBarProps,

public componentDidUpdate(prevProps: IEditorSideBarProps) {
if (prevProps.thumbnailSize !== this.props.thumbnailSize) {
this.listRef.current.recomputeGridSize();
this.listRef.current.recomputeRowHeights();
}

if (!prevProps.selectedAsset && !this.props.selectedAsset) {
Expand All @@ -78,11 +77,8 @@ export default class EditorSideBar extends React.Component<IEditorSideBarProps,
}
}

private getColumnWidth = (height: number) => {
const padding = 16;
const aspectRatio = (4 / 3);

return (height - padding) * aspectRatio;
private getRowHeight = (width: number) => {
return width / (4 / 3) + 16;
}

private selectAsset = (selectedAsset: IAsset): void => {
Expand All @@ -91,7 +87,7 @@ export default class EditorSideBar extends React.Component<IEditorSideBarProps,
this.setState({
scrollToIndex,
}, () => {
this.listRef.current.forceUpdate();
this.listRef.current.forceUpdateGrid();
});
}

Expand All @@ -106,8 +102,8 @@ export default class EditorSideBar extends React.Component<IEditorSideBarProps,
this.props.onAssetSelected(asset);
}

private rowRenderer = ({ columnIndex, key, style }): JSX.Element => {
const asset = this.props.assets[columnIndex];
private rowRenderer = ({ key, index, style }): JSX.Element => {
const asset = this.props.assets[index];
const selectedAsset = this.props.selectedAsset;

return (
Expand Down