-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Add flighting support (#2621)
- Loading branch information
Showing
13 changed files
with
134 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const ALWAYSSHOWBUTTONS = 'alwaysShowButtons'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* eslint-disable max-len */ | ||
import { VariantAssignmentRequest } from 'expvariantassignmentsdk/src/interfaces/VariantAssignmentRequest'; | ||
import {VariantAssignmentServiceClient} from 'expvariantassignmentsdk/src/contracts/VariantAssignmentServiceClient'; | ||
import { VariantAssignmentClientSettings } from 'expvariantassignmentsdk/src/contracts/VariantAssignmentClientSettings'; | ||
import { errorTypes, telemetry } from '../../telemetry'; | ||
import { readFromLocalStorage, saveToLocalStorage } from '../utils/local-storage'; | ||
import { EXP_URL } from './graph-constants'; | ||
import { SeverityLevel } from '@microsoft/applicationinsights-web'; | ||
|
||
|
||
interface TasResponse { | ||
Id: string; | ||
Parameters: Parameters; | ||
} | ||
interface Parameters { | ||
[key: string]: string | boolean | number; | ||
} | ||
class VariantService { | ||
|
||
private endpoint = EXP_URL; | ||
private expResponse: TasResponse[] | null = []; | ||
private assignmentContext: string = ''; | ||
|
||
public async initialize() { | ||
const settings: VariantAssignmentClientSettings = { endpoint: this.endpoint }; | ||
this.createUser(); | ||
const request: VariantAssignmentRequest = | ||
{ | ||
parameters: this.getParameters() | ||
}; | ||
|
||
const client = new VariantAssignmentServiceClient(settings); | ||
const response = await client.getVariantAssignments(request); | ||
Promise.resolve(response).then((r) => { | ||
if (r){ | ||
this.expResponse = r.featureVariables as TasResponse[] | null; | ||
this.assignmentContext = r.assignmentContext; | ||
} | ||
}) | ||
.catch((error) => { | ||
telemetry.trackException(new Error(errorTypes.UNHANDLED_ERROR), SeverityLevel.Error, error); | ||
}); | ||
} | ||
|
||
public createUser() { | ||
const userid = telemetry.getUserId(); | ||
saveToLocalStorage('userid', userid.toString()); | ||
} | ||
|
||
public getAssignmentContext() { | ||
return this.assignmentContext; | ||
} | ||
|
||
public async getFeatureVariables(namespace: string, flagname: string) { | ||
const defaultConfig = this.expResponse?.find(c => c.Id === namespace); | ||
return defaultConfig?.Parameters[flagname]; | ||
} | ||
|
||
// Parameters will include randomization units (you can have more than one in a single call!) | ||
// and audience filters like market/region, browser, ismsft etc., | ||
private getParameters(): Map<string, string[]> { | ||
const map: Map<string, string[]> = new Map<string, string[]>(); | ||
map.set('userid', [readFromLocalStorage('userid')]); | ||
return map; | ||
} | ||
} | ||
|
||
export default new VariantService(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export const saveToLocalStorage = (key: string, value: Object|string) => { | ||
if (typeof value === 'string') { | ||
localStorage.setItem(key, value); | ||
} else { | ||
localStorage.setItem(key, JSON.stringify(value)); | ||
} | ||
}; | ||
|
||
export const readFromLocalStorage = (key: string) => { | ||
const value = localStorage.getItem(key); | ||
|
||
if (value && typeof value === 'object') { | ||
return JSON.parse(value); | ||
} else{ | ||
return value; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { saveTheme, readTheme } from './theme-utils'; | ||
import { CURRENT_THEME } from '../app/services/graph-constants'; | ||
import { readFromLocalStorage, saveToLocalStorage } from '../app/utils/local-storage'; | ||
|
||
describe('Tests theme utils should', () => { | ||
it('save theme to local storage then retrieve the saved theme', () => { | ||
const theme = 'dark'; | ||
saveTheme(theme); | ||
expect(readTheme()).toEqual(theme); | ||
saveToLocalStorage(CURRENT_THEME,theme); | ||
expect(readFromLocalStorage(CURRENT_THEME)).toEqual(theme); | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.