Skip to content

Commit 88be222

Browse files
authored
Merge pull request #46 from REST-API-Client/feature/sidebar-click-feature
[2022/09/02] - Add logic to fill up Main UI with clicked history collection
2 parents 4de6bc7 + 78c8005 commit 88be222

File tree

13 files changed

+82
-11
lines changed

13 files changed

+82
-11
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.0.7
4+
5+
#### Feature Clicking history collection from sidebar now fills up the UI in main request panel
6+
37
## 1.0.6
48

59
#### Fix README displaying anchor tag in VSCode marketplace due to wrong way of closing anchor tag

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Simply click Open Menu button or open the Command Palette and type the command b
153153

154154
## 🗒 Changelog
155155

156-
#### Current version 1.0.6
156+
#### Current version 1.0.7
157157

158158
Visit [here](https://github.com/REST-API-Client/API-Client-VSCode-Extension/blob/main/CHANGELOG.md) for a detailed release notes
159159

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"displayName": "REST API Client",
55
"icon": "icons/images/icon.png",
66
"description": "Simple and intuitive API Client made into a VSCode extension.",
7-
"version": "1.0.6",
7+
"version": "1.0.7",
88
"license": "MIT",
99
"bugs": {
1010
"url": "https://github.com/REST-API-Client/API-Client-VSCode-Extension/issues"

src/MainWebViewPanel.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,17 @@ class MainWebViewPanel {
7070

7171
return;
7272
}
73-
73+
const requestObject = {
74+
requestMethod,
75+
requestUrl,
76+
authOption,
77+
authData,
78+
bodyOption,
79+
bodyRawOption,
80+
bodyRawData,
81+
keyValueTableData,
82+
command,
83+
};
7484
this.#url = getUrl(requestUrl);
7585
this.#method = requestMethod;
7686
this.#headers = getHeaders(keyValueTableData, authOption, authData);
@@ -81,12 +91,12 @@ class MainWebViewPanel {
8191
bodyRawData,
8292
);
8393

84-
this.#postWebviewMessage();
94+
this.#postWebviewMessage(requestObject);
8595
},
8696
);
8797
}
8898

89-
async #postWebviewMessage() {
99+
async #postWebviewMessage(requestObject) {
90100
const { userRequestHistory } = this.stateManager.getExtensionContext(
91101
COLLECTION.HISTORY_COLLECTION,
92102
);
@@ -114,6 +124,7 @@ class MainWebViewPanel {
114124
favoritedTime: null,
115125
isUserFavorite: false,
116126
id: uuidv4(),
127+
requestObject,
117128
},
118129
],
119130
},
@@ -129,6 +140,7 @@ class MainWebViewPanel {
129140
favoritedTime: null,
130141
isUserFavorite: false,
131142
id: uuidv4(),
143+
requestObject,
132144
},
133145
...userRequestHistory,
134146
],
@@ -137,6 +149,9 @@ class MainWebViewPanel {
137149
}
138150
}
139151

152+
console.log(
153+
this.stateManager.getExtensionContext(COLLECTION.HISTORY_COLLECTION),
154+
);
140155
this.mainPanel.webview.postMessage(responseObject);
141156
this.sidebarWebViewPanel.postMainWebViewPanelMessage(
142157
this.stateManager.getExtensionContext(COLLECTION.HISTORY_COLLECTION),

src/SidebarWebViewPanel.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import vscode from "vscode";
22

3-
import { CATEGORY, COLLECTION, COMMAND, MESSAGE } from "./constants";
3+
import { CATEGORY, COLLECTION, COMMAND, MESSAGE, TYPE } from "./constants";
44
import { filterObjectKey, generateResponseObject, getNonce } from "./utils";
55

66
class SidebarWebViewPanel {
@@ -114,6 +114,10 @@ class SidebarWebViewPanel {
114114
);
115115

116116
this.mainWebViewPanel.webview.postMessage(responseObject);
117+
this.mainWebViewPanel.webview.postMessage({
118+
type: TYPE.SIDE_BAR_DATA,
119+
...selectedCollection.requestObject,
120+
});
117121
}, 1000);
118122
}
119123
});

src/constants/types.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const TYPE = {
88
BEARER_TOKEN: "Bearer Token",
99
AUTHORIZATION: "Authorization",
1010
WEB_VIEW_TYPE: "RestApiClient",
11+
SIDE_BAR_DATA: "Selected Collection Data",
1112
BODY_FORM_URLENCODED: "x-www-form-urlencoded",
1213
};
1314

