alexandrusoare commented on code in PR #38519:
URL: https://github.com/apache/superset/pull/38519#discussion_r2910579406
##########
superset-frontend/packages/superset-ui-chart-controls/src/sections/matrixify.tsx:
##########
@@ -119,13 +108,12 @@ export const matrixifySection: ControlPanelSectionConfig
= {
};
export const matrixifyRowSection: ControlPanelSectionConfig = {
- label: t('Vertical layout (rows)'),
expanded: false,
visibility: ({ controls }) =>
- controls?.matrixify_enable_vertical_layout?.value === true,
+ controls?.matrixify_mode_rows?.value !== undefined &&
Review Comment:
Can the control ever be null?
##########
superset-frontend/packages/superset-ui-core/src/chart/components/Matrixify/MatrixifyGridRenderer.test.tsx:
##########
@@ -160,8 +161,8 @@ test('should handle exact division of columns', () => {
const formData = {
viz_type: 'test_chart',
- matrixify_enable_vertical_layout: true,
- matrixify_enable_horizontal_layout: true,
+ matrixify_mode_rows: 'metrics' as MatrixifyMode,
+ matrixify_mode_columns: 'metrics' as MatrixifyMode,
matrixify_fit_columns_dynamically: false,
Review Comment:
Do we also need to set "matrixify_enable" to "True"?
##########
superset-frontend/packages/superset-ui-core/src/chart/types/matrixify.ts:
##########
@@ -145,69 +142,78 @@ export interface MatrixifyConfig {
export function getMatrixifyConfig(
formData: MatrixifyFormData & any,
): MatrixifyConfig | null {
- const hasRowConfig = formData.matrixify_mode_rows;
- const hasColumnConfig = formData.matrixify_mode_columns;
+ const rowEnabled = isAxisEnabled(formData.matrixify_mode_rows);
+ const colEnabled = isAxisEnabled(formData.matrixify_mode_columns);
- if (!hasRowConfig && !hasColumnConfig) {
+ if (!rowEnabled && !colEnabled) {
return null;
}
return {
rows: {
- mode: formData.matrixify_mode_rows || 'metrics',
+ mode: formData.matrixify_mode_rows || 'disabled',
metrics: formData.matrixify_rows,
selectionMode: formData.matrixify_dimension_selection_mode_rows,
dimension: formData.matrixify_dimension_rows,
topnValue: formData.matrixify_topn_value_rows,
topnMetric: formData.matrixify_topn_metric_rows,
- topnOrder: formData.matrixify_topn_order_rows,
+ topnOrder: formData.matrixify_topn_order_rows !== false ? 'desc' : 'asc',
},
columns: {
- mode: formData.matrixify_mode_columns || 'metrics',
+ mode: formData.matrixify_mode_columns || 'disabled',
metrics: formData.matrixify_columns,
selectionMode: formData.matrixify_dimension_selection_mode_columns,
dimension: formData.matrixify_dimension_columns,
topnValue: formData.matrixify_topn_value_columns,
topnMetric: formData.matrixify_topn_metric_columns,
- topnOrder: formData.matrixify_topn_order_columns,
+ topnOrder:
+ formData.matrixify_topn_order_columns !== false ? 'desc' : 'asc',
Review Comment:
What do you think about doing something like this?
`!formData.matrixify_topn_order_columns ?`
##########
superset-frontend/packages/superset-ui-core/src/chart/components/Matrixify/MatrixifyGridRenderer.test.tsx:
##########
@@ -160,8 +161,8 @@ test('should handle exact division of columns', () => {
const formData = {
viz_type: 'test_chart',
- matrixify_enable_vertical_layout: true,
- matrixify_enable_horizontal_layout: true,
+ matrixify_mode_rows: 'metrics' as MatrixifyMode,
+ matrixify_mode_columns: 'metrics' as MatrixifyMode,
matrixify_fit_columns_dynamically: false,
Review Comment:
Do we also need to set "matrixify_enable" to "True"?
##########
superset-frontend/packages/superset-ui-core/src/chart/types/matrixify.test.ts:
##########
@@ -260,10 +248,9 @@ test('should handle empty form data object', () => {
expect(isMatrixifyEnabled(formData)).toBe(false);
});
-test('isMatrixifyEnabled should return false when layout enabled but no axis
modes configured', () => {
+test('isMatrixifyEnabled should return false when no axis modes configured',
() => {
Review Comment:
This should simply check if the switch is ticked right or am I missing
something?
##########
superset-frontend/src/explore/components/controls/VerticalRadioControl.tsx:
##########
@@ -0,0 +1,104 @@
+/**
+ * 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 { type ReactNode } from 'react';
+import { css, useTheme } from '@apache-superset/core/theme';
+import { JsonValue } from '@superset-ui/core';
+import { Radio } from '@superset-ui/core/components/Radio';
+import { Space } from '@superset-ui/core/components/Space';
+import { Tooltip } from '@superset-ui/core/components/Tooltip';
+import { Icons } from '@superset-ui/core/components/Icons';
+import ControlHeader from '../ControlHeader';
+
+interface RadioOption {
+ value: JsonValue;
+ label: ReactNode;
+ disabled?: boolean;
+ tooltip?: string;
+}
+
+type RadioOptionTuple = [JsonValue, ReactNode];
+
+interface VerticalRadioControlProps {
+ value?: JsonValue;
+ label?: ReactNode;
+ description?: ReactNode;
+ hovered?: boolean;
+ options: (RadioOption | RadioOptionTuple)[];
+ onChange: (value: JsonValue) => void;
+ validationErrors?: string[];
+}
+
+function normalizeOption(option: RadioOption | RadioOptionTuple): RadioOption {
+ if (Array.isArray(option)) {
+ return { value: option[0], label: option[1] };
+ }
+ return option;
+}
+
+export default function VerticalRadioControl({
+ value: initialValue,
+ options,
+ onChange,
+ ...props
+}: VerticalRadioControlProps) {
+ const theme = useTheme();
+ const normalizedOptions = options.map(normalizeOption);
+ const currentValue = initialValue ?? normalizedOptions[0]?.value;
+
+ return (
+ <div
+ css={css`
+ .ant-radio-wrapper {
+ display: flex;
+ align-items: center;
+ }
+ `}
+ >
+ <ControlHeader {...props} />
+ <Radio.Group
+ value={currentValue}
+ onChange={e => onChange(e.target.value)}
+ >
+ <Space direction="vertical">
+ {normalizedOptions.map(
+ ({ value: val, label, disabled = false, tooltip }) => (
+ <Radio key={JSON.stringify(val)} value={val} disabled={disabled}>
+ {label}
+ {tooltip && (
+ <Tooltip title={tooltip} placement="right">
+ <Icons.InfoCircleOutlined
+ css={css`
+ margin-left: 4px;
+ font-size: 12px;
Review Comment:
I am not sure about the latest practices so should we use theme tokens
instead?
--
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]