refactor: update embed customize flow

This commit is contained in:
nivedin
2023-12-06 14:27:05 +05:30
committed by Andrew Bastin
parent 09e9601940
commit 4bd3e89f89
4 changed files with 59 additions and 61 deletions

View File

@@ -38,15 +38,11 @@
:loading="loading" :loading="loading"
@click="createSharedRequest" @click="createSharedRequest"
/> />
<HoppButtonPrimary
v-else
:label="t('action.save')"
:loading="loading"
@click="saveSharedRequest"
/>
<HoppButtonSecondary <HoppButtonSecondary
:label="t('action.cancel')" :label="step === 1 ? t('action.cancel') : t('action.close')"
class="ml-2" class="ml-2"
filled
outline
@click="hideModal" @click="hideModal"
/> />
</div> </div>
@@ -151,7 +147,6 @@ const emit = defineEmits<{
type: string | undefined type: string | undefined
} }
): void ): void
(e: "save-shared-request"): void
}>() }>()
const createSharedRequest = () => { const createSharedRequest = () => {
@@ -166,10 +161,6 @@ const copySharedRequest = (payload: {
emit("copy-shared-request", payload) emit("copy-shared-request", payload)
} }
const saveSharedRequest = () => {
emit("save-shared-request")
}
const hideModal = () => { const hideModal = () => {
emit("hide-modal") emit("hide-modal")
selectedWidget.value = { selectedWidget.value = {

View File

@@ -88,7 +88,6 @@
@hide-modal="displayCustomizeRequestModal(false, null)" @hide-modal="displayCustomizeRequestModal(false, null)"
@copy-shared-request="copySharedRequest" @copy-shared-request="copySharedRequest"
@create-shared-request="createSharedRequest" @create-shared-request="createSharedRequest"
@save-shared-request="saveSharedRequest"
/> />
</template> </template>
@@ -117,6 +116,7 @@ import { copyToClipboard } from "~/helpers/utils/clipboard"
import * as E from "fp-ts/Either" import * as E from "fp-ts/Either"
import { RESTTabService } from "~/services/tab/rest" import { RESTTabService } from "~/services/tab/rest"
import { useService } from "dioc/vue" import { useService } from "dioc/vue"
import { watch } from "vue"
const t = useI18n() const t = useI18n()
const colorMode = useColorMode() const colorMode = useColorMode()
@@ -139,17 +139,17 @@ const embedOptions = ref<EmbedOption>({
{ {
value: "parameters", value: "parameters",
label: t("tab.parameters"), label: t("tab.parameters"),
enabled: true, enabled: false,
}, },
{ {
value: "body", value: "body",
label: t("tab.body"), label: t("tab.body"),
enabled: true, enabled: false,
}, },
{ {
value: "headers", value: "headers",
label: t("tab.headers"), label: t("tab.headers"),
enabled: true, enabled: false,
}, },
{ {
value: "authorization", value: "authorization",
@@ -162,7 +162,7 @@ const embedOptions = ref<EmbedOption>({
const updateEmbedProperty = async ( const updateEmbedProperty = async (
shareRequestID: string, shareRequestID: string,
properties: string | null properties: string
) => { ) => {
const customizeEmbedResult = await updateEmbedProperties( const customizeEmbedResult = await updateEmbedProperties(
shareRequestID, shareRequestID,
@@ -172,27 +172,30 @@ const updateEmbedProperty = async (
if (E.isLeft(customizeEmbedResult)) { if (E.isLeft(customizeEmbedResult)) {
toast.error(`${customizeEmbedResult.left.error}`) toast.error(`${customizeEmbedResult.left.error}`)
toast.error(t("error.something_went_wrong")) toast.error(t("error.something_went_wrong"))
} else if (E.isRight(customizeEmbedResult)) { }
if (customizeEmbedResult.right.updateEmbedProperties) { }
if (customizeEmbedResult.right.updateEmbedProperties.properties) {
const parsedEmbedProperties = JSON.parse(
customizeEmbedResult.right.updateEmbedProperties.properties
)
embedOptions.value = { watch(
selectedTab: parsedEmbedProperties.options[0], () => embedOptions.value,
tabs: embedOptions.value.tabs.map((tab) => { () => {
return { if (
...tab, requestToShare.value &&
enabled: parsedEmbedProperties.options.includes(tab.value), requestToShare.value.id &&
} showShareRequestModal.value
}), ) {
theme: parsedEmbedProperties.theme, if (selectedWidget.value.value === "embed") {
} const properties = {
} options: embedOptions.value.tabs
.filter((tab) => tab.enabled)
.map((tab) => tab.value),
theme: embedOptions.value.theme,
} }
updateEmbedProperty(requestToShare.value.id, JSON.stringify(properties))
} }
} }
},
{ deep: true }
)
const restTab = useService(RESTTabService) const restTab = useService(RESTTabService)
@@ -306,6 +309,32 @@ const displayCustomizeRequestModal = (
label: t("shared_requests.button"), label: t("shared_requests.button"),
info: t("shared_requests.button_info"), info: t("shared_requests.button_info"),
} }
embedOptions.value = {
selectedTab: "parameters",
tabs: [
{
value: "parameters",
label: t("tab.parameters"),
enabled: false,
},
{
value: "body",
label: t("tab.body"),
enabled: false,
},
{
value: "headers",
label: t("tab.headers"),
enabled: false,
},
{
value: "authorization",
label: t("tab.authorization"),
enabled: false,
},
],
theme: "system",
}
} else { } else {
const parsedEmbedProperties = JSON.parse(embedProperties) const parsedEmbedProperties = JSON.parse(embedProperties)
embedOptions.value = { embedOptions.value = {
@@ -395,25 +424,6 @@ const copySharedRequest = (payload: {
} }
} }
const saveSharedRequest = () => {
if (requestToShare.value && requestToShare.value.id) {
if (selectedWidget.value.value === "embed") {
const properties = {
options: embedOptions.value.tabs
.filter((tab) => tab.enabled)
.map((tab) => tab.value),
theme: embedOptions.value.theme,
}
updateEmbedProperty(requestToShare.value.id, JSON.stringify(properties))
} else {
updateEmbedProperty(requestToShare.value.id, null)
}
toast.success(t("shared_requests.modified"))
displayShareRequestModal(false)
}
}
const openInNewTab = (request: HoppRESTRequest) => { const openInNewTab = (request: HoppRESTRequest) => {
restTab.createNewTab({ restTab.createNewTab({
isDirty: false, isDirty: false,

View File

@@ -6,13 +6,13 @@
}" }"
> >
<div <div
class="flex items-stretch space-x-4 rounded border-divider" class="flex items-stretch space-x-2 rounded border-divider"
:class="{ :class="{
'bg-accentContrast': isEmbedThemeLight, 'bg-accentContrast': isEmbedThemeLight,
}" }"
> >
<span <span
class="flex max-w-[4rem] items-center justify-center rounded border border-divider px-1 py-2 text-tiny" class="flex max-w-[4rem] items-center justify-center rounded border border-divider p-2 text-tiny"
:class="{ :class="{
'!border-dividerLight bg-accentContrast text-primary': '!border-dividerLight bg-accentContrast text-primary':
isEmbedThemeLight, isEmbedThemeLight,

View File

@@ -35,10 +35,7 @@ export const deleteShortcode = (code: string) =>
code, code,
}) })
export const updateEmbedProperties = ( export const updateEmbedProperties = (code: string, properties: string) =>
code: string,
properties: string | null
) =>
runMutation< runMutation<
UpdateEmbedPropertiesMutation, UpdateEmbedPropertiesMutation,
UpdateEmbedPropertiesMutationVariables, UpdateEmbedPropertiesMutationVariables,