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

Slim down view mode dropdown by using icons #6900

Merged
merged 6 commits into from
Mar 6, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released

### Changed
- Upgraded antd UI library to v4.24.8 [#6865](https://github.com/scalableminds/webknossos/pull/6865)
- The view mode dropdown was slimmed down by using icons to make the toolbar more space efficient. [#6900](https://github.com/scalableminds/webknossos/pull/6900)

### Fixed
- Fixed a bug where N5 datasets reading with end-chunks that have a chunk size differing from the metadata-supplied chunk size would fail for some areas. [#6890](https://github.com/scalableminds/webknossos/pull/6890)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Props = {
};
const positionIconStyle: React.CSSProperties = {
transform: "rotate(-45deg)",
marginRight: 0,
};
const warningColors: React.CSSProperties = {
color: "rgb(255, 155, 85)",
Expand Down
67 changes: 47 additions & 20 deletions frontend/javascripts/oxalis/view/action-bar/view_modes_view.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Select } from "antd";
import { Button, Dropdown, MenuProps, Space } from "antd";
import { connect } from "react-redux";
import type { Dispatch } from "redux";
import React, { PureComponent } from "react";
Expand All @@ -9,9 +9,9 @@ import {
import type { OxalisState, AllowedMode } from "oxalis/store";
import Store from "oxalis/store";
import * as Utils from "libs/utils";
import type { ViewMode } from "oxalis/constants";
import { ViewMode, ViewModeValues } from "oxalis/constants";
import constants from "oxalis/constants";
const { Option } = Select;

type StateProps = {
viewMode: ViewMode;
allowedModes: Array<AllowedMode>;
Expand All @@ -21,6 +21,17 @@ type DispatchProps = {
};
type Props = StateProps & DispatchProps;

const VIEW_MODE_TO_ICON = {
[constants.MODE_PLANE_TRACING]: <i className="fas fa-th-large without-icon-margin" />,
[constants.MODE_ARBITRARY]: <i className="fas fa-globe without-icon-margin" />,
[constants.MODE_ARBITRARY_PLANE]: (
<i
className="fas fa-square-full without-icon-margin"
style={{ transform: "scale(0.8, 1) rotate(-45deg)" }}
/>
),
};

class ViewModesView extends PureComponent<Props, {}> {
handleChange = (mode: ViewMode) => {
// If we switch back from any arbitrary mode we stop recording.
Expand Down Expand Up @@ -51,24 +62,40 @@ class ViewModesView extends PureComponent<Props, {}> {
}

render() {
const handleMenuClick: MenuProps["onClick"] = (args) => {
if (ViewModeValues.includes(args.key as ViewMode)) {
this.handleChange(args.key as ViewMode);
}
};

const MENU_ITEMS: MenuProps["items"] = [
{
key: "1",
type: "group",
label: "Select View Mode",
children: ViewModeValues.map((mode) => ({
label: Utils.capitalize(mode),
key: mode,
disabled: this.isDisabled(mode),
icon: <span style={{ marginRight: 8 }}>{VIEW_MODE_TO_ICON[mode]}</span>,
})),
},
];

const menuProps = {
items: MENU_ITEMS,
onClick: handleMenuClick,
};

return (
<Select
value={this.props.viewMode}
style={{
width: 120,
}}
onChange={this.handleChange}
>
{[
constants.MODE_PLANE_TRACING,
constants.MODE_ARBITRARY,
constants.MODE_ARBITRARY_PLANE,
].map((mode) => (
<Option key={mode} disabled={this.isDisabled(mode)} value={mode}>
Copy link
Member

Choose a reason for hiding this comment

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

What happened to the disabled prop? The new dropdown will always show all the modes, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, very good point 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed now!

{Utils.capitalize(mode)}
</Option>
))}
</Select>
// The outer div is necessary for proper spacing.
<div>
<Dropdown menu={menuProps}>
<Button>
<Space>{VIEW_MODE_TO_ICON[this.props.viewMode]}</Space>
</Button>
</Dropdown>
</div>
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"@airbrake/browser": "^2.1.7",
"@ant-design/colors": "^6.0.0",
"@ant-design/icons": "^4.6.2",
"@fortawesome/fontawesome-free": "^5.14.0",
"@fortawesome/fontawesome-free": "^5.15.4",
"@rehooks/document-title": "^1.0.2",
"@scalableminds/prop-types": "^15.6.1",
"@tanstack/query-sync-storage-persister": "^4.14.1",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,10 @@
minimatch "^3.0.4"
strip-json-comments "^3.1.1"

"@fortawesome/fontawesome-free@^5.14.0":
version "5.15.1"
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-free/-/fontawesome-free-5.15.1.tgz#ccfef6ddbe59f8fe8f694783e1d3eb88902dc5eb"
integrity sha512-OEdH7SyC1suTdhBGW91/zBfR6qaIhThbcN8PUXtXilY4GYnSBbVqOntdHbC1vXwsDnX0Qix2m2+DSU1J51ybOQ==
"@fortawesome/fontawesome-free@^5.15.4":
version "5.15.4"
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-free/-/fontawesome-free-5.15.4.tgz#ecda5712b61ac852c760d8b3c79c96adca5554e5"
integrity sha512-eYm8vijH/hpzr/6/1CJ/V/Eb1xQFW2nnUKArb3z+yUWv7HTwj6M7SP957oMjfZjAHU6qpoNc2wQvIxBLWYa/Jg==

"@humanwhocodes/config-array@^0.9.2":
version "0.9.5"
Expand Down