From 18d2860d7bc9d86602f98de2549e169236379884 Mon Sep 17 00:00:00 2001 From: Shaurya Sharma Date: Wed, 5 Mar 2025 01:04:29 +0530 Subject: [PATCH] Modularisation fixes added --- .../CodeBuilder/Elements/ColorSwatches.jsx | 105 -------- .../CodeEditor/DynamicFxTypeRenderer.jsx | 2 +- .../GlobalSettings/ThemeSelect.jsx | 233 ------------------ .../LeftSidebar/GlobalSettings/index.jsx | 2 +- frontend/src/_styles/theme.scss | 11 +- .../ColorSwatches/ColorSwatches.jsx | 9 + .../components/ColorSwatches/index.js | 1 + .../components/ThemeSelect/ThemeSelect.jsx | 6 + .../components/ThemeSelect/index.js | 1 + .../modules/Appbuilder/components/index.js | 4 +- .../BaseColorSwatches/BaseColorSwatches.jsx | 144 +++++++++++ .../components/BaseColorSwatches/index.js | 1 + .../src/modules/common/components/index.js | 2 + 13 files changed, 178 insertions(+), 343 deletions(-) delete mode 100644 frontend/src/AppBuilder/CodeBuilder/Elements/ColorSwatches.jsx delete mode 100644 frontend/src/AppBuilder/LeftSidebar/GlobalSettings/ThemeSelect.jsx create mode 100644 frontend/src/modules/Appbuilder/components/ColorSwatches/ColorSwatches.jsx create mode 100644 frontend/src/modules/Appbuilder/components/ColorSwatches/index.js create mode 100644 frontend/src/modules/Appbuilder/components/ThemeSelect/ThemeSelect.jsx create mode 100644 frontend/src/modules/Appbuilder/components/ThemeSelect/index.js create mode 100644 frontend/src/modules/common/components/BaseColorSwatches/BaseColorSwatches.jsx create mode 100644 frontend/src/modules/common/components/BaseColorSwatches/index.js diff --git a/frontend/src/AppBuilder/CodeBuilder/Elements/ColorSwatches.jsx b/frontend/src/AppBuilder/CodeBuilder/Elements/ColorSwatches.jsx deleted file mode 100644 index 586a4c0c6a..0000000000 --- a/frontend/src/AppBuilder/CodeBuilder/Elements/ColorSwatches.jsx +++ /dev/null @@ -1,105 +0,0 @@ -import React, { useState } from 'react'; -import ToggleGroup from '@/ToolJetUI/SwitchGroup/ToggleGroup'; -import ToggleGroupItem from '@/ToolJetUI/SwitchGroup/ToggleGroupItem'; -import cx from 'classnames'; -import { Color } from './Color'; -import CheckIcon from '@/components/ui/Checkbox/CheckboxUtils/CheckIcon'; -import useStore from '@/AppBuilder/_stores/store'; -import { shallow } from 'zustand/shallow'; - -export const ColorSwatches = ({ - value, - onChange, - pickerStyle = {}, - cyLabel, - asBoxShadowPopover = true, - meta, - outerWidth = '142px', - component, - styleDefinition, -}) => { - const [componentType, setComponentType] = useState('color'); - const selectedTheme = useStore((state) => state.globalSettings.theme, shallow); - const darkMode = localStorage.getItem('darkMode') === 'true'; - const brandColors = selectedTheme?.definition?.brand?.colors || {}; - //Todo: Remove all hardcoded brand once all theme values are added. - return ( - { - acc[`var(--${colorType}-brand)`] = colorType; - return acc; - }, {})} - onChange={onChange} - pickerStyle={pickerStyle} - cyLabel={cyLabel} - asBoxShadowPopover={asBoxShadowPopover} - meta={meta} - outerWidth={outerWidth} - component={component} - styleDefinition={styleDefinition} - componentType={componentType} - SwatchesToggle={() => ( - <> - - - )} - CustomOptionList={() => ( -
- {Object.keys(brandColors)?.map((colorType, index) => ( - - ))} -
- )} - /> - ); -}; - -const SwatchesToggle = ({ value, onChange }) => { - return ( -
-
- { - onChange(value); - }} - defaultValue={value} - > - - Swatches - - - Color picker - - -
-
- ); -}; - -const CustomOption = ({ darkMode, onChange, colorType, color, value }) => { - const isSelected = `var(--${colorType}-brand)` === value; - return ( -
-
{ - onChange(`var(--${colorType}-brand)`); - }} - > -
- {isSelected && } -
- Brand/{colorType.charAt(0).toUpperCase() + colorType.slice(1)} -
-
-
- ); -}; diff --git a/frontend/src/AppBuilder/CodeEditor/DynamicFxTypeRenderer.jsx b/frontend/src/AppBuilder/CodeEditor/DynamicFxTypeRenderer.jsx index 2e2d17d4af..9a204b9cf2 100644 --- a/frontend/src/AppBuilder/CodeEditor/DynamicFxTypeRenderer.jsx +++ b/frontend/src/AppBuilder/CodeEditor/DynamicFxTypeRenderer.jsx @@ -18,7 +18,7 @@ import { NumberInput } from '../CodeBuilder/Elements/NumberInput'; import { Datepicker } from '../CodeBuilder/Elements/Datepicker'; import TableRowHeightInput from '../CodeBuilder/Elements/TableRowHeightInput'; import { TimePicker } from '../CodeBuilder/Elements/TimePicker'; -import { ColorSwatches } from '../CodeBuilder/Elements/ColorSwatches'; +import { ColorSwatches } from '@/modules/Appbuilder/components'; const AllElements = { Color, diff --git a/frontend/src/AppBuilder/LeftSidebar/GlobalSettings/ThemeSelect.jsx b/frontend/src/AppBuilder/LeftSidebar/GlobalSettings/ThemeSelect.jsx deleted file mode 100644 index 15aa24e5d5..0000000000 --- a/frontend/src/AppBuilder/LeftSidebar/GlobalSettings/ThemeSelect.jsx +++ /dev/null @@ -1,233 +0,0 @@ -import React, { useEffect, useState } from 'react'; -import Select from '@/_ui/Select'; -import CheckMark from '@/_ui/Icon/bulkIcons/CheckMark'; -import { components } from 'react-select'; -import { ButtonSolid } from '@/_ui/AppButton/AppButton'; -import useStore from '@/AppBuilder/_stores/store'; -import { shallow } from 'zustand/shallow'; -import { useNavigate } from 'react-router-dom'; -import { getWorkspaceId } from '@/_helpers/utils'; -import { appThemesService } from '../../../../ee/modules/WorkspaceSettings/pages/ManageThemes/service/app_themes.service'; -import { LicenseTooltip } from '@/LicenseTooltip'; - -const ThemeSelect = ({ darkMode }) => { - const [themesList, setThemesList] = useState([]); - const selectedTheme = useStore((state) => state.globalSettings.theme, shallow); - const featureAccess = useStore((state) => state?.license?.featureAccess, shallow); - const licenseValid = !featureAccess?.licenseStatus?.isExpired && featureAccess?.licenseStatus?.isLicenseValid; - const globalSettingsChanged = useStore((state) => state.globalSettingsChanged, shallow); - const workspaceId = getWorkspaceId(); - const appId = useStore((state) => state.app.appId, shallow); - const versionId = useStore((state) => state.currentVersionId, shallow); - const isDisabled = !licenseValid || !featureAccess?.customThemes; - const navigate = useNavigate(); - - const fetchAllThemes = async () => { - const themes = await appThemesService.fetchAllThemes(); - - const options = themes.map((theme) => ({ - value: theme.id, - name: theme.name, - label: theme.name, - color: theme?.definition?.brand?.colors?.primary, - isDefault: theme?.isDefault, - theme: theme, - })); - - setThemesList(options); - }; - - const setTheme = async (themeId) => { - await appThemesService.updateAppTheme(appId, versionId, themeId); - }; - - useEffect(() => { - fetchAllThemes(); - }, []); - - const customSelectStyles = { - control: (provided) => ({ - ...provided, - width: '158px', - height: '32px', - minHeight: '32px', - flexWrap: 'nowrap', - overflow: 'hidden', - }), - input: (provided) => ({ - ...provided, - width: '150px', - height: 'auto', - padding: '0px', - color: darkMode ? '#fff' : '#000', - }), - singleValue: (provided) => ({ - ...provided, - color: darkMode ? '#fff' : '#000', // Set selected value color based on darkMode - }), - valueContainer: (provided, _state) => ({ - ...provided, - fontSize: '12px', - height: '100%', - color: darkMode ? '#fff' : '#000', - }), - menu: (provided) => ({ - ...provided, - width: '220px', - right: '0', - left: 'auto', - }), - menuList: (provided) => ({ - ...provided, - width: '220px', - textAlign: 'left', - overflowY: 'auto', // Enable scrolling if needed - scrollbarWidth: 'none', // Hide scrollbar for Firefox - borderRadius: '8px', - }), - menuPortal: (base) => ({ - ...base, - top: base.top + 2, // Adjust the top position - }), - option: (provided, state) => ({ - ...provided, - backgroundColor: state.isFocused - ? '#f0f0f0' // Hover color - : state.isSelected - ? '#e6e6e6' // Selected background color - : 'white', - color: state.isSelected ? '#333' : 'black', // Adjust text color for selected state - padding: '0px', - paddingLeft: '20px', - - position: 'relative', - }), - }; - - const CustomOption = (props) => { - const { data, isSelected } = props; - return ( - -
- {isSelected && ( - - )} -
- {data.label} - {data?.isDefault && ( - - Default - - )} -
- - ); - }; - - const CustomValueContainer = ({ children, ...props }) => { - return ( - -
-
- {children} -
- - ); - }; - - const CustomMenuList = (props) => { - return ( - -
- - On your workspace - -
- {props.children} -
- { - navigate(`/${workspaceId}/workspace-settings/themes`); - }} - variant="tertiary" - leftIcon="addrectangle" - fill="#3e63dd" - iconWidth="16" - className="tj-text-xsm theme-create-btn" - > - Create a new theme - -
-
- ); - }; - - return ( -
-
-

Theme

-
- -