Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: modify body with ai & feedback on ai requests hoppscotch-common bindings #4386

Merged
merged 4 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat: add feedback UI for request rename
  • Loading branch information
amk-dev authored and jamesgeorge007 committed Sep 30, 2024
commit 2818e855975719b88197f19ead49425c683d2fe3
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
v-if="show"
dialog
:title="t('request.new')"
@close="$emit('hide-modal')"
@close="hideModal"
>
<template #body>
<div class="flex gap-1">
Expand All @@ -30,20 +30,61 @@
</div>
</template>
<template #footer>
<span class="flex space-x-2">
<HoppButtonPrimary
:label="t('action.save')"
:loading="loadingState"
outline
@click="addRequest"
/>
<HoppButtonSecondary
:label="t('action.cancel')"
outline
filled
@click="hideModal"
/>
</span>
<div class="flex justify-between items-center w-full">
<div class="flex space-x-2">
<HoppButtonPrimary
:label="t('action.save')"
:loading="loadingState"
outline
@click="addRequest"
/>
<HoppButtonSecondary
:label="t('action.cancel')"
outline
filled
@click="hideModal"
/>
</div>

<div
v-if="lastTraceID && !submittedFeedback"
class="flex items-center gap-2"
>
<p>{{ t("ai_experiments.feedback_cta_request_name") }}</p>
<template v-if="!isSubmitFeedbackPending">
<HoppButtonSecondary
:icon="IconThumbsUp"
outline
@click="
async () => {
if (lastTraceID) {
await submitFeedback('positive', lastTraceID)
submittedFeedback = true
}
}
"
/>
<HoppButtonSecondary
:icon="IconThumbsDown"
outline
@click="
() => {
if (lastTraceID) {
submitFeedback('negative', lastTraceID)
submittedFeedback = true
}
}
"
/>
</template>
<template v-else>
<HoppSmartSpinner />
</template>
</div>
<div v-if="submittedFeedback">
<p>{{ t("ai_experiments.feedback_thank_you") }}</p>
</div>
</div>
</template>
</HoppSmartModal>
</template>
Expand All @@ -54,9 +95,14 @@ import { useI18n } from "@composables/i18n"
import { useToast } from "@composables/toast"
import { useService } from "dioc/vue"
import { RESTTabService } from "~/services/tab/rest"
import { useRequestNameGeneration } from "~/composables/ai-experiments"
import {
useRequestNameGeneration,
useSubmitFeedback,
} from "~/composables/ai-experiments"
import { HoppRESTRequest } from "@hoppscotch/data"
import IconSparkle from "~icons/lucide/sparkles"
import IconThumbsUp from "~icons/lucide/thumbs-up"
import IconThumbsDown from "~icons/lucide/thumbs-down"
const toast = useToast()
const t = useI18n()
Expand Down Expand Up @@ -85,8 +131,22 @@ const {
generateRequestName,
isGenerateRequestNamePending,
canDoRequestNameGeneration,
lastTraceID,
} = useRequestNameGeneration(editingName)
watch(
() => props.show,
(newVal) => {
if (!newVal) {
submittedFeedback.value = false
lastTraceID.value = null
}
}
)
const submittedFeedback = ref(false)
const { submitFeedback, isSubmitFeedbackPending } = useSubmitFeedback()
const tabs = useService(RESTTabService)
watch(
() => props.show,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,61 @@
</div>
</template>
<template #footer>
<span class="flex space-x-2">
<HoppButtonPrimary
:label="t('action.save')"
:loading="loadingState"
outline
@click="editRequest"
/>
<HoppButtonSecondary
:label="t('action.cancel')"
outline
filled
@click="hideModal"
/>
</span>
<div class="flex justify-between items-center w-full">
<div class="flex space-x-2">
<HoppButtonPrimary
:label="t('action.save')"
:loading="loadingState"
outline
@click="editRequest"
/>
<HoppButtonSecondary
:label="t('action.cancel')"
outline
filled
@click="hideModal"
/>
</div>

<div
v-if="lastTraceID && !submittedFeedback"
class="flex items-center gap-2"
>
<p>{{ t("ai_experiments.feedback_cta_request_name") }}</p>
<template v-if="!isSubmitFeedbackPending">
<HoppButtonSecondary
:icon="IconThumbsUp"
outline
@click="
async () => {
if (lastTraceID) {
await submitFeedback('positive', lastTraceID)
submittedFeedback = true
}
}
"
/>
<HoppButtonSecondary
:icon="IconThumbsDown"
outline
@click="
() => {
if (lastTraceID) {
submitFeedback('negative', lastTraceID)
submittedFeedback = true
}
}
"
/>
</template>
<template v-else>
<HoppSmartSpinner />
</template>
</div>
<div v-if="submittedFeedback">
<p>{{ t("ai_experiments.feedback_thank_you") }}</p>
</div>
</div>
</template>
</HoppSmartModal>
</template>
Expand All @@ -53,8 +94,14 @@ import { useI18n } from "@composables/i18n"
import { useToast } from "@composables/toast"
import { HoppRESTRequest } from "@hoppscotch/data"
import { useVModel } from "@vueuse/core"
import { useRequestNameGeneration } from "~/composables/ai-experiments"
import { ref, watch } from "vue"
import {
useRequestNameGeneration,
useSubmitFeedback,
} from "~/composables/ai-experiments"
import IconSparkle from "~icons/lucide/sparkles"
import IconThumbsUp from "~icons/lucide/thumbs-up"
import IconThumbsDown from "~icons/lucide/thumbs-down"

const toast = useToast()
const t = useI18n()
Expand Down Expand Up @@ -85,8 +132,22 @@ const {
generateRequestName,
canDoRequestNameGeneration,
isGenerateRequestNamePending,
lastTraceID,
} = useRequestNameGeneration(editingName)

watch(
() => props.show,
(newVal) => {
if (!newVal) {
submittedFeedback.value = false
lastTraceID.value = null
}
}
)

const submittedFeedback = ref(false)
const { submitFeedback, isSubmitFeedbackPending } = useSubmitFeedback()

const editRequest = () => {
if (editingName.value.trim() === "") {
toast.error(t("request.invalid_name"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,61 @@
</div>
</template>
<template #footer>
<span class="flex space-x-2">
<HoppButtonPrimary
:label="`${t('action.save')}`"
:loading="modalLoadingState"
outline
@click="saveRequestAs"
/>
<HoppButtonSecondary
:label="`${t('action.cancel')}`"
outline
filled
@click="hideModal"
/>
</span>
<div class="flex justify-between items-center w-full">
<div class="flex space-x-2">
<HoppButtonPrimary
:label="`${t('action.save')}`"
:loading="modalLoadingState"
outline
@click="saveRequestAs"
/>
<HoppButtonSecondary
:label="`${t('action.cancel')}`"
outline
filled
@click="hideModal"
/>
</div>

<div
v-if="lastTraceID && !submittedFeedback"
class="flex items-center gap-2"
>
<p>{{ t("ai_experiments.feedback_cta_request_name") }}</p>
<template v-if="!isSubmitFeedbackPending">
<HoppButtonSecondary
:icon="IconThumbsUp"
outline
@click="
async () => {
if (lastTraceID) {
await submitFeedback('positive', lastTraceID)
submittedFeedback = true
}
}
"
/>
<HoppButtonSecondary
:icon="IconThumbsDown"
outline
@click="
() => {
if (lastTraceID) {
submitFeedback('negative', lastTraceID)
submittedFeedback = true
}
}
"
/>
</template>
<template v-else>
<HoppSmartSpinner />
</template>
</div>
<div v-if="submittedFeedback">
<p>{{ t("ai_experiments.feedback_thank_you") }}</p>
</div>
</div>
</template>
</HoppSmartModal>
</template>
Expand All @@ -84,7 +125,10 @@ import * as TE from "fp-ts/TaskEither"
import { pipe } from "fp-ts/function"
import { cloneDeep } from "lodash-es"
import { computed, nextTick, reactive, ref, watch } from "vue"
import { useRequestNameGeneration } from "~/composables/ai-experiments"
import {
useRequestNameGeneration,
useSubmitFeedback,
} from "~/composables/ai-experiments"
import { GQLError } from "~/helpers/backend/GQLClient"
import {
createRequestInCollection,
Expand All @@ -103,6 +147,8 @@ import { GQLTabService } from "~/services/tab/graphql"
import { RESTTabService } from "~/services/tab/rest"
import { TeamWorkspace } from "~/services/workspace.service"
import IconSparkle from "~icons/lucide/sparkles"
import IconThumbsDown from "~icons/lucide/thumbs-down"
import IconThumbsUp from "~icons/lucide/thumbs-up"

const t = useI18n()
const toast = useToast()
Expand Down Expand Up @@ -185,8 +231,22 @@ const {
canDoRequestNameGeneration,
generateRequestName,
isGenerateRequestNamePending,
lastTraceID,
} = useRequestNameGeneration(requestName)

watch(
() => props.show,
(newVal) => {
if (!newVal) {
submittedFeedback.value = false
lastTraceID.value = null
}
}
)

const submittedFeedback = ref(false)
const { submitFeedback, isSubmitFeedbackPending } = useSubmitFeedback()

watch(
() => [RESTTabs.currentActiveTab.value, GQLTabs.currentActiveTab.value],
() => {
Expand Down
Loading