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

[Backport 2.x] Implement redirection to explorer within data sources #1553

Merged
merged 1 commit into from
Mar 18, 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
2 changes: 1 addition & 1 deletion common/types/data_connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
id: string;
name: string;
database: string;
type: string;
type: AccelerationIndexType | 'table';
accelerations: Acceleration[];
columns?: TableColumn[];
}
Expand Down Expand Up @@ -70,7 +70,7 @@
interface AsyncApiDataResponse {
status: string;
schema?: Array<{ name: string; type: string }>;
datarows?: any;

Check warning on line 73 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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
index: string;
acceleration: CachedAcceleration;
dataSourceName: string;
resetFlyout: () => void;
}

const getMappings = (index: string): Promise<OpenSearchDashboardsResponse> | undefined => {
Expand All @@ -57,11 +58,11 @@
};

export const AccelerationDetailsFlyout = (props: AccelerationDetailsFlyoutProps) => {
const { index, dataSourceName, acceleration } = props;
const { index, dataSourceName, acceleration, resetFlyout } = props;
console.log(index, acceleration, dataSourceName);
const { flintIndexName } = acceleration;
const [selectedTab, setSelectedTab] = useState('details');
const tabsMap: { [key: string]: any } = {

Check warning on line 65 in public/components/datasources/components/manage/accelerations/acceleration_details_flyout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
details: AccelerationDetailsTab,
schema: AccelerationSchemaTab,
sql_definition: AccelerationSqlTab,
Expand Down Expand Up @@ -104,12 +105,17 @@
if (flintIndexName !== undefined && flintIndexName.trim().length > 0) {
getAccDetail(flintIndexName);
}
}, [flintIndexName]);

Check warning on line 108 in public/components/datasources/components/manage/accelerations/acceleration_details_flyout.tsx

View workflow job for this annotation

GitHub Actions / Lint

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

const DiscoverButton = () => {
// TODO: display button if can be sent to discover
return (
<EuiButtonEmpty onClick={onDiscoverButtonClick}>
<EuiButtonEmpty
onClick={() => {
onDiscoverButtonClick(acceleration, dataSourceName);
resetFlyout();

Check warning on line 116 in public/components/datasources/components/manage/accelerations/acceleration_details_flyout.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/accelerations/acceleration_details_flyout.tsx#L114-L116

Added lines #L114 - L116 were not covered by tests
}}
>
<EuiIcon type={'discoverApp'} size="m" />
</EuiButtonEmpty>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

interface AccelerationTableProps {
dataSourceName: string;
cacheLoadingHooks: any;

Check warning on line 43 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
}

export const AccelerationTable = ({
Expand Down Expand Up @@ -77,7 +77,7 @@
setAccelerations(cachedDataSource.accelerations);
setUpdatedTime(cachedDataSource.lastUpdated);
}
}, []);

Check warning on line 80 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 @@ -93,7 +93,7 @@
setIsRefreshing(false);
console.log('Refresh process is failed.');
}
}, [accelerationsLoadStatus]);

Check warning on line 96 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 = () => {
console.log('Initiating refresh...');
Expand Down Expand Up @@ -179,7 +179,9 @@
description: 'Open in Discover',
icon: 'discoverApp',
type: 'icon',
onClick: onDiscoverButtonClick,
onClick: (acc: CachedAcceleration) => {
onDiscoverButtonClick(acc, dataSourceName);

Check warning on line 183 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#L182-L183

Added lines #L182 - L183 were not covered by tests
},
},
{
name: 'Refresh',
Expand Down Expand Up @@ -282,7 +284,7 @@
name: 'Actions',
actions: tableActions,
},
] as Array<EuiBasicTableColumn<any>>;

Check warning on line 287 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 @@ -6,6 +6,11 @@
import React from 'react';
import { EuiHealth } from '@elastic/eui';
import { CachedAcceleration } from '../../../../../../../common/types/data_connections';
import {
redirectToExplorerOSIdx,
redirectToExplorerWithDataSrc,
} from '../../associated_objects/utils/associated_objects_tab_utils';
import { DATA_SOURCE_TYPES } from '../../../../../../../common/constants/data_sources';

