Skip to content

Commit 6934c7a

Browse files
authored
FUI - Redesign toggle (#2500)
1 parent f4743a2 commit 6934c7a

File tree

9 files changed

+78
-8
lines changed

9 files changed

+78
-8
lines changed

src/admin/leftPanel.tsx

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import * as React from 'react';
22
import { Resolve } from '@paperbits/react/decorators';
3+
import { ISiteService } from '@paperbits/common/sites';
4+
import { EventManager } from '@paperbits/common/events';
35
import { ViewManager } from '@paperbits/common/ui';
46
import { Router } from '@paperbits/common/routing';
57
import { initializeIcons } from '@fluentui/font-icons-mdl2';
6-
import { CommandBarButton, Icon, IIconProps, Separator, Stack, Text } from '@fluentui/react';
8+
import { CommandBarButton, Icon, IIconProps, Separator, Stack, Text, Toggle } from '@fluentui/react';
79
import { Pages } from './pages/pages';
810
import { Navigation } from './navigation/navigation';
911
import { Urls } from './urls/urls';
@@ -14,7 +16,7 @@ import { MediaModal } from './media/mediaModal';
1416
import { CustomWidgets } from './custom-widgets/customWidgets';
1517
import { OnboardingModal } from './onboardingModal';
1618
import { lightTheme } from './utils/themes';
17-
import { mobileBreakpoint } from '../constants';
19+
import { isRedesignEnabledSetting, mobileBreakpoint } from '../constants';
1820
initializeIcons();
1921

2022
const enum NavItem {
@@ -35,7 +37,8 @@ const enum NavItem {
3537
interface LeftPanelState {
3638
selectedNavItem: NavItem,
3739
isMobile: boolean,
38-
showOnboardingModal: boolean
40+
showOnboardingModal: boolean,
41+
isRedesignEnabled: boolean
3942
}
4043

4144
const pageIcon: IIconProps = { iconName: 'Page' };
@@ -53,6 +56,12 @@ const helpIcon: IIconProps = { iconName: 'Help' };
5356
const iconStyles = { root: { color: lightTheme.palette.themePrimary, fontSize: 20 } };
5457

5558
export class LeftPanel extends React.Component<{}, LeftPanelState> {
59+
@Resolve('siteService')
60+
public siteService: ISiteService;
61+
62+
@Resolve('eventManager')
63+
public eventManager: EventManager;
64+
5665
@Resolve('viewManager')
5766
public viewManager: ViewManager;
5867

@@ -65,12 +74,14 @@ export class LeftPanel extends React.Component<{}, LeftPanelState> {
6574
this.state = {
6675
selectedNavItem: NavItem.Main,
6776
isMobile: window.innerWidth < mobileBreakpoint,
68-
showOnboardingModal: false
77+
showOnboardingModal: false,
78+
isRedesignEnabled: false
6979
};
7080
}
7181

7282
componentDidMount(): void {
7383
if (!localStorage.getItem('isOnboardingSeen')) this.setState({ showOnboardingModal: true });
84+
this.loadSettings();
7485

7586
window.addEventListener('resize', this.checkScreenSize.bind(this));
7687
}
@@ -79,6 +90,11 @@ export class LeftPanel extends React.Component<{}, LeftPanelState> {
7990
window.removeEventListener('resize', this.checkScreenSize.bind(this));
8091
}
8192

93+
loadSettings = async (): Promise<void> => {
94+
const redesignSetting = await this.siteService.getSetting(isRedesignEnabledSetting);
95+
this.setState({ isRedesignEnabled: !!redesignSetting });
96+
}
97+
8298
checkScreenSize = (): void => {
8399
if (window.innerWidth < mobileBreakpoint) {
84100
this.setState({ isMobile: true });
@@ -217,6 +233,18 @@ export class LeftPanel extends React.Component<{}, LeftPanelState> {
217233
{ this.state.selectedNavItem === NavItem.Media && <MediaModal onDismiss={this.handleBackButtonClick.bind(this)} /> }
218234
{ this.state.selectedNavItem === NavItem.Settings && <SettingsModal onDismiss={this.handleBackButtonClick.bind(this)} /> }
219235
{ this.state.selectedNavItem === NavItem.Help && <HelpModal onDismiss={this.handleBackButtonClick.bind(this)} /> }
236+
<Toggle
237+
label={"Preview new UI design"}
238+
onText={"On"}
239+
offText={"Off"}
240+
checked={this.state.isRedesignEnabled}
241+
onChange={async (ev, checked) => {
242+
this.setState({ isRedesignEnabled: checked });
243+
await this.siteService.setSetting(isRedesignEnabledSetting, checked);
244+
this.eventManager.dispatchEvent('onSaveChanges');
245+
this.eventManager.dispatchEvent('onDataPush'); // Needed to reload the runtime part
246+
}}
247+
/>
220248
</div>
221249
</>
222250
)
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
<fui-api-details data-bind="attr: { props: runtimeConfig }"></fui-api-details>
1+
<!-- ko if: isRedesignEnabled -->
2+
<fui-api-details data-bind="attr: { props: runtimeConfig }"></fui-api-details>
3+
<!-- /ko -->
4+
<!-- ko ifnot: isRedesignEnabled -->
5+
<api-details data-bind="attr: { params: runtimeConfig }"></api-details>
6+
<!-- /ko -->

src/components/apis/details-of-api/ko/detailsOfApiViewModel.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import { StyleModel } from "@paperbits/common/styles";
1010
export class DetailsOfApiViewModel {
1111
public readonly runtimeConfig: ko.Observable<string>;
1212
public readonly styles: ko.Observable<StyleModel>;
13+
public readonly isRedesignEnabled: ko.Observable<boolean>;
1314

1415
constructor() {
1516
this.runtimeConfig = ko.observable();
1617
this.styles = ko.observable<StyleModel>();
18+
this.isRedesignEnabled = ko.observable<boolean>();
1719
}
1820
}

src/components/apis/details-of-api/ko/detailsOfApiViewModelBinder.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import { StyleCompiler } from "@paperbits/common/styles";
22
import { ViewModelBinder, WidgetState } from "@paperbits/common/widgets";
3+
import { ISiteService } from "@paperbits/common/sites";
34
import { DetailsOfApiModel } from "../detailsOfApiModel";
45
import { DetailsOfApiViewModel } from "./detailsOfApiViewModel";
6+
import { isRedesignEnabledSetting } from "../../../../constants";
57

68

79
export class DetailsOfApiViewModelBinder implements ViewModelBinder<DetailsOfApiModel, DetailsOfApiViewModel> {
8-
constructor(private readonly styleCompiler: StyleCompiler) { }
10+
constructor(
11+
private readonly styleCompiler: StyleCompiler,
12+
private readonly siteService: ISiteService
13+
) { }
914

1015
public stateToInstance(state: WidgetState, componentInstance: DetailsOfApiViewModel): void {
1116
componentInstance.styles(state.styles);
17+
componentInstance.isRedesignEnabled(state.isRedesignEnabled);
1218

1319
componentInstance.runtimeConfig(JSON.stringify({
1420
changeLogPageUrl: state.changeLogPageHyperlink
@@ -23,5 +29,7 @@ export class DetailsOfApiViewModelBinder implements ViewModelBinder<DetailsOfApi
2329
if (model.styles) {
2430
state.styles = await this.styleCompiler.getStyleModelAsync(model.styles);
2531
}
32+
33+
state.isRedesignEnabled = !!(await this.siteService.getSetting(isRedesignEnabledSetting));
2634
}
2735
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
<fui-operation-list class="d-block" data-bind="attr: { props: runtimeConfig }"></fui-operation-list>
1+
<!-- ko if: isRedesignEnabled -->
2+
<fui-operation-list class="d-block" data-bind="attr: { props: runtimeConfig }"></fui-operation-list>
3+
<!-- /ko -->
4+
<!-- ko ifnot: isRedesignEnabled -->
5+
<operation-list class="d-block" data-bind="attr: { params: runtimeConfig }"></operation-list>
6+
<!-- /ko -->

src/components/operations/operation-list/ko/operationListViewModel.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import { StyleModel } from "@paperbits/common/styles";
1010
export class OperationListViewModel {
1111
public readonly runtimeConfig: ko.Observable<string>;
1212
public readonly styles: ko.Observable<StyleModel>;
13+
public readonly isRedesignEnabled: ko.Observable<boolean>;
1314

1415
constructor() {
1516
this.runtimeConfig = ko.observable();
1617
this.styles = ko.observable<StyleModel>();
18+
this.isRedesignEnabled = ko.observable<boolean>();
1719
}
1820
}

src/components/operations/operation-list/ko/operationListViewModelBinder.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ import { ViewModelBinder, WidgetState } from "@paperbits/common/widgets";
22
import { OperationListViewModel } from "./operationListViewModel";
33
import { OperationListModel } from "../operationListModel";
44
import { StyleCompiler } from "@paperbits/common/styles";
5+
import { ISiteService } from "@paperbits/common/sites";
6+
import { isRedesignEnabledSetting } from "../../../../constants";
57

68

79
export class OperationListViewModelBinder implements ViewModelBinder<OperationListModel, OperationListViewModel> {
8-
constructor(private readonly styleCompiler: StyleCompiler) { }
10+
constructor(
11+
private readonly styleCompiler: StyleCompiler,
12+
private readonly siteService: ISiteService
13+
) { }
914

1015
public stateToInstance(state: WidgetState, componentInstance: OperationListViewModel): void {
1116
componentInstance.styles(state.styles);
17+
componentInstance.isRedesignEnabled(state.isRedesignEnabled);
1218

1319
componentInstance.runtimeConfig(JSON.stringify({
1420
allowSelection: state.allowSelection,
@@ -35,5 +41,7 @@ export class OperationListViewModelBinder implements ViewModelBinder<OperationLi
3541
if (model.styles) {
3642
state.styles = await this.styleCompiler.getStyleModelAsync(model.styles);
3743
}
44+
45+
state.isRedesignEnabled = !!(await this.siteService.getSetting(isRedesignEnabledSetting));
3846
}
3947
}

src/constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,8 @@ export const fuiTheme: Theme = {
358358
fontFamilyMonospace: "inherit",
359359
fontFamilyNumeric: "inherit",
360360
};
361+
362+
/**
363+
* Key for the setting that enables the runtime redesign of the portal
364+
*/
365+
export const isRedesignEnabledSetting = "isRedesignEnabled";

src/themes/designer/styles/admin.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939

4040
.side-panel {
4141
padding: 12px;
42+
display: flex;
43+
flex-direction: column;
44+
height: 100%;
45+
46+
.navigation {
47+
flex: 1;
48+
}
4249
}
4350

4451
.admin-side-panel-opener {

0 commit comments

Comments
 (0)