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

Bug fix for data-sources page #1830

Merged
merged 7 commits into from
May 23, 2024
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
22 changes: 22 additions & 0 deletions common/types/data_connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
interface AsyncApiDataResponse {
status: string;
schema?: Array<{ name: string; type: string }>;
datarows?: any;

Check warning on line 75 in common/types/data_connections.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
total?: number;
size?: number;
error?: string;
Expand Down Expand Up @@ -252,3 +252,25 @@
databaseName?: string;
tableName?: string;
}

export interface RenderAccelerationFlyoutParams {
dataSource: string;
dataSourceMDSId?: string;
databaseName?: string;
tableName?: string;
handleRefresh?: () => void;
}

export interface RenderAssociatedObjectsDetailsFlyoutParams {
tableDetail: AssociatedObject;
dataSourceName: string;
handleRefresh?: () => void;
dataSourceMDSId?: string;
}

export interface RenderAccelerationDetailsFlyoutParams {
acceleration: CachedAcceleration;
dataSourceName: string;
handleRefresh?: () => void;
dataSourceMDSId?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

interface AccelerationTableProps {
dataSourceName: string;
cacheLoadingHooks: any;

Check warning on line 47 in public/components/datasources/components/manage/accelerations/acceleration_table.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
}

interface ModalState {
Expand Down Expand Up @@ -75,7 +75,7 @@
if (operationSuccess) {
handleRefresh();
}
}, [operationSuccess]);

Check warning on line 78 in public/components/datasources/components/manage/accelerations/acceleration_table.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'handleRefresh'. Either include it or remove the dependency array

const handleActionClick = (
actionType: ModalState['actionType'],
Expand Down Expand Up @@ -115,7 +115,7 @@
setAccelerations(cachedDataSource.accelerations);
setUpdatedTime(cachedDataSource.lastUpdated);
}
}, []);

Check warning on line 118 in public/components/datasources/components/manage/accelerations/acceleration_table.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has missing dependencies: 'accelerationsLoadStatus', 'dataSourceName', and 'startLoadingAccelerations'. Either include them or remove the dependency array

useEffect(() => {
if (accelerationsLoadStatus === DirectQueryLoadingStatus.SUCCESS) {
Expand All @@ -129,14 +129,14 @@
if (accelerationsLoadStatus === DirectQueryLoadingStatus.FAILED) {
setIsRefreshing(false);
}
}, [accelerationsLoadStatus]);

Check warning on line 132 in public/components/datasources/components/manage/accelerations/acceleration_table.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'dataSourceName'. Either include it or remove the dependency array

const handleRefresh = useCallback(() => {
if (!isCatalogCacheFetching(accelerationsLoadStatus)) {
setIsRefreshing(true);
startLoadingAccelerations(dataSourceName);
startLoadingAccelerations({ dataSourceName });
}
}, [accelerationsLoadStatus]);

Check warning on line 139 in public/components/datasources/components/manage/accelerations/acceleration_table.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useCallback has missing dependencies: 'dataSourceName' and 'startLoadingAccelerations'. Either include them or remove the dependency array

const RefreshButton = () => {
return (
Expand Down Expand Up @@ -246,7 +246,11 @@
return (
<EuiLink
onClick={() => {
renderAccelerationDetailsFlyout(acceleration, dataSourceName, handleRefresh);
renderAccelerationDetailsFlyout({

Check warning on line 249 in public/components/datasources/components/manage/accelerations/acceleration_table.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/accelerations/acceleration_table.tsx#L249

Added line #L249 was not covered by tests
acceleration,
dataSourceName,
handleRefresh,
});
}}
>
{displayName}
Expand Down Expand Up @@ -317,7 +321,7 @@
name: 'Actions',
actions: tableActions,
},
] as Array<EuiTableFieldDataColumnType<any>>;

Check warning on line 324 in public/components/datasources/components/manage/accelerations/acceleration_table.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type

const pagination = {
initialPageSize: 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
}>
>;
tableFieldsLoading: boolean;
dataSourceMDSId?: string;
}

export const SelectorLoadDatabases = ({
Expand All @@ -32,6 +33,7 @@
loadingComboBoxes,
setLoadingComboBoxes,
tableFieldsLoading,
dataSourceMDSId,
}: SelectorLoadDatabasesProps) => {
const [isLoading, setIsLoading] = useState(false);
const {
Expand All @@ -42,7 +44,7 @@

const onClickRefreshDatabases = () => {
setIsLoading(true);
startDatabasesLoading({ dataSourceName });
startDatabasesLoading({ dataSourceName, dataSourceMDSId });

Check warning on line 47 in public/components/datasources/components/manage/accelerations/create_accelerations_flyout/selectors/selector_helpers/load_databases.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/accelerations/create_accelerations_flyout/selectors/selector_helpers/load_databases.tsx#L47

Added line #L47 was not covered by tests
};

useEffect(() => {
Expand All @@ -56,17 +58,17 @@
) {
setIsLoading(false);
}
}, [loadDatabasesStatus]);

Check warning on line 61 in public/components/datasources/components/manage/accelerations/create_accelerations_flyout/selectors/selector_helpers/load_databases.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'loadDatabases'. Either include it or remove the dependency array. If 'loadDatabases' changes too often, find the parent component that defines it and wrap that definition in useCallback

useEffect(() => {
setLoadingComboBoxes({ ...loadingComboBoxes, database: isLoading });
}, [isLoading]);

Check warning on line 65 in public/components/datasources/components/manage/accelerations/create_accelerations_flyout/selectors/selector_helpers/load_databases.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has missing dependencies: 'loadingComboBoxes' and 'setLoadingComboBoxes'. Either include them or remove the dependency array. If 'setLoadingComboBoxes' changes too often, find the parent component that defines it and wrap that definition in useCallback

useEffect(() => {
return () => {
stopDatabasesLoading();
};
}, []);

Check warning on line 71 in public/components/datasources/components/manage/accelerations/create_accelerations_flyout/selectors/selector_helpers/load_databases.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'stopDatabasesLoading'. Either include it or remove the dependency array

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
}>
>;
tableFieldsLoading: boolean;
dataSourceMDSId?: string;
}

