From df725de674ccca7027fb64ec2e21aa74b7082932 Mon Sep 17 00:00:00 2001 From: Benjamin Elo Date: Thu, 18 Jul 2019 08:10:41 -0700 Subject: [PATCH] Added NavigationInfoBox component Summary: Here I added an info box to display the info of the incoming navigation events. The component is currently missing interaction (navigating to uris and favoriting), but I will add that in my next diff. While I was here, I modified the component file structure a tiny bit to make importing components easier. Reviewed By: jknoxville Differential Revision: D16357204 fbshipit-source-id: 70b137e052181559a2fda02b091a71e54cb1ade0 --- .../components/NavigationInfoBox.js | 70 +++++++++++++++++++ .../navigation/components/SearchBar.js | 2 +- src/plugins/navigation/components/index.js | 11 +++ src/plugins/navigation/index.js | 2 +- src/plugins/navigation/util/uri.js | 25 +++++++ 5 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 src/plugins/navigation/components/NavigationInfoBox.js create mode 100644 src/plugins/navigation/components/index.js create mode 100644 src/plugins/navigation/util/uri.js diff --git a/src/plugins/navigation/components/NavigationInfoBox.js b/src/plugins/navigation/components/NavigationInfoBox.js new file mode 100644 index 000000000..c4310c5b9 --- /dev/null +++ b/src/plugins/navigation/components/NavigationInfoBox.js @@ -0,0 +1,70 @@ +/** + * Copyright 2018-present Facebook. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * @format + * @flow strict-local + */ + +import {styled} from 'flipper'; +import {parseURIParameters} from '../util/uri'; + +type Props = {| + uri: ?string, + onNavigate: (query: string) => void, + onFavorite: (query: string) => void, +|}; + +const NavigationInfoBoxContainer = styled('div')({ + backgroundColor: '#FDFDEA', + maxWidth: 500, + height: 'fit-content', + padding: 20, + borderRadius: 10, + margin: 20, + width: 'fit-content', + position: 'relative', + '.nav-info-text': { + color: '#707070', + fontSize: '1.2em', + lineHeight: '1.25em', + }, + '.nav-info-text.bold': { + fontWeight: 'bold', + marginTop: '10px', + }, + '.nav-info-text.selectable': { + userSelect: 'text', + cursor: 'text', + }, +}); + +export default (props: Props) => { + const {uri} = props; + if (uri == null) { + return ( + +
View has no URI information
+
+ ); + } else { + const parameters = parseURIParameters(uri); + return ( + +
uri:
+
{uri}
+ {parameters.size > 0 ? ( + <> +
parameters:
+ {Array.from(parameters, ([key, value]) => ( +
+ {key} + {value ? `: ${value}` : ''} +
+ ))} + + ) : null} +
+ ); + } +}; diff --git a/src/plugins/navigation/components/SearchBar.js b/src/plugins/navigation/components/SearchBar.js index 2bfb15a32..abe5654a7 100644 --- a/src/plugins/navigation/components/SearchBar.js +++ b/src/plugins/navigation/components/SearchBar.js @@ -14,7 +14,7 @@ import { Toolbar, Glyph, } from 'flipper'; -import SearchBarButton from './SearchBarButton'; +import {SearchBarButton} from './'; type Props = {| onFavorite: (query: string) => void, diff --git a/src/plugins/navigation/components/index.js b/src/plugins/navigation/components/index.js new file mode 100644 index 000000000..5fb0c608f --- /dev/null +++ b/src/plugins/navigation/components/index.js @@ -0,0 +1,11 @@ +/** + * Copyright 2018-present Facebook. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * @format + * @flow strict-local + */ + +export {default as NavigationInfoBox} from './NavigationInfoBox'; +export {default as SearchBar} from './SearchBar'; +export {default as SearchBarButton} from './SearchBarButton'; diff --git a/src/plugins/navigation/index.js b/src/plugins/navigation/index.js index f0835e293..cee9fef80 100644 --- a/src/plugins/navigation/index.js +++ b/src/plugins/navigation/index.js @@ -7,7 +7,7 @@ */ import {FlipperPlugin, FlexColumn} from 'flipper'; -import SearchBar from './components/SearchBar'; +import {SearchBar} from './components'; type State = {||}; diff --git a/src/plugins/navigation/util/uri.js b/src/plugins/navigation/util/uri.js new file mode 100644 index 000000000..bd4262489 --- /dev/null +++ b/src/plugins/navigation/util/uri.js @@ -0,0 +1,25 @@ +/** + * Copyright 2018-present Facebook. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * @format + * @flow strict-local + */ + +import querystring from 'querystring'; + +export const parseURIParameters: string => Map = ( + query: string, +) => { + // get parameters from query string and store in Map + const parameters = query + .split('?') + .splice(1) + .join(''); + const parametersObj = querystring.parse(parameters); + const parametersMap = new Map(); + for (const key in parametersObj) { + parametersMap.set(key, parametersObj[key]); + } + return parametersMap; +};