-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): added validation to the shellhub instance append
- Loading branch information
1 parent
2059bc9
commit 805d168
Showing
10 changed files
with
213 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<template> | ||
<v-dialog v-model="showDialog" width="400"> | ||
<v-card class="bg-v-theme-surface" data-test="deviceRename-card"> | ||
<v-card-title class="text-h5 pa-5 bg-primary"> Add Instance </v-card-title> | ||
<v-divider /> | ||
<v-form class="ma-2" @submit.prevent="addInstance"> | ||
<v-col> | ||
<v-text-field | ||
v-model="newInstanceForm.name" | ||
color="primary" | ||
prepend-inner-icon="mdi-text-box-outline" | ||
required | ||
label="Name" | ||
variant="outlined" | ||
/> | ||
|
||
<v-text-field | ||
v-model="newInstanceForm.url" | ||
color="primary" | ||
:error="requestError" | ||
:error-messages="errorMsg" | ||
prepend-inner-icon="mdi-link" | ||
label="URL" | ||
required | ||
variant="outlined" | ||
data-test="password-text" | ||
/> | ||
<v-card-actions class="justify-center pa-0"> | ||
<v-btn color="primary" block type="submit" variant="flat"> SAVE </v-btn> | ||
</v-card-actions> | ||
</v-col> | ||
</v-form> | ||
</v-card> | ||
</v-dialog> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { useAppStore } from '@renderer/stores' | ||
import { computed, reactive, ref } from 'vue' | ||
import Ajv from 'ajv' | ||
const props = defineProps({ | ||
show: { | ||
type: Boolean, | ||
default: false | ||
} | ||
}) | ||
const ajv = new Ajv() | ||
const showDialog = computed(() => props.show) | ||
const newInstanceForm = reactive({ name: '', url: '' }) | ||
const requestError = ref(false) | ||
const errorMsg = ref('') | ||
const store = useAppStore() | ||
const infoSchema = { | ||
type: 'object', | ||
required: ['version', 'endpoints'], | ||
properties: { | ||
version: { type: 'string' }, | ||
endpoints: { | ||
type: 'object', | ||
required: ['api', 'ssh'], | ||
properties: { | ||
api: { type: 'string' }, | ||
ssh: { type: 'string' } | ||
} | ||
} | ||
} | ||
} | ||
const request = async (url: string, config: RequestInit) => { | ||
try { | ||
const response = await fetch(url, config) | ||
const responseData = await response.json() | ||
const isValid = ajv.validate(infoSchema, responseData) | ||
if (!isValid) { | ||
requestError.value = true | ||
errorMsg.value = "The version method used in this URL isn't from a real ShellHub instance" | ||
} | ||
return responseData | ||
} catch (error: unknown) { | ||
requestError.value = true | ||
errorMsg.value = | ||
"An error occurred while validating the URL, indicating it isn't from a real ShellHub instance" | ||
} | ||
} | ||
const addInstance = async () => { | ||
await request(`https://${newInstanceForm.url}/info`, { | ||
method: 'GET' | ||
}) | ||
store.appendInstance({ | ||
name: newInstanceForm.name, | ||
url: newInstanceForm.url, | ||
permanent: false | ||
}) | ||
store.selectInstance(store.instances[store.instances.length - 1]) | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
<template> | ||
<v-app> | ||
<router-view :key="currentRoute.value.path" /> | ||
|
||
<router-view :key="currentRoute.value.path" /> | ||
</v-app> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed } from "vue" | ||
import { computed } from 'vue' | ||
import { useRouter } from 'vue-router' | ||
const router = useRouter(); | ||
const currentRoute = computed(() => router.currentRoute); | ||
const router = useRouter() | ||
const currentRoute = computed(() => router.currentRoute) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.