Automatically filtler out optional parameters from uri
Summary: When a user enters a uri with optional parameters in the nav bar, I chose to automatically filter these out, yet still show the parameters in the nav bar. The device receive uri's with no optional parameters, but the user will still see the parameters in the UI. Reviewed By: danielbuechele Differential Revision: D16762529 fbshipit-source-id: e3bbdf886dca7fba793b140b5fb303c4a77926ba
This commit is contained in:
committed by
Facebook Github Bot
parent
9c80021d7c
commit
c4a89da960
@@ -10,6 +10,7 @@ import {
|
||||
getRequiredParameters,
|
||||
parameterIsNumberType,
|
||||
replaceRequiredParametersWithValues,
|
||||
filterOptionalParameters,
|
||||
} from '../util/uri';
|
||||
|
||||
test('parse required parameters from uri', () => {
|
||||
@@ -52,3 +53,11 @@ test('detect if required parameter is numeric type', () => {
|
||||
test('detect if required parameter is not numeric type', () => {
|
||||
expect(parameterIsNumberType('{numerictype}')).toBe(false);
|
||||
});
|
||||
|
||||
test('filter optional parameters from uri', () => {
|
||||
const testURI =
|
||||
'fb://test_uri/{?param_here}/?parameter1={parameter1}¶meter2={?parameter2}&numericParameter={#numericParameter}¶meter3={?parameter3}';
|
||||
const expextedResult =
|
||||
'fb://test_uri/?parameter1={parameter1}&numericParameter={#numericParameter}';
|
||||
expect(filterOptionalParameters(testURI)).toBe(expextedResult);
|
||||
});
|
||||
|
||||
@@ -26,7 +26,7 @@ import {
|
||||
DefaultProvider,
|
||||
} from './util/autoCompleteProvider';
|
||||
import {getAppMatchPatterns} from './util/appMatchPatterns';
|
||||
import {getRequiredParameters} from './util/uri';
|
||||
import {getRequiredParameters, filterOptionalParameters} from './util/uri';
|
||||
|
||||
import type {
|
||||
State,
|
||||
@@ -114,7 +114,7 @@ export default class extends FlipperPlugin<State, {}, PersistedState> {
|
||||
const requiredParameters = getRequiredParameters(query);
|
||||
if (requiredParameters.length === 0) {
|
||||
this.getDevice().then(device => {
|
||||
device.navigateToLocation(query);
|
||||
device.navigateToLocation(filterOptionalParameters(query));
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
|
||||
import querystring from 'querystring';
|
||||
|
||||
export const filterOptionalParameters: string => string = (uri: string) => {
|
||||
return uri.replace(/[/&]?([^&?={}\/]*=)?{\?.*?}/g, '');
|
||||
};
|
||||
|
||||
export const parseURIParameters: string => Map<string, string> = (
|
||||
query: string,
|
||||
) => {
|
||||
|
||||
Reference in New Issue
Block a user