kgabryje commented on code in PR #27891:
URL: https://github.com/apache/superset/pull/27891#discussion_r1568663241
##########
superset-frontend/src/components/AlteredSliceTag/index.tsx:
##########
@@ -98,48 +94,83 @@ function alterForComparison(value?: string | null | []):
string | null {
return null;
}
return value;
-}
-
-class AlteredSliceTag extends React.Component<
- AlteredSliceTagProps,
- AlteredSliceTagState
-> {
- constructor(props: AlteredSliceTagProps) {
- super(props);
- const diffs = this.getDiffs(props);
- const controlsMap: ControlMap = getControlsForVizType(
- props.origFormData.viz_type,
- ) as ControlMap;
- const rows = this.getRowsFromDiffs(diffs, controlsMap);
+};
- this.state = { rows, hasDiffs: !isEmpty(diffs), controlsMap };
+export const formatValueHandler = (
+ value: any,
+ key: string,
+ controlsMap: ControlMap,
+): string | number => {
+ if (value === undefined) {
+ return 'N/A';
}
-
- UNSAFE_componentWillReceiveProps(newProps: AlteredSliceTagProps): void {
- if (isEqual(this.props, newProps)) {
- return;
+ if (value === null) {
+ return 'null';
+ }
+ if (controlsMap[key]?.type === 'AdhocFilterControl' && Array.isArray(value))
{
+ if (!value.length) {
+ return '[]';
}
- const diffs = this.getDiffs(newProps);
- this.setState(prevState => ({
- rows: this.getRowsFromDiffs(diffs, prevState.controlsMap),
- hasDiffs: !isEmpty(diffs),
- }));
+ return value
+ .map((v: any) => {
+ const filterVal =
+ v.comparator && v.comparator.constructor === Array
+ ? `[${v.comparator.join(', ')}]`
+ : v.comparator;
+ return `${v.subject} ${v.operator} ${filterVal}`;
+ })
+ .join(', ');
}
-
- getRowsFromDiffs(
- diffs: { [key: string]: DiffType },
- controlsMap: ControlMap,
- ): RowType[] {
- return Object.entries(diffs).map(([key, diff]) => ({
- control: controlsMap[key]?.label || key,
- before: this.formatValue(diff.before, key, controlsMap),
- after: this.formatValue(diff.after, key, controlsMap),
- }));
+ if (controlsMap[key]?.type === 'BoundsControl') {
+ return `Min: ${value[0]}, Max: ${value[1]}`;
+ }
+ if (controlsMap[key]?.type === 'CollectionControl' && Array.isArray(value)) {
+ return value.map((v: any) => safeStringify(v)).join(', ');
+ }
+ if (
+ controlsMap[key]?.type === 'MetricsControl' &&
+ value.constructor === Array
+ ) {
+ const formattedValue = value.map((v: any) => v?.label ?? v);
Review Comment:
same here
--
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]