Skip to content

Commit

Permalink
Merge branch 'dev' into feature/powershell-snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
Millicent Achieng committed Dec 6, 2021
2 parents 41c2e14 + 65209d8 commit a47fd3a
Show file tree
Hide file tree
Showing 26 changed files with 871 additions and 175 deletions.
3 changes: 2 additions & 1 deletion src/app/services/actions/query-action-creators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ContentType } from '../../../types/enums';
import { IHistoryItem } from '../../../types/history';
import { IQuery } from '../../../types/query-runner';
import { IStatus } from '../../../types/status';
import { setStatusMessage } from '../../utils/status-message';
import { writeHistoryData } from '../../views/sidebar/history/history-utils';
import {
anonymousRequest,
Expand Down Expand Up @@ -95,7 +96,7 @@ export function runQuery(query: IQuery): Function {

if (response) {
status.status = response.status;
status.statusText = response.statusText;
status.statusText = response.statusText === '' ? setStatusMessage(response.status) : response.statusText;
}

if (response && response.ok) {
Expand Down
19 changes: 18 additions & 1 deletion src/app/services/actions/resource-explorer-action-creators.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { IAction } from '../../../types/action';
import { FETCH_RESOURCES_SUCCESS, FETCH_RESOURCES_PENDING, FETCH_RESOURCES_ERROR } from '../redux-constants';
import {
FETCH_RESOURCES_SUCCESS, FETCH_RESOURCES_PENDING,
FETCH_RESOURCES_ERROR, RESOURCEPATHS_ADD_SUCCESS, RESOURCEPATHS_DELETE_SUCCESS
} from '../redux-constants';
import { IResource } from '../../../types/resources';
import { IRootState } from '../../../types/root';
import { IRequestOptions } from '../../../types/request';
Expand All @@ -24,6 +27,20 @@ export function fetchResourcesError(response: object): IAction {
};
}

export function addResourcePaths(response: object): IAction {
return {
type: RESOURCEPATHS_ADD_SUCCESS,
response
};
}

export function removeResourcePaths(response: object): IAction {
return {
type: RESOURCEPATHS_DELETE_SUCCESS,
response
};
}

export function fetchResources(): Function {
return async (dispatch: Function, getState: Function) => {
try {
Expand Down
41 changes: 35 additions & 6 deletions src/app/services/reducers/resources-reducer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { IAction } from '../../../types/action';
import { IResource, IResources } from '../../../types/resources';
import { IResource, IResourceLink, IResources } from '../../../types/resources';
import content from '../../utils/resources/resources.json';
import { FETCH_RESOURCES_ERROR, FETCH_RESOURCES_PENDING, FETCH_RESOURCES_SUCCESS } from '../redux-constants';
import {
FETCH_RESOURCES_ERROR, FETCH_RESOURCES_PENDING,
FETCH_RESOURCES_SUCCESS, RESOURCEPATHS_ADD_SUCCESS, RESOURCEPATHS_DELETE_SUCCESS
} from '../redux-constants';

const res = JSON.parse(JSON.stringify(content)) as IResource;
const initialState: IResources = {
Expand All @@ -11,7 +14,8 @@ const initialState: IResources = {
labels: [],
segment: ''
},
error: null
error: null,
paths: []
};

export function resources(state: IResources = initialState, action: IAction): IResources {
Expand All @@ -20,19 +24,44 @@ export function resources(state: IResources = initialState, action: IAction): IR
return {
pending: false,
data: action.response,
error: null
error: null,
paths: []
};
case FETCH_RESOURCES_ERROR:
return {
pending: false,
error: action.response,
data: res
data: res,
paths: []
};
case FETCH_RESOURCES_PENDING:
return {
pending: true,
data: initialState.data,
error: null
error: null,
paths: []
};
case RESOURCEPATHS_ADD_SUCCESS:
const paths: IResourceLink[] = [...state.paths];
action.response.forEach((element: any) => {
const exists = !!paths.find(k => k.key === element.key);
if (!exists) {
paths.push(element);
}
});
return {
...state,
paths
};
case RESOURCEPATHS_DELETE_SUCCESS:
const list: IResourceLink[] = [...state.paths];
action.response.forEach((path: IResourceLink) => {
const index = list.findIndex(k => k.key === path.key);
list.splice(index, 1);
});
return {
...state,
paths: list
};
default:
return state;
Expand Down
2 changes: 2 additions & 0 deletions src/app/services/redux-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ export const FETCH_RESOURCES_PENDING = 'FETCH_RESOURCES_PENDING';
export const GET_POLICY_SUCCESS = 'GET_POLICY_SUCCESS';
export const GET_POLICY_ERROR = 'GET_POLICY_ERROR';
export const GET_POLICY_PENDING = 'GET_POLICY_PENDING';
export const RESOURCEPATHS_ADD_SUCCESS = 'RESOURCEPATHS_ADD_SUCCESS';
export const RESOURCEPATHS_DELETE_SUCCESS = 'RESOURCEPATHS_DELETE_SUCCESS';
10 changes: 10 additions & 0 deletions src/app/utils/download.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function downloadToLocal(content: any, filename: string) {
const blob = new Blob([JSON.stringify(content, null, 4)], { type: 'text/json' });

const elem = window.document.createElement('a');
elem.href = window.URL.createObjectURL(blob);
elem.download = filename;
document.body.appendChild(elem);
elem.click();
document.body.removeChild(elem);
}
49 changes: 49 additions & 0 deletions src/app/utils/status-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,52 @@ export function getMatchesAndParts(message: string) {
const parts: string[] = message.split(numberPattern);
return { matches, parts };
}

const httpStatusMessage = new Map([
[100, 'Continue'],
[101, 'Switching Protocols'],
[102, 'Processing'],
[200, 'OK'],
[201, 'Created'],
[202, 'Accepted'],
[203, 'Non Authoritative'],
[204, 'No Content'],
[205, 'Reset Content'],
[206, 'Partial Content'],
[300, 'Multiple Choices'],
[301, 'Moved Permanently'],
[302, 'Found'],
[303, 'See Other'],
[304, 'Not Modified'],
[305, 'Use Proxy'],
[307, 'Temporary Redirect'],
[400, 'Bad Request'],
[401, 'Unauthorized'],
[403, 'Forbidden'],
[404, 'Not Found'],
[405, 'Method Not Allowed'],
[406, 'Not Acceptable'],
[407, 'Proxy Authentication Required'],
[408, 'Request Timeout'],
[409, 'Conflict'],
[410, 'Gone'],
[411, 'Length Required'],
[412, 'Precondition Failed'],
[413, 'Request Entity Too Large'],
[414, 'Request-URI Too Long'],
[415, 'Unsupported Media Type'],
[416, 'Requested Range Not Satisfiable'],
[417, 'Expectation Failed'],
[422, 'Unprocessable Entity'],
[500, 'Internal Server Error'],
[501, 'Not Implemented'],
[502, 'Bad Gateway'],
[503, 'Service Unavailable'],
[504, 'Gateway Timeout'],
[505, 'HTTP Version Not Supported']
]);

export function setStatusMessage(status: number): string {
const statusMessage = httpStatusMessage.get(status);
return statusMessage ? statusMessage : '';
}
2 changes: 1 addition & 1 deletion src/app/views/query-runner/request/Request.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class Request extends Component<IRequestComponent, any> {
const requestPivotItems = this.getPivotItems(dimensions.request.height);
const { selectedPivot } = this.state;
const pivot = selectedPivot.replace('.$', '');
const minHeight = 260;
const minHeight = 60;
const maxHeight = 800;
return (
<>
Expand Down
10 changes: 2 additions & 8 deletions src/app/views/sidebar/history/har-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IHarFormat, IHarHeaders, IHarPayload } from '../../../../types/har';
import { IHistoryItem } from '../../../../types/history';
import { downloadToLocal } from '../../../utils/download';

export function createHarPayload(query: IHistoryItem): IHarPayload {
const queryResult = JSON.stringify(query.result);
Expand Down Expand Up @@ -108,18 +109,11 @@ function createEntries(payloads: IHarPayload[]) {
}

export function exportQuery(content: IHarFormat, requestUrl: string) {
const blob = new Blob([JSON.stringify(content)], { type: 'text/json' });

const url = requestUrl.substr(8).split('/');
url.pop();

const filename = `${url.join('_')}.har`;
const elem = window.document.createElement('a');
elem.href = window.URL.createObjectURL(blob);
elem.download = filename;
document.body.appendChild(elem);
elem.click();
document.body.removeChild(elem);
downloadToLocal(content, filename);
}


46 changes: 46 additions & 0 deletions src/app/views/sidebar/resource-explorer/CommandOptions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { CommandBar, ICommandBarItemProps } from '@fluentui/react';
import React, { useState } from 'react';

import { translateMessage } from '../../../utils/translate-messages';
import PathsReview from './panels/PathsReview';

interface ICommandOptions {
version: string;
}

const CommandOptions = (props: ICommandOptions) => {
const [isOpen, setIsOpen] = useState(false);
const { version } = props;
const options: ICommandBarItemProps[] = [
{
key: 'preview',
text: translateMessage('Preview collection'),
iconProps: { iconName: 'View' },
onClick: () => toggleSelectedResourcesPreview()
}
];

const toggleSelectedResourcesPreview = () => {
let open = isOpen;
open = !open;
setIsOpen(open);
}

return (
<div>
<CommandBar
items={options}
ariaLabel='Selection actions'
primaryGroupAriaLabel='Selection actions'
farItemsGroupAriaLabel='More selection actions'
/>
<PathsReview
isOpen={isOpen}
version={version}
toggleSelectedResourcesPreview={toggleSelectedResourcesPreview}
/>
</div>
)
}

export default CommandOptions;
119 changes: 0 additions & 119 deletions src/app/views/sidebar/resource-explorer/QueryParameters.tsx

This file was deleted.

Loading

0 comments on commit a47fd3a

Please sign in to comment.