export const ACC_PANEL_TITLE = 'Accelerations';
export const ACC_PANEL_DESC =
Expand Down Expand Up @@ -75,17 +80,27 @@
return 'inputOutput';
};

export const onRefreshButtonClick = (acceleration: any) => {

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

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
// TODO: send request to refresh
console.log('refreshing', acceleration.name);
};

export const onDiscoverButtonClick = (acceleration: any) => {
// TODO: send user to Discover
console.log('sending user to discover for', acceleration.name);
export const onDiscoverButtonClick = (acceleration: CachedAcceleration, dataSourceName: string) => {
// boolean determining whether its a skipping index table or mv/ci
if (acceleration.type === undefined) return;
if (acceleration.type === 'skipping') {
redirectToExplorerWithDataSrc(

Check warning on line 92 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#L92

Added line #L92 was not covered by tests
dataSourceName,
DATA_SOURCE_TYPES.S3Glue,
acceleration.database,
acceleration.table
);
} else {
redirectToExplorerOSIdx(acceleration.flintIndexName);

Check warning on line 99 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#L98-L99

Added lines #L98 - L99 were not covered by tests
}
};

export const onDeleteButtonClick = (acceleration: any) => {

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

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
// TODO: delete acceleration
console.log('deleting', acceleration.name);
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import {
onAccelerateButtonClick,
onDeleteButtonClick,
onDiscoverButtonClick,
redirectToExplorerWithDataSrc,
} from './utils/associated_objects_tab_utils';
import { getRenderAccelerationDetailsFlyout } from '../../../../../plugin';
import { AccelerationStatus } from '../accelerations/utils/acceleration_utils';
Expand All @@ -38,16 +38,32 @@
ACCE_NO_DATA_DESCRIPTION,
CREATE_ACCELERATION_DESCRIPTION,
} from '../associated_objects/utils/associated_objects_tab_utils';
import { DATA_SOURCE_TYPES } from '../../../../../../common/constants/data_sources';

export interface AssociatedObjectsFlyoutProps {
tableDetail: AssociatedObject;
resetFlyout: () => void;
}

export const AssociatedObjectsDetailsFlyout = ({ tableDetail }: AssociatedObjectsFlyoutProps) => {
export const AssociatedObjectsDetailsFlyout = ({
tableDetail,
resetFlyout,
}: AssociatedObjectsFlyoutProps) => {
const DiscoverButton = () => {
// TODO: display button if can be sent to discover
return (
<EuiButtonEmpty onClick={onDiscoverButtonClick}>
<EuiButtonEmpty
onClick={() => {

Check warning on line 56 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#L56

Added line #L56 was not covered by tests
if (tableDetail.type !== 'table') return;
redirectToExplorerWithDataSrc(

Check warning on line 58 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#L58

Added line #L58 was not covered by tests
tableDetail.datasource,
DATA_SOURCE_TYPES.S3Glue,
tableDetail.database,
tableDetail.name
);
resetFlyout();

Check warning on line 64 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#L64

Added line #L64 was not covered by tests
}}
>
<EuiIcon type={'discoverApp'} size="m" />
</EuiButtonEmpty>
);
Expand All @@ -69,7 +85,7 @@
);
};

const DetailComponent = (detailProps: { title: string; description: any }) => {

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

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const { title, description } = detailProps;
return (
<EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export const AssociatedObjectsTab: React.FC<AssociatedObjectsTabProps> = (props)
name: getAccelerationName(acceleration.indexName, acceleration, datasource.name),
database: acceleration.database,
type: ACCELERATION_INDEX_TYPES.find((accelType) => accelType.value === acceleration.type)!
.label,
.value,
// Temporary dummy array
accelerations: [],
columns: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@
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 @@ -97,6 +103,10 @@
defaultMessage: 'Type',
}),
sortable: true,
render: (type) => {
if (type === 'table') return 'Table';
return ACCELERATION_INDEX_TYPES.find((accType) => type === accType.value)!.label;
},
},
{
field: 'accelerations',
Expand Down Expand Up @@ -134,7 +144,22 @@
),
type: 'icon',
icon: 'discoverApp',
onClick: (item: AssociatedObject) => console.log('Discover', item),
onClick: (asscObj: AssociatedObject) => {

Check warning on line 147 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#L147

Added line #L147 was not covered by tests
if (asscObj.type === 'covering' || asscObj.type === 'materialized') {
// find the flint index name through the cached acceleration
const acceleration = cachedAccelerations.find(
(acc) => getAccelerationName(acc.indexName, acc, datasourceName) === asscObj.name

Check warning on line 151 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#L150-L151

Added lines #L150 - L151 were not covered by tests
);
redirectToExplorerOSIdx(acceleration!.flintIndexName);

Check warning on line 153 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#L153

Added line #L153 was not covered by tests
} else if (asscObj.type === 'table') {
redirectToExplorerWithDataSrc(

Check warning on line 155 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#L155

Added line #L155 was not covered by tests
asscObj.datasource,
DATA_SOURCE_TYPES.S3Glue,
asscObj.database,
asscObj.name
);
}
},
},
{
name: i18n.translate('datasources.associatedObjectsTab.action.accelerate.name', {
Expand All @@ -148,7 +173,7 @@
),
type: 'icon',
icon: 'bolt',
available: (item: AssociatedObject) => item.type === 'Table',
available: (item: AssociatedObject) => item.type === 'table',
onClick: (item: AssociatedObject) => console.log('Accelerate', item),
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { coreRefs } from '../../../../../../framework/core_refs';
import { DirectQueryLoadingStatus } from '../../../../../../../common/types/explorer';
import {
DEFAULT_DATA_SOURCE_NAME,
DEFAULT_DATA_SOURCE_TYPE,
} from '../../../../../../../common/constants/data_sources';
import { observabilityLogsID } from '../../../../../../../common/constants/shared';

export const ASSC_OBJ_TABLE_SUBJ = 'associatedObjectsTable';

Expand Down Expand Up @@ -36,11 +42,6 @@
console.log('accelerating', tableDetail.name);
};

export const onDiscoverButtonClick = (tabaleDetail: any) => {
// TODO: send user to Discover
console.log('sending user to discover for', tabaleDetail.name);
};

export const onDeleteButtonClick = (tableDetail: any) => {
// TODO: delete table
console.log('deleting', tableDetail.name);
Expand All @@ -57,3 +58,33 @@
catalogCacheFetchingStatus.includes(status)
);
};

