Added AppMatchPatterns provider to nav bar
Summary: This commit adds the match patterns that were parsed from the app into the nav bar. Planned for next commit: Alerting the user if they havn't filled in required parameters, and automatically excluding non-required parameters if not filled in. Reviewed By: danielbuechele Differential Revision: D16646774 fbshipit-source-id: 0f9130d659b6b635bfa1240dbd05c5956c6756ce
This commit is contained in:
committed by
Facebook Github Bot
parent
c3b266c925
commit
fe5df63d41
@@ -13,6 +13,8 @@ import type {Bookmark, PersistedState, URI} from '../flow-types';
|
||||
|
||||
function constructPersistedStateMock(): PersistedState {
|
||||
return {
|
||||
appMatchPatterns: [],
|
||||
appMatchPatternsProvider: new DefaultProvider(),
|
||||
bookmarksProvider: new DefaultProvider(),
|
||||
bookmarks: new Map<URI, Bookmark>(),
|
||||
navigationEvents: [],
|
||||
@@ -21,6 +23,8 @@ function constructPersistedStateMock(): PersistedState {
|
||||
|
||||
function constructPersistedStateMockWithEvents(): PersistedState {
|
||||
return {
|
||||
appMatchPatterns: [],
|
||||
appMatchPatternsProvider: new DefaultProvider(),
|
||||
bookmarksProvider: new DefaultProvider(),
|
||||
bookmarks: new Map<URI, Bookmark>(),
|
||||
navigationEvents: [
|
||||
|
||||
@@ -17,6 +17,8 @@ export type PersistedState = {|
|
||||
bookmarks: Map<URI, Bookmark>,
|
||||
navigationEvents: Array<NavigationEvent>,
|
||||
bookmarksProvider: AutoCompleteProvider,
|
||||
appMatchPatterns: Array<AppMatchPattern>,
|
||||
appMatchPatternsProvider: AutoCompleteProvider,
|
||||
|};
|
||||
|
||||
export type NavigationEvent = {|
|
||||
|
||||
@@ -20,9 +20,11 @@ import {
|
||||
writeBookmarkToDB,
|
||||
} from './util/indexedDB';
|
||||
import {
|
||||
appMatchPatternsToAutoCompleteProvider,
|
||||
bookmarksToAutoCompleteProvider,
|
||||
DefaultProvider,
|
||||
} from './util/autoCompleteProvider';
|
||||
import {getAppMatchPatterns} from './util/appMatchPatterns';
|
||||
|
||||
import type {
|
||||
State,
|
||||
@@ -41,6 +43,8 @@ export default class extends FlipperPlugin<State, {}, PersistedState> {
|
||||
navigationEvents: [],
|
||||
bookmarks: new Map<string, Bookmark>(),
|
||||
bookmarksProvider: new DefaultProvider(),
|
||||
appMatchPatterns: [],
|
||||
appMatchPatternsProvider: new DefaultProvider(),
|
||||
};
|
||||
|
||||
state = {
|
||||
@@ -73,6 +77,19 @@ export default class extends FlipperPlugin<State, {}, PersistedState> {
|
||||
};
|
||||
|
||||
componentDidMount = () => {
|
||||
const {selectedApp} = this.props;
|
||||
getAppMatchPatterns(selectedApp)
|
||||
.then(patterns => {
|
||||
this.props.setPersistedState({
|
||||
appMatchPatterns: patterns,
|
||||
appMatchPatternsProvider: appMatchPatternsToAutoCompleteProvider(
|
||||
patterns,
|
||||
),
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
/* Silently fail here. */
|
||||
});
|
||||
readBookmarksFromDB().then(bookmarks => {
|
||||
this.props.setPersistedState({
|
||||
bookmarks: bookmarks,
|
||||
@@ -128,9 +145,10 @@ export default class extends FlipperPlugin<State, {}, PersistedState> {
|
||||
const {
|
||||
bookmarks,
|
||||
bookmarksProvider,
|
||||
appMatchPatternsProvider,
|
||||
navigationEvents,
|
||||
} = this.props.persistedState;
|
||||
const autoCompleteProviders = [bookmarksProvider];
|
||||
const autoCompleteProviders = [bookmarksProvider, appMatchPatternsProvider];
|
||||
return (
|
||||
<ScrollableFlexColumn>
|
||||
<SearchBar
|
||||
|
||||
@@ -11,6 +11,7 @@ import type {
|
||||
Bookmark,
|
||||
AutoCompleteProvider,
|
||||
AutoCompleteLineItem,
|
||||
AppMatchPattern,
|
||||
} from '../flow-types';
|
||||
|
||||
export function DefaultProvider(): AutoCompleteProvider {
|
||||
@@ -33,6 +34,24 @@ export const bookmarksToAutoCompleteProvider: (
|
||||
return autoCompleteProvider;
|
||||
};
|
||||
|
||||
export const appMatchPatternsToAutoCompleteProvider = (
|
||||
appMatchPatterns: Array<AppMatchPattern>,
|
||||
) => {
|
||||
const autoCompleteProvider = {
|
||||
icon: 'mobile',
|
||||
matchPatterns: new Map<string, URI>(),
|
||||
};
|
||||
appMatchPatterns.forEach(appMatchPattern => {
|
||||
const matchPattern =
|
||||
appMatchPattern.className + ' - ' + appMatchPattern.pattern;
|
||||
autoCompleteProvider.matchPatterns.set(
|
||||
matchPattern,
|
||||
appMatchPattern.pattern,
|
||||
);
|
||||
});
|
||||
return (autoCompleteProvider: AutoCompleteProvider);
|
||||
};
|
||||
|
||||
export const filterMatchPatterns: (
|
||||
Map<string, URI>,
|
||||
string,
|
||||
@@ -70,7 +89,7 @@ export const filterProvidersToLineItems: (
|
||||
for (const provider of providers) {
|
||||
const filteredProvider = filterProvider(provider, query, itemsLeft);
|
||||
filteredProvider.matchPatterns.forEach((uri, matchPattern) => {
|
||||
lineItems.unshift({
|
||||
lineItems.push({
|
||||
icon: provider.icon,
|
||||
matchPattern,
|
||||
uri,
|
||||
|
||||
Reference in New Issue
Block a user