justinpark commented on code in PR #34526: URL: https://github.com/apache/superset/pull/34526#discussion_r2261376544
########## superset-frontend/packages/superset-ui-chart-controls/src/shared-controls/sharedControls.tsx: ########## @@ -473,3 +473,181 @@ export default { sort_by_metric, order_by_cols, }; + +// dynamically add matrixify controls +['columns', 'rows'].forEach(axisParam => { + const axis = axisParam; // Capture the value in a local variable + sharedControls[`matrixify_mode_${axis}`] = { + type: 'RadioButtonControl', + label: t(`Metrics / Dimensions`), + default: 'metrics', + options: [ + ['metrics', t('Metrics')], + ['dimensions', t('Dimension Members')], + ], + renderTrigger: true, + }; + + sharedControls[`matrixify_${axis}`] = { + ...dndAdhocMetricControl, + label: t(`Metrics`), + multi: true, + validators: [], // Not required + // description: t(`Select metrics for ${axis}`), + renderTrigger: true, + visibility: ({ controls }) => + controls?.[`matrixify_mode_${axis}`]?.value === 'metrics', + }; + + // Combined dimension and values control + sharedControls[`matrixify_dimension_${axis}`] = { + type: 'MatrixifyDimensionControl', + label: t(`Dimension Selection`), + description: t(`Select dimension and values`), + default: { dimension: '', values: [] }, + validators: [], // Not required + renderTrigger: true, + mapStateToProps: ({ datasource, controls }) => ({ + datasource, + selectionMode: + controls?.[`matrixify_dimension_selection_mode_${axis}`]?.value || + 'members', + }), + visibility: ({ controls }) => + controls?.[`matrixify_mode_${axis}`]?.value === 'dimensions', + }; + + // Add selection mode control (Dimension Members vs TopN) + sharedControls[`matrixify_dimension_selection_mode_${axis}`] = { + type: 'RadioButtonControl', + label: t(`Selection Method`), + default: 'members', + options: [ + ['members', t('Dimension Members')], + ['topn', t('Top N')], + ], + renderTrigger: true, + visibility: ({ controls }) => + controls?.[`matrixify_mode_${axis}`]?.value === 'dimensions', + }; + + // TopN controls + sharedControls[`matrixify_topn_value_${axis}`] = { + type: 'TextControl', + label: t(`Top N`), + description: t(`Number of top values to select`), + default: 10, + isInt: true, + visibility: ({ controls }) => + controls?.[`matrixify_mode_${axis}`]?.value === 'dimensions' && + !!(controls?.[`matrixify_dimension_${axis}`]?.value as any)?.dimension && + controls?.[`matrixify_dimension_selection_mode_${axis}`]?.value === + 'topn', + }; + + sharedControls[`matrixify_topn_metric_${axis}`] = { + ...dndAdhocMetricControl, + label: t(`Metric for ordering`), + multi: false, + validators: [], // Not required + description: t(`Metric to use for ordering Top N values`), + visibility: ({ controls }) => + controls?.[`matrixify_mode_${axis}`]?.value === 'dimensions' && + !!(controls?.[`matrixify_dimension_${axis}`]?.value as any)?.dimension && + controls?.[`matrixify_dimension_selection_mode_${axis}`]?.value === + 'topn', + }; + + sharedControls[`matrixify_topn_order_${axis}`] = { + type: 'RadioButtonControl', + label: t(`Sort Order`), + default: 'desc', + options: [ + ['asc', t('asc')], + ['desc', t('desc')], + ], + visibility: ({ controls }) => + controls?.[`matrixify_mode_${axis}`]?.value === 'dimensions' && + !!(controls?.[`matrixify_dimension_${axis}`]?.value as any)?.dimension && + controls?.[`matrixify_dimension_selection_mode_${axis}`]?.value === + 'topn', + }; + // Add grid layout controls + sharedControls.matrixify_row_height = { + type: 'TextControl', + label: t('Row Height'), + description: t('Height of each row in pixels'), + default: 300, + isInt: true, + validators: [], + renderTrigger: true, + }; + + sharedControls.matrixify_fit_columns_dynamically = { + type: 'CheckboxControl', + label: t('Fit Columns Dynamically'), + description: t( + 'Automatically adjust column width based on available space', + ), + default: true, + renderTrigger: true, + }; + + sharedControls.matrixify_charts_per_row = { + type: 'SelectControl', + label: t('Charts Per Row'), + description: t('Number of charts to display per row'), + default: 4, + choices: [ + [1, '1'], + [2, '2'], + [3, '3'], + [4, '4'], + [6, '6'], + [12, '12'], + ], + clearable: false, + renderTrigger: true, + visibility: ({ controls }) => + !controls?.matrixify_fit_columns_dynamically?.value, + }; +}); Review Comment: It appears that this block does not need to be inside the forEach loop. ```suggestion }); sharedControls.matrixify_row_height = { type: 'TextControl', label: t('Row Height'), description: t('Height of each row in pixels'), default: 300, isInt: true, validators: [], renderTrigger: true, }; sharedControls.matrixify_fit_columns_dynamically = { type: 'CheckboxControl', label: t('Fit Columns Dynamically'), description: t( 'Automatically adjust column width based on available space', ), default: true, renderTrigger: true, }; sharedControls.matrixify_charts_per_row = { type: 'SelectControl', label: t('Charts Per Row'), description: t('Number of charts to display per row'), default: 4, choices: [ [1, '1'], [2, '2'], [3, '3'], [4, '4'], [6, '6'], [12, '12'], ], clearable: false, renderTrigger: true, visibility: ({ controls }) => !controls?.matrixify_fit_columns_dynamically?.value, }; ``` -- 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: notifications-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org