Skip to content

Commit 26b8101

Browse files
Expose the default value of UIImplementation to portal
ref DEV-1789
2 parents 546292d + 7212c9f commit 26b8101

File tree

9 files changed

+89
-50
lines changed

9 files changed

+89
-50
lines changed

pkg/lib/web/ui_implementation.go

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func (s *UIImplementationService) GetUIImplementation() config.UIImplementation
3939
default:
4040
// The ultimate default is still interaction.
4141
// It is expected that the deployment set it to authflowv2 during the transition period.
42+
// When you change this, you also need to change portal/src/system-config.ts
4243
return config.UIImplementationInteraction
4344
}
4445
}
@@ -61,6 +62,7 @@ func (s *UIImplementationService) GetSettingsUIImplementation() config.SettingsU
6162
default:
6263
// The ultimate default is still v1
6364
// It is expected that the deployment set it to v1 during the transition period.
65+
// When you change this, you also need to change portal/src/system-config.ts
6466
return config.SettingsUIImplementationV1
6567
}
6668
}

pkg/portal/deps/deps.go

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ var DependencySet = wire.NewSet(
8383
"NFTIndexerAPIEndpoint",
8484
"DenoEndpoint",
8585
"AppHostSuffixes",
86+
"UIImplementation",
87+
"UISettingsImplementation",
8688
),
8789
wire.FieldsOf(new(*RequestProvider),
8890
"RootProvider",

pkg/portal/model/system_config.go

+17-15
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@ import (
55
)
66

77
type SystemConfig struct {
8-
AuthgearClientID string `json:"authgearClientID"`
9-
AuthgearEndpoint string `json:"authgearEndpoint"`
10-
SentryDSN string `json:"sentryDSN,omitempty"`
11-
AppHostSuffix string `json:"appHostSuffix"`
12-
AvailableLanguages []string `json:"availableLanguages"`
13-
BuiltinLanguages []string `json:"builtinLanguages"`
14-
Themes interface{} `json:"themes,omitempty"`
15-
Translations interface{} `json:"translations,omitempty"`
16-
SearchEnabled bool `json:"searchEnabled"`
17-
Web3Enabled bool `json:"web3Enabled"`
18-
AuditLogEnabled bool `json:"auditLogEnabled"`
19-
AnalyticEnabled bool `json:"analyticEnabled"`
20-
AnalyticEpoch *timeutil.Date `json:"analyticEpoch,omitempty"`
21-
GitCommitHash string `json:"gitCommitHash,omitempty"`
22-
GTMContainerID string `json:"gtmContainerID,omitempty"`
8+
AuthgearClientID string `json:"authgearClientID"`
9+
AuthgearEndpoint string `json:"authgearEndpoint"`
10+
SentryDSN string `json:"sentryDSN,omitempty"`
11+
AppHostSuffix string `json:"appHostSuffix"`
12+
AvailableLanguages []string `json:"availableLanguages"`
13+
BuiltinLanguages []string `json:"builtinLanguages"`
14+
Themes interface{} `json:"themes,omitempty"`
15+
Translations interface{} `json:"translations,omitempty"`
16+
SearchEnabled bool `json:"searchEnabled"`
17+
Web3Enabled bool `json:"web3Enabled"`
18+
AuditLogEnabled bool `json:"auditLogEnabled"`
19+
AnalyticEnabled bool `json:"analyticEnabled"`
20+
AnalyticEpoch *timeutil.Date `json:"analyticEpoch,omitempty"`
21+
GitCommitHash string `json:"gitCommitHash,omitempty"`
22+
GTMContainerID string `json:"gtmContainerID,omitempty"`
23+
UIImplementation string `json:"uiImplementation,omitempty"`
24+
UISettingsImplementation string `json:"uiSettingsImplementation,omitempty"`
2325
}

pkg/portal/service/system_config.go

+28-24
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ type ResourceManager interface {
2020
}
2121

2222
type SystemConfigProvider struct {
23-
AuthgearConfig *config.AuthgearConfig
24-
AppConfig *config.AppConfig
25-
SearchConfig *config.SearchConfig
26-
Web3Config *config.Web3Config
27-
AuditLogConfig *config.AuditLogConfig
28-
AnalyticConfig *configlib.AnalyticConfig
29-
GTMConfig *config.GoogleTagManagerConfig
30-
FrontendSentryConfig *config.PortalFrontendSentryConfig
31-
Resources ResourceManager
23+
AuthgearConfig *config.AuthgearConfig
24+
AppConfig *config.AppConfig
25+
SearchConfig *config.SearchConfig
26+
Web3Config *config.Web3Config
27+
AuditLogConfig *config.AuditLogConfig
28+
AnalyticConfig *configlib.AnalyticConfig
29+
GTMConfig *config.GoogleTagManagerConfig
30+
FrontendSentryConfig *config.PortalFrontendSentryConfig
31+
GlobalUIImplementation configlib.GlobalUIImplementation
32+
GlobalUISettingsImplementation configlib.GlobalUISettingsImplementation
33+
Resources ResourceManager
3234
}
3335

3436
func (p *SystemConfigProvider) SystemConfig() (*model.SystemConfig, error) {
@@ -48,21 +50,23 @@ func (p *SystemConfigProvider) SystemConfig() (*model.SystemConfig, error) {
4850
}
4951

5052
return &model.SystemConfig{
51-
AuthgearClientID: p.AuthgearConfig.ClientID,
52-
AuthgearEndpoint: p.AuthgearConfig.Endpoint,
53-
SentryDSN: p.FrontendSentryConfig.DSN,
54-
AppHostSuffix: p.AppConfig.HostSuffix,
55-
AvailableLanguages: intl.AvailableLanguages,
56-
BuiltinLanguages: intl.BuiltinLanguages,
57-
Themes: themes,
58-
Translations: translations,
59-
SearchEnabled: p.SearchConfig.Enabled,
60-
Web3Enabled: p.Web3Config.Enabled,
61-
AuditLogEnabled: p.AuditLogConfig.Enabled,
62-
AnalyticEnabled: p.AnalyticConfig.Enabled,
63-
AnalyticEpoch: analyticEpoch,
64-
GitCommitHash: strings.TrimPrefix(version.Version, "git-"),
65-
GTMContainerID: p.GTMConfig.ContainerID,
53+
AuthgearClientID: p.AuthgearConfig.ClientID,
54+
AuthgearEndpoint: p.AuthgearConfig.Endpoint,
55+
SentryDSN: p.FrontendSentryConfig.DSN,
56+
AppHostSuffix: p.AppConfig.HostSuffix,
57+
AvailableLanguages: intl.AvailableLanguages,
58+
BuiltinLanguages: intl.BuiltinLanguages,
59+
Themes: themes,
60+
Translations: translations,
61+
SearchEnabled: p.SearchConfig.Enabled,
62+
Web3Enabled: p.Web3Config.Enabled,
63+
AuditLogEnabled: p.AuditLogConfig.Enabled,
64+
AnalyticEnabled: p.AnalyticConfig.Enabled,
65+
AnalyticEpoch: analyticEpoch,
66+
GitCommitHash: strings.TrimPrefix(version.Version, "git-"),
67+
GTMContainerID: p.GTMConfig.ContainerID,
68+
UIImplementation: string(p.GlobalUIImplementation),
69+
UISettingsImplementation: string(p.GlobalUISettingsImplementation),
6670
}, nil
6771
}
6872

pkg/portal/wire_gen.go

+14-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

portal/src/AppRoot.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import ShowLoading from "./ShowLoading";
99
import CookieLifetimeConfigurationScreen from "./graphql/portal/CookieLifetimeConfigurationScreen";
1010
import { useUnauthenticatedDialogContext } from "./components/auth/UnauthenticatedDialogContext";
1111
import EditConfigurationScreen from "./graphql/portal/EditConfigurationScreen";
12+
import { useUIImplementation } from "./hook/useUIImplementation";
1213

1314
const RolesScreen = lazy(async () => import("./graphql/adminapi/RolesScreen"));
1415
const AddRoleScreen = lazy(
@@ -179,6 +180,10 @@ const AppRoot: React.VFC = function AppRoot() {
179180
const { effectiveAppConfig, loading, error } =
180181
useAppAndSecretConfigQuery(appID);
181182

183+
const uiImplementation = useUIImplementation(
184+
effectiveAppConfig?.ui?.implementation
185+
);
186+
182187
if (loading) {
183188
return <ShowLoading />;
184189
}
@@ -192,7 +197,7 @@ const AppRoot: React.VFC = function AppRoot() {
192197
return <Navigate to="/projects" replace={true} />;
193198
}
194199

195-
const useAuthUIV2 = effectiveAppConfig?.ui?.implementation === "authflowv2";
200+
const useAuthUIV2 = uiImplementation === "authflowv2";
196201

197202
return (
198203
<ApolloProvider client={client}>

portal/src/graphql/portal/LoginMethodConfigurationScreen.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ import {
125125
LocalValidationError,
126126
makeLocalValidationError,
127127
} from "../../error/validation";
128+
import { useUIImplementation } from "../../hook/useUIImplementation";
128129

129130
function splitByNewline(text: string): string[] {
130131
return text
@@ -3114,7 +3115,7 @@ const LoginMethodConfigurationContent: React.VFC<LoginMethodConfigurationContent
31143115
const { renderToString } = useContext(Context);
31153116

31163117
const {
3117-
uiImplementation,
3118+
uiImplementation: projectUIImplementation,
31183119
identitiesControl,
31193120
primaryAuthenticatorsControl,
31203121
loginIDKeyConfigsControl,
@@ -3312,6 +3313,8 @@ const LoginMethodConfigurationContent: React.VFC<LoginMethodConfigurationContent
33123313
[setState]
33133314
);
33143315

3316+
const uiImplementation = useUIImplementation(projectUIImplementation);
3317+
33153318
return (
33163319
<ScreenContent>
33173320
<ScreenTitle className={styles.widget}>
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { useSystemConfig } from "../context/SystemConfigContext";
2+
import { UIImplementation } from "../types";
3+
4+
export function useUIImplementation(
5+
projectValue: UIImplementation | undefined
6+
): UIImplementation {
7+
const systemConfig = useSystemConfig();
8+
if (projectValue != null) {
9+
return projectValue;
10+
}
11+
return systemConfig.uiImplementation as UIImplementation;
12+
}

portal/src/system-config.ts

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export interface SystemConfig {
1818
analyticEnabled: boolean;
1919
analyticEpoch: string;
2020
gtmContainerID: string;
21+
uiImplementation: string;
22+
uiSettingsImplemenation: string;
2123
}
2224

2325
export interface SystemConfigThemes {
@@ -268,5 +270,7 @@ export function instantiateSystemConfig(
268270
analyticEnabled: config.analyticEnabled ?? false,
269271
analyticEpoch: config.analyticEpoch ?? "",
270272
gtmContainerID: config.gtmContainerID ?? "",
273+
uiImplementation: config.uiImplementation ?? "interaction",
274+
uiSettingsImplemenation: config.uiSettingsImplemenation ?? "v1",
271275
};
272276
}

0 commit comments

Comments
 (0)