refactor: wire remaining request actions
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
flex
|
flex
|
||||||
p-2
|
p-2
|
||||||
top-0
|
top-0
|
||||||
|
z-10
|
||||||
items-center
|
items-center
|
||||||
sticky
|
sticky
|
||||||
justify-between
|
justify-between
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
v-show="show"
|
v-show="show"
|
||||||
class="inset-0 transition-opacity z-10 fixed"
|
class="inset-0 transition-opacity z-20 fixed"
|
||||||
@keydown.esc="close()"
|
@keydown.esc="close()"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -11,10 +11,9 @@
|
|||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
id="selectLabelSaveReq"
|
id="selectLabelSaveReq"
|
||||||
v-model="requestData.name"
|
v-model="requestName"
|
||||||
class="input"
|
class="input"
|
||||||
type="text"
|
type="text"
|
||||||
@keyup.enter="saveRequestAs"
|
|
||||||
/>
|
/>
|
||||||
<label class="font-semibold text-xs px-4 pt-4 pb-4">
|
<label class="font-semibold text-xs px-4 pt-4 pb-4">
|
||||||
Select Location
|
Select Location
|
||||||
@@ -47,6 +46,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { defineComponent } from "@nuxtjs/composition-api"
|
||||||
import * as teamUtils from "~/helpers/teams/utils"
|
import * as teamUtils from "~/helpers/teams/utils"
|
||||||
import {
|
import {
|
||||||
saveRESTRequestAs,
|
saveRESTRequestAs,
|
||||||
@@ -54,20 +54,23 @@ import {
|
|||||||
editGraphqlRequest,
|
editGraphqlRequest,
|
||||||
saveGraphqlRequestAs,
|
saveGraphqlRequestAs,
|
||||||
} from "~/newstore/collections"
|
} from "~/newstore/collections"
|
||||||
|
import { getRESTRequest, useRESTRequestName } from "~/newstore/RESTSession"
|
||||||
|
|
||||||
export default {
|
export default defineComponent({
|
||||||
props: {
|
props: {
|
||||||
// mode can be either "graphql" or "rest"
|
// mode can be either "graphql" or "rest"
|
||||||
mode: { type: String, default: "rest" },
|
mode: { type: String, default: "rest" },
|
||||||
show: Boolean,
|
show: Boolean,
|
||||||
editingRequest: { type: Object, default: () => {} },
|
},
|
||||||
|
setup() {
|
||||||
|
return {
|
||||||
|
requestName: useRESTRequestName(),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
defaultRequestName: "Untitled Request",
|
|
||||||
path: "Path will appear here",
|
|
||||||
requestData: {
|
requestData: {
|
||||||
name: undefined,
|
name: this.requestName,
|
||||||
collectionIndex: undefined,
|
collectionIndex: undefined,
|
||||||
folderName: undefined,
|
folderName: undefined,
|
||||||
requestIndex: undefined,
|
requestIndex: undefined,
|
||||||
@@ -114,10 +117,7 @@ export default {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestUpdated = {
|
const requestUpdated = getRESTRequest()
|
||||||
...this.$props.editingRequest,
|
|
||||||
name: this.$data.requestData.name,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter out all REST file inputs
|
// Filter out all REST file inputs
|
||||||
if (this.mode === "rest" && requestUpdated.bodyParams) {
|
if (this.mode === "rest" && requestUpdated.bodyParams) {
|
||||||
@@ -180,5 +180,5 @@ export default {
|
|||||||
this.$emit("hide-modal")
|
this.$emit("hide-modal")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -109,6 +109,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { translateToNewRequest } from "~/helpers/types/HoppRESTRequest"
|
||||||
|
import { setRESTRequest } from "~/newstore/RESTSession"
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
request: { type: Object, default: () => {} },
|
request: { type: Object, default: () => {} },
|
||||||
@@ -158,8 +160,7 @@ export default {
|
|||||||
requestIndex: this.requestIndex,
|
requestIndex: this.requestIndex,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
else
|
else setRESTRequest(translateToNewRequest(this.request))
|
||||||
this.$store.commit("postwoman/selectRequest", { request: this.request })
|
|
||||||
},
|
},
|
||||||
dragStart({ dataTransfer }) {
|
dragStart({ dataTransfer }) {
|
||||||
this.dragging = !this.dragging
|
this.dragging = !this.dragging
|
||||||
|
|||||||
@@ -102,6 +102,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { translateToNewRequest } from "~/helpers/types/HoppRESTRequest"
|
||||||
|
import { setRESTRequest } from "~/newstore/RESTSession"
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
request: { type: Object, default: () => {} },
|
request: { type: Object, default: () => {} },
|
||||||
@@ -145,8 +147,7 @@ export default {
|
|||||||
requestID: this.requestIndex,
|
requestID: this.requestIndex,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
else
|
else setRESTRequest(translateToNewRequest(this.request))
|
||||||
this.$store.commit("postwoman/selectRequest", { request: this.request })
|
|
||||||
},
|
},
|
||||||
removeRequest() {
|
removeRequest() {
|
||||||
this.$emit("remove-request", {
|
this.$emit("remove-request", {
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
setRESTRequest(
|
setRESTRequest(
|
||||||
makeRESTRequest({
|
makeRESTRequest({
|
||||||
|
name: "Untitled request",
|
||||||
endpoint,
|
endpoint,
|
||||||
method,
|
method,
|
||||||
params,
|
params,
|
||||||
|
|||||||
@@ -116,7 +116,7 @@
|
|||||||
:label="$t('clear_all')"
|
:label="$t('clear_all')"
|
||||||
icon="clear_all"
|
icon="clear_all"
|
||||||
@click.native="
|
@click.native="
|
||||||
clearContent('', $event)
|
clearContent()
|
||||||
$refs.sendOptions.tippy().hide()
|
$refs.sendOptions.tippy().hide()
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
@@ -127,7 +127,7 @@
|
|||||||
:label="$t('save')"
|
:label="$t('save')"
|
||||||
:shortcut="[getSpecialKey(), 'S']"
|
:shortcut="[getSpecialKey(), 'S']"
|
||||||
outline
|
outline
|
||||||
@click.native="newSendRequest"
|
@click.native="showSaveRequestModal = true"
|
||||||
/>
|
/>
|
||||||
<span class="inline-flex">
|
<span class="inline-flex">
|
||||||
<tippy
|
<tippy
|
||||||
@@ -147,7 +147,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<input
|
<input
|
||||||
id="request-name"
|
id="request-name"
|
||||||
v-model="name"
|
v-model="requestName"
|
||||||
:placeholder="$t('request_name')"
|
:placeholder="$t('request_name')"
|
||||||
name="request-name"
|
name="request-name"
|
||||||
type="text"
|
type="text"
|
||||||
@@ -167,7 +167,7 @@
|
|||||||
:label="$t('save_to_collections')"
|
:label="$t('save_to_collections')"
|
||||||
icon="create_new_folder"
|
icon="create_new_folder"
|
||||||
@click.native="
|
@click.native="
|
||||||
saveRequest()
|
showSaveRequestModal = true
|
||||||
$refs.saveOptions.tippy().hide()
|
$refs.saveOptions.tippy().hide()
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
@@ -182,21 +182,34 @@
|
|||||||
:show="showCodegenModal"
|
:show="showCodegenModal"
|
||||||
@hide-modal="showCodegenModal = false"
|
@hide-modal="showCodegenModal = false"
|
||||||
/>
|
/>
|
||||||
|
<CollectionsSaveRequest
|
||||||
|
mode="rest"
|
||||||
|
:show="showSaveRequestModal"
|
||||||
|
@hide-modal="showSaveRequestModal = false"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { defineComponent } from "@nuxtjs/composition-api"
|
||||||
import {
|
import {
|
||||||
updateRESTResponse,
|
updateRESTResponse,
|
||||||
restEndpoint$,
|
restEndpoint$,
|
||||||
setRESTEndpoint,
|
setRESTEndpoint,
|
||||||
restMethod$,
|
restMethod$,
|
||||||
updateRESTMethod,
|
updateRESTMethod,
|
||||||
|
resetRESTRequest,
|
||||||
|
useRESTRequestName,
|
||||||
} from "~/newstore/RESTSession"
|
} from "~/newstore/RESTSession"
|
||||||
import { getPlatformSpecialKey } from "~/helpers/platformutils"
|
import { getPlatformSpecialKey } from "~/helpers/platformutils"
|
||||||
import { runRESTRequest$ } from "~/helpers/RequestRunner"
|
import { runRESTRequest$ } from "~/helpers/RequestRunner"
|
||||||
|
|
||||||
export default {
|
export default defineComponent({
|
||||||
|
setup() {
|
||||||
|
return {
|
||||||
|
requestName: useRESTRequestName(),
|
||||||
|
}
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
newMethod$: "",
|
newMethod$: "",
|
||||||
@@ -218,6 +231,7 @@ export default {
|
|||||||
showCodegenModal: false,
|
showCodegenModal: false,
|
||||||
navigatorShare: navigator.share,
|
navigatorShare: navigator.share,
|
||||||
loading: false,
|
loading: false,
|
||||||
|
showSaveRequestModal: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
subscriptions() {
|
subscriptions() {
|
||||||
@@ -252,6 +266,33 @@ export default {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
copyRequest() {
|
||||||
|
if (navigator.share) {
|
||||||
|
const time = new Date().toLocaleTimeString()
|
||||||
|
const date = new Date().toLocaleDateString()
|
||||||
|
navigator
|
||||||
|
.share({
|
||||||
|
title: "Hoppscotch",
|
||||||
|
text: `Hoppscotch • Open source API development ecosystem at ${time} on ${date}`,
|
||||||
|
url: window.location.href,
|
||||||
|
})
|
||||||
|
.then(() => {})
|
||||||
|
.catch(() => {})
|
||||||
|
} else {
|
||||||
|
const dummy = document.createElement("input")
|
||||||
|
document.body.appendChild(dummy)
|
||||||
|
dummy.value = window.location.href
|
||||||
|
dummy.select()
|
||||||
|
document.execCommand("copy")
|
||||||
|
document.body.removeChild(dummy)
|
||||||
|
this.$toast.info(this.$t("copied_to_clipboard"), {
|
||||||
|
icon: "done",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
clearContent() {
|
||||||
|
resetRESTRequest()
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ export type HoppRESTReqBody = {
|
|||||||
export interface HoppRESTRequest {
|
export interface HoppRESTRequest {
|
||||||
v: string
|
v: string
|
||||||
|
|
||||||
|
name: string
|
||||||
method: string
|
method: string
|
||||||
endpoint: string
|
endpoint: string
|
||||||
params: HoppRESTParam[]
|
params: HoppRESTParam[]
|
||||||
@@ -80,6 +81,7 @@ export function translateToNewRequest(x: any): HoppRESTRequest {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const name = x.name
|
||||||
const method = x.method
|
const method = x.method
|
||||||
|
|
||||||
const preRequestScript = x.preRequestScript
|
const preRequestScript = x.preRequestScript
|
||||||
@@ -88,6 +90,7 @@ export function translateToNewRequest(x: any): HoppRESTRequest {
|
|||||||
const body = parseRequestBody(x)
|
const body = parseRequestBody(x)
|
||||||
|
|
||||||
const result: HoppRESTRequest = {
|
const result: HoppRESTRequest = {
|
||||||
|
name,
|
||||||
endpoint,
|
endpoint,
|
||||||
headers,
|
headers,
|
||||||
params,
|
params,
|
||||||
|
|||||||
@@ -119,21 +119,24 @@ type RESTSession = {
|
|||||||
testResults: HoppTestResult | null
|
testResults: HoppTestResult | null
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultRESTSession: RESTSession = {
|
const defaultRESTRequest: HoppRESTRequest = {
|
||||||
request: {
|
v: RESTReqSchemaVersion,
|
||||||
v: RESTReqSchemaVersion,
|
endpoint: "https://httpbin.org/get",
|
||||||
endpoint: "https://httpbin.org/get",
|
name: "Untitled request",
|
||||||
params: [],
|
params: [],
|
||||||
headers: [],
|
headers: [],
|
||||||
method: "GET",
|
method: "GET",
|
||||||
preRequestScript: "// pw.env.set('variable', 'value');",
|
preRequestScript: "// pw.env.set('variable', 'value');",
|
||||||
testScript: "// pw.expect('variable').toBe('value');",
|
testScript: "// pw.expect('variable').toBe('value');",
|
||||||
body: {
|
body: {
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
body: "",
|
body: "",
|
||||||
isRaw: false,
|
isRaw: false,
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultRESTSession: RESTSession = {
|
||||||
|
request: defaultRESTRequest,
|
||||||
response: null,
|
response: null,
|
||||||
testResults: null,
|
testResults: null,
|
||||||
}
|
}
|
||||||
@@ -144,6 +147,14 @@ const dispatchers = defineDispatchers({
|
|||||||
request: req,
|
request: req,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
setRequestName(curr: RESTSession, { newName }: { newName: string }) {
|
||||||
|
return {
|
||||||
|
request: {
|
||||||
|
...curr.request,
|
||||||
|
name: newName,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
setEndpoint(curr: RESTSession, { newEndpoint }: { newEndpoint: string }) {
|
setEndpoint(curr: RESTSession, { newEndpoint }: { newEndpoint: string }) {
|
||||||
const paramsInNewURL = getParamsInURL(newEndpoint)
|
const paramsInNewURL = getParamsInURL(newEndpoint)
|
||||||
const updatedParams = recalculateParams(
|
const updatedParams = recalculateParams(
|
||||||
@@ -362,6 +373,10 @@ export function setRESTRequest(req: HoppRESTRequest) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function resetRESTRequest() {
|
||||||
|
setRESTRequest(defaultRESTRequest)
|
||||||
|
}
|
||||||
|
|
||||||
export function setRESTEndpoint(newEndpoint: string) {
|
export function setRESTEndpoint(newEndpoint: string) {
|
||||||
restSessionStore.dispatch({
|
restSessionStore.dispatch({
|
||||||
dispatcher: "setEndpoint",
|
dispatcher: "setEndpoint",
|
||||||
@@ -371,6 +386,15 @@ export function setRESTEndpoint(newEndpoint: string) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setRESTRequestName(newName: string) {
|
||||||
|
restSessionStore.dispatch({
|
||||||
|
dispatcher: "setRequestName",
|
||||||
|
payload: {
|
||||||
|
newName,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export function addRESTParam(newParam: HoppRESTParam) {
|
export function addRESTParam(newParam: HoppRESTParam) {
|
||||||
restSessionStore.dispatch({
|
restSessionStore.dispatch({
|
||||||
dispatcher: "addParam",
|
dispatcher: "addParam",
|
||||||
@@ -507,6 +531,11 @@ export const restRequest$ = restSessionStore.subject$.pipe(
|
|||||||
distinctUntilChanged()
|
distinctUntilChanged()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
export const restRequestName$ = restRequest$.pipe(
|
||||||
|
pluck("name"),
|
||||||
|
distinctUntilChanged()
|
||||||
|
)
|
||||||
|
|
||||||
export const restEndpoint$ = restSessionStore.subject$.pipe(
|
export const restEndpoint$ = restSessionStore.subject$.pipe(
|
||||||
pluck("request", "endpoint"),
|
pluck("request", "endpoint"),
|
||||||
distinctUntilChanged()
|
distinctUntilChanged()
|
||||||
@@ -608,3 +637,11 @@ export function useRESTRequestBody(): Ref<HoppRESTReqBody> {
|
|||||||
setRESTReqBody
|
setRESTReqBody
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useRESTRequestName(): Ref<string> {
|
||||||
|
return useStream(
|
||||||
|
restRequestName$,
|
||||||
|
restSessionStore.value.request.name,
|
||||||
|
setRESTRequestName
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -287,13 +287,6 @@
|
|||||||
</Pane>
|
</Pane>
|
||||||
</Splitpanes>
|
</Splitpanes>
|
||||||
|
|
||||||
<CollectionsSaveRequest
|
|
||||||
mode="rest"
|
|
||||||
:show="showSaveRequestModal"
|
|
||||||
@hide-modal="hideRequestModal"
|
|
||||||
:editing-request="editRequest"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<HttpTokenList
|
<HttpTokenList
|
||||||
:show="showTokenListModal"
|
:show="showTokenListModal"
|
||||||
:tokens="tokens"
|
:tokens="tokens"
|
||||||
@@ -449,7 +442,6 @@ export default defineComponent({
|
|||||||
showTokenListModal: false,
|
showTokenListModal: false,
|
||||||
showTokenRequest: false,
|
showTokenRequest: false,
|
||||||
showTokenRequestList: false,
|
showTokenRequestList: false,
|
||||||
showSaveRequestModal: false,
|
|
||||||
editRequest: {},
|
editRequest: {},
|
||||||
files: [],
|
files: [],
|
||||||
filenames: "",
|
filenames: "",
|
||||||
@@ -1291,35 +1283,6 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
copyRequest() {
|
|
||||||
if (navigator.share) {
|
|
||||||
const time = new Date().toLocaleTimeString()
|
|
||||||
const date = new Date().toLocaleDateString()
|
|
||||||
navigator
|
|
||||||
.share({
|
|
||||||
title: "Hoppscotch",
|
|
||||||
text: `Hoppscotch • Open source API development ecosystem at ${time} on ${date}`,
|
|
||||||
url: window.location.href,
|
|
||||||
})
|
|
||||||
.then(() => {})
|
|
||||||
.catch(() => {})
|
|
||||||
} else {
|
|
||||||
const dummy = document.createElement("input")
|
|
||||||
document.body.appendChild(dummy)
|
|
||||||
dummy.value = window.location.href
|
|
||||||
dummy.select()
|
|
||||||
document.execCommand("copy")
|
|
||||||
document.body.removeChild(dummy)
|
|
||||||
this.$refs.copyRequest.innerHTML = this.doneButton
|
|
||||||
this.$toast.info(this.$t("copied_to_clipboard"), {
|
|
||||||
icon: "done",
|
|
||||||
})
|
|
||||||
setTimeout(
|
|
||||||
() => (this.$refs.copyRequest.innerHTML = this.copyButton),
|
|
||||||
1000
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
setRouteQueryState() {
|
setRouteQueryState() {
|
||||||
const flat = (key) => (this[key] !== "" ? `${key}=${this[key]}&` : "")
|
const flat = (key) => (this[key] !== "" ? `${key}=${this[key]}&` : "")
|
||||||
const deep = (key) => {
|
const deep = (key) => {
|
||||||
@@ -1448,35 +1411,6 @@ export default defineComponent({
|
|||||||
1000
|
1000
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
saveRequest() {
|
|
||||||
let urlAndPath = parseUrlAndPath(this.uri)
|
|
||||||
this.editRequest = {
|
|
||||||
url: decodeURI(urlAndPath.url),
|
|
||||||
path: decodeURI(urlAndPath.path),
|
|
||||||
method: this.method,
|
|
||||||
auth: this.auth,
|
|
||||||
httpUser: this.httpUser,
|
|
||||||
httpPassword: this.httpPassword,
|
|
||||||
passwordFieldType: this.passwordFieldType,
|
|
||||||
bearerToken: this.bearerToken,
|
|
||||||
headers: this.headers,
|
|
||||||
params: this.params,
|
|
||||||
bodyParams: this.bodyParams,
|
|
||||||
rawParams: this.rawParams,
|
|
||||||
rawInput: this.rawInput,
|
|
||||||
contentType: this.contentType,
|
|
||||||
requestType: this.requestType,
|
|
||||||
preRequestScript:
|
|
||||||
this.showPreRequestScript == true ? this.preRequestScript : null,
|
|
||||||
testScript: this.testScript,
|
|
||||||
name: this.requestName,
|
|
||||||
}
|
|
||||||
this.showSaveRequestModal = true
|
|
||||||
},
|
|
||||||
hideRequestModal() {
|
|
||||||
this.showSaveRequestModal = false
|
|
||||||
this.editRequest = {}
|
|
||||||
},
|
|
||||||
setExclude(excludedField, excluded) {
|
setExclude(excludedField, excluded) {
|
||||||
const update = clone(this.URL_EXCLUDES)
|
const update = clone(this.URL_EXCLUDES)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user