export const SelectorLoadObjects = ({
Expand All @@ -38,6 +39,7 @@
loadingComboBoxes,
setLoadingComboBoxes,
tableFieldsLoading,
dataSourceMDSId,
}: SelectorLoadDatabasesProps) => {
const { setToast } = useToast();
const [isLoading, setIsLoading] = useState({
Expand Down Expand Up @@ -65,8 +67,8 @@
tableStatus: true,
accelerationsStatus: true,
});
startLoadingTables({ dataSourceName, databaseName });
startLoadingAccelerations({ dataSourceName });
startLoadingTables({ dataSourceName, databaseName, dataSourceMDSId });
startLoadingAccelerations({ dataSourceName, dataSourceMDSId });

Check warning on line 71 in public/components/datasources/components/manage/accelerations/create_accelerations_flyout/selectors/selector_helpers/load_objects.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/accelerations/create_accelerations_flyout/selectors/selector_helpers/load_objects.tsx#L70-L71

Added lines #L70 - L71 were not covered by tests
};

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const AccelerationDataSourceSelector = ({
const loadDataSource = () => {
setLoadingComboBoxes({ ...loadingComboBoxes, dataSource: true });
http
.get(DATACONNECTIONS_BASE + `/dataSourceMDSId=${dataSourceMDSId}`)
.get(`${DATACONNECTIONS_BASE}/dataSourceMDSId=${dataSourceMDSId ?? ''}`)
.then((res) => {
const isValidDataSource = res.some(
(connection: any) =>
Expand Down Expand Up @@ -232,6 +232,7 @@ export const AccelerationDataSourceSelector = ({
loadingComboBoxes={loadingComboBoxes}
setLoadingComboBoxes={setLoadingComboBoxes}
tableFieldsLoading={tableFieldsLoading}
dataSourceMDSId={dataSourceMDSId}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down Expand Up @@ -281,6 +282,7 @@ export const AccelerationDataSourceSelector = ({
loadingComboBoxes={loadingComboBoxes}
setLoadingComboBoxes={setLoadingComboBoxes}
tableFieldsLoading={tableFieldsLoading}
dataSourceMDSId={dataSourceMDSId}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import { EuiButton, EuiHealth } from '@elastic/eui';
import React from 'react';
import { DATA_SOURCE_TYPES } from '../../../../../../../common/constants/data_sources';
import { CachedAcceleration } from '../../../../../../../common/types/data_connections';
import {
CachedAcceleration,
RenderAccelerationFlyoutParams,
} from '../../../../../../../common/types/data_connections';
import {
redirectToExplorerOSIdx,
redirectToExplorerWithDataSrc,
} from '../../associated_objects/utils/associated_objects_tab_utils';

export const ACC_PANEL_TITLE = 'Accelerations';
export const ACC_PANEL_DESC =
'Accelerations optimize query performance by indexing external data into OpenSearch.';
Expand Down Expand Up @@ -91,26 +93,23 @@
handleRefresh,
}: {
dataSourceName: string;
renderCreateAccelerationFlyout: (
dataSource: string,
dataSourceMDSId?: string,
databaseName?: string,
tableName?: string,
handleRefresh?: () => void
) => void;
renderCreateAccelerationFlyout: ({
dataSource,
databaseName,
tableName,
handleRefresh,
dataSourceMDSId,
}: RenderAccelerationFlyoutParams) => void;
handleRefresh: () => void;
}) => {
return (
<>
<EuiButton
onClick={() =>
renderCreateAccelerationFlyout(
dataSourceName,
undefined,
undefined,
undefined,
handleRefresh
)
renderCreateAccelerationFlyout({

Check warning on line 109 in public/components/datasources/components/manage/accelerations/utils/acceleration_utils.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/accelerations/utils/acceleration_utils.tsx#L109

Added line #L109 was not covered by tests
dataSource: dataSourceName,
handleRefresh,
})
}
fill
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,12 @@
return (
<EuiButtonEmpty
onClick={() =>
renderCreateAccelerationFlyout(
datasourceName,
'',
tableDetail.database,
tableDetail.name,
handleRefresh
)
renderCreateAccelerationFlyout({

Check warning on line 96 in public/components/datasources/components/manage/associated_objects/associated_objects_details_flyout.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects/associated_objects_details_flyout.tsx#L96

Added line #L96 was not covered by tests
dataSource: datasourceName,
databaseName: tableDetail.database,
tableName: tableDetail.name,
handleRefresh,
})
}
>
<EuiIcon type={'bolt'} size="m" />
Expand Down Expand Up @@ -156,7 +155,12 @@
return (
<EuiLink
onClick={() =>
renderAccelerationDetailsFlyout(item, datasourceName, handleRefresh, dataSourceMDSId)
renderAccelerationDetailsFlyout({
acceleration: item,
dataSourceName: datasourceName,
handleRefresh,
dataSourceMDSId,
})
}
>
{name}
Expand Down Expand Up @@ -196,13 +200,12 @@
color="primary"
fill
onClick={() =>
renderCreateAccelerationFlyout(
datasourceName,
'',
tableDetail.database,
tableDetail.name,
handleRefresh
)
renderCreateAccelerationFlyout({

Check warning on line 203 in public/components/datasources/components/manage/associated_objects/associated_objects_details_flyout.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects/associated_objects_details_flyout.tsx#L203

Added line #L203 was not covered by tests
dataSource: datasourceName,
databaseName: tableDetail.database,
tableName: tableDetail.name,
handleRefresh,
})
}
iconType="popout"
iconSide="left"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@

const onRefreshButtonClick = () => {
if (!isCatalogCacheFetching(databasesLoadStatus, tablesLoadStatus, accelerationsLoadStatus)) {
startLoadingDatabases({ databaseName: datasource.name });
startLoadingDatabases({ dataSourceName: datasource.name });

Check warning on line 103 in public/components/datasources/components/manage/associated_objects/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects/associated_objects_tab.tsx#L103

Added line #L103 was not covered by tests
setIsRefreshing(true);
}
};
Expand Down Expand Up @@ -167,7 +167,7 @@
datasourceCache.status === CachedDataSourceStatus.Failed) &&
!isCatalogCacheFetching(databasesLoadStatus)
) {
startLoadingDatabases(datasource.name);
startLoadingDatabases({ dataSourceName: datasource.name });

Check warning on line 170 in public/components/datasources/components/manage/associated_objects/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects/associated_objects_tab.tsx#L170

Added line #L170 was not covered by tests
} else if (datasourceCache.status === CachedDataSourceStatus.Updated) {
setCachedDatabases(datasourceCache.databases);
setIsFirstTimeLoading(false);
Expand Down Expand Up @@ -224,7 +224,7 @@
databaseCache.status === CachedDataSourceStatus.Failed) &&
!isCatalogCacheFetching(tablesLoadStatus)
) {
startLoadingTables(datasource.name, selectedDatabase);
startLoadingTables({ dataSourceName: datasource.name, databaseName: selectedDatabase });

Check warning on line 227 in public/components/datasources/components/manage/associated_objects/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects/associated_objects_tab.tsx#L227

Added line #L227 was not covered by tests
setIsObjectsLoading(true);
} else if (databaseCache.status === CachedDataSourceStatus.Updated) {
setCachedTables(databaseCache.tables);
Expand All @@ -235,7 +235,7 @@
isRefreshing) &&
!isCatalogCacheFetching(accelerationsLoadStatus)
) {
startLoadingAccelerations(datasource.name);
startLoadingAccelerations({ dataSourceName: datasource.name });

Check warning on line 238 in public/components/datasources/components/manage/associated_objects/associated_objects_tab.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects/associated_objects_tab.tsx#L238

Added line #L238 was not covered by tests
setIsObjectsLoading(true);
} else if (accelerationsCache.status === CachedDataSourceStatus.Updated) {
setCachedAccelerations(accelerationsCache.accelerations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useEffect, useState } from 'react';
import {
EuiInMemoryTable,
EuiLink,
SearchFilterConfig,
EuiTableFieldDataColumnType,
SearchFilterConfig,
} from '@elastic/eui';
import { i18n } from '@osd/i18n';
import React, { useEffect, useState } from 'react';
import {
ACCELERATION_INDEX_TYPES,
DATA_SOURCE_TYPES,
} from '../../../../../../../common/constants/data_sources';
import {
AssociatedObject,
CachedAcceleration,
Expand All @@ -20,18 +24,14 @@
getRenderAssociatedObjectsDetailsFlyout,
getRenderCreateAccelerationFlyout,
} from '../../../../../../plugin';
import { getAccelerationName } from '../../accelerations/utils/acceleration_utils';
import {
ASSC_OBJ_TABLE_ACC_COLUMN_NAME,
ASSC_OBJ_TABLE_SEARCH_HINT,
ASSC_OBJ_TABLE_SUBJ,
redirectToExplorerOSIdx,
redirectToExplorerWithDataSrc,
} from '../utils/associated_objects_tab_utils';
import { getAccelerationName } from '../../accelerations/utils/acceleration_utils';
import {
ACCELERATION_INDEX_TYPES,
DATA_SOURCE_TYPES,
} from '../../../../../../../common/constants/data_sources';

interface AssociatedObjectsTableProps {
datasourceName: string;
Expand Down Expand Up @@ -69,11 +69,18 @@
<EuiLink
onClick={() => {
if (item.type === 'table') {
renderAssociatedObjectsDetailsFlyout(item, datasourceName, handleRefresh);
renderAssociatedObjectsDetailsFlyout({

Check warning on line 72 in public/components/datasources/components/manage/associated_objects/modules/associated_objects_table.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects/modules/associated_objects_table.tsx#L72

Added line #L72 was not covered by tests
tableDetail: item,
dataSourceName: datasourceName,
handleRefresh,
});
} else {
const acceleration = cachedAccelerations.find((acc) => acc.indexName === item.id);
if (acceleration) {
renderAccelerationDetailsFlyout(acceleration, datasourceName);
renderAccelerationDetailsFlyout({

Check warning on line 80 in public/components/datasources/components/manage/associated_objects/modules/associated_objects_table.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects/modules/associated_objects_table.tsx#L80

Added line #L80 was not covered by tests
acceleration,
dataSourceName: datasourceName,
});
}
}
}}
Expand Down Expand Up @@ -108,7 +115,11 @@
return (
<EuiLink
onClick={() =>
renderAccelerationDetailsFlyout(accelerations[0], datasourceName, handleRefresh)
renderAccelerationDetailsFlyout({

Check warning on line 118 in public/components/datasources/components/manage/associated_objects/modules/associated_objects_table.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects/modules/associated_objects_table.tsx#L118

Added line #L118 was not covered by tests
acceleration: accelerations[0],
dataSourceName: datasourceName,
handleRefresh,
})
}
>
{name}
Expand All @@ -118,7 +129,11 @@
return (
<EuiLink
onClick={() =>
renderAssociatedObjectsDetailsFlyout(obj, datasourceName, handleRefresh)
renderAssociatedObjectsDetailsFlyout({

Check warning on line 132 in public/components/datasources/components/manage/associated_objects/modules/associated_objects_table.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects/modules/associated_objects_table.tsx#L132

Added line #L132 was not covered by tests
tableDetail: obj,
dataSourceName: datasourceName,
handleRefresh,
})
}
>
View all {accelerations.length}
Expand All @@ -128,7 +143,11 @@
return (
<EuiLink
onClick={() =>
renderAssociatedObjectsDetailsFlyout(accelerations, datasourceName, handleRefresh)
renderAssociatedObjectsDetailsFlyout({

Check warning on line 146 in public/components/datasources/components/manage/associated_objects/modules/associated_objects_table.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects/modules/associated_objects_table.tsx#L146

Added line #L146 was not covered by tests
tableDetail: accelerations,
dataSourceName: datasourceName,
handleRefresh,
})
}
>
{accelerations.name}
Expand Down Expand Up @@ -185,7 +204,12 @@
icon: 'bolt',
available: (item: AssociatedObject) => item.type === 'table',
onClick: (item: AssociatedObject) =>
renderCreateAccelerationFlyout(datasourceName, item.database, item.name, handleRefresh),
renderCreateAccelerationFlyout({

Check warning on line 207 in public/components/datasources/components/manage/associated_objects/modules/associated_objects_table.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects/modules/associated_objects_table.tsx#L207

Added line #L207 was not covered by tests
dataSource: datasourceName,
databaseName: item.database,
tableName: item.tableName,
handleRefresh,
}),
},
],
},
Expand Down
Loading
Loading