Skip to content

Commit

Permalink
Merge pull request #829 from microsoftgraph/feature/samples-testing
Browse files Browse the repository at this point in the history
Feature: Enable loading of samples and Permissions descriptions files from Github
  • Loading branch information
MaggieKimani1 authored Feb 8, 2021
2 parents ad0d2e4 + 888e77d commit 220bacb
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/app/services/actions/devxApi-action-creators.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IAction } from '../../../types/action';
import { SET_DEVX_API_URL_SUCCESS } from '../redux-constants';

export function setDevxApiUrl(response: string): any {
export function setDevxApiUrl(response: object): IAction {
return {
type: SET_DEVX_API_URL_SUCCESS,
response,
Expand Down
7 changes: 6 additions & 1 deletion src/app/services/actions/permissions-action-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export function fetchScopes(query?: IQuery): Function {
return async (dispatch: Function, getState: Function) => {
try {
const { devxApi } = getState();
let permissionsUrl = `${devxApi}/permissions`;
let permissionsUrl = `${devxApi.baseUrl}/permissions`;

let hasUrl = false; // whether permissions are for a specific url

if (query) {
Expand All @@ -49,6 +50,10 @@ export function fetchScopes(query?: IQuery): Function {
hasUrl = true;
}

if (devxApi.parameters) {
permissionsUrl = `${permissionsUrl}${query ? '&' : '?'}${devxApi.parameters}`;
}

const headers = {
'Content-Type': 'application/json',
'Accept-Language': geLocale
Expand Down
4 changes: 3 additions & 1 deletion src/app/services/actions/samples-action-creators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export function fetchSamplesPending(): any {
export function fetchSamples(): Function {
return async (dispatch: Function, getState: Function) => {
const { devxApi } = getState();
const samplesUrl = `${devxApi}/samples`;
let samplesUrl = `${devxApi.baseUrl}/samples`;

samplesUrl = (devxApi.parameters) ? `${samplesUrl}?${devxApi.parameters}` : `${samplesUrl}`;

const headers = {
'Content-Type': 'application/json',
Expand Down
7 changes: 6 additions & 1 deletion src/app/services/reducers/devxApi-reducers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { IAction } from '../../../types/action';
import { IDevxAPI } from '../../../types/devx-api';
import { DEVX_API_URL } from '../graph-constants';
import { SET_DEVX_API_URL_SUCCESS } from '../redux-constants';

export function devxApi(state: string = DEVX_API_URL, action: IAction): any {
const initialState: IDevxAPI = {
baseUrl: DEVX_API_URL,
parameters: ''
};
export function devxApi(state: IDevxAPI = initialState, action: IAction): any {
switch (action.type) {

case SET_DEVX_API_URL_SUCCESS:
Expand Down
14 changes: 13 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { loadGETheme } from './themes';
import { readTheme } from './themes/theme-utils';
import { Mode } from './types/enums';
import { IHistoryItem } from './types/history';
import { IDevxAPI } from './types/devx-api';

// removes the loading spinner from GE html after the app is loaded
const spinner = document.getElementById('spinner');
Expand Down Expand Up @@ -107,7 +108,18 @@ if (theme) {
const devxApiUrl = new URLSearchParams(location.search).get('devx-api');

if (devxApiUrl) {
appState.dispatch(setDevxApiUrl(devxApiUrl));
const org = new URLSearchParams(location.search).get('org');
const branchName = new URLSearchParams(location.search).get('branchName');

const devxApi: IDevxAPI = {
baseUrl: devxApiUrl,
parameters: ''
};

if (org && branchName) {
devxApi.parameters = `org=${org}&branchName=${branchName}`;
}
appState.dispatch(setDevxApiUrl(devxApi));
}

readHistoryData().then((data: any) => {
Expand Down
4 changes: 4 additions & 0 deletions src/types/devx-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface IDevxAPI {
baseUrl: string;
parameters: string;
}

0 comments on commit 220bacb

Please sign in to comment.