Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tableselector to dataset creation page #21075

Merged
merged 34 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
85bcbca
add database selector
pkdotson Aug 5, 2022
cd87fda
add schema util
pkdotson Aug 8, 2022
413aea9
add pagination
pkdotson Aug 12, 2022
aeb0d6f
remove conosle.logs
pkdotson Aug 12, 2022
0f0ded9
add search
pkdotson Aug 18, 2022
7e1ca34
remove logs
pkdotson Aug 18, 2022
96b609a
Merge branch 'master' of https://github.com/preset-io/superset into f…
pkdotson Aug 23, 2022
3bbe070
more updates
pkdotson Aug 24, 2022
23e03b1
update loading style and add state
pkdotson Aug 24, 2022
b0cf236
remove header styles
pkdotson Aug 25, 2022
3c680b5
add test, fix types, other updates
pkdotson Aug 25, 2022
8e5d195
Update superset-frontend/src/views/CRUD/data/dataset/AddDataset/LeftP…
pkdotson Aug 25, 2022
1ffcf86
Update superset-frontend/src/views/CRUD/data/dataset/AddDataset/LeftP…
pkdotson Aug 25, 2022
b7fb96d
Update superset-frontend/src/views/CRUD/data/dataset/AddDataset/LeftP…
pkdotson Aug 25, 2022
2fbc0b1
Update superset-frontend/src/views/CRUD/data/dataset/AddDataset/LeftP…
pkdotson Aug 25, 2022
d982996
Update superset-frontend/src/views/CRUD/data/dataset/AddDataset/LeftP…
pkdotson Aug 25, 2022
16ae23b
Update superset-frontend/src/views/CRUD/data/dataset/AddDataset/LeftP…
pkdotson Aug 25, 2022
e0097b2
fix types
pkdotson Aug 26, 2022
434f934
Merge branch 'feat-add-tableselector' of https://github.com/preset-io…
pkdotson Aug 26, 2022
472a27b
fix styles
pkdotson Aug 26, 2022
d3ed28e
Merge branch 'master' of https://github.com/preset-io/superset into f…
pkdotson Aug 29, 2022
48b15b2
update type
pkdotson Aug 29, 2022
ee25dc7
fix tests
pkdotson Aug 30, 2022
a4258ba
fix test
pkdotson Aug 30, 2022
4ce4d29
run precommit
pkdotson Aug 30, 2022
a02db58
add suggestions
pkdotson Aug 31, 2022
1689774
match styles and desgin
pkdotson Sep 1, 2022
b169378
update test
pkdotson Sep 1, 2022
2012690
update test and last changes
pkdotson Sep 6, 2022
9745842
Merge branch 'master' of https://github.com/preset-io/superset into f…
pkdotson Sep 6, 2022
e81484f
fix merge
pkdotson Sep 6, 2022
f0dd386
fix indentation
pkdotson Sep 6, 2022
4057c66
remove log
pkdotson Sep 6, 2022
8a92b3e
fix parent component tests
pkdotson Sep 7, 2022
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
Prev Previous commit
Next Next commit
add test, fix types, other updates
  • Loading branch information
pkdotson committed Aug 25, 2022
commit 3c680b598856662a03e64597343d94cef1b17294
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,76 @@
* under the License.
*/
import React from 'react';
import { SupersetClient } from '@superset-ui/core';
import { render, screen } from 'spec/helpers/testing-library';
import LeftPanel from 'src/views/CRUD/data/dataset/AddDataset/LeftPanel';

