-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4567 from navikt/feature/rydd-i-toggles
implementer by-tiltakskode custom strategy for unleash
- Loading branch information
Showing
16 changed files
with
190 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
frontend/mr-admin-flate/src/api/features/useFeatureToggle.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { FeatureToggleService, Toggles } from "@mr/api-client"; | ||
import { QueryKeys } from "@/api/QueryKeys"; | ||
import { FeatureToggleService, Tiltakskode, Toggles } from "@mr/api-client"; | ||
|
||
export type Features = Record<Toggles, boolean>; | ||
|
||
/** | ||
* Hook for å bruke en spesifikk feature toggle for å skjule eller vise funksjonalitet | ||
* @param feature Navn på feature-toggle du vil bruke | ||
* @param tiltakskoder Input til "by-tiltakskode"-stategi | ||
* @returns true hvis toggle er skrudd på, eller false hvis ikke | ||
*/ | ||
export function useFeatureToggle(feature: Toggles) { | ||
export function useFeatureToggle(feature: Toggles, tiltakskoder: Tiltakskode[] = []) { | ||
return useQuery({ | ||
queryKey: QueryKeys.features(feature), | ||
queryFn: () => FeatureToggleService.getFeatureToggle({ feature }), | ||
queryKey: ["feature", feature, tiltakskoder], | ||
queryFn: () => FeatureToggleService.getFeatureToggle({ feature, tiltakskoder }), | ||
throwOnError: false, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 6 additions & 5 deletions
11
frontend/mulighetsrommet-veileder-flate/src/api/feature-toggles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
import { QueryKeys } from "./query-keys"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { FeatureToggleService, Toggles } from "@mr/api-client"; | ||
import { FeatureToggleService, Tiltakskode, Toggles } from "@mr/api-client"; | ||
|
||
export type Features = Record<Toggles, boolean>; | ||
|
||
/** | ||
* Hook for å bruke en spesifikk feature toggle for å skjule eller vise funksjonalitet | ||
* @param feature Navn på feature-toggle du vil bruke | ||
* @param tiltakskoder Input til "by-tiltakskode"-stategi | ||
* @returns true hvis toggle er skrudd på, eller false hvis ikke | ||
*/ | ||
export function useFeatureToggle(feature: Toggles) { | ||
export function useFeatureToggle(feature: Toggles, tiltakskoder: Tiltakskode[] = []) { | ||
return useQuery({ | ||
queryKey: QueryKeys.features(feature), | ||
queryFn: () => FeatureToggleService.getFeatureToggle({ feature }), | ||
queryKey: ["feature", feature, tiltakskoder], | ||
queryFn: () => FeatureToggleService.getFeatureToggle({ feature, tiltakskoder }), | ||
throwOnError: false, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
mulighetsrommet-api/src/main/kotlin/no/nav/mulighetsrommet/unleash/FeatureToggleContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
package no.nav.mulighetsrommet.unleash | ||
|
||
import no.nav.mulighetsrommet.domain.Tiltakskode | ||
|
||
data class FeatureToggleContext( | ||
val userId: String, | ||
val sessionId: String, | ||
val remoteAddress: String, | ||
val tiltakskoder: List<Tiltakskode>, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...et-api/src/main/kotlin/no/nav/mulighetsrommet/unleash/strategies/ByTiltakskodeStrategy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package no.nav.mulighetsrommet.unleash.strategies | ||
|
||
import io.getunleash.UnleashContext | ||
import io.getunleash.strategy.Strategy | ||
import no.nav.mulighetsrommet.domain.Tiltakskode | ||
|
||
class ByTiltakskodeStrategy : Strategy { | ||
companion object { | ||
const val TILTAKSKODER_PARAM = "tiltakskoder" | ||
} | ||
|
||
override fun getName(): String { | ||
return "by-tiltakskode" | ||
} | ||
|
||
override fun isEnabled(parameters: MutableMap<String, String>): Boolean { | ||
return false | ||
} | ||
|
||
override fun isEnabled(parameters: MutableMap<String, String>, context: UnleashContext): Boolean { | ||
val enabledTiltakskoder = parameters[TILTAKSKODER_PARAM] | ||
.takeIf { !it.isNullOrBlank() } | ||
?.let { parseTiltakskoder(it) } | ||
?: return false | ||
|
||
return context.getByName(TILTAKSKODER_PARAM) | ||
.map { parseTiltakskoder(it) } | ||
.map { requestedTiltakskoder -> | ||
enabledTiltakskoder.containsAll(requestedTiltakskoder) | ||
} | ||
.orElse(false) | ||
} | ||
} | ||
|
||
private fun parseTiltakskoder(it: String) = it.split(",").map { Tiltakskode.valueOf(it) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.