export const redirectToExplorerWithDataSrc = (
datasourceName: string,
datasourceType: string,
databaseName: string,
tableName: string
) => {
const queryIndex = `${datasourceName}.${databaseName}.${tableName}`;
redirectToExplorerWithQuery(datasourceName, datasourceType, queryIndex);

Check warning on line 69 in public/components/datasources/components/manage/associated_objects/utils/associated_objects_tab_utils.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects/utils/associated_objects_tab_utils.tsx#L67-L69

Added lines #L67 - L69 were not covered by tests
};

export const redirectToExplorerOSIdx = (indexName: string) => {
redirectToExplorerWithQuery(DEFAULT_DATA_SOURCE_NAME, DEFAULT_DATA_SOURCE_TYPE, indexName);

Check warning on line 73 in public/components/datasources/components/manage/associated_objects/utils/associated_objects_tab_utils.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects/utils/associated_objects_tab_utils.tsx#L73

Added line #L73 was not covered by tests
};

const redirectToExplorerWithQuery = (
datasourceName: string,
datasourceType: string,
queriedIndex: string
) => {

Check warning on line 80 in public/components/datasources/components/manage/associated_objects/utils/associated_objects_tab_utils.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects/utils/associated_objects_tab_utils.tsx#L80

Added line #L80 was not covered by tests
// navigate to explorer
coreRefs?.application!.navigateToApp(observabilityLogsID, {

Check warning on line 82 in public/components/datasources/components/manage/associated_objects/utils/associated_objects_tab_utils.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/associated_objects/utils/associated_objects_tab_utils.tsx#L82

Added line #L82 was not covered by tests
path: `#/explorer`,
state: {
datasourceName,
datasourceType,
queryToRun: `source = ${queriedIndex} | head 10`,
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
useLoadDatabasesToCache,
useLoadTablesToCache,
} from '../../../../../public/framework/catalog_cache/cache_loader';
import { DATA_SOURCE_TYPES } from '../../../../../common/constants/data_sources';
import { coreRefs } from '../../../../framework/core_refs';
import { getRenderCreateAccelerationFlyout } from '../../../../plugin';
import { NoAccess } from '../no_access';
Expand Down Expand Up @@ -81,48 +82,6 @@
startLoadingAccelerations,
};

// Dummy accelerations variables for mock purposes
// Actual accelerations should be retrieved from the backend
// const sampleSql = 'select * from `httplogs`.`default`.`table2` limit 10';
const _dummyAccelerations = [
{
flintIndexName: 'flint_mys3_default_http_logs_skipping_index',
kind: 'skipping',
database: 'default',
table: 'test',
indexName: 'skipping_index',
autoRefresh: true,
status: 'Active',
},
{
flintIndexName: 'flint_mys3_default_test_mycv_index',
kind: 'covering',
database: 'default',
table: 'test',
indexName: 'mycv',
autoRefresh: false,
status: 'Active',
},
{
flintIndexName: 'flint_mys3_default_mymv',
kind: ' ',
database: 'default',
table: '',
indexName: 'mymv',
autoRefresh: true,
status: 'Active',
},
{
flintIndexName: 'flint_mys3_default_sample_mv',
kind: 'mv',
database: 'default',
table: 'sample_table',
indexName: 'sample_mv',
autoRefresh: true,
status: 'Active',
},
];

const [dataSourceIntegrations, setDataSourceIntegrations] = useState(
[] as IntegrationInstanceResult[]
);
Expand Down Expand Up @@ -156,7 +115,13 @@
};

const onclickDiscoverCard = () => {
application!.navigateToApp(observabilityLogsID);
application!.navigateToApp(observabilityLogsID, {

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

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/data_connection.tsx#L118

Added line #L118 was not covered by tests
path: `#/explorer`,
state: {
datasourceName: dataSource,
datasourceType: DATA_SOURCE_TYPES.S3Glue,
},
});
};

const DefaultDatasourceCards = () => {
Expand Down
40 changes: 39 additions & 1 deletion public/components/event_analytics/explorer/explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import React, {
useState,
} from 'react';
import { batch, useDispatch, useSelector } from 'react-redux';
import { createBrowserHistory } from 'history';
import { LogExplorerRouterContext } from '..';
import {
DEFAULT_DATA_SOURCE_TYPE,
Expand Down Expand Up @@ -98,7 +99,10 @@ import { findMinInterval } from '../../common/query_utils';
import { onItemSelect, parseGetSuggestions } from '../../common/search/autocomplete_logic';
import { Search } from '../../common/search/search';
import { processMetricsData } from '../../custom_panels/helpers/utils';
import { selectSearchMetaData } from '../../event_analytics/redux/slices/search_meta_data_slice';
import {
selectSearchMetaData,
update as updateSearchMetaData,
} from '../../event_analytics/redux/slices/search_meta_data_slice';
import { getVizContainerProps } from '../../visualizations/charts/helpers';
import { TabContext, useFetchEvents, useFetchPatterns, useFetchVisualizations } from '../hooks';
import {
Expand Down Expand Up @@ -263,6 +267,40 @@ export const Explorer = ({
);
};

const historyFromRedirection = createBrowserHistory();
useEffect(() => {
console.log(historyFromRedirection.location.state);
if (!historyFromRedirection.location.state) return;
const {
datasourceName,
datasourceType,
queryToRun,
}: any = historyFromRedirection.location.state;
batch(() => {
dispatch(
updateSearchMetaData({
tabId,
data: {
datasources: [
{
label: datasourceName,
type: datasourceType,
value: datasourceName,
name: datasourceName,
},
],
},
})
);
dispatch(
changeQuery({
tabId,
query: { [RAW_QUERY]: queryToRun },
})
);
});
}, []);

useEffect(() => {
const handleSetBrowserTabFocus = () => {
if (document.hidden) setBrowserTabFocus(false);
Expand Down
Loading
Loading