Support auto completion on discovered bookmarks and filling out params
Summary: This diff adds support for finding appPatterns (not sure how the feature is called) in the device, and auto completing on it. Also improved the styling of bookmark sections. This diff also adds support of showing a dialog in which params an be filled out if needed. The behavior around optional arguments seems buggy, as in, no dialog will show up, but since I didn't want to change the logic around this unilaterally, left it as-is for now. Updated the dialog to Ant so that the renderReactRoot utility could be used safely Reviewed By: cekkaewnumchai Differential Revision: D24889855 fbshipit-source-id: 6af264abec2e9e5b921ef7da6deb1d0021615e9e
This commit is contained in:
committed by
Facebook GitHub Bot
parent
5118727cb7
commit
273b895e30
@@ -8,14 +8,18 @@
|
||||
*/
|
||||
|
||||
import React, {useCallback, useMemo} from 'react';
|
||||
import {AutoComplete, Input} from 'antd';
|
||||
import {AutoComplete, Input, Typography} from 'antd';
|
||||
import {StarFilled, StarOutlined} from '@ant-design/icons';
|
||||
import {useStore} from '../../utils/useStore';
|
||||
import {NUX, useValue} from 'flipper-plugin';
|
||||
import {Layout, NUX, useValue} from 'flipper-plugin';
|
||||
import {navPluginStateSelector} from '../../chrome/LocationsButton';
|
||||
|
||||
// eslint-disable-next-line flipper/no-relative-imports-across-packages
|
||||
import type {NavigationPlugin} from '../../../../plugins/navigation/index';
|
||||
import {useMemoize} from '../../utils/useMemoize';
|
||||
import styled from '@emotion/styled';
|
||||
|
||||
const {Text} = Typography;
|
||||
|
||||
export function BookmarkSection() {
|
||||
const navPlugin = useStore(navPluginStateSelector);
|
||||
@@ -32,15 +36,22 @@ export function BookmarkSection() {
|
||||
function BookmarkSectionInput({navPlugin}: {navPlugin: NavigationPlugin}) {
|
||||
const currentURI = useValue(navPlugin.currentURI);
|
||||
const bookmarks = useValue(navPlugin.bookmarks);
|
||||
const patterns = useValue(navPlugin.appMatchPatterns);
|
||||
|
||||
const isBookmarked = useMemo(() => bookmarks.has(currentURI), [
|
||||
bookmarks,
|
||||
currentURI,
|
||||
]);
|
||||
|
||||
const autoCompleteItems = useMemoize(
|
||||
navPlugin.getAutoCompleteAppMatchPatterns,
|
||||
[currentURI, bookmarks, patterns, 20],
|
||||
);
|
||||
|
||||
const handleBookmarkClick = useCallback(() => {
|
||||
if (isBookmarked) {
|
||||
navPlugin.removeBookmark(currentURI);
|
||||
} else {
|
||||
} else if (currentURI) {
|
||||
navPlugin.addBookmark({
|
||||
uri: currentURI,
|
||||
commonName: null,
|
||||
@@ -55,15 +66,31 @@ function BookmarkSectionInput({navPlugin}: {navPlugin: NavigationPlugin}) {
|
||||
);
|
||||
|
||||
return (
|
||||
<AutoComplete
|
||||
<StyledAutoComplete
|
||||
dropdownMatchSelectWidth={500}
|
||||
value={currentURI}
|
||||
onSelect={navPlugin.navigateTo}
|
||||
options={Array.from(bookmarks.values()).map((bookmark) => ({
|
||||
value: bookmark.uri,
|
||||
label: bookmark.commonName
|
||||
? `${bookmark.commonName} - ${bookmark.uri}`
|
||||
: bookmark.uri,
|
||||
}))}>
|
||||
style={{flex: 1}}
|
||||
options={[
|
||||
{
|
||||
label: <Text strong>Bookmarks</Text>,
|
||||
options: Array.from(bookmarks.values()).map((bookmark) => ({
|
||||
value: bookmark.uri,
|
||||
label: (
|
||||
<NavigationEntry label={bookmark.commonName} uri={bookmark.uri} />
|
||||
),
|
||||
})),
|
||||
},
|
||||
{
|
||||
label: <Text strong>Entry points</Text>,
|
||||
options: autoCompleteItems.map((value) => ({
|
||||
value: value.pattern,
|
||||
label: (
|
||||
<NavigationEntry label={value.className} uri={value.pattern} />
|
||||
),
|
||||
})),
|
||||
},
|
||||
]}>
|
||||
<Input
|
||||
addonAfter={bookmarkButton}
|
||||
defaultValue="<select a bookmark>"
|
||||
@@ -71,10 +98,27 @@ function BookmarkSectionInput({navPlugin}: {navPlugin: NavigationPlugin}) {
|
||||
onChange={(e) => {
|
||||
navPlugin.currentURI.set(e.target.value);
|
||||
}}
|
||||
onPressEnter={(e) => {
|
||||
onPressEnter={() => {
|
||||
navPlugin.navigateTo(currentURI);
|
||||
}}
|
||||
/>
|
||||
</AutoComplete>
|
||||
</StyledAutoComplete>
|
||||
);
|
||||
}
|
||||
|
||||
function NavigationEntry({label, uri}: {label: string | null; uri: string}) {
|
||||
return (
|
||||
<Layout.Container>
|
||||
<Text>{label ?? uri}</Text>
|
||||
<Text type="secondary">{uri}</Text>
|
||||
</Layout.Container>
|
||||
);
|
||||
}
|
||||
|
||||
const StyledAutoComplete = styled(AutoComplete)({
|
||||
display: 'flex',
|
||||
flex: 1,
|
||||
'.ant-select-selector': {
|
||||
flex: 1,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user