Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { BOTTOMBAR_HEIGHT } from "./constants";
import { useEditorType } from "ee/hooks";
import { useParentEntityInfo } from "ee/hooks/datasourceEditorHooks";
import DatasourceInfo from "./DatasourceInfo";
import { getPlugin } from "ee/selectors/entitiesSelector";

interface Props {
datasourceId: string;
Expand All @@ -45,6 +46,8 @@ const Datasource = (props: Props) => {
getPluginIdFromDatasourceId(state, props.datasourceId),
);

const plugin = useSelector((state) => getPlugin(state, pluginId || ""));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Improve plugin selector error handling

The empty string fallback for pluginId could fetch an invalid plugin. Consider adding error handling and loading states.

- const plugin = useSelector((state) => getPlugin(state, pluginId || ""));
+ const plugin = useSelector((state) => {
+   if (!pluginId) return undefined;
+   return getPlugin(state, pluginId);
+ });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const plugin = useSelector((state) => getPlugin(state, pluginId || ""));
const plugin = useSelector((state) => {
if (!pluginId) return undefined;
return getPlugin(state, pluginId);
});


const editorType = useEditorType(location.pathname);
const { parentEntityId } = useParentEntityInfo(editorType);

Expand Down Expand Up @@ -143,6 +146,7 @@ const Datasource = (props: Props) => {
<DatasourceInfo
datasourceId={props.datasourceId}
datasourceName={props.datasourceName}
plugin={plugin}
showEditButton={!isLoading}
/>
<StatusDisplay
Expand Down Expand Up @@ -170,6 +174,7 @@ const Datasource = (props: Props) => {
datasourceId={props.datasourceId}
datasourceName={props.datasourceName}
datasourceStructure={datasourceStructure}
plugin={plugin}
selectedTable={selectedTable}
setSelectedTable={setSelectedTable}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ import { getQueryParams } from "utils/URLUtils";
import history from "utils/history";
import { useEditorType } from "ee/hooks";
import { useParentEntityInfo } from "ee/hooks/datasourceEditorHooks";
import type { Plugin } from "api/PluginApi";

interface Props {
datasourceId: string;
datasourceName: string;
showEditButton: boolean;
plugin?: Plugin;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Maintain prop optionality consistency with child component

If DatasourceSelector requires plugin prop, DatasourceInfo should also make it required to maintain contract consistency.

- plugin?: Plugin;
+ plugin: Plugin;

Also applies to: 56-56

}

const DatasourceInfo = ({
datasourceId,
datasourceName,
plugin,
showEditButton,
}: Props) => {
const editorType = useEditorType(location.pathname);
Expand Down Expand Up @@ -50,6 +53,7 @@ const DatasourceInfo = ({
<DatasourceSelector
datasourceId={datasourceId}
datasourceName={datasourceName}
plugin={plugin}
/>
{showEditButton && (
<Tooltip content={createMessage(EDIT_DS_CONFIG)} placement="top">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";
import { UIComponentTypes } from "api/PluginApi";
import { usePluginActionContext } from "PluginActionEditor/PluginActionContext";
import { UIComponentTypes, type Plugin } from "api/PluginApi";
import ApiDatasourceSelector from "./ApiDatasourceSelector";
import QueryDatasourceSelector from "./QueryDatasourceSelector";
import {
Expand All @@ -16,16 +15,17 @@ const API_FORM_COMPONENTS = [
export interface DatasourceProps {
datasourceId: string;
datasourceName: string;
plugin?: Plugin;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider making plugin prop required instead of optional

The component's rendering logic depends on the plugin prop, but the interface marks it as optional. This could lead to unexpected null renders.

-  plugin?: Plugin;
+  plugin: Plugin;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
plugin?: Plugin;
plugin: Plugin;

}

const DatasourceSelector = (props: DatasourceProps) => {
const { plugin } = usePluginActionContext();

return API_FORM_COMPONENTS.includes(plugin.uiComponent) ? (
<ApiDatasourceSelector {...props} formName={API_EDITOR_FORM_NAME} />
) : (
<QueryDatasourceSelector {...props} formName={QUERY_EDITOR_FORM_NAME} />
);
return props.plugin ? (
API_FORM_COMPONENTS.includes(props.plugin.uiComponent) ? (
<ApiDatasourceSelector {...props} formName={API_EDITOR_FORM_NAME} />
) : (
<QueryDatasourceSelector {...props} formName={QUERY_EDITOR_FORM_NAME} />
)
) : null;
};

export default DatasourceSelector;
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { refreshDatasourceStructure } from "actions/datasourceActions";
import { useDispatch } from "react-redux";
import { SchemaTableContainer } from "./styles";
import DatasourceInfo from "./DatasourceInfo";
import type { Plugin } from "api/PluginApi";

interface Props {
datasourceId: string;
datasourceName: string;
currentActionId: string;
datasourceStructure: DatasourceStructure;
plugin?: Plugin;
setSelectedTable: (table: string) => void;
selectedTable: string | undefined;
}
Expand All @@ -24,6 +26,7 @@ const DatasourceTables = ({
datasourceId,
datasourceName,
datasourceStructure,
plugin,
selectedTable,
setSelectedTable,
}: Props) => {
Expand Down Expand Up @@ -56,6 +59,7 @@ const DatasourceTables = ({
<DatasourceInfo
datasourceId={datasourceId}
datasourceName={datasourceName}
plugin={plugin}
showEditButton
/>
<Button
Expand Down