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

Make markdown modal faster (e.g., editing of annotation description) #7769

Merged
merged 3 commits into from
Apr 24, 2024
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 @@ -24,6 +24,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
- When proofreading segments and merging two segments, the segment item that doesn't exist anymore after the merge is automatically removed. [#7729](https://github.com/scalableminds/webknossos/pull/7729)
- Changed some internal APIs to use spelling dataset instead of dataSet. This requires all connected datastores to be the latest version. [#7690](https://github.com/scalableminds/webknossos/pull/7690)
- Toasts are shown until WEBKNOSSOS is running in the active browser tab again. Also, the content of most toasts that show errors or warnings is printed to the browser's console. [#7741](https://github.com/scalableminds/webknossos/pull/7741)
- Improved UI speed when editing the description of an annotation. [#7769](https://github.com/scalableminds/webknossos/pull/7769)

### Fixed
- Fixed that the Command modifier on MacOS wasn't treated correctly for some shortcuts. Also, instead of the Alt key, the ⌥ key is shown as a hint in the status bar on MacOS. [#7659](https://github.com/scalableminds/webknossos/pull/7659)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,20 @@ class EditableTextLabel extends React.PureComponent<EditableTextLabelProp, State
}
}

handleInputChange = (event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => {
handleInputChangeFromEvent = (
Copy link
Member

Choose a reason for hiding this comment

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

Why does the component have two change handlers? Just for type safety?

Copy link
Member Author

Choose a reason for hiding this comment

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

The component can use the MarkdownModal as well as the usual Input component. Since I changed the MarkdownModal to not use the event parameter anymore, the parent component now needs both variants. It's a bit unfortunate, but still the best trade-off in my opinion.

event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>,
) => {
this.setState({
value: event.target.value,
});
};

handleInputChange = (newValue: string) => {
this.setState({
value: newValue,
});
};

handleOnChange = () => {
const validateAndUpdateValue = () => {
if (this.validateFields()) {
Expand Down Expand Up @@ -120,7 +128,7 @@ class EditableTextLabel extends React.PureComponent<EditableTextLabelProp, State
const margin = this.props.margin != null ? this.props.margin : "0 10px";
const inputComponentProps: InputProps = {
value: this.state.value,
onChange: this.handleInputChange,
onChange: this.handleInputChangeFromEvent,
onPressEnter: this.handleOnChange,
style: {
width: this.props.width != null ? this.props.width : "60%",
Expand Down
25 changes: 19 additions & 6 deletions frontend/javascripts/oxalis/view/components/markdown_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,32 @@ export function MarkdownModal({
isOpen?: boolean;
placeholder?: string;
onOk: () => void;
onChange: React.ChangeEventHandler<HTMLTextAreaElement>;
onChange: (newValue: string) => void;
}) {
const placeholderText = placeholder ? placeholder : `Add ${label}`;
const [currentValue, setCurrentValue] = React.useState(source);

const onConfirm = () => {
onChange(currentValue);
onOk();
};

const setCurrentValueFromEvent = (
event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>,
) => {
setCurrentValue(event.target.value);
};

return (
<Modal
key="comment-markdown-modal"
title={<span>{`Edit ${label}`}</span>}
open={isOpen}
onCancel={onOk}
closable={false}
closable={true}
width={700}
footer={[
<Button key="back" onClick={onOk}>
<Button key="back" onClick={onConfirm}>
Ok
</Button>,
]}
Expand All @@ -71,9 +84,9 @@ export function MarkdownModal({
<Row gutter={16}>
<Col span={12}>
<Input.TextArea
defaultValue={source}
defaultValue={currentValue}
placeholder={placeholderText}
onChange={onChange}
onChange={setCurrentValueFromEvent}
rows={5}
autoSize={{
minRows: 5,
Expand All @@ -88,7 +101,7 @@ export function MarkdownModal({
overflowY: "auto",
}}
>
<MarkdownWrapper source={source} />
<MarkdownWrapper source={currentValue} />
</Col>
</Row>
</Modal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,7 @@ class CommentTabView extends React.Component<PropsWithSkeleton, CommentTabState>
this.nextComment(false);
};

handleChangeInput = (
evt: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
insertLineBreaks: boolean = false,
) => {
// @ts-ignore
const commentText = evt.target.value;

handleChangeInput = (commentText: string, insertLineBreaks: boolean = false) => {
if (commentText) {
this.props.createComment(insertLineBreaks ? commentText.replace(/\\n/g, "\n") : commentText);
} else {
Expand Down Expand Up @@ -466,7 +460,7 @@ class CommentTabView extends React.Component<PropsWithSkeleton, CommentTabState>
: messages["tracing.read_only_mode_notification"]
}
onChange={(evt: React.ChangeEvent<HTMLInputElement>) =>
this.handleChangeInput(evt, true)
this.handleChangeInput(evt.target.value, true)
}
onPressEnter={(evt: React.KeyboardEvent<HTMLInputElement>) =>
(evt.target as HTMLElement).blur()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Tooltip, Typography, Tag } from "antd";
import { SettingOutlined, InfoCircleOutlined, EditOutlined } from "@ant-design/icons";
import { connect } from "react-redux";
import Markdown from "react-remarkable";
import React, { CSSProperties, ChangeEvent } from "react";
import React, { CSSProperties } from "react";
import { Link } from "react-router-dom";
import type { APIDataset, APIUser } from "types/api_flow_types";
import { ControlModeEnum } from "oxalis/constants";
Expand Down Expand Up @@ -278,10 +278,6 @@ export class DatasetInfoTabView extends React.PureComponent<Props, State> {
this.props.setAnnotationName(newName);
};

setAnnotationDescription = (evt: ChangeEvent<HTMLTextAreaElement>) => {
this.props.setAnnotationDescription(evt.target.value);
};

componentDidMount(): void {
this.fetchData();
}
Expand Down Expand Up @@ -500,7 +496,7 @@ export class DatasetInfoTabView extends React.PureComponent<Props, State> {
source={this.props.annotation.description}
isOpen={this.state.isMarkdownModalOpen}
onOk={() => this.setState({ isMarkdownModalOpen: false })}
onChange={this.setAnnotationDescription}
onChange={this.props.setAnnotationDescription}
/>
</div>
);
Expand Down