[go: nahoru, domu]

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: CLI collection runner command generation UI flow #4141

Merged
merged 12 commits into from
Jun 27, 2024
Merged
Prev Previous commit
Next Next commit
feat: add Environment Properties modal
Add a new `properties` action under the context menu for environments.
  • Loading branch information
jamesgeorge007 committed Jun 27, 2024
commit 3106ca136042a2ed8512d1fda03ec509caf6344d
108 changes: 108 additions & 0 deletions packages/hoppscotch-common/src/components/environments/Properties.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<template>
<HoppSmartModal
dialog
:full-width-body="true"
title="Environment Properties"
@close="hideModal"
>
<template #body>
<HoppSmartTabs
v-model="activeTab"
styles="sticky overflow-x-auto flex-shrink-0 bg-primary top-0 z-10 !-py-4"
render-inactive-tabs
>
<HoppSmartTab id="details" label="Details">
<div
class="flex flex-shrink-0 items-center justify-between border-b border-dividerLight bg-primary pl-4"
>
<span>Environment ID</span>

<!-- TODO: Make it point to the section about accessing environments via the ID -->
<HoppButtonSecondary
v-tippy="{ theme: 'tooltip' }"
to="https://docs.hoppscotch.io/documentation/clients/cli"
blank
:title="t('app.wiki')"
:icon="IconHelpCircle"
/>
</div>

<div class="p-4">
<div
class="flex items-center justify-between py-2 px-4 rounded-md bg-primaryLight"
>
<div class="text-secondaryDark">
{{ environmentID }}
</div>

<HoppButtonSecondary
filled
:icon="copyIcon"
@click="copyEnvironmentID"
/>
</div>
</div>

<div
class="bg-bannerInfo px-4 py-2 flex items-center sticky bottom-0"
>
<icon-lucide-info class="svg-icons mr-2" />
This environment ID will be used for CLI collection runner for
Hoppscotch.
</div>
</HoppSmartTab>
</HoppSmartTabs>
</template>

<template #footer>
<HoppButtonPrimary
:label="t('action.close')"
outline
filled
@click="hideModal"
/>
</template>
</HoppSmartModal>
</template>

<script setup lang="ts">
import { useI18n } from "@composables/i18n"
import { refAutoReset, useVModel } from "@vueuse/core"
import { useToast } from "~/composables/toast"

import { copyToClipboard } from "~/helpers/utils/clipboard"
import IconCheck from "~icons/lucide/check"
import IconCopy from "~icons/lucide/copy"
import IconHelpCircle from "~icons/lucide/help-circle"

const t = useI18n()
const toast = useToast()

const props = defineProps<{
modelValue: string
environmentID: string
}>()

const emit = defineEmits<{
(e: "hide-modal"): void
(e: "update:modelValue"): void
}>()

const activeTab = useVModel(props, "modelValue", emit)

const copyIcon = refAutoReset<typeof IconCopy | typeof IconCheck>(
IconCopy,
1000
)

const hideModal = () => {
emit("hide-modal")
}

const copyEnvironmentID = () => {
copyToClipboard(props.environmentID)
copyIcon.value = IconCheck

toast.success(`${t("state.copied_to_clipboard")}`)
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@keyup.d="duplicate!.$el.click()"
@keyup.j="exportAsJsonEl!.$el.click()"
@keyup.delete="deleteAction!.$el.click()"
@keyup.p="propertiesAction!.$el.click()"
@keyup.escape="options!.tippy().hide()"
>
<HoppSmartItem
Expand Down Expand Up @@ -94,6 +95,18 @@
}
"
/>
<HoppSmartItem
ref="propertiesAction"
:icon="IconSettings2"
:label="t('action.properties')"
:shortcut="['P']"
@click="
() => {
emit('show-environment-properties')
hide()
}
"
/>
</div>
</template>
</tippy>
Expand All @@ -108,26 +121,28 @@
</template>

