Skip to content

Commit 7036d13

Browse files
authored
Added Color customization to embedded object browser (#2246)
Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>
1 parent 697910c commit 7036d13

File tree

24 files changed

+512
-142
lines changed

24 files changed

+512
-142
lines changed

models/principal.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

models/session_response.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/auth/token.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type TokenClaims struct {
6868
AccountAccessKey string `json:"accountAccessKey,omitempty"`
6969
HideMenu bool `json:"hm,omitempty"`
7070
ObjectBrowser bool `json:"ob,omitempty"`
71+
CustomStyleOB string `json:"customStyleOb,omitempty"`
7172
}
7273

7374
// STSClaims claims struct for STS Token
@@ -79,6 +80,7 @@ type STSClaims struct {
7980
type SessionFeatures struct {
8081
HideMenu bool
8182
ObjectBrowser bool
83+
CustomStyleOB string
8284
}
8385

8486
// SessionTokenAuthenticate takes a session token, decode it, extract claims and validate the signature
@@ -123,7 +125,9 @@ func NewEncryptedTokenForClient(credentials *credentials.Value, accountAccessKey
123125
if features != nil {
124126
tokenClaims.HideMenu = features.HideMenu
125127
tokenClaims.ObjectBrowser = features.ObjectBrowser
128+
tokenClaims.CustomStyleOB = features.CustomStyleOB
126129
}
130+
127131
encryptedClaims, err := encryptClaims(tokenClaims)
128132
if err != nil {
129133
return "", err

portal-ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"react-window-infinite-loader": "^1.0.7",
4646
"recharts": "^2.1.1",
4747
"superagent": "^6.1.0",
48+
"tinycolor2": "^1.4.2",
4849
"websocket": "^1.0.31"
4950
},
5051
"scripts": {

portal-ui/src/ProtectedRoutes.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ import {
2727
globalSetDistributedSetup,
2828
operatorMode,
2929
selOpMode,
30+
setOverrideStyles,
3031
setSiteReplicationInfo,
3132
userLogged,
3233
} from "./systemSlice";
3334
import { SRInfoStateType } from "./types";
3435
import { AppState, useAppDispatch } from "./store";
3536
import { saveSessionResponse } from "./screens/Console/consoleSlice";
37+
import { getOverrideColorVariants } from "./utils/stylesUtils";
3638

3739
interface ProtectedRouteProps {
3840
Component: any;
@@ -67,6 +69,16 @@ const ProtectedRoute = ({ Component }: ProtectedRouteProps) => {
6769
dispatch(directPVMode(!!res.directPV));
6870
document.title = "MinIO Operator";
6971
}
72+
73+
if (res.customStyles && res.customStyles !== "") {
74+
const overrideColorVariants = getOverrideColorVariants(
75+
res.customStyles
76+
);
77+
78+
if (overrideColorVariants !== false) {
79+
dispatch(setOverrideStyles(overrideColorVariants));
80+
}
81+
}
7082
})
7183
.catch(() => setSessionLoading(false));
7284
}, [dispatch]);

portal-ui/src/StyleHandler.tsx

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
// This file is part of MinIO Console Server
2+
// Copyright (c) 2021 MinIO, Inc.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
import React, { Fragment } from "react";
18+
import {
19+
StyledEngineProvider,
20+
Theme,
21+
ThemeProvider,
22+
} from "@mui/material/styles";
23+
import withStyles from "@mui/styles/withStyles";
24+
import theme from "./theme/main";
25+
import "react-virtualized/styles.css";
26+
import "react-grid-layout/css/styles.css";
27+
import "react-resizable/css/styles.css";
28+
29+
import { generateOverrideTheme } from "./utils/stylesUtils";
30+
import "./index.css";
31+
import { useSelector } from "react-redux";
32+
import { AppState } from "./store";
33+
34+
declare module "@mui/styles/defaultTheme" {
35+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
36+
interface DefaultTheme extends Theme {}
37+
}
38+
39+
interface IStyleHandler {
40+
children: React.ReactNode;
41+
}
42+
43+
const StyleHandler = ({ children }: IStyleHandler) => {
44+
const colorVariants = useSelector(
45+
(state: AppState) => state.system.overrideStyles
46+
);
47+
48+
let thm = theme;
49+
let globalBody: any = {};
50+
let rowColor: any = { color: "#393939" };
51+
let detailsListPanel: any = { backgroundColor: "#fff" };
52+
53+
if (colorVariants) {
54+
thm = generateOverrideTheme(colorVariants);
55+
56+
globalBody = { backgroundColor: colorVariants.backgroundColor };
57+
rowColor = { color: colorVariants.fontColor };
58+
detailsListPanel = {
59+
backgroundColor: colorVariants.backgroundColor,
60+
color: colorVariants.fontColor,
61+
};
62+
}
63+
64+
const GlobalCss = withStyles({
65+
// @global is handled by jss-plugin-global.
66+
"@global": {
67+
body: {
68+
height: "100vh",
69+
width: "100vw",
70+
fontFamily: "Lato, sans-serif",
71+
...globalBody,
72+
},
73+
"#root": {
74+
height: "100%",
75+
width: "100%",
76+
display: "flex",
77+
flexFlow: "column",
78+
alignItems: "stretch",
79+
},
80+
".min-icon": {
81+
width: 26,
82+
},
83+
".MuiButton-endIcon": {
84+
"& .min-icon": {
85+
width: 16,
86+
},
87+
},
88+
// You should target [class*="MuiButton-root"] instead if you nest themes.
89+
".MuiButton-root:not(.noDefaultHeight)": {
90+
height: 38,
91+
},
92+
".MuiButton-contained": {
93+
fontSize: "14px",
94+
textTransform: "capitalize",
95+
padding: "15px 25px 15px 25px",
96+
borderRadius: 3,
97+
},
98+
".MuiButton-sizeSmall": {
99+
padding: "4px 10px",
100+
fontSize: "0.8125rem",
101+
},
102+
".MuiTableCell-head": {
103+
borderRadius: "3px 3px 0px 0px",
104+
fontSize: 13,
105+
},
106+
".MuiPaper-root": {
107+
borderRadius: 3,
108+
},
109+
".MuiDrawer-paperAnchorDockedLeft": {
110+
borderRight: 0,
111+
},
112+
".MuiDrawer-root": {
113+
"& .MuiPaper-root": {
114+
borderRadius: 0,
115+
},
116+
},
117+
".rowLine": {
118+
...rowColor,
119+
},
120+
".detailsListPanel": {
121+
...detailsListPanel,
122+
},
123+
hr: {
124+
borderTop: 0,
125+
borderLeft: 0,
126+
borderRight: 0,
127+
borderColor: "#999999",
128+
backgroundColor: "transparent" as const,
129+
},
130+
ul: {
131+
paddingLeft: 20,
132+
listStyle: "none" /* Remove default bullets */,
133+
"& li::before:not(.Mui*)": {
134+
content: '"■"',
135+
color: "#2781B0",
136+
fontSize: 20,
137+
display:
138+
"inline-block" /* Needed to add space between the bullet and the text */,
139+
width: "1em" /* Also needed for space (tweak if needed) */,
140+
marginLeft: "-1em" /* Also needed for space (tweak if needed) */,
141+
},
142+
"& ul": {
143+
listStyle: "none" /* Remove default bullets */,
144+
"& li::before:not(.Mui*)": {
145+
content: '"○"',
146+
color: "#2781B0",
147+
fontSize: 20,
148+
display:
149+
"inline-block" /* Needed to add space between the bullet and the text */,
150+
width: "1em" /* Also needed for space (tweak if needed) */,
151+
marginLeft: "-1em" /* Also needed for space (tweak if needed) */,
152+
},
153+
},
154+
},
155+
},
156+
})(() => null);
157+
158+
return (
159+
<Fragment>
160+
<GlobalCss />
161+
<StyledEngineProvider injectFirst>
162+
<ThemeProvider theme={thm}>{children}</ThemeProvider>
163+
</StyledEngineProvider>
164+
</Fragment>
165+
);
166+
};
167+
168+
export default StyleHandler;

portal-ui/src/common/types.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,3 +462,18 @@ export interface IBytesCalc {
462462
total: number;
463463
unit: string;
464464
}
465+
466+
export interface IEmbeddedCustomButton {
467+
backgroundColor?: string;
468+
textColor?: string;
469+
hoverColor?: string;
470+
hoverText?: string;
471+
activeColor?: string;
472+
activeText?: string;
473+
}
474+
475+
export interface IEmbeddedCustomStyles {
476+
backgroundColor: string;
477+
fontColor: string;
478+
buttonStyles: IEmbeddedCustomButton;
479+
}

0 commit comments

Comments
 (0)