EditRequest.vue 2.1 KB

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