Skip to content

Commit

Permalink
linking create accelerations flyouts, loading columns
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Li <[email protected]>
  • Loading branch information
sejli committed Mar 18, 2024
1 parent 2a575ed commit fa5d8db
Show file tree
Hide file tree
Showing 13 changed files with 199 additions and 98 deletions.
4 changes: 2 additions & 2 deletions common/types/data_connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export interface AssociatedObject {
name: string;
database: string;
type: AccelerationIndexType | 'table';
accelerations: Acceleration[];
columns?: TableColumn[];
accelerations: CachedAcceleration[];
columns?: CachedColumn[];
}

export type Role = EuiComboBoxOptionOption;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ exports[`AssociatedObjectsTab Component renders correctly with associated object
]
}
data-test-subj="associatedObjectsTable"
hasActions={true}
items={
Array [
Object {
Expand Down Expand Up @@ -773,7 +774,7 @@ exports[`AssociatedObjectsTab Component renders correctly with associated object
Object {
"box": Object {
"incremental": true,
"placeholder": "database:database_1 database: database_2 accelerations:skipping_index_1",
"placeholder": "accelerations:skipping_index_1",
"schema": Object {
"fields": Object {
"database": Object {
Expand Down Expand Up @@ -815,14 +816,14 @@ exports[`AssociatedObjectsTab Component renders correctly with associated object
},
}
}
tableLayout="fixed"
tableLayout="auto"
>
<div>
<EuiSearchBar
box={
Object {
"incremental": true,
"placeholder": "database:database_1 database: database_2 accelerations:skipping_index_1",
"placeholder": "accelerations:skipping_index_1",
"schema": Object {
"fields": Object {
"database": Object {
Expand Down Expand Up @@ -877,7 +878,7 @@ exports[`AssociatedObjectsTab Component renders correctly with associated object
incremental={true}
isInvalid={false}
onSearch={[Function]}
placeholder="database:database_1 database: database_2 accelerations:skipping_index_1"
placeholder="accelerations:skipping_index_1"
query=""
>
<EuiFieldSearch
Expand All @@ -891,7 +892,7 @@ exports[`AssociatedObjectsTab Component renders correctly with associated object
isInvalid={false}
isLoading={false}
onSearch={[Function]}
placeholder="database:database_1 database: database_2 accelerations:skipping_index_1"
placeholder="accelerations:skipping_index_1"
>
<EuiFormControlLayout
compressed={false}
Expand All @@ -913,7 +914,7 @@ exports[`AssociatedObjectsTab Component renders correctly with associated object
className="euiFieldSearch euiFieldSearch--fullWidth"
defaultValue=""
onKeyUp={[Function]}
placeholder="database:database_1 database: database_2 accelerations:skipping_index_1"
placeholder="accelerations:skipping_index_1"
type="search"
/>
</EuiValidatableControl>
Expand Down Expand Up @@ -1253,6 +1254,7 @@ exports[`AssociatedObjectsTab Component renders correctly with associated object
]
}
data-test-subj="associatedObjectsTable"
hasActions={true}
items={
Array [
Object {
Expand Down Expand Up @@ -1345,7 +1347,7 @@ exports[`AssociatedObjectsTab Component renders correctly with associated object
},
}
}
tableLayout="fixed"
tableLayout="auto"
>
<div
className="euiBasicTable"
Expand Down Expand Up @@ -1528,10 +1530,10 @@ exports[`AssociatedObjectsTab Component renders correctly with associated object
<EuiTable
id="random_html_id"
responsive={true}
tableLayout="fixed"
tableLayout="auto"
>
<table
className="euiTable euiTable--responsive"
className="euiTable euiTable--responsive euiTable--auto"
id="random_html_id"
tabIndex={-1}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ jest.mock('../../../../framework/catalog_cache/cache_loader', () => ({

jest.mock('../../../../plugin', () => ({
getRenderAccelerationDetailsFlyout: jest.fn(() => jest.fn()),
getRenderCreateAccelerationFlyout: jest.fn(() => jest.fn()),
}));

describe('AccelerationTable Component', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import { AssociatedObjectsDetailsFlyout } from '../manage/associated_objects/ass
import * as plugin from '../../../../plugin';
import { act } from '@testing-library/react';
import { mockAssociatedObjects } from '../../../../../test/datasources';
import { getAccelerationName } from '../manage/accelerations/utils/acceleration_utils';

configure({ adapter: new Adapter() });

jest.mock('../../../../plugin', () => ({
getRenderAccelerationDetailsFlyout: jest.fn(() => jest.fn()),
getRenderAssociatedObjectsDetailsFlyout: jest.fn(() => jest.fn()),
getRenderCreateAccelerationFlyout: jest.fn(() => jest.fn()),
}));

describe('AssociatedObjectsDetailsFlyout Integration Tests', () => {
Expand All @@ -26,7 +28,9 @@ describe('AssociatedObjectsDetailsFlyout Integration Tests', () => {
});

it('renders acceleration details correctly and triggers flyout on click', () => {
const wrapper = mount(<AssociatedObjectsDetailsFlyout tableDetail={mockTableDetail} />);
const wrapper = mount(
<AssociatedObjectsDetailsFlyout tableDetail={mockTableDetail} datasourceName="flint_s3" />
);
expect(wrapper.find('EuiInMemoryTable').at(0).find('EuiLink').length).toBeGreaterThan(0);

wrapper.find('EuiInMemoryTable').at(0).find('EuiLink').first().simulate('click');
Expand All @@ -38,13 +42,16 @@ describe('AssociatedObjectsDetailsFlyout Integration Tests', () => {
...mockTableDetail,
accelerations: [],
columns: [
{ name: 'column1', dataType: 'string' },
{ name: 'column2', dataType: 'number' },
{ fieldName: 'column1', dataType: 'string' },
{ fieldName: 'column2', dataType: 'number' },
],
};

const wrapper = mount(
<AssociatedObjectsDetailsFlyout tableDetail={mockDetailNoAccelerations} />
<AssociatedObjectsDetailsFlyout
tableDetail={mockDetailNoAccelerations}
datasourceName="flint_s3"
/>
);

expect(wrapper.text()).toContain('You have no accelerations');
Expand All @@ -54,24 +61,28 @@ describe('AssociatedObjectsDetailsFlyout Integration Tests', () => {
});

it('renders schema table correctly with column data', () => {
const wrapper = mount(<AssociatedObjectsDetailsFlyout tableDetail={mockTableDetail} />);
const wrapper = mount(
<AssociatedObjectsDetailsFlyout tableDetail={mockTableDetail} datasourceName="flint_s3" />
);

expect(wrapper.find('EuiInMemoryTable').at(1).exists()).toBe(true);
expect(wrapper.find('EuiInMemoryTable').at(1).text()).toContain(
mockTableDetail.columns[0].name
mockTableDetail.columns[0].fieldName
);
});

it('triggers details flyout on acceleration link click', async () => {
const wrapper = mount(<AssociatedObjectsDetailsFlyout tableDetail={mockTableDetail} />);
const wrapper = mount(
<AssociatedObjectsDetailsFlyout tableDetail={mockTableDetail} datasourceName="flint_s3" />
);

await act(async () => {
// Wait a tick for async updates
await new Promise((resolve) => setTimeout(resolve, 0));
wrapper.update();
});

const accName = mockTableDetail.accelerations[0]?.name;
const accName = getAccelerationName(mockTableDetail.accelerations[0], 'flint_s3');
const accLink = wrapper
.find('EuiLink')
.findWhere((node) => node.text() === accName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { DirectQueryLoadingStatus } from '../../../../../common/types/explorer';
jest.mock('../../../../plugin', () => ({
getRenderAccelerationDetailsFlyout: jest.fn(() => jest.fn()),
getRenderAssociatedObjectsDetailsFlyout: jest.fn(() => jest.fn()),
getRenderCreateAccelerationFlyout: jest.fn(() => jest.fn()),
}));

describe('AssociatedObjectsTab Component', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import {
} from '../../../../../../common/types/data_connections';
import { DirectQueryLoadingStatus } from '../../../../../../common/types/explorer';
import { isCatalogCacheFetching } from '../associated_objects/utils/associated_objects_tab_utils';
import { getRenderAccelerationDetailsFlyout } from '../../../../../plugin';
import {
getRenderAccelerationDetailsFlyout,
getRenderCreateAccelerationFlyout,
} from '../../../../../plugin';
import {
ACC_LOADING_MSG,
ACC_PANEL_DESC,
Expand Down Expand Up @@ -118,11 +121,9 @@ export const AccelerationTable = ({
};

const CreateButton = () => {
// TODO: Create button should call create_acceleration.tsx, which will be brought
// over from dashboards-query-workbench/public/components/acceleration/create/create_accelerations.tsx
return (
<>
<EuiButton onClick={() => console.log('clicked on create accelerations button')} fill>
<EuiButton onClick={() => renderCreateAccelerationFlyout(dataSourceName)} fill>
Create acceleration
</EuiButton>
</>
Expand Down Expand Up @@ -204,7 +205,7 @@ export const AccelerationTable = ({
name: 'Name',
sortable: true,
render: (indexName: string, acceleration: CachedAcceleration) => {
const displayName = getAccelerationName(indexName, acceleration, dataSourceName);
const displayName = getAccelerationName(acceleration, dataSourceName);
return (
<EuiLink
onClick={() => {
Expand Down Expand Up @@ -299,6 +300,7 @@ export const AccelerationTable = ({
};

const renderAccelerationDetailsFlyout = getRenderAccelerationDetailsFlyout();
const renderCreateAccelerationFlyout = getRenderCreateAccelerationFlyout();

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ export const ACC_PANEL_DESC =
'Accelerations optimize query performance by indexing external data into OpenSearch.';
export const ACC_LOADING_MSG = 'Loading/Refreshing accelerations...';

export const getAccelerationName = (
indexName: string,
acceleration: CachedAcceleration,
datasource: string
) => {
export const getAccelerationName = (acceleration: CachedAcceleration, datasource: string) => {
return (
indexName || `${datasource}_${acceleration.database}_${acceleration.table}`.replace(/\s+/g, '_')
acceleration.indexName ||
`${datasource}_${acceleration.database}_${acceleration.table}`.replace(/\s+/g, '_')
);
};

Expand Down
Loading

0 comments on commit fa5d8db

Please sign in to comment.