codeant-ai-for-open-source[bot] commented on code in PR #37396:
URL: https://github.com/apache/superset/pull/37396#discussion_r3348121431
##########
superset-frontend/src/explore/components/DataTablesPane/types.ts:
##########
@@ -78,6 +76,7 @@ export interface TableControlsProps {
export interface QueryResultInterface {
colnames: string[];
+ collabels: string[];
Review Comment:
Yes — that’s exactly the source of the mismatch.
`ensureIsArray(response.collabels)` only normalizes the value **at runtime**
from `undefined | null | array` into an array, but it doesn’t mean the API
contract guarantees `collabels` is always present.
## Why the issue is still valid
In this PR, `QueryResultInterface` makes `collabels` required:
```ts
export interface QueryResultInterface {
colnames: string[];
collabels: string[];
coltypes: GenericDataType[];
...
}
```
But the feature itself is meant to be optional: headers should **use labels
if provided, otherwise fall back to column names**.
So typing it as required implies every result must have labels, which isn’t
true for all callers and API responses.
## How to resolve it
Make `collabels` optional in the shared result type, and keep the fallback
logic in the UI.
```ts
export interface QueryResultInterface {
colnames: string[];
collabels?: string[];
coltypes: GenericDataType[];
rowcount: number;
data: Record<string, any>[][];
}
```
Then the existing code can safely do:
```ts
const headerLabel = collabels?.[index] ?? key;
```
or equivalent.
## About `ensureIsArray`
You’re right that `ensureIsArray(response.collabels)` protects `SamplesPane`
from `undefined` at runtime, but it doesn’t justify making the type required
globally. It only means that one consumer is resilient.
So the review comment is correct: the type should reflect that labels are
optional, while the UI can normalize or fall back as needed.
--
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]