EnxDev commented on code in PR #34182:
URL: https://github.com/apache/superset/pull/34182#discussion_r2228242868


##########
superset-frontend/src/dashboard/components/CssEditor/index.tsx:
##########
@@ -151,8 +256,17 @@ class CssEditor extends PureComponent<CssEditorProps, 
CssEditorState> {
               width="100%"
               editorProps={{ $blockScrolling: true }}
               enableLiveAutocompletion
-              value={this.state.css || ''}
+              value={this.state.pendingCss || ''}
             />
+            <div style={{ marginTop: 16, textAlign: 'right' }}>

Review Comment:
   I think it should be better to use `sizeUnit` and `float: right`



##########
superset-frontend/src/dashboard/components/SaveModal.tsx:
##########
@@ -144,96 +115,87 @@ class SaveModal extends PureComponent<SaveModalProps, 
SaveModalState> {
       css: customCss,
       dashboard_title:
         saveType === SAVE_TYPE_NEWDASHBOARD ? newDashName : dashboardTitle,
-      duplicate_slices: this.state.duplicateSlices,
+      duplicate_slices: duplicateSlices,
       last_modified_time: lastModifiedTime,
       owners: dashboardInfo.owners,
       roles: dashboardInfo.roles,
       metadata: {
         ...dashboardInfo?.metadata,
-        positions,
-        refresh_frequency: refreshFrequency,
+        positions: layout,
+        refresh_frequency: refreshFrequencyToUse,
       },
     };
 
     if (saveType === SAVE_TYPE_NEWDASHBOARD && !newDashName) {
-      this.props.addDangerToast(
-        t('You must pick a name for the new dashboard'),
-      );
+      addDangerToast(t('You must pick a name for the new dashboard'));
     } else {
-      this.onSave(data, dashboardId, saveType).then((resp: JsonResponse) => {
-        if (saveType === SAVE_TYPE_NEWDASHBOARD && resp.json?.result?.id) {
-          navigateTo(`/superset/dashboard/${resp.json.result.id}/`);
-        }
-      });
-      this.modal?.current?.close?.();
+      onSave(data, dashboardId, saveType);
+      modal?.current?.close?.();
     }
-  }
-
-  render() {
-    const { theme } = themeObject;
-    return (
-      <ModalTrigger
-        ref={this.modal}
-        triggerNode={this.props.triggerNode}
-        modalTitle={t('Save dashboard')}
-        modalBody={
-          <Form layout="vertical">
-            <Form.Item>
-              <Radio
-                value={SAVE_TYPE_OVERWRITE}
-                onChange={this.handleSaveTypeChange}
-                checked={this.state.saveType === SAVE_TYPE_OVERWRITE}
-                disabled={!this.props.canOverwrite}
-              >
-                {t('Overwrite Dashboard [%s]', this.props.dashboardTitle)}
-              </Radio>
-            </Form.Item>
-
-            <Divider />
-
-            <Form.Item style={{ marginBottom: theme.sizeUnit }}>
-              <Radio
-                value={SAVE_TYPE_NEWDASHBOARD}
-                onChange={this.handleSaveTypeChange}
-                checked={this.state.saveType === SAVE_TYPE_NEWDASHBOARD}
-              >
-                {t('Save as:')}
-              </Radio>
-            </Form.Item>
-
-            <Form.Item style={{ marginBottom: theme.sizeUnit }}>
-              <Input
-                placeholder={t('[dashboard name]')}
-                value={this.state.newDashName}
-                onFocus={e => this.handleNameChange(e.target.value)}
-                onChange={e => this.handleNameChange(e.target.value)}
-              />
-            </Form.Item>
-
-            <Form.Item>
-              <Checkbox
-                checked={this.state.duplicateSlices}
-                onChange={() => this.toggleDuplicateSlices()}
-              >
-                {t('also copy (duplicate) charts')}
-              </Checkbox>
-            </Form.Item>
-          </Form>
-        }
-        modalFooter={
-          <Space style={{ display: 'flex', justifyContent: 'flex-end' }}>
-            <Button
-              type="primary"
-              data-test="modal-save-dashboard-button"
-              onClick={this.saveDashboard}
+  };
+
+  return (
+    <ModalTrigger
+      ref={modal}
+      triggerNode={triggerNode}
+      modalTitle={t('Save dashboard')}
+      modalBody={
+        <Form layout="vertical">
+          <Form.Item>
+            <Radio
+              value={SAVE_TYPE_OVERWRITE}
+              onChange={handleSaveTypeChange}
+              checked={saveType === SAVE_TYPE_OVERWRITE}
+              disabled={!canOverwrite}
+            >
+              {t('Overwrite Dashboard [%s]', dashboardTitle)}
+            </Radio>
+          </Form.Item>
+
+          <Divider />
+
+          <Form.Item style={{ marginBottom: theme.sizeUnit }}>
+            <Radio
+              value={SAVE_TYPE_NEWDASHBOARD}
+              onChange={handleSaveTypeChange}
+              checked={saveType === SAVE_TYPE_NEWDASHBOARD}
+            >
+              {t('Save as:')}
+            </Radio>
+          </Form.Item>
+
+          <Form.Item style={{ marginBottom: theme.sizeUnit }}>
+            <Input
+              placeholder={t('[dashboard name]')}
+              value={newDashName}
+              onFocus={e => handleNameChange(e.target.value)}
+              onChange={e => handleNameChange(e.target.value)}
+            />
+          </Form.Item>
+
+          <Form.Item>
+            <Checkbox
+              checked={duplicateSlices}
+              onChange={() => toggleDuplicateSlices()}
             >
-              {t('Save')}
-            </Button>
-          </Space>
-        }
-      />
-    );
-  }
+              {t('also copy (duplicate) charts')}
+            </Checkbox>
+          </Form.Item>
+        </Form>
+      }
+      modalFooter={
+        <Space style={{ display: 'flex', justifyContent: 'flex-end' }}>

Review Comment:
   ```suggestion
           <Flex justify="flex-end">
   ```



##########
superset-frontend/src/features/themes/ThemeModal.tsx:
##########
@@ -0,0 +1,394 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { FunctionComponent, useState, useEffect, ChangeEvent } from 'react';
+
+import { css, styled, t, useTheme } from '@superset-ui/core';
+import { useSingleViewResource } from 'src/views/CRUD/hooks';
+import { useThemeContext } from 'src/theme/ThemeProvider';
+
+import { Icons } from '@superset-ui/core/components/Icons';
+import withToasts from 'src/components/MessageToasts/withToasts';
+import {
+  Input,
+  Modal,
+  JsonEditor,
+  Button,
+  Form,
+  Tooltip,
+  Alert,
+} from '@superset-ui/core/components';
+import { Typography } from '@superset-ui/core/components/Typography';
+
+import { OnlyKeyWithType } from 'src/utils/types';
+import { ThemeObject } from './types';
+
+interface ThemeModalProps {
+  addDangerToast: (msg: string) => void;
+  addSuccessToast?: (msg: string) => void;
+  theme?: ThemeObject | null;
+  onThemeAdd?: (theme?: ThemeObject) => void;
+  onHide: () => void;
+  show: boolean;
+  canDevelop?: boolean;
+}
+
+type ThemeStringKeys = keyof Pick<
+  ThemeObject,
+  OnlyKeyWithType<ThemeObject, String>
+>;
+
+const StyledJsonEditor = styled.div`
+  ${({ theme }) => css`
+    border-radius: ${theme.borderRadius}px;
+    border: 1px solid ${theme.colorBorder};
+
+    .ace_editor {
+      border-radius: ${theme.borderRadius}px;
+    }
+  `}
+`;
+
+const ThemeModal: FunctionComponent<ThemeModalProps> = ({
+  addDangerToast,
+  addSuccessToast,
+  onThemeAdd,
+  onHide,
+  show,
+  theme = null,
+  canDevelop = false,
+}) => {
+  const supersetTheme = useTheme();
+  const { setTemporaryTheme } = useThemeContext();
+  const [disableSave, setDisableSave] = useState<boolean>(true);
+  const [currentTheme, setCurrentTheme] = useState<ThemeObject | null>(null);
+  const [isHidden, setIsHidden] = useState<boolean>(true);
+  const isEditMode = theme !== null;
+  const isSystemTheme = currentTheme?.is_system === true;
+  const isReadOnly = isSystemTheme;
+  const canDevelopThemes = canDevelop;
+
+  // theme fetch logic
+  const {
+    state: { loading, resource },
+    fetchResource,
+    createResource,
+    updateResource,
+  } = useSingleViewResource<ThemeObject>('theme', t('theme'), addDangerToast);
+
+  // Functions
+  const hide = () => {
+    onHide();
+    setCurrentTheme(null);
+  };
+
+  const onSave = () => {
+    if (isEditMode) {
+      // Edit
+      if (currentTheme?.id) {
+        const update_id = currentTheme.id;
+        delete currentTheme.id;
+        delete currentTheme.created_by;
+        delete currentTheme.changed_by;
+        delete currentTheme.changed_on_delta_humanized;
+
+        updateResource(update_id, currentTheme).then(response => {
+          if (!response) {
+            return;
+          }
+
+          if (onThemeAdd) {
+            onThemeAdd();
+          }
+
+          hide();
+        });
+      }
+    } else if (currentTheme) {
+      // Create
+      createResource(currentTheme).then(response => {
+        if (!response) {
+          return;
+        }
+
+        if (onThemeAdd) {
+          onThemeAdd();
+        }
+
+        hide();
+      });
+    }
+  };
+
+  const onApply = () => {
+    if (currentTheme?.json_data && isValidJson(currentTheme.json_data)) {
+      try {
+        const themeConfig = JSON.parse(currentTheme.json_data);
+        setTemporaryTheme(themeConfig);
+        if (addSuccessToast) {
+          addSuccessToast(t('Local theme set for preview'));
+        }
+      } catch (error) {
+        addDangerToast(t('Failed to apply theme: Invalid JSON'));
+      }
+    }
+  };
+
+  const onThemeNameChange = (event: ChangeEvent<HTMLInputElement>) => {
+    const { target } = event;
+
+    const data = {
+      ...currentTheme,
+      theme_name: currentTheme ? currentTheme.theme_name : '',
+      json_data: currentTheme ? currentTheme.json_data : '',
+    };
+
+    data[target.name as ThemeStringKeys] = target.value;
+    setCurrentTheme(data);
+  };
+
+  const onJsonDataChange = (jsonData: string) => {
+    const data = {
+      ...currentTheme,
+      theme_name: currentTheme ? currentTheme.theme_name : '',
+      json_data: jsonData,
+    };
+    setCurrentTheme(data);
+  };
+
+  const isValidJson = (str?: string) => {
+    if (!str) return false;
+    try {
+      JSON.parse(str);
+      return true;
+    } catch (e) {
+      return false;
+    }
+  };
+
+  const validate = () => {
+    if (isReadOnly) {
+      setDisableSave(true);
+      return;
+    }
+
+    if (
+      currentTheme?.theme_name.length &&
+      currentTheme?.json_data?.length &&
+      isValidJson(currentTheme.json_data)
+    ) {
+      setDisableSave(false);
+    } else {
+      setDisableSave(true);
+    }
+  };
+
+  // Initialize
+  useEffect(() => {
+    if (
+      isEditMode &&
+      (!currentTheme?.id ||
+        (theme && theme?.id !== currentTheme.id) ||
+        (isHidden && show))
+    ) {
+      if (theme?.id && !loading) {
+        fetchResource(theme.id);
+      }
+    } else if (
+      !isEditMode &&
+      (!currentTheme || currentTheme.id || (isHidden && show))
+    ) {
+      setCurrentTheme({
+        theme_name: '',
+        json_data: JSON.stringify({}, null, 2),
+      });
+    }
+  }, [theme, show]);
+
+  useEffect(() => {
+    if (resource) {
+      setCurrentTheme(resource);
+    }
+  }, [resource]);
+
+  // Validation
+  useEffect(() => {
+    validate();
+  }, [
+    currentTheme ? currentTheme.theme_name : '',
+    currentTheme ? currentTheme.json_data : '',
+    isReadOnly,
+  ]);
+
+  // Show/hide
+  if (isHidden && show) {
+    setIsHidden(false);
+  }
+
+  return (
+    <Modal
+      disablePrimaryButton={isReadOnly || disableSave}
+      onHandledPrimaryAction={isReadOnly ? undefined : onSave}
+      onHide={hide}
+      primaryButtonName={isEditMode ? t('Save') : t('Add')}
+      show={show}
+      width="55%"
+      footer={[
+        <Button key="cancel" onClick={hide} buttonStyle="secondary">
+          {isReadOnly ? t('Close') : t('Cancel')}
+        </Button>,
+        ...(!isReadOnly
+          ? [
+              <Button
+                key="save"
+                onClick={onSave}
+                disabled={disableSave}
+                buttonStyle="primary"
+              >
+                {isEditMode ? t('Save') : t('Add')}
+              </Button>,
+            ]
+          : []),
+      ]}
+      title={
+        <Typography.Title level={4} data-test="theme-modal-title">
+          {isEditMode ? (
+            <Icons.EditOutlined
+              iconSize="l"
+              css={css`
+                margin: auto ${supersetTheme.sizeUnit * 2}px auto 0;
+              `}
+            />
+          ) : (
+            <Icons.PlusOutlined
+              iconSize="l"
+              css={css`
+                margin: auto ${supersetTheme.sizeUnit * 2}px auto 0;
+              `}
+            />
+          )}
+          {isEditMode
+            ? isReadOnly
+              ? t('View theme properties')
+              : t('Edit theme properties')
+            : t('Add theme')}
+        </Typography.Title>
+      }
+    >
+      <Form layout="vertical">
+        {isSystemTheme && (
+          <Typography.Text
+            type="secondary"
+            style={{
+              fontSize: '14px',
+              fontStyle: 'italic',
+              marginBottom: '16px',
+              display: 'block',
+            }}
+          >
+            {t('System Theme - Read Only')}
+          </Typography.Text>
+        )}
+
+        <Form.Item
+          label={t('Name')}
+          required={!isReadOnly}
+          style={{ marginBottom: '24px' }}
+        >
+          <Input
+            name="theme_name"
+            onChange={onThemeNameChange}
+            value={currentTheme?.theme_name}
+            readOnly={isReadOnly}
+            placeholder={t('Enter theme name')}
+          />
+        </Form.Item>
+
+        <Alert
+          type="info"
+          showIcon
+          closable={false}
+          message={
+            <span>
+              {t('Design with')}{' '}
+              <a
+                href="https://ant.design/theme-editor";
+                target="_blank"
+                rel="noopener noreferrer"
+              >
+                {t('Ant Design Theme Editor')}
+              </a>
+              {t(', then paste the JSON below. See our')}{' '}
+              <a
+                href="https://superset.apache.org/docs/configuration/theming/";
+                target="_blank"
+                rel="noopener noreferrer"
+              >
+                {t('documentation')}
+              </a>

Review Comment:
   is it better to use `Typography.Link` here? 



##########
superset-frontend/src/features/themes/ThemeModal.tsx:
##########
@@ -0,0 +1,394 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { FunctionComponent, useState, useEffect, ChangeEvent } from 'react';
+
+import { css, styled, t, useTheme } from '@superset-ui/core';
+import { useSingleViewResource } from 'src/views/CRUD/hooks';
+import { useThemeContext } from 'src/theme/ThemeProvider';
+
+import { Icons } from '@superset-ui/core/components/Icons';
+import withToasts from 'src/components/MessageToasts/withToasts';
+import {
+  Input,
+  Modal,
+  JsonEditor,
+  Button,
+  Form,
+  Tooltip,
+  Alert,
+} from '@superset-ui/core/components';
+import { Typography } from '@superset-ui/core/components/Typography';
+
+import { OnlyKeyWithType } from 'src/utils/types';
+import { ThemeObject } from './types';
+
+interface ThemeModalProps {
+  addDangerToast: (msg: string) => void;
+  addSuccessToast?: (msg: string) => void;
+  theme?: ThemeObject | null;
+  onThemeAdd?: (theme?: ThemeObject) => void;
+  onHide: () => void;
+  show: boolean;
+  canDevelop?: boolean;
+}
+
+type ThemeStringKeys = keyof Pick<
+  ThemeObject,
+  OnlyKeyWithType<ThemeObject, String>
+>;
+
+const StyledJsonEditor = styled.div`
+  ${({ theme }) => css`
+    border-radius: ${theme.borderRadius}px;
+    border: 1px solid ${theme.colorBorder};
+
+    .ace_editor {
+      border-radius: ${theme.borderRadius}px;
+    }
+  `}
+`;
+
+const ThemeModal: FunctionComponent<ThemeModalProps> = ({
+  addDangerToast,
+  addSuccessToast,
+  onThemeAdd,
+  onHide,
+  show,
+  theme = null,
+  canDevelop = false,
+}) => {
+  const supersetTheme = useTheme();
+  const { setTemporaryTheme } = useThemeContext();
+  const [disableSave, setDisableSave] = useState<boolean>(true);
+  const [currentTheme, setCurrentTheme] = useState<ThemeObject | null>(null);
+  const [isHidden, setIsHidden] = useState<boolean>(true);
+  const isEditMode = theme !== null;
+  const isSystemTheme = currentTheme?.is_system === true;
+  const isReadOnly = isSystemTheme;
+  const canDevelopThemes = canDevelop;
+
+  // theme fetch logic
+  const {
+    state: { loading, resource },
+    fetchResource,
+    createResource,
+    updateResource,
+  } = useSingleViewResource<ThemeObject>('theme', t('theme'), addDangerToast);
+
+  // Functions
+  const hide = () => {
+    onHide();
+    setCurrentTheme(null);
+  };
+
+  const onSave = () => {
+    if (isEditMode) {
+      // Edit
+      if (currentTheme?.id) {
+        const update_id = currentTheme.id;
+        delete currentTheme.id;
+        delete currentTheme.created_by;
+        delete currentTheme.changed_by;
+        delete currentTheme.changed_on_delta_humanized;
+
+        updateResource(update_id, currentTheme).then(response => {
+          if (!response) {
+            return;
+          }
+
+          if (onThemeAdd) {
+            onThemeAdd();
+          }
+
+          hide();
+        });
+      }
+    } else if (currentTheme) {
+      // Create
+      createResource(currentTheme).then(response => {
+        if (!response) {
+          return;
+        }
+
+        if (onThemeAdd) {
+          onThemeAdd();
+        }
+
+        hide();
+      });
+    }
+  };
+
+  const onApply = () => {
+    if (currentTheme?.json_data && isValidJson(currentTheme.json_data)) {
+      try {
+        const themeConfig = JSON.parse(currentTheme.json_data);
+        setTemporaryTheme(themeConfig);
+        if (addSuccessToast) {
+          addSuccessToast(t('Local theme set for preview'));
+        }
+      } catch (error) {
+        addDangerToast(t('Failed to apply theme: Invalid JSON'));
+      }
+    }
+  };
+
+  const onThemeNameChange = (event: ChangeEvent<HTMLInputElement>) => {
+    const { target } = event;
+
+    const data = {
+      ...currentTheme,
+      theme_name: currentTheme ? currentTheme.theme_name : '',
+      json_data: currentTheme ? currentTheme.json_data : '',
+    };
+
+    data[target.name as ThemeStringKeys] = target.value;
+    setCurrentTheme(data);
+  };
+
+  const onJsonDataChange = (jsonData: string) => {
+    const data = {
+      ...currentTheme,
+      theme_name: currentTheme ? currentTheme.theme_name : '',
+      json_data: jsonData,
+    };
+    setCurrentTheme(data);
+  };
+
+  const isValidJson = (str?: string) => {
+    if (!str) return false;
+    try {
+      JSON.parse(str);
+      return true;
+    } catch (e) {
+      return false;
+    }
+  };
+
+  const validate = () => {
+    if (isReadOnly) {
+      setDisableSave(true);
+      return;
+    }
+
+    if (
+      currentTheme?.theme_name.length &&
+      currentTheme?.json_data?.length &&
+      isValidJson(currentTheme.json_data)
+    ) {
+      setDisableSave(false);
+    } else {
+      setDisableSave(true);
+    }
+  };
+
+  // Initialize
+  useEffect(() => {
+    if (
+      isEditMode &&
+      (!currentTheme?.id ||
+        (theme && theme?.id !== currentTheme.id) ||
+        (isHidden && show))
+    ) {
+      if (theme?.id && !loading) {
+        fetchResource(theme.id);
+      }
+    } else if (
+      !isEditMode &&
+      (!currentTheme || currentTheme.id || (isHidden && show))
+    ) {
+      setCurrentTheme({
+        theme_name: '',
+        json_data: JSON.stringify({}, null, 2),
+      });
+    }
+  }, [theme, show]);
+
+  useEffect(() => {
+    if (resource) {
+      setCurrentTheme(resource);
+    }
+  }, [resource]);
+
+  // Validation
+  useEffect(() => {
+    validate();
+  }, [
+    currentTheme ? currentTheme.theme_name : '',
+    currentTheme ? currentTheme.json_data : '',
+    isReadOnly,
+  ]);
+
+  // Show/hide
+  if (isHidden && show) {
+    setIsHidden(false);
+  }
+
+  return (
+    <Modal
+      disablePrimaryButton={isReadOnly || disableSave}
+      onHandledPrimaryAction={isReadOnly ? undefined : onSave}
+      onHide={hide}
+      primaryButtonName={isEditMode ? t('Save') : t('Add')}
+      show={show}
+      width="55%"
+      footer={[
+        <Button key="cancel" onClick={hide} buttonStyle="secondary">
+          {isReadOnly ? t('Close') : t('Cancel')}
+        </Button>,
+        ...(!isReadOnly
+          ? [
+              <Button
+                key="save"
+                onClick={onSave}
+                disabled={disableSave}
+                buttonStyle="primary"
+              >
+                {isEditMode ? t('Save') : t('Add')}
+              </Button>,
+            ]
+          : []),
+      ]}
+      title={
+        <Typography.Title level={4} data-test="theme-modal-title">
+          {isEditMode ? (
+            <Icons.EditOutlined
+              iconSize="l"
+              css={css`
+                margin: auto ${supersetTheme.sizeUnit * 2}px auto 0;
+              `}
+            />
+          ) : (
+            <Icons.PlusOutlined
+              iconSize="l"
+              css={css`
+                margin: auto ${supersetTheme.sizeUnit * 2}px auto 0;
+              `}
+            />
+          )}
+          {isEditMode
+            ? isReadOnly
+              ? t('View theme properties')
+              : t('Edit theme properties')
+            : t('Add theme')}
+        </Typography.Title>
+      }
+    >
+      <Form layout="vertical">
+        {isSystemTheme && (
+          <Typography.Text
+            type="secondary"
+            style={{
+              fontSize: '14px',
+              fontStyle: 'italic',
+              marginBottom: '16px',
+              display: 'block',
+            }}
+          >
+            {t('System Theme - Read Only')}
+          </Typography.Text>
+        )}
+
+        <Form.Item
+          label={t('Name')}
+          required={!isReadOnly}
+          style={{ marginBottom: '24px' }}

Review Comment:
   Do you think we should use `css` with `theme.sizeUnit` here?



##########
superset-frontend/src/features/themes/ThemeModal.tsx:
##########
@@ -0,0 +1,394 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { FunctionComponent, useState, useEffect, ChangeEvent } from 'react';
+
+import { css, styled, t, useTheme } from '@superset-ui/core';
+import { useSingleViewResource } from 'src/views/CRUD/hooks';
+import { useThemeContext } from 'src/theme/ThemeProvider';
+
+import { Icons } from '@superset-ui/core/components/Icons';
+import withToasts from 'src/components/MessageToasts/withToasts';
+import {
+  Input,
+  Modal,
+  JsonEditor,
+  Button,
+  Form,
+  Tooltip,
+  Alert,
+} from '@superset-ui/core/components';
+import { Typography } from '@superset-ui/core/components/Typography';
+
+import { OnlyKeyWithType } from 'src/utils/types';
+import { ThemeObject } from './types';
+
+interface ThemeModalProps {
+  addDangerToast: (msg: string) => void;
+  addSuccessToast?: (msg: string) => void;
+  theme?: ThemeObject | null;
+  onThemeAdd?: (theme?: ThemeObject) => void;
+  onHide: () => void;
+  show: boolean;
+  canDevelop?: boolean;
+}
+
+type ThemeStringKeys = keyof Pick<
+  ThemeObject,
+  OnlyKeyWithType<ThemeObject, String>
+>;
+
+const StyledJsonEditor = styled.div`
+  ${({ theme }) => css`
+    border-radius: ${theme.borderRadius}px;
+    border: 1px solid ${theme.colorBorder};
+
+    .ace_editor {
+      border-radius: ${theme.borderRadius}px;
+    }
+  `}
+`;
+
+const ThemeModal: FunctionComponent<ThemeModalProps> = ({
+  addDangerToast,
+  addSuccessToast,
+  onThemeAdd,
+  onHide,
+  show,
+  theme = null,
+  canDevelop = false,
+}) => {
+  const supersetTheme = useTheme();
+  const { setTemporaryTheme } = useThemeContext();
+  const [disableSave, setDisableSave] = useState<boolean>(true);
+  const [currentTheme, setCurrentTheme] = useState<ThemeObject | null>(null);
+  const [isHidden, setIsHidden] = useState<boolean>(true);
+  const isEditMode = theme !== null;
+  const isSystemTheme = currentTheme?.is_system === true;
+  const isReadOnly = isSystemTheme;
+  const canDevelopThemes = canDevelop;
+
+  // theme fetch logic
+  const {
+    state: { loading, resource },
+    fetchResource,
+    createResource,
+    updateResource,
+  } = useSingleViewResource<ThemeObject>('theme', t('theme'), addDangerToast);
+
+  // Functions
+  const hide = () => {
+    onHide();
+    setCurrentTheme(null);
+  };
+
+  const onSave = () => {
+    if (isEditMode) {
+      // Edit
+      if (currentTheme?.id) {
+        const update_id = currentTheme.id;
+        delete currentTheme.id;
+        delete currentTheme.created_by;
+        delete currentTheme.changed_by;
+        delete currentTheme.changed_on_delta_humanized;
+
+        updateResource(update_id, currentTheme).then(response => {
+          if (!response) {
+            return;
+          }
+
+          if (onThemeAdd) {
+            onThemeAdd();
+          }
+
+          hide();
+        });
+      }
+    } else if (currentTheme) {
+      // Create
+      createResource(currentTheme).then(response => {
+        if (!response) {
+          return;
+        }
+
+        if (onThemeAdd) {
+          onThemeAdd();
+        }
+
+        hide();
+      });
+    }
+  };
+
+  const onApply = () => {
+    if (currentTheme?.json_data && isValidJson(currentTheme.json_data)) {
+      try {
+        const themeConfig = JSON.parse(currentTheme.json_data);
+        setTemporaryTheme(themeConfig);
+        if (addSuccessToast) {
+          addSuccessToast(t('Local theme set for preview'));
+        }
+      } catch (error) {
+        addDangerToast(t('Failed to apply theme: Invalid JSON'));
+      }
+    }
+  };
+
+  const onThemeNameChange = (event: ChangeEvent<HTMLInputElement>) => {
+    const { target } = event;
+
+    const data = {
+      ...currentTheme,
+      theme_name: currentTheme ? currentTheme.theme_name : '',
+      json_data: currentTheme ? currentTheme.json_data : '',
+    };
+
+    data[target.name as ThemeStringKeys] = target.value;
+    setCurrentTheme(data);
+  };
+
+  const onJsonDataChange = (jsonData: string) => {
+    const data = {
+      ...currentTheme,
+      theme_name: currentTheme ? currentTheme.theme_name : '',
+      json_data: jsonData,
+    };
+    setCurrentTheme(data);
+  };
+
+  const isValidJson = (str?: string) => {
+    if (!str) return false;
+    try {
+      JSON.parse(str);
+      return true;
+    } catch (e) {
+      return false;
+    }
+  };
+
+  const validate = () => {
+    if (isReadOnly) {
+      setDisableSave(true);
+      return;
+    }
+
+    if (
+      currentTheme?.theme_name.length &&
+      currentTheme?.json_data?.length &&
+      isValidJson(currentTheme.json_data)
+    ) {
+      setDisableSave(false);
+    } else {
+      setDisableSave(true);
+    }
+  };
+
+  // Initialize
+  useEffect(() => {
+    if (
+      isEditMode &&
+      (!currentTheme?.id ||
+        (theme && theme?.id !== currentTheme.id) ||
+        (isHidden && show))
+    ) {
+      if (theme?.id && !loading) {
+        fetchResource(theme.id);
+      }
+    } else if (
+      !isEditMode &&
+      (!currentTheme || currentTheme.id || (isHidden && show))
+    ) {
+      setCurrentTheme({
+        theme_name: '',
+        json_data: JSON.stringify({}, null, 2),
+      });
+    }
+  }, [theme, show]);
+
+  useEffect(() => {
+    if (resource) {
+      setCurrentTheme(resource);
+    }
+  }, [resource]);
+
+  // Validation
+  useEffect(() => {
+    validate();
+  }, [
+    currentTheme ? currentTheme.theme_name : '',
+    currentTheme ? currentTheme.json_data : '',
+    isReadOnly,
+  ]);
+
+  // Show/hide
+  if (isHidden && show) {
+    setIsHidden(false);
+  }
+
+  return (
+    <Modal
+      disablePrimaryButton={isReadOnly || disableSave}
+      onHandledPrimaryAction={isReadOnly ? undefined : onSave}
+      onHide={hide}
+      primaryButtonName={isEditMode ? t('Save') : t('Add')}
+      show={show}
+      width="55%"
+      footer={[
+        <Button key="cancel" onClick={hide} buttonStyle="secondary">
+          {isReadOnly ? t('Close') : t('Cancel')}
+        </Button>,
+        ...(!isReadOnly
+          ? [
+              <Button
+                key="save"
+                onClick={onSave}
+                disabled={disableSave}
+                buttonStyle="primary"
+              >
+                {isEditMode ? t('Save') : t('Add')}
+              </Button>,
+            ]
+          : []),
+      ]}
+      title={
+        <Typography.Title level={4} data-test="theme-modal-title">
+          {isEditMode ? (
+            <Icons.EditOutlined
+              iconSize="l"
+              css={css`
+                margin: auto ${supersetTheme.sizeUnit * 2}px auto 0;
+              `}
+            />
+          ) : (
+            <Icons.PlusOutlined
+              iconSize="l"
+              css={css`
+                margin: auto ${supersetTheme.sizeUnit * 2}px auto 0;
+              `}
+            />
+          )}
+          {isEditMode
+            ? isReadOnly
+              ? t('View theme properties')
+              : t('Edit theme properties')
+            : t('Add theme')}
+        </Typography.Title>
+      }
+    >
+      <Form layout="vertical">
+        {isSystemTheme && (
+          <Typography.Text
+            type="secondary"
+            style={{
+              fontSize: '14px',
+              fontStyle: 'italic',
+              marginBottom: '16px',

Review Comment:
   Do we need these styles here? 



##########
superset-frontend/src/features/themes/ThemeModal.tsx:
##########
@@ -0,0 +1,394 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { FunctionComponent, useState, useEffect, ChangeEvent } from 'react';
+
+import { css, styled, t, useTheme } from '@superset-ui/core';
+import { useSingleViewResource } from 'src/views/CRUD/hooks';
+import { useThemeContext } from 'src/theme/ThemeProvider';
+
+import { Icons } from '@superset-ui/core/components/Icons';
+import withToasts from 'src/components/MessageToasts/withToasts';
+import {
+  Input,
+  Modal,
+  JsonEditor,
+  Button,
+  Form,
+  Tooltip,
+  Alert,
+} from '@superset-ui/core/components';
+import { Typography } from '@superset-ui/core/components/Typography';
+
+import { OnlyKeyWithType } from 'src/utils/types';
+import { ThemeObject } from './types';
+
+interface ThemeModalProps {
+  addDangerToast: (msg: string) => void;
+  addSuccessToast?: (msg: string) => void;
+  theme?: ThemeObject | null;
+  onThemeAdd?: (theme?: ThemeObject) => void;
+  onHide: () => void;
+  show: boolean;
+  canDevelop?: boolean;
+}
+
+type ThemeStringKeys = keyof Pick<
+  ThemeObject,
+  OnlyKeyWithType<ThemeObject, String>
+>;
+
+const StyledJsonEditor = styled.div`
+  ${({ theme }) => css`
+    border-radius: ${theme.borderRadius}px;
+    border: 1px solid ${theme.colorBorder};
+
+    .ace_editor {
+      border-radius: ${theme.borderRadius}px;
+    }
+  `}
+`;
+
+const ThemeModal: FunctionComponent<ThemeModalProps> = ({
+  addDangerToast,
+  addSuccessToast,
+  onThemeAdd,
+  onHide,
+  show,
+  theme = null,
+  canDevelop = false,
+}) => {
+  const supersetTheme = useTheme();
+  const { setTemporaryTheme } = useThemeContext();
+  const [disableSave, setDisableSave] = useState<boolean>(true);
+  const [currentTheme, setCurrentTheme] = useState<ThemeObject | null>(null);
+  const [isHidden, setIsHidden] = useState<boolean>(true);
+  const isEditMode = theme !== null;
+  const isSystemTheme = currentTheme?.is_system === true;
+  const isReadOnly = isSystemTheme;
+  const canDevelopThemes = canDevelop;
+
+  // theme fetch logic
+  const {
+    state: { loading, resource },
+    fetchResource,
+    createResource,
+    updateResource,
+  } = useSingleViewResource<ThemeObject>('theme', t('theme'), addDangerToast);
+
+  // Functions
+  const hide = () => {
+    onHide();
+    setCurrentTheme(null);
+  };
+
+  const onSave = () => {
+    if (isEditMode) {
+      // Edit
+      if (currentTheme?.id) {
+        const update_id = currentTheme.id;
+        delete currentTheme.id;
+        delete currentTheme.created_by;
+        delete currentTheme.changed_by;
+        delete currentTheme.changed_on_delta_humanized;
+
+        updateResource(update_id, currentTheme).then(response => {
+          if (!response) {
+            return;
+          }
+
+          if (onThemeAdd) {
+            onThemeAdd();
+          }
+
+          hide();
+        });
+      }
+    } else if (currentTheme) {
+      // Create
+      createResource(currentTheme).then(response => {
+        if (!response) {
+          return;
+        }
+
+        if (onThemeAdd) {
+          onThemeAdd();
+        }
+
+        hide();
+      });
+    }
+  };
+
+  const onApply = () => {
+    if (currentTheme?.json_data && isValidJson(currentTheme.json_data)) {
+      try {
+        const themeConfig = JSON.parse(currentTheme.json_data);
+        setTemporaryTheme(themeConfig);
+        if (addSuccessToast) {
+          addSuccessToast(t('Local theme set for preview'));
+        }
+      } catch (error) {
+        addDangerToast(t('Failed to apply theme: Invalid JSON'));
+      }
+    }
+  };
+
+  const onThemeNameChange = (event: ChangeEvent<HTMLInputElement>) => {
+    const { target } = event;
+
+    const data = {
+      ...currentTheme,
+      theme_name: currentTheme ? currentTheme.theme_name : '',
+      json_data: currentTheme ? currentTheme.json_data : '',
+    };
+
+    data[target.name as ThemeStringKeys] = target.value;
+    setCurrentTheme(data);
+  };
+
+  const onJsonDataChange = (jsonData: string) => {
+    const data = {
+      ...currentTheme,
+      theme_name: currentTheme ? currentTheme.theme_name : '',
+      json_data: jsonData,
+    };
+    setCurrentTheme(data);
+  };
+
+  const isValidJson = (str?: string) => {
+    if (!str) return false;
+    try {
+      JSON.parse(str);
+      return true;
+    } catch (e) {
+      return false;
+    }
+  };
+
+  const validate = () => {
+    if (isReadOnly) {
+      setDisableSave(true);
+      return;
+    }
+
+    if (
+      currentTheme?.theme_name.length &&
+      currentTheme?.json_data?.length &&
+      isValidJson(currentTheme.json_data)
+    ) {
+      setDisableSave(false);
+    } else {
+      setDisableSave(true);
+    }
+  };
+
+  // Initialize
+  useEffect(() => {
+    if (
+      isEditMode &&
+      (!currentTheme?.id ||
+        (theme && theme?.id !== currentTheme.id) ||
+        (isHidden && show))
+    ) {
+      if (theme?.id && !loading) {
+        fetchResource(theme.id);
+      }
+    } else if (
+      !isEditMode &&
+      (!currentTheme || currentTheme.id || (isHidden && show))
+    ) {
+      setCurrentTheme({
+        theme_name: '',
+        json_data: JSON.stringify({}, null, 2),
+      });
+    }
+  }, [theme, show]);
+
+  useEffect(() => {
+    if (resource) {
+      setCurrentTheme(resource);
+    }
+  }, [resource]);
+
+  // Validation
+  useEffect(() => {
+    validate();
+  }, [
+    currentTheme ? currentTheme.theme_name : '',
+    currentTheme ? currentTheme.json_data : '',
+    isReadOnly,
+  ]);
+
+  // Show/hide
+  if (isHidden && show) {
+    setIsHidden(false);
+  }
+
+  return (
+    <Modal
+      disablePrimaryButton={isReadOnly || disableSave}
+      onHandledPrimaryAction={isReadOnly ? undefined : onSave}
+      onHide={hide}
+      primaryButtonName={isEditMode ? t('Save') : t('Add')}
+      show={show}
+      width="55%"
+      footer={[
+        <Button key="cancel" onClick={hide} buttonStyle="secondary">
+          {isReadOnly ? t('Close') : t('Cancel')}
+        </Button>,
+        ...(!isReadOnly
+          ? [
+              <Button
+                key="save"
+                onClick={onSave}
+                disabled={disableSave}
+                buttonStyle="primary"
+              >
+                {isEditMode ? t('Save') : t('Add')}
+              </Button>,
+            ]
+          : []),
+      ]}
+      title={
+        <Typography.Title level={4} data-test="theme-modal-title">
+          {isEditMode ? (
+            <Icons.EditOutlined
+              iconSize="l"
+              css={css`
+                margin: auto ${supersetTheme.sizeUnit * 2}px auto 0;
+              `}
+            />
+          ) : (
+            <Icons.PlusOutlined
+              iconSize="l"
+              css={css`
+                margin: auto ${supersetTheme.sizeUnit * 2}px auto 0;
+              `}
+            />
+          )}
+          {isEditMode
+            ? isReadOnly
+              ? t('View theme properties')
+              : t('Edit theme properties')
+            : t('Add theme')}
+        </Typography.Title>
+      }
+    >
+      <Form layout="vertical">
+        {isSystemTheme && (
+          <Typography.Text
+            type="secondary"
+            style={{
+              fontSize: '14px',
+              fontStyle: 'italic',
+              marginBottom: '16px',
+              display: 'block',
+            }}
+          >
+            {t('System Theme - Read Only')}
+          </Typography.Text>
+        )}
+
+        <Form.Item
+          label={t('Name')}
+          required={!isReadOnly}
+          style={{ marginBottom: '24px' }}
+        >
+          <Input
+            name="theme_name"
+            onChange={onThemeNameChange}
+            value={currentTheme?.theme_name}
+            readOnly={isReadOnly}
+            placeholder={t('Enter theme name')}
+          />
+        </Form.Item>
+
+        <Alert
+          type="info"
+          showIcon
+          closable={false}
+          message={
+            <span>
+              {t('Design with')}{' '}
+              <a
+                href="https://ant.design/theme-editor";
+                target="_blank"
+                rel="noopener noreferrer"
+              >
+                {t('Ant Design Theme Editor')}
+              </a>
+              {t(', then paste the JSON below. See our')}{' '}
+              <a
+                href="https://superset.apache.org/docs/configuration/theming/";
+                target="_blank"
+                rel="noopener noreferrer"
+              >
+                {t('documentation')}
+              </a>
+              {t(' for details.')}
+            </span>
+          }
+          style={{ marginBottom: '16px' }}
+        />
+
+        <Form.Item
+          label={t('JSON Configuration')}
+          required={!isReadOnly}
+          style={{ marginBottom: '24px' }}

Review Comment:
   Should we add `Space` component between the items instead of using `margin`? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


Reply via email to