Skip to content

Commit e4d8588

Browse files
authored
feat(region): Connect region components to store (#416)
1 parent 1336117 commit e4d8588

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+620
-187
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
"raw-loader": "^4.0.0",
127127
"react-immutable-proptypes": "^2.1.0",
128128
"react-process-string": "^1.2.0",
129+
"regenerator-runtime": "^0.13.5",
129130
"sass-loader": "^8.0.1",
130131
"style-loader": "^1.1.2",
131132
"stylelint": "^12.0.0",

scripts/jest/enzyme-adapter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'core-js/es/map';
22
import 'core-js/es/set';
33
import 'raf/polyfill';
4+
import 'regenerator-runtime/runtime';
45
import Enzyme, { mount, shallow } from 'enzyme';
56
import Adapter from 'enzyme-adapter-react-16';
67

src/@types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ import './global';
33
export * from './api';
44
export * from './i18n';
55
export * from './model';
6+
export * from './new';

src/@types/new.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Target } from './model';
2+
3+
export interface NewAnnotation {
4+
description?: NewReply;
5+
target: Target;
6+
}
7+
8+
export interface NewReply {
9+
message: string;
10+
type: 'reply';
11+
}

src/common/BaseManager.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ import { IntlShape } from 'react-intl';
22
import { Store } from 'redux';
33

44
export type Options = {
5-
page: string;
5+
page: number;
66
pageEl: HTMLElement;
77
referenceEl: HTMLElement;
88
};
99

1010
export type Props = {
11-
annotations: any[]; // eslint-disable-line @typescript-eslint/no-explicit-any
1211
intl: IntlShape;
1312
scale: number;
1413
store: Store;

src/components/AnnotationTarget/AnnotationTarget.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ const AnnotationTarget = (props: Props, ref: React.Ref<HTMLAnchorElement>): JSX.
3737

3838
// We use an anchor to allow the target to be used inside of SVG shapes where buttons aren't supported
3939
return (
40+
// eslint-disable-next-line jsx-a11y/anchor-is-valid
4041
<a
4142
ref={ref}
4243
className={classNames('ba-AnnotationTarget', className)}
44+
href="#" // Needed for IE11 to handle click events properly
4345
onClick={handleClick}
4446
onFocus={handleFocus}
4547
onKeyPress={handleKeyPress}

src/components/Popups/PopupBase.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ export default class PopupBase extends React.PureComponent<Props> {
5959
};
6060

6161
handleEvent = (event: React.SyntheticEvent): void => {
62-
event.preventDefault();
6362
event.stopPropagation();
6463
event.nativeEvent.stopImmediatePropagation();
6564
};

src/components/Popups/PopupReply.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ import './PopupReply.scss';
99

1010
export type Props = {
1111
className?: string;
12+
defaultValue?: string;
1213
onCancel: (text?: string) => void;
1314
onChange: (text?: string) => void;
1415
onSubmit: (text: string) => void;
1516
reference: HTMLElement;
1617
};
1718

18-
export default function PopupReply({ onCancel, onChange, onSubmit, ...rest }: Props): JSX.Element {
19+
export default function PopupReply({ defaultValue, onCancel, onChange, onSubmit, ...rest }: Props): JSX.Element {
1920
const [text, setText] = React.useState('');
2021
const textareaRef = React.useRef<HTMLTextAreaElement>(null);
2122

2223
// Event Handlers
2324
const handleEvent = (event: React.SyntheticEvent): void => {
24-
event.preventDefault();
2525
event.stopPropagation();
2626
event.nativeEvent.stopImmediatePropagation();
2727
};
@@ -46,8 +46,14 @@ export default function PopupReply({ onCancel, onChange, onSubmit, ...rest }: Pr
4646
onCancel(text);
4747
};
4848
const handleFirstUpdate = (): void => {
49-
if (textareaRef.current) {
50-
textareaRef.current.focus();
49+
const { current: textarea } = textareaRef;
50+
51+
if (textarea) {
52+
const { value } = textarea;
53+
54+
textarea.focus();
55+
textarea.selectionStart = value.length; // Force cursor to the end after focus
56+
textarea.selectionEnd = value.length; // Force cursor to the end after focus
5157
}
5258
};
5359

@@ -58,6 +64,7 @@ export default function PopupReply({ onCancel, onChange, onSubmit, ...rest }: Pr
5864
ref={textareaRef}
5965
className="ba-Popup-text"
6066
data-testid="ba-Popup-text"
67+
defaultValue={defaultValue}
6168
onChange={handleChange}
6269
onClick={handleEvent}
6370
/>

src/components/Popups/__tests__/PopupBase-test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ describe('PopupBase', () => {
3131
wrapper.simulate(event, mockEvent);
3232

3333
expect(mockEvent.nativeEvent.stopImmediatePropagation).toHaveBeenCalled();
34-
expect(mockEvent.preventDefault).toHaveBeenCalled();
3534
expect(mockEvent.stopPropagation).toHaveBeenCalled();
3635
},
3736
);

src/components/Popups/__tests__/PopupReply-test.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ describe('PopupReply', () => {
4747
button.simulate('click', mockEvent);
4848

4949
expect(mockEvent.nativeEvent.stopImmediatePropagation).toHaveBeenCalled();
50-
expect(mockEvent.preventDefault).toHaveBeenCalled();
5150
expect(mockEvent.stopPropagation).toHaveBeenCalled();
5251
expect(defaults[callback]).toHaveBeenCalled();
5352
});
@@ -63,7 +62,6 @@ describe('PopupReply', () => {
6362
wrapper.simulate('keyDown', { ...mockEvent, key });
6463

6564
expect(mockEvent.nativeEvent.stopImmediatePropagation).toHaveBeenCalledTimes(callCount);
66-
expect(mockEvent.preventDefault).toHaveBeenCalledTimes(callCount);
6765
expect(mockEvent.stopPropagation).toHaveBeenCalledTimes(callCount);
6866
expect(defaults.onCancel).toHaveBeenCalledTimes(callCount);
6967
});

0 commit comments

Comments
 (0)