codeant-ai-for-open-source[bot] commented on code in PR #39760:
URL: https://github.com/apache/superset/pull/39760#discussion_r3613186105
##########
superset-frontend/plugins/plugin-chart-cartodiagram/src/util/layerUtil.tsx:
##########
@@ -137,6 +152,36 @@ export const createWfsLayer = async (wfsLayerConf:
WfsLayerConf) => {
});
};
+/**
+ * Create a DATA layer.
+ *
+ * @param dataLayerConf The layer configuration
+ * @param featureCollection The featureCollection for the layer source
+ *
+ * @returns The created DATA layer
+ */
+export const createDataLayer = async (dataLayerConf: DataLayerConf) => {
Review Comment:
**Suggestion:** The doc comment states there is a `featureCollection`
parameter, but the function does not accept it; this mismatch is misleading and
will cause incorrect usage assumptions. Update the comment to match the actual
function contract. [comment mismatch]
<details>
<summary><b>Severity Level:</b> Minor ๐งน</summary>
```mdx
- WARNING misleading JSDoc may confuse future data-layer callers.
- WARNING documentation-only issue, runtime behavior remains correct.
```
</details>
<details>
<summary><b>Steps of Reproduction โ
</b></summary>
```mdx
1. A developer reads the JSDoc comment for `createDataLayer` at
`superset-frontend/plugins/plugin-chart-cartodiagram/src/util/layerUtil.tsx:155-162`,
which documents both `dataLayerConf` and `featureCollection` parameters.
2. Based on the comment, the developer attempts to call
`createDataLayer(dataLayerConf,
featureCollection)` from a new component.
3. TypeScript at the call site reports an argument count/type mismatch
because the
implementation at `layerUtil.tsx:163` only accepts a single `dataLayerConf:
DataLayerConf`
parameter.
4. The developer must inspect the implementation to realize
`featureCollection` is not
part of the contract; existing callers do not pass this parameter today, so
the mismatch
is documentation-only and does not currently affect runtime behavior.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=320815aab77e442b8f6a55912aeadc04&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=320815aab77e442b8f6a55912aeadc04&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/plugins/plugin-chart-cartodiagram/src/util/layerUtil.tsx
**Line:** 158:163
**Comment:**
*Comment Mismatch: The doc comment states there is a
`featureCollection` parameter, but the function does not accept it; this
mismatch is misleading and will cause incorrect usage assumptions. Update the
comment to match the actual function contract.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39760&comment_hash=436f6fa38b5001258c1a6f36e3d058b566471a52ffd6574be09e2cdfd81ed757&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39760&comment_hash=436f6fa38b5001258c1a6f36e3d058b566471a52ffd6574be09e2cdfd81ed757&reaction=dislike'>๐</a>
##########
superset-frontend/plugins/plugin-chart-cartodiagram/src/util/layerUtil.tsx:
##########
@@ -152,8 +197,71 @@ export const createLayer = async (layerConf: LayerConf) =>
{
layer = await createWfsLayer(layerConf);
} else if (isXyzLayerConf(layerConf)) {
layer = createXyzLayer(layerConf);
+ } else if (isDataLayerConf(layerConf)) {
+ layer = await createDataLayer(layerConf);
} else {
console.warn('Provided layerconfig is not recognized');
}
return layer;
};
+
+export const removeSelectionLayer = (olMap: Map) => {
+ const selectionLayer = olMap
+ .getLayers()
+ .getArray()
+ .filter(l => l.get(LAYER_NAME_PROP) === SELECTION_LAYER_NAME)
+ .pop();
+ if (selectionLayer) {
+ olMap.removeLayer(selectionLayer);
+ }
+};
+
+export const getSelectedFeatures = (
+ dataLayers: VectorLayer<VectorSource>[],
+ filterState: FilterState,
+ crossFilterColumn: string,
+) => {
+ let selectedFeatures: Feature[] = [];
+ if (
+ filterState.selectedValues !== null &&
+ filterState.selectedValues !== undefined &&
+ dataLayers
+ ) {
+ selectedFeatures = dataLayers.flatMap(dataLayer =>
+ dataLayer
+ .getSource()!
+ .getFeatures()
+ .filter(f =>
+ filterState.selectedValues.includes(f.get(crossFilterColumn)),
+ ),
+ );
+ }
+ return selectedFeatures;
+};
+
+export const setSelectionBackgroundOpacity = (
+ dataLayers: VectorLayer<VectorSource>[],
+ opacity: number,
+) => {
+ dataLayers.forEach(dataLayer => {
+ dataLayer.setOpacity(opacity);
+ });
+};
+
+export const createSelectionLayer = (
+ dataLayers: VectorLayer<VectorSource>[],
+ features: Feature[],
+) => {
+ const selectionLayer = new VectorLayer({
+ source: new VectorSource({
+ features,
+ }),
+ });
+ selectionLayer.set(LAYER_NAME_PROP, SELECTION_LAYER_NAME);
+ // TODO how can we handle multiple data layers?
+ const layerStyle = dataLayers[0].getStyle();
Review Comment:
**Suggestion:** `createSelectionLayer` assumes at least one data layer
exists and directly reads index `0`; when an empty array is passed this throws
at runtime. Add a guard for an empty array before accessing the first element
and only copy style when a source layer is present. [possible bug]
<details>
<summary><b>Severity Level:</b> Major โ ๏ธ</summary>
```mdx
- CRITICAL selection overlay creation throws when no data layers.
- WARNING map cross-filter highlight fails degrading user experience.
```
</details>
<details>
<summary><b>Steps of Reproduction โ
</b></summary>
```mdx
1. Import `createSelectionLayer` from
`superset-frontend/plugins/plugin-chart-cartodiagram/src/util/layerUtil.tsx:251-267`
in a
test or development harness.
2. Call `createSelectionLayer([] as VectorLayer[], features)` with an empty
`dataLayers`
array and any valid `Feature[]` (for example, features returned from
`VectorSource.getFeatures()`).
3. Inside `createSelectionLayer`, the code at `layerUtil.tsx:262` evaluates
`dataLayers[0].getStyle()` without checking that `dataLayers.length > 0`.
4. At runtime `dataLayers[0]` is `undefined`, so accessing `.getStyle()`
throws a
`TypeError`, aborting selection layer creation; current repo graph context
shows no
callers yet, so this is a latent bug that will manifest as soon as the
helper is used with
an empty layer list.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=7b59e8ee91124f58a67f57150483dd2c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=7b59e8ee91124f58a67f57150483dd2c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/plugins/plugin-chart-cartodiagram/src/util/layerUtil.tsx
**Line:** 262:262
**Comment:**
*Possible Bug: `createSelectionLayer` assumes at least one data layer
exists and directly reads index `0`; when an empty array is passed this throws
at runtime. Add a guard for an empty array before accessing the first element
and only copy style when a source layer is present.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39760&comment_hash=54eee555a05a30d76b8615cac6da0ec9502ba0c645d37d3491599d98d88f1609&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39760&comment_hash=54eee555a05a30d76b8615cac6da0ec9502ba0c645d37d3491599d98d88f1609&reaction=dislike'>๐</a>
--
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]