fix: fix typescript issues

This commit is contained in:
Andrew Bastin
2021-07-24 17:45:48 -04:00
parent f0aaca2639
commit 4508e309c2
5 changed files with 38 additions and 39 deletions

View File

@@ -135,15 +135,10 @@
</AppSection> </AppSection>
</template> </template>
<script lang="ts"> <script>
import { defineComponent, toRef } from "@nuxtjs/composition-api" export default {
import { useRESTRequestBody } from "~/newstore/RESTSession" props: {
bodyParams: { type: Array, default: () => [] },
export default defineComponent({
setup() {
return {
bodyParams: toRef(useRESTRequestBody(), "body"),
}
}, },
computed: { computed: {
contentType() { contentType() {
@@ -168,15 +163,15 @@ export default defineComponent({
} }
}, },
methods: { methods: {
clearContent(bodyParams: string, $event: any) { clearContent(bodyParams, $event) {
this.$emit("clear-content", bodyParams, $event) this.$emit("clear-content", bodyParams, $event)
}, },
setRouteQueryState() { setRouteQueryState() {
this.$emit("set-route-query-state") this.$emit("set-route-query-state")
}, },
removeRequestBodyParam(index: number) { removeRequestBodyParam(index) {
const paramArr = this.$store.state.request.bodyParams.filter( const paramArr = this.$store.state.request.bodyParams.filter(
(item: { active: boolean }, itemIndex: any) => (item, itemIndex) =>
itemIndex !== index && itemIndex !== index &&
(Object.prototype.hasOwnProperty.call(item, "active") (Object.prototype.hasOwnProperty.call(item, "active")
? item.active === true ? item.active === true
@@ -188,35 +183,30 @@ export default defineComponent({
addRequestBodyParam() { addRequestBodyParam() {
this.$emit("add-request-body-param") this.$emit("add-request-body-param")
}, },
setRequestAttachment(event: { target: { files: any } }, index: number) { setRequestAttachment(event, index) {
const { files } = event.target const { files } = event.target
this.$store.commit("setFilesBodyParams", { this.$store.commit("setFilesBodyParams", {
index, index,
value: Array.from(files), value: Array.from(files),
}) })
}, },
requestBodyParamIsFile(index: number) { requestBodyParamIsFile(index) {
const bodyParamValue = this.bodyParams?.[index]?.value const bodyParamValue = this.bodyParams?.[index]?.value
const isFile = bodyParamValue?.[0] instanceof File const isFile = bodyParamValue?.[0] instanceof File
return isFile return isFile
}, },
chipDelete(paramIndex: number, fileIndex: number) { chipDelete(paramIndex, fileIndex) {
this.$store.commit("removeFile", { this.$store.commit("removeFile", {
index: paramIndex, index: paramIndex,
fileIndex, fileIndex,
}) })
}, },
updateBodyParams( updateBodyParams(event, index, type) {
event: { target: { value: any } },
index: number,
type: string
) {
this.$store.commit(type, { this.$store.commit(type, {
index, index,
value: event.target.value, value: event.target.value,
}) })
const paramArr = this.$store.state.request.bodyParams.filter( const paramArr = this.$store.state.request.bodyParams.filter((item) =>
(item: { active: boolean }) =>
Object.prototype.hasOwnProperty.call(item, "active") Object.prototype.hasOwnProperty.call(item, "active")
? item.active === true ? item.active === true
: true : true
@@ -224,9 +214,9 @@ export default defineComponent({
this.setRawParams(paramArr) this.setRawParams(paramArr)
}, },
toggleActive(index: number, param: { active: any }) { toggleActive(index, param) {
const paramArr = this.$store.state.request.bodyParams.filter( const paramArr = this.$store.state.request.bodyParams.filter(
(item: { active: boolean }, itemIndex: any) => { (item, itemIndex) => {
if (index === itemIndex) { if (index === itemIndex) {
return !param.active return !param.active
} else { } else {
@@ -246,9 +236,9 @@ export default defineComponent({
: false, : false,
}) })
}, },
setRawParams(filteredParamArr: any[]) { setRawParams(filteredParamArr) {
let rawParams = {} let rawParams = {}
filteredParamArr.forEach((_param: { key: any; value: any }) => { filteredParamArr.forEach((_param) => {
rawParams = { rawParams = {
...rawParams, ...rawParams,
[_param.key]: _param.value, [_param.key]: _param.value,
@@ -261,7 +251,7 @@ export default defineComponent({
}) })
}, },
}, },
}) }
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">

View File

@@ -108,6 +108,11 @@ export default defineComponent({
headers, headers,
preRequestScript: "", preRequestScript: "",
testScript: "", testScript: "",
body: {
contentType: "application/json",
body: "",
isRaw: false,
},
}) })
) )
} catch (error) { } catch (error) {

View File

@@ -93,16 +93,16 @@ export default defineComponent({
} }
}, },
computed: { computed: {
totalTests() { totalTests(): number | undefined {
return this.testResults.expectResults.length return this.testResults?.expectResults.length
}, },
failedTests() { failedTests(): number | undefined {
return this.testResults.expectResults.filter( return this.testResults?.expectResults.filter(
(result: { status: string }) => result.status === "fail" (result: { status: string }) => result.status === "fail"
).length ).length
}, },
passedTests() { passedTests(): number | undefined {
return this.testResults.expectResults.filter( return this.testResults?.expectResults.filter(
(result: { status: string }) => result.status === "pass" (result: { status: string }) => result.status === "pass"
).length ).length
}, },

View File

@@ -1,5 +1,6 @@
import { import {
customRef, customRef,
DeepReadonly,
onBeforeUnmount, onBeforeUnmount,
readonly, readonly,
Ref, Ref,
@@ -8,7 +9,10 @@ import {
} from "@nuxtjs/composition-api" } from "@nuxtjs/composition-api"
import { Observable, Subscription } from "rxjs" import { Observable, Subscription } from "rxjs"
export function useReadonlyStream<T>(stream$: Observable<T>, initialValue: T) { export function useReadonlyStream<T>(
stream$: Observable<T>,
initialValue: T
): Ref<DeepReadonly<T>> {
let sub: Subscription | null = null let sub: Subscription | null = null
onBeforeUnmount(() => { onBeforeUnmount(() => {

View File

@@ -71,7 +71,7 @@ export default defineComponent({
}) })
this.$subscribeTo(getSettingSubject("BG_COLOR"), (color) => { this.$subscribeTo(getSettingSubject("BG_COLOR"), (color) => {
this.$colorMode.preference = color ;(this as any).$colorMode.preference = color
}) })
}, },
async mounted() { async mounted() {
@@ -85,7 +85,7 @@ export default defineComponent({
"background-color:black;padding:4px 8px;border-radius:8px;font-size:16px;color:white;" "background-color:black;padding:4px 8px;border-radius:8px;font-size:16px;color:white;"
) )
const workbox = await window.$workbox const workbox = await (window as any).$workbox
if (workbox) { if (workbox) {
workbox.addEventListener("installed", (event: any) => { workbox.addEventListener("installed", (event: any) => {
if (event.isUpdate) { if (event.isUpdate) {