Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Enable loading of samples and Permissions descriptions files from Github #829

Merged
merged 14 commits into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 5 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,11 @@ 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`;

if (devxApi.parameters) {
samplesUrl = `${samplesUrl}?${devxApi.parameters}`;
}
thewahome marked this conversation as resolved.
Show resolved Hide resolved

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;
}