fix: enhance datasource structure retrieval in useTableOrSpreadsheet hook (#40612)

## Description
<ins>Problem</ins>  
App was crashing when the data source configuration was undefined or in
an error state.

<ins>Root cause</ins>  
The code attempted to access properties from an undefined data source
config (e.g., MongoDB), leading to runtime errors.

<ins>Solution</ins>  
This PR handles adding an optional check before accessing the data
source config to prevent crashes when the config is undefined or in an
error state.

Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags="@tag.JSONForm, @tag.PropertyPane, @tag.GenerateCRUD,
@tag.Datasource, @tag.Sanity, @tag.Widget"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/14905964982>
> Commit: bcd0f9d2d009bcf07bb10afda1a30ff1a93bc9ae
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=14905964982&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.JSONForm, @tag.PropertyPane, @tag.GenerateCRUD,
@tag.Datasource, @tag.Sanity, @tag.Widget`
> Spec:
> <hr>Thu, 08 May 2025 13:32:39 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Improved stability when accessing data source tables, preventing
potential errors if data source information is missing.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Rahul Barwal 2025-05-09 12:03:54 +05:30 committed by GitHub
parent 1c531661c7
commit 7322d72e63
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -87,7 +87,7 @@ export function useTableOrSpreadsheet() {
}, },
})); }));
} else if (isMongoDBPluginDS(selectedDatasourcePluginPackageName)) { } else if (isMongoDBPluginDS(selectedDatasourcePluginPackageName)) {
return (datasourceStructure.tables || []).map((table) => ({ return (datasourceStructure?.tables || []).map((table) => ({
id: table.name, id: table.name,
label: table.name, label: table.name,
value: table.name, value: table.name,
@ -97,7 +97,7 @@ export function useTableOrSpreadsheet() {
disabled: false, disabled: false,
})); }));
} else if (datasourceStructure) { } else if (datasourceStructure) {
return (datasourceStructure.tables || []).map((table) => { return (datasourceStructure?.tables || []).map((table) => {
const hasPrimaryKeys = tableHasPrimaryKeys(table); const hasPrimaryKeys = tableHasPrimaryKeys(table);
return { return {