You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by jl...@apache.org on 2025/11/05 01:05:14 UTC
(superset) 06/07: fix(DatasourceControl): use Partial for type alignment
This is an automated email from the ASF dual-hosted git repository.
jli pushed a commit to branch api-mocks-for-datasource-control
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 398fbe5db6634e0a1e17060b2e0ce59d0a74e85b
Author: Joe Li <jo...@preset.io>
AuthorDate: Tue Nov 4 16:43:26 2025 -0800
fix(DatasourceControl): use Partial<DatasetObject> for type alignment
Remove custom TestDataset type and use Partial<DatasetObject> directly to
ensure test fixtures stay aligned with the actual API contract. Add type
assertions at call sites where simplified test fixtures don't strictly match.
Changes:
- Remove custom TestDataset type that duplicated dataset shape
- Change openAndSaveChanges parameter to Partial<DatasetObject>
- Add type assertions via `unknown` at 3 call sites using simplified fixtures
- Tests now track real dataset fields automatically instead of drifting
This prevents type drift as the datasets feature gets properly typed and
maintains type safety aligned with the canonical DatasetObject.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <no...@anthropic.com>
---
.../DatasourceControl/DatasourceControl.test.tsx | 26 ++++------------------
1 file changed, 4 insertions(+), 22 deletions(-)
diff --git a/superset-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx b/superset-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx
index 0eace4c560..2934be266f 100644
--- a/superset-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx
+++ b/superset-frontend/src/explore/components/controls/DatasourceControl/DatasourceControl.test.tsx
@@ -91,25 +91,7 @@ const createProps = (overrides: JsonObject = {}) => ({
...overrides,
});
-type TestDataset = {
- id?: number;
- name?: string;
- type?: DatasetObject['type'] | string;
- main_dttm_col?: string | null;
- columns?: Array<{
- column_name?: string;
- is_dttm?: boolean;
- [key: string]: unknown;
- }>;
- metrics?: Array<{
- id?: number;
- metric_name?: string;
- [key: string]: unknown;
- }>;
- [key: string]: unknown;
-};
-
-async function openAndSaveChanges(datasource: TestDataset) {
+async function openAndSaveChanges(datasource: Partial<DatasetObject>) {
fetchMock.get(
'glob:*/api/v1/database/?q=*',
{ result: [] },
@@ -416,7 +398,7 @@ test('should set the default temporal column', async () => {
useRouter: true,
});
- await openAndSaveChanges(overrideProps.datasource);
+ await openAndSaveChanges(overrideProps.datasource as unknown as Partial<DatasetObject>);
await waitFor(() => {
expect(props.actions.setControlValue).toHaveBeenCalledWith(
'granularity_sqla',
@@ -452,7 +434,7 @@ test('should set the first available temporal column', async () => {
useRouter: true,
});
- await openAndSaveChanges(overrideProps.datasource);
+ await openAndSaveChanges(overrideProps.datasource as unknown as Partial<DatasetObject>);
await waitFor(() => {
expect(props.actions.setControlValue).toHaveBeenCalledWith(
'granularity_sqla',
@@ -488,7 +470,7 @@ test('should not set the temporal column', async () => {
useRouter: true,
});
- await openAndSaveChanges(overrideProps.datasource);
+ await openAndSaveChanges(overrideProps.datasource as unknown as Partial<DatasetObject>);
await waitFor(() => {
expect(props.actions.setControlValue).toHaveBeenCalledWith(
'granularity_sqla',