Skip to content

Commit ba25ddf

Browse files
committed
update the badge numbers of all tabs in the Request Editor to count inherited and environment (if applicable) entries
1 parent f0dd132 commit ba25ddf

File tree

3 files changed

+72
-29
lines changed

3 files changed

+72
-29
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66

77
## [Unreleased]
88

9-
Nothing yet.
9+
The current behavior of badge numbers, in the Request Editor, that do not count inherited properties does not bring convenience in practical. This behavior is changed starting from this version.
10+
11+
### Changed
12+
13+
- The badge numbers of Body, Query, Header, Pre Flight, Post Flight tabs in the Request Editor now count inherited entries
14+
- The badge number of the Variable tab in the Request Editor now counts inherited and environment variables
1015

1116

1217
## [1.8.0] -- 2025-06-16

src/jvmMain/kotlin/com/sunnychung/application/multiplatform/hellohttp/model/UserRequestTemplate.kt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,9 @@ data class UserRequestTemplate(
179179
data class Scope(val baseExample: UserRequestExample, val selectedExample: UserRequestExample, val variableResolver: VariableResolver) {
180180
fun String.resolveVariables(): String = variableResolver.resolve(this)
181181

182-
fun getMergedKeyValues(
182+
fun concatActiveValues(
183183
propertyGetter: (UserRequestExample) -> List<UserKeyValuePair>?,
184184
disabledIds: Set<String>?,
185-
isResolveKeyVariable: Boolean = true,
186-
isUniqueKey: Boolean = false,
187185
environmentPropertyGetter: (Environment) -> List<UserKeyValuePair> = { emptyList() },
188186
): List<UserKeyValuePair> {
189187
val envValues = (variableResolver.environment?.let { env -> environmentPropertyGetter(env) } ?: emptyList())
@@ -196,6 +194,20 @@ data class UserRequestTemplate(
196194
.filter { it.isEnabled }
197195

198196
return (envValues + baseValues + currentValues)
197+
}
198+
199+
fun getMergedKeyValues(
200+
propertyGetter: (UserRequestExample) -> List<UserKeyValuePair>?,
201+
disabledIds: Set<String>?,
202+
isResolveKeyVariable: Boolean = true,
203+
isUniqueKey: Boolean = false,
204+
environmentPropertyGetter: (Environment) -> List<UserKeyValuePair> = { emptyList() },
205+
): List<UserKeyValuePair> {
206+
return concatActiveValues(
207+
propertyGetter = propertyGetter,
208+
environmentPropertyGetter = environmentPropertyGetter,
209+
disabledIds = disabledIds
210+
)
199211
.map { it.copy(
200212
key = it.key.let { if (isResolveKeyVariable) it.resolveVariables() else it },
201213
value = it.value.resolveVariables(),
@@ -234,11 +246,15 @@ data class UserRequestTemplate(
234246
}
235247
}
236248

237-
fun <R> withScope(exampleId: String, environment: Environment?, resolveVariableMode: ResolveVariableMode = ExpandByEnvironment, action: Scope.() -> R): R {
249+
fun createScope(exampleId: String, environment: Environment?, resolveVariableMode: ResolveVariableMode = ExpandByEnvironment): Scope {
238250
val baseExample = examples.first()
239251
val selectedExample = examples.first { it.id == exampleId }
240252

241-
return Scope(baseExample, selectedExample, VariableResolver(environment, this, exampleId, resolveVariableMode)).action()
253+
return Scope(baseExample, selectedExample, VariableResolver(environment, this, exampleId, resolveVariableMode))
254+
}
255+
256+
fun <R> withScope(exampleId: String, environment: Environment?, resolveVariableMode: ResolveVariableMode = ExpandByEnvironment, action: Scope.() -> R): R {
257+
return createScope(exampleId, environment, resolveVariableMode).action()
242258
}
243259

244260
fun getPreFlightVariables(exampleId: String, environment: Environment?) = withScope(exampleId, environment) {

src/jvmMain/kotlin/com/sunnychung/application/multiplatform/hellohttp/ux/RequestEditorView.kt

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -606,30 +606,52 @@ fun RequestEditorView(
606606
}
607607

608608
fun List<UserKeyValuePair>.countActive() = count { it.isEnabled }
609-
610-
val tabBadgeNum = { tab: RequestTab -> when (tab) {
611-
RequestTab.Body -> when (val body = selectedExample.body) {
612-
is FileBody -> isApplicable { it.overrides?.isOverrideBody } * body.filePath.countNotBlank()
613-
is FormUrlEncodedBody -> body.value.countActive()
614-
is MultipartBody -> body.value.countActive()
615-
is GraphqlBody -> isApplicable { it.overrides?.isOverrideBodyContent } * body.document.countNotBlank() +
616-
isApplicable { it.overrides?.isOverrideBodyVariables } * body.variables.countNotBlank()
617-
is StringBody -> isApplicable { it.overrides?.isOverrideBody } * body.value.countNotBlank()
618-
null -> 0
609+
fun UserRequestTemplate.Scope.countActive(
610+
propertyGetter: (UserRequestExample) -> List<UserKeyValuePair>?,
611+
disabledIds: Set<String>?,
612+
environmentPropertyGetter: (Environment) -> List<UserKeyValuePair> = { emptyList() },
613+
) = concatActiveValues(propertyGetter, disabledIds, environmentPropertyGetter).count()
614+
615+
fun UserRequestTemplate.Scope.countNotBlank(
616+
propertyGetter: (UserRequestExample) -> String?,
617+
isOverride: Boolean?
618+
): Int {
619+
val example = if (isOverride == true) {
620+
selectedExample
621+
} else {
622+
baseExample
619623
}
620-
RequestTab.Query -> selectedExample.queryParameters.countActive()
621-
RequestTab.Header -> selectedExample.headers.countActive()
622-
RequestTab.PreFlight -> isApplicable { it.overrides?.isOverridePreFlightScript } *
623-
selectedExample.preFlight.executeCode.countNotBlank() +
624-
selectedExample.preFlight.updateVariablesFromHeader.countActive() +
625-
selectedExample.preFlight.updateVariablesFromQueryParameters.countActive() +
626-
selectedExample.preFlight.updateVariablesFromBody.countActive() +
627-
selectedExample.preFlight.updateVariablesFromGraphqlVariables.countActive()
628-
RequestTab.PostFlight -> selectedExample.postFlight.updateVariablesFromHeader.countActive() +
629-
selectedExample.postFlight.updateVariablesFromBody.countActive()
630-
RequestTab.Cookie -> if (subprojectConfig.isCookieEnabled()) applicableCookies.countActive() else 0
631-
RequestTab.Variable -> selectedExample.variables.countActive()
632-
} }
624+
return propertyGetter(example).countNotBlank()
625+
}
626+
627+
val scope = request.createScope(selectedExample.id, environment)
628+
629+
val tabBadgeNum = with(scope) {
630+
val overrides = selectedExample.overrides
631+
{ tab: RequestTab -> when (tab) {
632+
RequestTab.Body -> when (selectedExample.body) {
633+
is FileBody -> countNotBlank({ (it.body as? FileBody)?.filePath }, overrides?.isOverrideBody)
634+
is FormUrlEncodedBody -> countActive({ (it.body as? FormUrlEncodedBody)?.value }, overrides?.disabledBodyKeyValueIds)
635+
is MultipartBody -> countActive({ (it.body as? MultipartBody)?.value }, overrides?.disabledBodyKeyValueIds)
636+
is GraphqlBody -> countNotBlank({ (it.body as? GraphqlBody)?.document }, overrides?.isOverrideBodyContent) +
637+
countNotBlank({ (it.body as? GraphqlBody)?.variables }, overrides?.isOverrideBodyVariables)
638+
is StringBody -> countNotBlank({ (it.body as? StringBody)?.value }, overrides?.isOverrideBody)
639+
null -> 0
640+
}
641+
RequestTab.Query -> countActive({ it.queryParameters }, overrides?.disabledQueryParameterIds)
642+
RequestTab.Header -> countActive({ it.headers }, overrides?.disabledHeaderIds)
643+
RequestTab.PreFlight ->
644+
countNotBlank({ it.preFlight.executeCode }, overrides?.isOverridePreFlightScript) +
645+
countActive({ it.preFlight.updateVariablesFromHeader }, overrides?.disablePreFlightUpdateVarIds) +
646+
countActive({ it.preFlight.updateVariablesFromBody }, overrides?.disablePreFlightUpdateVarIds) +
647+
countActive({ it.preFlight.updateVariablesFromQueryParameters }, overrides?.disablePreFlightUpdateVarIds) +
648+
countActive({ it.preFlight.updateVariablesFromGraphqlVariables }, overrides?.disablePreFlightUpdateVarIds)
649+
RequestTab.PostFlight -> countActive({ it.postFlight.updateVariablesFromHeader }, overrides?.disablePostFlightUpdateVarIds) +
650+
countActive({ it.postFlight.updateVariablesFromBody }, overrides?.disablePostFlightUpdateVarIds)
651+
RequestTab.Cookie -> if (subprojectConfig.isCookieEnabled()) applicableCookies.countActive() else 0
652+
RequestTab.Variable -> request.getAllVariables(selectedExampleId, environment).count()
653+
} }
654+
}
633655

634656
TabsView(
635657
modifier = Modifier.fillMaxWidth().background(color = colors.backgroundLight).testTag(TestTag.RequestParameterTypeTabContainer.name),

0 commit comments

Comments
 (0)