Skip to content

Commit

Permalink
fix: environment tooltip update bug (#3819)
Browse files Browse the repository at this point in the history
  • Loading branch information
nivedin committed Feb 13, 2024
1 parent de4635d commit 45b5327
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ import {
AggregateEnvironment,
aggregateEnvsWithSecrets$,
getAggregateEnvsWithSecrets,
getCurrentEnvironment,
getSelectedEnvironmentType,
} from "~/newstore/environments"
import { invokeAction } from "~/helpers/actions"
import IconUser from "~icons/lucide/user?raw"
import IconUsers from "~icons/lucide/users?raw"
import IconEdit from "~icons/lucide/edit?raw"
import { SecretEnvironmentService } from "~/services/secret-environment.service"
import { getService } from "~/modules/dioc"

const HOPP_ENVIRONMENT_REGEX = /(<<[a-zA-Z0-9-_]+>>)/g

Expand All @@ -28,6 +31,8 @@ const HOPP_ENV_HIGHLIGHT =
const HOPP_ENV_HIGHLIGHT_FOUND = "env-found"
const HOPP_ENV_HIGHLIGHT_NOT_FOUND = "env-not-found"

const secretEnvironmentService = getService(SecretEnvironmentService)

const cursorTooltipField = (aggregateEnvs: AggregateEnvironment[]) =>
hoverTooltip(
(view, pos, side) => {
Expand Down Expand Up @@ -67,9 +72,21 @@ const cursorTooltipField = (aggregateEnvs: AggregateEnvironment[]) =>
const envName = tooltipEnv?.sourceEnv ?? "Choose an Environment"

let envValue = "Not Found"

const currentSelectedEnvironment = getCurrentEnvironment()

const hasSecretEnv = secretEnvironmentService.hasSecretValue(
tooltipEnv?.sourceEnv !== "Global"
? currentSelectedEnvironment.id
: "Global",
tooltipEnv?.key ?? ""
)

if (!tooltipEnv?.secret && tooltipEnv?.value) envValue = tooltipEnv.value
else if (tooltipEnv?.secret && tooltipEnv.value) {
else if (tooltipEnv?.secret && hasSecretEnv) {
envValue = "******"
} else if (tooltipEnv?.secret && !hasSecretEnv) {
envValue = "Empty"
} else if (!tooltipEnv?.sourceEnv) {
envValue = "Not Found"
} else if (!tooltipEnv?.value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ const EnvironmentVariablesSchema = z.union([
key: z.string(),
secret: z.literal(true),
}),
z.object({
key: z.string(),
value: z.string(),
}),
])

export const SECRET_ENVIRONMENT_VARIABLE_SCHEMA = z.union([
Expand Down Expand Up @@ -405,7 +409,9 @@ const HoppTestResultSchema = z
.object({
additions: z.array(EnvironmentVariablesSchema),
updations: z.array(
EnvironmentVariablesSchema.refine((x) => !x.secret).and(
EnvironmentVariablesSchema.refine(
(x) => "secret" in x && !x.secret
).and(
z.object({
previousValue: z.string(),
})
Expand All @@ -418,7 +424,9 @@ const HoppTestResultSchema = z
.object({
additions: z.array(EnvironmentVariablesSchema),
updations: z.array(
EnvironmentVariablesSchema.refine((x) => !x.secret).and(
EnvironmentVariablesSchema.refine(
(x) => "secret" in x && !x.secret
).and(
z.object({
previousValue: z.string(),
})
Expand Down

0 comments on commit 45b5327

Please sign in to comment.