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

Adjusting Create Acceleration Flyout Props #289

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
}

export enum AsyncQueryStatus {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this state equivalent to DirectQueryLoadingStatus?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Initial = 'initial',
Pending = 'pending',
Success = 'success',
Failed = 'failed',
Expand Down Expand Up @@ -127,7 +128,7 @@
interface AsyncApiDataResponse {
status: string;
schema?: Array<{ name: string; type: string }>;
datarows?: any;

Check warning on line 131 in common/types/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
total?: number;
size?: number;
error?: string;
Expand Down
39 changes: 39 additions & 0 deletions public/components/SQLPage/AccelerationFlyoutButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { EuiButton } from '@elastic/eui';
import React, { useEffect } from 'react';
import { catalogCacheRefs } from '../../../public/framework/catalog_cache_refs';
import { getRenderCreateAccelerationFlyout } from '../../../public/dependencies/register_observability_dependencies';

interface AccelerationFlyoutButtonProps {
datasource: string;
asyncLoading: boolean;
}

export const AccelerationFlyoutButton = (props: AccelerationFlyoutButtonProps) => {
const { datasource, asyncLoading } = props;

const renderCreateAccelerationFlyout = getRenderCreateAccelerationFlyout();
const { loadStatus, startLoading, stopLoading } = catalogCacheRefs.useLoadTableColumnsToCache();

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

Check warning on line 26 in public/components/SQLPage/AccelerationFlyoutButton.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'stopLoading'. Either include it or remove the dependency array
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing dependency.


return (
<EuiButton
className="sql-accelerate-button"
onClick={() =>
renderCreateAccelerationFlyout(datasource, loadStatus, startLoading, stopLoading)
}
isDisabled={asyncLoading}
>
Accelerate Table
</EuiButton>
);
};
23 changes: 13 additions & 10 deletions public/components/SQLPage/SQLPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import { SAMPLE_SQL_QUERY } from '../../../common/constants';
import { getRenderCreateAccelerationFlyout } from '../../dependencies/register_observability_dependencies';
import { ResponseDetail, TranslateResult } from '../Main/main';
import { catalogCacheRefs } from '../../framework/catalog_cache_refs';
import { AccelerationFlyoutButton } from './AccelerationFlyoutButton';

interface SQLPageProps {
http: CoreStart['http'];
Expand All @@ -34,7 +36,7 @@
onClear: () => void;
updateSQLQueries: (query: string) => void;
sqlQuery: string;
sqlTranslations: ResponseDetail<TranslateResult>[];

Check failure on line 39 in public/components/SQLPage/SQLPage.tsx

View workflow job for this annotation

GitHub Actions / Lint

Array type using 'T[]' is forbidden for non-simple types. Use 'Array<T>' instead
selectedDatasource: EuiComboBoxOptionOption[];
asyncLoading: boolean;
openAccelerationFlyout: boolean;
Expand Down Expand Up @@ -67,7 +69,13 @@
}

setAccelerationFlyout = () => {
this.renderCreateAccelerationFlyout(this.props.selectedDatasource[0].label);
const { loadStatus, startLoading, stopLoading } = catalogCacheRefs.useLoadTableColumnsToCache();
this.renderCreateAccelerationFlyout(
this.props.selectedDatasource[0].label,
loadStatus,
startLoading,
stopLoading
);
Comment on lines 71 to +78
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this function used for?
cc: @ps48 for more context

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used for users coming from URL to see the acceleration flyout open.

};

componentDidUpdate(prevProps: SQLPageProps) {
Expand Down Expand Up @@ -98,7 +106,7 @@

const explainContent = sqlTranslationsNotEmpty()
? this.props.sqlTranslations
.map((queryTranslation: any) => JSON.stringify(queryTranslation.data, null, 2))

Check warning on line 109 in public/components/SQLPage/SQLPage.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
.join('\n')
: 'This query is not explainable.';

Expand Down Expand Up @@ -210,15 +218,10 @@
{this.props.selectedDatasource &&
this.props.selectedDatasource[0].label !== 'OpenSearch' && (
<EuiFlexItem grow={false}>
<EuiButton
className="sql-accelerate-button"
onClick={() =>
this.renderCreateAccelerationFlyout(this.props.selectedDatasource[0].label)
}
isDisabled={this.props.asyncLoading}
>
Accelerate Table
</EuiButton>
<AccelerationFlyoutButton
datasource={this.props.selectedDatasource[0].label}
asyncLoading={this.props.asyncLoading}
/>
</EuiFlexItem>
)}
</EuiFlexGroup>
Expand Down
11 changes: 10 additions & 1 deletion public/dependencies/register_observability_dependencies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ export const [
export const [
getRenderCreateAccelerationFlyout,
setRenderCreateAccelerationFlyout,
] = createGetterSetter<(dataSource: string) => void>('renderCreateAccelerationFlyout');
] = createGetterSetter<
(
dataSource: string,
loadStatus: any,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should DirectQueryLoadingStatus be brought over from dashboards-observability?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use AsyncQueryStatus

startLoading: (dataSourceName: string, databaseName?: string, tableName?: string) => void,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw there are repeated patterns not only in this PR where we have a same set of interfaces for functions and components but the interfaces are duplicated and redefined repeatedly, feel like we should define common interfaces and reuse them or leverage utility types for composing types and interfaces. It's ok for this PR and release but we should follow up on this later.

stopLoading: () => void,
databaseName?: string,
tableName?: string
) => void
>('renderCreateAccelerationFlyout');

export const registerObservabilityDependencies = (start?: ObservabilityStart) => {
if (!start) return;
Expand Down
Loading