Copilot commented on code in PR #40865:
URL: https://github.com/apache/superset/pull/40865#discussion_r3382694186
##########
superset-frontend/src/explore/controlUtils/standardizedFormData.ts:
##########
@@ -156,6 +156,36 @@ export class StandardizedFormData {
return controls;
}
+ // Time shifts only meaningful for viz types whose "Time shift" control
offers
+ // them (Big Number / Table period-over-period). Other viz types reuse the
same
+ // `time_compare` key without these choices.
+ private static specialTimeShifts = ['inherit', 'custom'];
+
+ // Drop `time_compare` markers the target viz can't honor so they don't carry
+ // over as un-removable tags when switching chart types.
+ static dropUnsupportedTimeShifts(
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ controlsState: Record<string, any>,
+ ): void {
+ const control = controlsState?.time_compare;
+ if (!control || !Array.isArray(control.value)) {
+ return;
+ }
+ const supportedChoices = new Set(
+ ensureIsArray(control.choices).map(
+ (choice: [string, string]) => choice[0],
+ ),
+ );
+ const filtered = control.value.filter(
+ (shift: string) =>
+ !StandardizedFormData.specialTimeShifts.includes(shift) ||
+ supportedChoices.has(shift),
+ );
+ if (filtered.length !== control.value.length) {
+ control.value = filtered.length ? filtered : null;
+ }
+ }
Review Comment:
`dropUnsupportedTimeShifts` introduces a new `any`-typed controls state
parameter and then assumes `time_compare.choices` is a tuple array of `[string,
string]`. You can keep this logic but make it type-safe with `unknown` +
runtime guards so future control-state shape changes won’t silently bypass
filtering (and to avoid expanding `any` usage in this file).
--
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]