webview/constants/response.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const RESPONSE = {
88
META_DATA: "Meta Data",
99
VIEW_FORMAT: "View Format",
1010
RESPONSE_BODY: "Response Body",
11+
SIDE_BAR_DATA: "Selected Collection Data",
1112
COLLECTION_REQUEST: "Collection Request",
1213
};
1314

webview/features/Request/Method/RequestMethod.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
import React from "react";
22
import styled from "styled-components";
3+
import shallow from "zustand/shallow";
34

45
import { OPTION, REQUEST } from "../../../constants";
56
import useStore from "../../../store/useStore";
67

78
const RequestMethod = () => {
8-
const handleRequestMethodChange = useStore(
9-
(state) => state.handleRequestMethodChange,
9+
const { requestMethod, handleRequestMethodChange } = useStore(
10+
(state) => ({
11+
requestMethod: state.requestMethod,
12+
handleRequestMethodChange: state.handleRequestMethodChange,
13+
}),
14+
shallow,
1015
);
1116

1217
return (
1318
<MethodSelectOptionWrapper
1419
name="httpRequestMethods"
20+
value={requestMethod}
1521
onChange={(event) => handleRequestMethodChange(event.target.value)}
1622
>
1723
{OPTION.REQUEST_METHOD_OPTIONS.map((requestMethod, index) => (

webview/features/Response/Panel/ResponsePanel.js

+24
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ const ResponsePanel = () => {
1515
requestInProcess,
1616
handleResponseData,
1717
handleRequestProcessStatus,
18+
handleSidebarCollectionHeaders,
19+
handleSidebarCollectionClick,
1820
} = useStore(
1921
(state) => ({
2022
responseData: state.responseData,
2123
requestInProcess: state.requestInProcess,
2224
handleResponseData: state.handleResponseData,
2325
handleRequestProcessStatus: state.handleRequestProcessStatus,
26+
handleSidebarCollectionClick: state.handleSidebarCollectionClick,
27+
handleSidebarCollectionHeaders: state.handleSidebarCollectionHeaders,
2428
}),
2529
shallow,
2630
);
@@ -34,6 +38,26 @@ const ResponsePanel = () => {
3438
handleRequestProcessStatus(RESPONSE.ERROR);
3539
} else if (event.data.type === RESPONSE.COLLECTION_REQUEST) {
3640
handleRequestProcessStatus(COMMON.LOADING);
41+
} else if (event.data.type === RESPONSE.SIDE_BAR_DATA) {
42+
const {
43+
keyValueTableData,
44+
authData,
45+
authOption,
46+
requestUrl,
47+
requestMethod,
48+
bodyOption,
49+
bodyRawOption,
50+
} = event.data;
51+
52+
handleSidebarCollectionClick({
53+
authData,
54+
authOption,
55+
requestUrl,
56+
requestMethod,
57+
bodyOption,
58+
bodyRawOption,
59+
});
60+
handleSidebarCollectionHeaders(keyValueTableData);
3761
}
3862
};
3963

webview/features/Response/Preview/ResponsePreview.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const IframeWrapper = styled.div`
1616
1717
iframe {
1818
width: 100%;
19-
height: 65vh;
19+
height: 55vh;
2020
background: white;
2121
overflow: scroll;
2222
}

webview/store/slices/keyValueTableDataSlice.js

+8
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ const keyValueTableDataSlice = (set) => ({
136136
),
137137
}));
138138
},
139+
140+
handleSidebarCollectionHeaders: (headers) => {
141+
set(() => {
142+
return {
143+
keyValueTableData: [...headers],
144+
};
145+
});
146+
},
139147
});
140148

141149
export default keyValueTableDataSlice;

webview/store/slices/requestDataSlice.js

+8
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ const requestDataSlice = (set) => ({
8888
})),
8989

9090
setCodeSnippetValue: (value) => set(() => ({ codeSnippetValue: value })),
91+
92+
handleSidebarCollectionClick: (value) =>
93+
set((state) => {
94+
return {
95+
...state,
96+
...value,
97+
};
98+
}),
9199
});
92100

93101
export default requestDataSlice;

0 commit comments

Comments
 (0)