EditRequest.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <SmartModal
  3. v-if="show"
  4. :title="`${$t('modal.edit_request')}`"
  5. @close="hideModal"
  6. >
  7. <template #body>
  8. <div class="flex flex-col px-2">
  9. <input
  10. id="selectLabelGqlEditReq"
  11. v-model="requestUpdateData.name"
  12. v-focus
  13. class="input floating-input"
  14. placeholder=" "
  15. type="text"
  16. autocomplete="off"
  17. @keyup.enter="saveRequest"
  18. />
  19. <label for="selectLabelGqlEditReq">
  20. {{ $t("action.label") }}
  21. </label>
  22. </div>
  23. </template>
  24. <template #footer>
  25. <span>
  26. <ButtonPrimary
  27. :label="`${$t('action.save')}`"
  28. @click.native="saveRequest"
  29. />
  30. <ButtonSecondary
  31. :label="`${$t('action.cancel')}`"
  32. @click.native="hideModal"
  33. />
  34. </span>
  35. </template>
  36. </SmartModal>
  37. </template>
  38. <script lang="ts">
  39. import { defineComponent, PropType } from "@nuxtjs/composition-api"
  40. import { HoppGQLRequest } from "@hoppscotch/data"
  41. import { editGraphqlRequest } from "~/newstore/collections"
  42. export default defineComponent({
  43. props: {
  44. show: Boolean,
  45. folderPath: { type: String, default: null },
  46. request: { type: Object as PropType<HoppGQLRequest>, default: () => {} },
  47. requestIndex: { type: Number, default: null },
  48. editingRequestName: { type: String, default: null },
  49. },
  50. data() {
  51. return {
  52. requestUpdateData: {
  53. name: null as any | null,
  54. },
  55. }
  56. },
  57. watch: {
  58. editingRequestName(val) {
  59. this.requestUpdateData.name = val
  60. },
  61. },
  62. methods: {
  63. saveRequest() {
  64. if (!this.requestUpdateData.name) {
  65. this.$toast.error(`${this.$t("collection.invalid_name")}`)
  66. return
  67. }
  68. const requestUpdated = {
  69. ...this.$props.request,
  70. name: this.$data.requestUpdateData.name || this.$props.request.name,
  71. }
  72. editGraphqlRequest(this.folderPath, this.requestIndex, requestUpdated)
  73. this.hideModal()
  74. },
  75. hideModal() {
  76. this.requestUpdateData = { name: null }
  77. this.$emit("hide-modal")
  78. },
  79. },
  80. })
  81. </script>