Parameterize zoom experiments (#339)

* Adding ability to set flags in url
* parameterizing tile layers
This commit is contained in:
Nat Hillard 2021-07-14 11:26:12 -04:00 committed by GitHub
commit 3cd6e06115
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 188 additions and 163 deletions

View file

@ -1,6 +1,8 @@
import * as React from 'react';
import * as queryString from 'query-string';
export type FlagContainer = { [key: string]: any };
/**
* FlagContext stores feature flags and passes them to consumers
*/
@ -8,7 +10,7 @@ import * as queryString from 'query-string';
/**
* Contains a list of all currently-active flags
*/
flags: string[];
flags: FlagContainer;
}
const FlagContext = React.createContext<IFlagContext>({flags: []});
@ -16,9 +18,9 @@ const FlagContext = React.createContext<IFlagContext>({flags: []});
/**
* `useFlags` returns all feature flags.
*
* @return {Flags[]} flags All project feature flags
* @return {FlagContainer} flags All project feature flags
*/
const useFlags = () : string[] => {
const useFlags = () : FlagContainer => {
const {flags} = React.useContext(FlagContext);
return flags;
};
@ -39,9 +41,18 @@ interface IURLFlagProviderProps {
**/
const URLFlagProvider = ({children, location}: IURLFlagProviderProps) => {
const flagString = queryString.parse(location.search).flags;
let flags: string[] = [];
const flags : FlagContainer = {};
let flagList: string[] = [];
if (flagString && typeof flagString === 'string') {
flags = (flagString as string).split(',');
flagList = (flagString as string).split(',');
}
for (const flag of flagList) {
if (flag.includes('=')) {
const [key, value] = flag.split('=');
flags[key] = value;
} else {
flags[flag] = true;
}
}
console.log(JSON.stringify(location), JSON.stringify(flags));