@samitouri / QOS-React-2 / commits / 0eac01abcd

Added missing Flow type coverage to DevTools context menu (#17733)

The param should probably be a generic type, but I'm not sure how to satisfy Flow with the current top-level Map. At least this adds basic coverage (which was missing before, oops).

Brian Vaughn committed Dec 29, 2019 at 08:44 UTC 0eac01abcd44579db03821347f103c816cd55372
4 files changed +55 -9
packages/react-devtools-shared/src/devtools/ContextMenu/ContextMenu.js
+11 -2
@@ -1,3 +1,12 @@
1 +/**
2 + * Copyright (c) Facebook, Inc. and its affiliates.
3 + *
4 + * This source code is licensed under the MIT license found in the
5 + * LICENSE file in the root directory of this source tree.
6 + *
7 + * @flow
8 + */
9 +
10 import React, {
11 useContext,
12 useEffect,
@@ -10,7 +19,7 @@ import {RegistryContext} from './Contexts';
19
20 import styles from './ContextMenu.css';
21
13 -function respositionToFit(element, pageX, pageY) {
22 +function respositionToFit(element: HTMLElement, pageX: number, pageY: number) {
23 const ownerWindow = element.ownerDocument.defaultView;
24 if (element !== null) {
25 if (pageY + element.offsetHeight >= ownerWindow.innerHeight) {
@@ -43,7 +52,7 @@ const HIDDEN_STATE = {
52 };
53
54 type Props = {|
46 - children: React$Node,
55 + children: (data: Object) => React$Node,
56 id: string,
57 |};
58
packages/react-devtools-shared/src/devtools/ContextMenu/ContextMenuItem.js
+10 -1
@@ -1,3 +1,12 @@
1 +/**
2 + * Copyright (c) Facebook, Inc. and its affiliates.
3 + *
4 + * This source code is licensed under the MIT license found in the
5 + * LICENSE file in the root directory of this source tree.
6 + *
7 + * @flow
8 + */
9 +
10 import React, {useContext} from 'react';
11 import {RegistryContext} from './Contexts';
12
@@ -5,7 +14,7 @@ import styles from './ContextMenuItem.css';
14
15 type Props = {|
16 children: React$Node,
8 - onClick: Object => void,
17 + onClick: () => void,
18 title: string,
19 |};
20
packages/react-devtools-shared/src/devtools/ContextMenu/Contexts.js
+14 -5
@@ -1,10 +1,19 @@
1 +/**
2 + * Copyright (c) Facebook, Inc. and its affiliates.
3 + *
4 + * This source code is licensed under the MIT license found in the
5 + * LICENSE file in the root directory of this source tree.
6 + *
7 + * @flow
8 + */
9 +
10 import {createContext} from 'react';
11
3 -export type ShowFn = ({data: Object, pageX: number, pageY: number}) => void;
12 +export type ShowFn = ({|data: Object, pageX: number, pageY: number|}) => void;
13 export type HideFn = () => void;
14
6 -const idToShowFnMap = new Map();
7 -const idToHideFnMap = new Map();
15 +const idToShowFnMap = new Map<string, ShowFn>();
16 +const idToHideFnMap = new Map<string, HideFn>();
17
18 let currentHideFn = null;
19
@@ -41,8 +50,8 @@ function registerMenu(id: string, showFn: ShowFn, hideFn: HideFn) {
50 idToHideFnMap.set(id, hideFn);
51
52 return function unregisterMenu() {
44 - idToShowFnMap.delete(id, showFn);
45 - idToHideFnMap.delete(id, hideFn);
53 + idToShowFnMap.delete(id);
54 + idToHideFnMap.delete(id);
55 };
56 }
57
packages/react-devtools-shared/src/devtools/ContextMenu/useContextMenu.js
+20 -1
@@ -1,7 +1,26 @@
1 +/**
2 + * Copyright (c) Facebook, Inc. and its affiliates.
3 + *
4 + * This source code is licensed under the MIT license found in the
5 + * LICENSE file in the root directory of this source tree.
6 + *
7 + * @flow
8 + */
9 +
10 import {useContext, useEffect} from 'react';
11 import {RegistryContext} from './Contexts';
12
4 -export default function useContextMenu({data, id, ref}) {
13 +import type {ElementRef} from 'react';
14 +
15 +export default function useContextMenu({
16 + data,
17 + id,
18 + ref,
19 +}: {|
20 + data: Object,
21 + id: string,
22 + ref: ElementRef<HTMLElement>,
23 +|}) {
24 const {showMenu} = useContext(RegistryContext);
25
26 useEffect(