Skip to content

Commit 3506005

Browse files
authored
Add toggle for style customization (#212)
1 parent 81537ef commit 3506005

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

web/src/components/devtools/Settings.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Checkbox, Button, Input, VStack, Text, Link, HStack, Box, Divider, AbsoluteCenter, Stack, Switch, Textarea, Radio, RadioGroup, IconButton, Icon, Tag, TagLabel, Badge } from '@chakra-ui/react';
22
import React, { useEffect, useState } from 'react';
33
import { dispatch, logoutState, resetState } from '../../state/dispatch';
4-
import { updateIsLocal, updateIsDevToolsOpen, updateUploadLogs, updateDevToolsTabName, DevToolsTabName, setConfirmChanges, setDemoMode, setDRMode, setGroupsEnabled, setModelsMode, setViewAllCatalogs, setEnableHighlightHelpers, setUseMemory } from '../../state/settings/reducer';
4+
import { updateIsLocal, updateIsDevToolsOpen, updateUploadLogs, updateDevToolsTabName, DevToolsTabName, setConfirmChanges, setDemoMode, setDRMode, setGroupsEnabled, setModelsMode, setViewAllCatalogs, setEnableHighlightHelpers, setUseMemory, setEnableStyleCustomization } from '../../state/settings/reducer';
55
import { useSelector } from 'react-redux';
66
import { RootState } from '../../state/store';
77
import { configs } from '../../constants';
@@ -70,6 +70,7 @@ const SettingsPage = () => {
7070
const thread = useSelector((state: RootState) => state.chat.activeThread)
7171
const activeThread = useSelector((state: RootState) => state.chat.threads[thread])
7272
const useMemory = useSelector((state: RootState) => state.settings.useMemory)
73+
const enableStyleCustomization = useSelector((state: RootState) => state.settings.enableStyleCustomization)
7374

7475
const reloadBillingInfo = async () => {
7576
await getBillingInfo().then((billingInfo) => {
@@ -124,6 +125,9 @@ const SettingsPage = () => {
124125
const updateUseMemory = (value: boolean) => {
125126
dispatch(setUseMemory(value))
126127
}
128+
const updateEnableStyleCustomization = (value: boolean) => {
129+
dispatch(setEnableStyleCustomization(value))
130+
}
127131

128132
// const CURRENT_ACTION_TESTS = ACTION_TESTS[tool];
129133
return (
@@ -208,6 +212,10 @@ const SettingsPage = () => {
208212
<Text color={"minusxBW.800"} fontSize="sm">Use Memory</Text>
209213
<Switch color={"minusxBW.800"} colorScheme='minusxGreen' size='md' isChecked={useMemory} onChange={(e) => updateUseMemory(e.target.checked)} />
210214
</HStack>
215+
<HStack justifyContent={"space-between"}>
216+
<Text color={"minusxBW.800"} fontSize="sm">Style Customization</Text>
217+
<Switch color={"minusxBW.800"} colorScheme='minusxGreen' size='md' isChecked={enableStyleCustomization} onChange={(e) => updateEnableStyleCustomization(e.target.checked)} />
218+
</HStack>
211219
</VStack>
212220
</SettingsBlock>
213221
<SettingsBlock title="Privacy">

web/src/components/devtools/index.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { configs } from '../../constants';
99
import { Context } from './Context';
1010
import { MinusXMD } from './Memory';
1111
import CSSCustomization from './CSSCustomization';
12+
import { useSelector } from 'react-redux';
13+
import { RootState } from '../../state/store';
1214

1315
const Monitors: MonitorDef[] = [
1416
{
@@ -29,6 +31,7 @@ const Monitors: MonitorDef[] = [
2931
{
3032
title: "CSS Customization",
3133
component: CSSCustomization,
34+
tags: ['production']
3235
},
3336
{
3437
title: "Dev Context",
@@ -45,11 +48,18 @@ const Monitors: MonitorDef[] = [
4548
]
4649

4750
export const DevToolsBox: React.FC = () => {
51+
const enableStyleCustomization = useSelector((state: RootState) => state.settings.enableStyleCustomization)
52+
4853
const monitors = Monitors.filter(Monitor => {
49-
if (configs.IS_DEV) {
50-
return true
54+
// Check existing dev/production logic
55+
const isAllowedByEnv = configs.IS_DEV || Monitor.tags?.includes('production')
56+
57+
// Special filtering for CSS Customization tab
58+
if (Monitor.title === 'CSS Customization') {
59+
return isAllowedByEnv && enableStyleCustomization
5160
}
52-
return Monitor.tags?.includes('production') || false
61+
62+
return isAllowedByEnv
5363
})
5464
console.log("Load assets here")
5565
return (

web/src/state/settings/reducer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ interface Settings {
114114
enable_highlight_helpers: boolean
115115
useMemory: boolean
116116
customCSS: string
117+
enableStyleCustomization: boolean
117118
}
118119

119120
const initialState: Settings = {
@@ -147,6 +148,7 @@ const initialState: Settings = {
147148
enable_highlight_helpers: false,
148149
useMemory: true,
149150
customCSS: '',
151+
enableStyleCustomization: false,
150152
}
151153

152154
export const settingsSlice = createSlice({
@@ -340,6 +342,9 @@ export const settingsSlice = createSlice({
340342
},
341343
setCustomCSS: (state, action: PayloadAction<string>) => {
342344
state.customCSS = action.payload
345+
},
346+
setEnableStyleCustomization: (state, action: PayloadAction<boolean>) => {
347+
state.enableStyleCustomization = action.payload
343348
}
344349
},
345350
})
@@ -351,7 +356,7 @@ export const { updateIsLocal, updateUploadLogs,
351356
updateSidePanelTabName, updateDevToolsTabName, setSuggestQueries,
352357
setIframeInfo, setConfirmChanges, setDemoMode, setAppRecording, setAiRules,
353358
applyTableDiff, setSelectedModels, setDRMode, setSelectedCatalog, saveCatalog, deleteCatalog, setMemberships,
354-
setGroupsEnabled, resetDefaultTablesDB, setModelsMode, setViewAllCatalogs, setEnableHighlightHelpers, setUseMemory, addMemory, setCustomCSS
359+
setGroupsEnabled, resetDefaultTablesDB, setModelsMode, setViewAllCatalogs, setEnableHighlightHelpers, setUseMemory, addMemory, setCustomCSS, setEnableStyleCustomization
355360
} = settingsSlice.actions
356361

357362
export default settingsSlice.reducer

web/src/state/store.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,17 @@ const migrations = {
415415
let newState = {...state}
416416
newState.settings.customCSS = ''
417417
return newState
418+
},
419+
38: (state: RootState) => {
420+
let newState = {...state}
421+
newState.settings.enableStyleCustomization = false
422+
return newState
418423
}
419424
}
420425

421426
const persistConfig = {
422427
key: 'root',
423-
version: 37,
428+
version: 38,
424429
storage,
425430
blacklist: ['billing', 'cache'],
426431
// @ts-ignore

0 commit comments

Comments
 (0)