mirror of
https://github.com/DOI-DO/j40-cejst-2.git
synced 2025-08-07 03:34:18 -07:00
Parameterize zoom experiments (#339)
* Adding ability to set flags in url * parameterizing tile layers
This commit is contained in:
parent
6c8d71c5b9
commit
3cd6e06115
6 changed files with 188 additions and 163 deletions
|
@ -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));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue