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:
Michel Weststrate
2020-11-12 04:13:16 -08:00
committed by Facebook GitHub Bot
parent 5118727cb7
commit 273b895e30
8 changed files with 171 additions and 185 deletions

View File

@@ -41,6 +41,7 @@ import {
useValue,
usePlugin,
Layout,
renderReactRoot,
} from 'flipper-plugin';
export type State = {
@@ -71,8 +72,6 @@ export function plugin(client: PluginClient<Events, Methods>) {
persist: 'appMatchPatterns',
});
const currentURI = createState('');
const shouldShowURIErrorDialog = createState(false);
const requiredParameters = createState<string[]>([]);
const shouldShowSaveBookmarkDialog = createState(false);
const saveBookmarkURI = createState<null | string>(null);
@@ -131,13 +130,18 @@ export function plugin(client: PluginClient<Events, Methods>) {
);
}
} else {
requiredParameters.set(params);
shouldShowURIErrorDialog.set(true);
renderReactRoot((unmount) => (
<RequiredParametersDialog
onHide={unmount}
uri={filteredQuery}
requiredParameters={params}
onSubmit={navigateTo}
/>
));
}
}
function onFavorite(uri: string) {
// TODO: why does this need a dialog?
shouldShowSaveBookmarkDialog.set(true);
saveBookmarkURI.set(uri);
}
@@ -169,11 +173,29 @@ export function plugin(client: PluginClient<Events, Methods>) {
bookmarks,
saveBookmarkURI,
shouldShowSaveBookmarkDialog,
shouldShowURIErrorDialog,
requiredParameters,
appMatchPatterns,
navigationEvents,
currentURI,
getAutoCompleteAppMatchPatterns(
query: string,
bookmarks: Map<string, Bookmark>,
appMatchPatterns: AppMatchPattern[],
limit: number,
): AppMatchPattern[] {
const q = query.toLowerCase();
const results: AppMatchPattern[] = [];
for (const item of appMatchPatterns) {
if (
!bookmarks.has(item.pattern) &&
(item.className.toLowerCase().includes(q) ||
item.pattern.toLowerCase().includes(q))
) {
results.push(item);
if (--limit < 1) break;
}
}
return results;
},
};
}
@@ -185,8 +207,6 @@ export function Component() {
const shouldShowSaveBookmarkDialog = useValue(
instance.shouldShowSaveBookmarkDialog,
);
const shouldShowURIErrorDialog = useValue(instance.shouldShowURIErrorDialog);
const requiredParameters = useValue(instance.requiredParameters);
const currentURI = useValue(instance.currentURI);
const navigationEvents = useValue(instance.navigationEvents);
@@ -227,15 +247,6 @@ export function Component() {
onSubmit={instance.addBookmark}
onRemove={instance.removeBookmark}
/>
<RequiredParametersDialog
shouldShow={shouldShowURIErrorDialog}
onHide={() => {
instance.shouldShowURIErrorDialog.set(false);
}}
uri={currentURI}
requiredParameters={requiredParameters}
onSubmit={instance.navigateTo}
/>
</Layout.Container>
);
}