describe('LeftPanel', () => {
it('renders a blank state LeftPanel', () => {
render(<LeftPanel />);
const mockFun = jest.fn();

const SupersetClientGet = jest.spyOn(SupersetClient, 'get');

const getSchemaMockFunction = async () =>
({
json: {
result: ['schema_a', 'schema_b'],
},
} as any);

const getTableMockFunction = async () =>
({
json: {
options: [
{ label: 'table_a', value: 'table_a' },
{ label: 'table_b', value: 'table_b' },
{ label: 'table_c', value: 'table_c' },
{ label: 'table_d', value: 'table_d' },
],
},
} as any);

it('should render', () => {
const { container } = render(<LeftPanel setDataset={mockFun} />, {
useRedux: true,
});
expect(container).toBeInTheDocument();
});

it('should render tableselector and databaselector container and selects', () => {
render(<LeftPanel setDataset={mockFun} />, { useRedux: true });

expect(screen.getByText(/select database & schema/i)).toBeVisible();
// expect(screen.getByText(/schema/i)).toBeVisible();
// expect(screen.getByText(/database/i)).toBeVisible();

const databaseSelect = screen.getByRole('combobox', {
name: 'Select database or type database name',
});
const schemaSelect = screen.getByRole('combobox', {
name: 'Select schema or type schema name',
});
expect(databaseSelect).toBeInTheDocument();
expect(schemaSelect).toBeInTheDocument();
});
it('renders a blank state LeftPanel if there is no schema selected', () => {
render(<LeftPanel setDataset={mockFun} />, { useRedux: true });

expect(screen.getByRole('img', { name: /empty/i })).toBeVisible();
expect(screen.getByText(/no database tables found/i)).toBeVisible();
expect(screen.getByText(/try selecting a different schema/i)).toBeVisible();
});
it.only('renders list of options when user clicks on schema', () => {
render(<LeftPanel setDataset={mockFun} schema="schema_a" dbId="1" />, {
useRedux: true,
});
// screen.debug('container', container)
SupersetClientGet.mockImplementation(getSchemaMockFunction);
SupersetClientGet.mockImplementation(getTableMockFunction);
const schemaSelect = screen.getByRole('combobox', {
name: 'Select schema or type schema name',
});
expect(screen.getByTestId('options-list')).toBeInTheDocument();
screen.logTestingPlaygroundURL();
expect.anything();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import DatabaseSelector from 'src/components/DatabaseSelector';
import { debounce } from 'lodash';
import { EmptyStateMedium } from 'src/components/EmptyState';
import { DatasetActionType } from '../types';
import { DatasetObject } from '../types';

interface LeftPanelProps {
setDataset: (db: any) => void;
Expand Down Expand Up @@ -95,7 +96,7 @@ export default function LeftPanel({
const [searchVal, setSearchVal] = useState('');
const [refresh, setRefresh] = useState(false);

const setDatabase = (db: any) => {
const setDatabase = (db: ) => {
setDataset({ type: DatasetActionType.selectDatabase, payload: db });
setResetTables(true);
};
Expand Down Expand Up @@ -123,8 +124,9 @@ export default function LeftPanel({
});
};

const setSchema = (schema: any) => {
const setSchema = (schema: string) => {
if (schema) {
console.log('schema', schema);
setDataset({ type: DatasetActionType.selectSchema, payload: schema });
setLoadTables(true);
}
Expand Down Expand Up @@ -205,7 +207,7 @@ export default function LeftPanel({
placeholder={t('Search Tables')}
/>
</Form>
<div className="options-list">
<div className="options-list" data-test="options-list">
{tableOptions.map((o, i) => (
<div className="options" key={i}>
{o.label}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ import Footer from './Footer';
import { DatasetActionType, DatasetObject, DSReducerActionType } from './types';
import DatasetLayout from '../DatasetLayout';

type Schema = {
schema: string;
};

export function datasetReducer(
state: Partial<DatasetObject> | null,
state: DatasetObject | null,
action: DSReducerActionType,
): Partial<DatasetObject> | null {
): Partial<DatasetObject> | Schema | null {
const trimmedState = {
...(state || {}),
};
Expand All @@ -43,7 +47,7 @@ export function datasetReducer(
case DatasetActionType.selectSchema:
return {
...trimmedState,
schema: action.payload,
schema: action.payload as string,
table_name: null,
};
case DatasetActionType.selectTable:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ export enum DatasetActionType {
}

export interface DatasetObject {
database: {
id: string;
database_name: string;
};
id: string;
database_name: string;
owners: number[];
schema?: string | null;
dataset_name: string;
Expand All @@ -39,12 +37,16 @@ interface DatasetReducerPayloadType {
value?: string;
}

export type Schema = {
schema?: string | null | undefined;
};

export type DSReducerActionType =
| {
type:
| DatasetActionType.selectDatabase
| DatasetActionType.selectSchema
| DatasetActionType.selectTable;
| DatasetActionType.selectTable
| DatasetActionType.selectSchema;
payload: Partial<DatasetObject>;
}
| {
Expand Down