Improved feature flag loading in frontend #446
This commit is contained in:
parent
0e4419312b
commit
36887f1bdf
@ -52,4 +52,5 @@ type Query {
|
|||||||
discord: Discord
|
discord: Discord
|
||||||
|
|
||||||
hasFeatureFlag(flag: String): FeatureFlag
|
hasFeatureFlag(flag: String): FeatureFlag
|
||||||
|
featureFlags: [FeatureFlag]
|
||||||
}
|
}
|
@ -40,6 +40,7 @@ type Server implements TableWithHistoryQuery {
|
|||||||
|
|
||||||
config: ServerConfig
|
config: ServerConfig
|
||||||
hasFeatureFlag(flag: String): FeatureFlag
|
hasFeatureFlag(flag: String): FeatureFlag
|
||||||
|
featureFlags: [FeatureFlag]
|
||||||
|
|
||||||
statistic(date: String): ServerStatistic
|
statistic(date: String): ServerStatistic
|
||||||
|
|
||||||
|
@ -116,6 +116,10 @@ class ServerQuery(DataQueryWithHistoryABC):
|
|||||||
"hasFeatureFlag",
|
"hasFeatureFlag",
|
||||||
lambda server, *_, **kwargs: self._resolve_has_feature_flag(server, *_, **kwargs),
|
lambda server, *_, **kwargs: self._resolve_has_feature_flag(server, *_, **kwargs),
|
||||||
)
|
)
|
||||||
|
self.set_field(
|
||||||
|
"featureFlags",
|
||||||
|
lambda server, *_, **kwargs: self._resolve_feature_flags(server, *_),
|
||||||
|
)
|
||||||
self.set_field("statistic", lambda server, *_, **kwargs: ServerStatistics(server, kwargs))
|
self.set_field("statistic", lambda server, *_, **kwargs: ServerStatistics(server, kwargs))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -142,3 +146,13 @@ class ServerQuery(DataQueryWithHistoryABC):
|
|||||||
"key": kwargs["flag"],
|
"key": kwargs["flag"],
|
||||||
"value": FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum(kwargs["flag"])),
|
"value": FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum(kwargs["flag"])),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _resolve_feature_flags(self, server: Server, *_) -> list[dict]:
|
||||||
|
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{server.discord_id}")
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
"key": flag,
|
||||||
|
"value": FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum(flag)),
|
||||||
|
}
|
||||||
|
for flag in [e.value for e in FeatureFlagsEnum]
|
||||||
|
]
|
||||||
|
@ -131,6 +131,10 @@ class Query(QueryABC):
|
|||||||
"hasFeatureFlag",
|
"hasFeatureFlag",
|
||||||
lambda *_, **kwargs: self._resolve_has_feature_flag(*_, **kwargs),
|
lambda *_, **kwargs: self._resolve_has_feature_flag(*_, **kwargs),
|
||||||
)
|
)
|
||||||
|
self.set_field(
|
||||||
|
"featureFlags",
|
||||||
|
lambda *_, **kwargs: self._resolve_feature_flags(*_),
|
||||||
|
)
|
||||||
|
|
||||||
def _resolve_has_feature_flag(self, *_, **kwargs):
|
def _resolve_has_feature_flag(self, *_, **kwargs):
|
||||||
settings: TechnicianConfig = self._config.get_configuration(TechnicianConfig)
|
settings: TechnicianConfig = self._config.get_configuration(TechnicianConfig)
|
||||||
@ -140,3 +144,13 @@ class Query(QueryABC):
|
|||||||
"key": kwargs["flag"],
|
"key": kwargs["flag"],
|
||||||
"value": FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum(kwargs["flag"])),
|
"value": FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum(kwargs["flag"])),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _resolve_feature_flags(self, *_) -> list[dict]:
|
||||||
|
settings: TechnicianConfig = self._config.get_configuration(TechnicianConfig)
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
"key": flag,
|
||||||
|
"value": FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum(flag)),
|
||||||
|
}
|
||||||
|
for flag in [e.value for e in FeatureFlagsEnum]
|
||||||
|
]
|
||||||
|
@ -128,6 +128,17 @@ export class Queries {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
static serverFeatureFlags = `
|
||||||
|
query HasServerFeatureFlag($filter: ServerFilter) {
|
||||||
|
servers(filter: $filter) {
|
||||||
|
featureFlags {
|
||||||
|
key
|
||||||
|
value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
static gameServerQuery = `
|
static gameServerQuery = `
|
||||||
query GameServersList($serverId: ID) {
|
query GameServersList($serverId: ID) {
|
||||||
servers(filter: {id: $serverId}) {
|
servers(filter: {id: $serverId}) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { GameServer, Server } from "../data/server.model";
|
import { GameServer, Server } from "../data/server.model";
|
||||||
import { User } from "../data/user.model";
|
import { User } from "../data/user.model";
|
||||||
import { AutoRole, AutoRoleRule } from "../data/auto_role.model";
|
import { AutoRole, AutoRoleRule } from "../data/auto_role.model";
|
||||||
import { Discord, Guild } from "../data/discord.model";
|
import { Discord } from "../data/discord.model";
|
||||||
import { Level } from "../data/level.model";
|
import { Level } from "../data/level.model";
|
||||||
import { Achievement, AchievementAttribute } from "../data/achievement.model";
|
import { Achievement, AchievementAttribute } from "../data/achievement.model";
|
||||||
import { TechnicianConfig } from "../config/technician-config.model";
|
import { TechnicianConfig } from "../config/technician-config.model";
|
||||||
@ -82,6 +82,10 @@ export interface HasServerFeatureFlagQuery {
|
|||||||
hasFeatureFlag: FeatureFlag;
|
hasFeatureFlag: FeatureFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FeatureFlagsQuery {
|
||||||
|
featureFlags: FeatureFlag[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface ShortRoleNameListQuery {
|
export interface ShortRoleNameListQuery {
|
||||||
shortRoleNameCount: number;
|
shortRoleNameCount: number;
|
||||||
shortRoleNames: ShortRoleName[];
|
shortRoleNames: ShortRoleName[];
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from "@angular/core";
|
import { Injectable } from "@angular/core";
|
||||||
import { MenuItem } from "primeng/api";
|
import { MenuItem } from "primeng/api";
|
||||||
import { BehaviorSubject, forkJoin, Observable } from "rxjs";
|
import { BehaviorSubject } from "rxjs";
|
||||||
import { AuthRoles } from "../../models/auth/auth-roles.enum";
|
import { AuthRoles } from "../../models/auth/auth-roles.enum";
|
||||||
import { AuthService } from "../auth/auth.service";
|
import { AuthService } from "../auth/auth.service";
|
||||||
import { TranslateService } from "@ngx-translate/core";
|
import { TranslateService } from "@ngx-translate/core";
|
||||||
@ -9,7 +9,7 @@ import { ThemeService } from "../theme/theme.service";
|
|||||||
import { Server } from "../../models/data/server.model";
|
import { Server } from "../../models/data/server.model";
|
||||||
import { UserDTO } from "../../models/auth/auth-user.dto";
|
import { UserDTO } from "../../models/auth/auth-user.dto";
|
||||||
import { ServerService } from "../server.service";
|
import { ServerService } from "../server.service";
|
||||||
import { HasServerFeatureFlagQuery, PossibleFeatureFlagsQuery, Query } from "../../models/graphql/query.model";
|
import { FeatureFlagsQuery, Query } from "../../models/graphql/query.model";
|
||||||
import { Queries } from "../../models/graphql/queries.model";
|
import { Queries } from "../../models/graphql/queries.model";
|
||||||
import { DataService } from "../data/data.service";
|
import { DataService } from "../data/data.service";
|
||||||
import { FeatureFlag } from "../../models/config/feature-flags.model";
|
import { FeatureFlag } from "../../models/config/feature-flags.model";
|
||||||
@ -165,31 +165,15 @@ export class SidebarService {
|
|||||||
|
|
||||||
if (server) {
|
if (server) {
|
||||||
this.featureFlags = [];
|
this.featureFlags = [];
|
||||||
this.data.query<PossibleFeatureFlagsQuery>("{possibleFeatureFlags}"
|
|
||||||
).subscribe(data => {
|
|
||||||
let observables: Observable<HasServerFeatureFlagQuery>[] = [];
|
|
||||||
data.possibleFeatureFlags.forEach(flag => {
|
|
||||||
observables.push(
|
|
||||||
this.data.query<HasServerFeatureFlagQuery>(Queries.hasServerFeatureFlag, {
|
|
||||||
filter: { id: server.id },
|
|
||||||
flag: flag
|
|
||||||
},
|
|
||||||
function(data: Query) {
|
|
||||||
return data.servers[0];
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
forkJoin(observables).subscribe(data => {
|
this.data.query<FeatureFlagsQuery>(Queries.serverFeatureFlags, {
|
||||||
data.forEach(flag => {
|
filter: { id: server.id }
|
||||||
if (!flag.hasFeatureFlag.value) {
|
},
|
||||||
return;
|
function(data: Query) {
|
||||||
}
|
return data.servers[0];
|
||||||
this.featureFlags.push(flag.hasFeatureFlag);
|
}).subscribe(data => {
|
||||||
});
|
this.featureFlags = data.featureFlags;
|
||||||
this._setMenu(build);
|
this._setMenu(build);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this._setMenu(build);
|
this._setMenu(build);
|
||||||
|
Loading…
Reference in New Issue
Block a user