<script setup lang="ts">
import { ref } from "vue"
import { pipe } from "fp-ts/function"
import * as TE from "fp-ts/TaskEither"
import { useToast } from "@composables/toast"
import { HoppSmartItem } from "@hoppscotch/ui"
import { useService } from "dioc/vue"
import * as TE from "fp-ts/TaskEither"
import { pipe } from "fp-ts/function"
import { ref } from "vue"
import { TippyComponent } from "vue-tippy"

import { useI18n } from "~/composables/i18n"
import { GQLError } from "~/helpers/backend/GQLClient"
import {
deleteTeamEnvironment,
createDuplicateEnvironment as duplicateEnvironment,
} from "~/helpers/backend/mutations/TeamEnvironment"
import { GQLError } from "~/helpers/backend/GQLClient"
import { exportAsJSON } from "~/helpers/import-export/export/environment"
import { TeamEnvironment } from "~/helpers/teams/TeamEnvironment"
import IconEdit from "~icons/lucide/edit"
import { SecretEnvironmentService } from "~/services/secret-environment.service"
import IconCopy from "~icons/lucide/copy"
import IconTrash2 from "~icons/lucide/trash-2"
import IconEdit from "~icons/lucide/edit"
import IconMoreVertical from "~icons/lucide/more-vertical"
import { TippyComponent } from "vue-tippy"
import { HoppSmartItem } from "@hoppscotch/ui"
import { exportAsJSON } from "~/helpers/import-export/export/environment"
import { useService } from "dioc/vue"
import { SecretEnvironmentService } from "~/services/secret-environment.service"
import IconSettings2 from "~icons/lucide/settings-2"
import IconTrash2 from "~icons/lucide/trash-2"

const t = useI18n()
const toast = useToast()
Expand All @@ -139,6 +154,7 @@ const props = defineProps<{

const emit = defineEmits<{
(e: "edit-environment"): void
(e: "show-environment-properties"): void
}>()

const secretEnvironmentService = useService(SecretEnvironmentService)
Expand All @@ -156,6 +172,7 @@ const edit = ref<typeof HoppSmartItem>()
const duplicate = ref<typeof HoppSmartItem>()
const deleteAction = ref<typeof HoppSmartItem>()
const exportAsJsonEl = ref<typeof HoppSmartItem>()
const propertiesAction = ref<typeof HoppSmartItem>()

const removeEnvironment = () => {
pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
:environment="environment"
:is-viewer="team?.role === 'VIEWER'"
@edit-environment="editEnvironment(environment)"
@show-environment-properties="
showEnvironmentProperties(environment.environment.id)
"
/>
</div>
<div v-if="loading" class="flex flex-col items-center justify-center p-4">
Expand Down Expand Up @@ -116,6 +119,12 @@
environment-type="TEAM_ENV"
@hide-modal="displayModalImportExport(false)"
/>
<EnvironmentsProperties
v-if="showEnvironmentsPropertiesModal"
v-model="environmentsPropertiesModalActiveTab"
:environment-i-d="selectedEnvironmentID!"
@hide-modal="showEnvironmentsPropertiesModal = false"
/>
</div>
</template>

Expand Down Expand Up @@ -149,6 +158,10 @@ const editingEnvironment = ref<TeamEnvironment | null>(null)
const editingVariableName = ref("")
const secretOptionSelected = ref(false)

const showEnvironmentsPropertiesModal = ref(false)
const environmentsPropertiesModalActiveTab = ref("details")
const selectedEnvironmentID = ref<string | null>(null)

const isTeamViewer = computed(() => props.team?.role === "VIEWER")

const displayModalAdd = (shouldDisplay: boolean) => {
Expand Down Expand Up @@ -187,6 +200,11 @@ const getErrorMessage = (err: GQLError<string>) => {
}
}

const showEnvironmentProperties = (environmentID: string) => {
showEnvironmentsPropertiesModal.value = true
selectedEnvironmentID.value = environmentID
}

defineActionHandler(
"modals.team.environment.edit",
({ envName, variableName, isSecret }) => {
Expand Down