Skip to content

Commit

Permalink
don't show skipping index option in create acceleration flyout
Browse files Browse the repository at this point in the history
Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>
  • Loading branch information
amsiglan committed May 18, 2024
1 parent e66ff7e commit 5334641
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import {
CachedTable,
CreateAccelerationForm,
S3GlueProperties,
} from '../../../../../../../../common/types/data_connections';
import { DirectQueryLoadingStatus } from '../../../../../../../../common/types/explorer';
import { useLoadTableColumnsToCache } from '../../../../../../../framework/catalog_cache/cache_loader';
Expand All @@ -39,6 +40,7 @@ import { QueryVisualEditor } from '../visual_editors/query_visual_editor';
import { CreateAccelerationButton } from './create_acceleration_button';
import { CreateAccelerationHeader } from './create_acceleration_header';
import { hasError } from './utils';
import { DATACONNECTIONS_BASE } from '../../../../../../../../common/constants/shared';

export interface CreateAccelerationProps {
selectedDatasource: string;
Expand All @@ -59,6 +61,7 @@ export const CreateAcceleration = ({
}: CreateAccelerationProps) => {
const { setToast } = useToast();
const http = coreRefs!.http;
const [isS3ConnectionWithLakeFormation, setIsS3ConnectionWithLakeFormation] = useState(false);
const [accelerationFormData, setAccelerationFormData] = useState<CreateAccelerationForm>({
dataSource: selectedDatasource,
database: databaseName ?? '',
Expand Down Expand Up @@ -167,6 +170,18 @@ export const CreateAcceleration = ({
}
};

const updateDataSourceConnectionInfo = () => {
coreRefs.http!.get(`${DATACONNECTIONS_BASE}/${selectedDatasource}`).then((data: any) => {
setIsS3ConnectionWithLakeFormation(
!!(data.properties as S3GlueProperties)['glue.lakeformation.enabled']
);
});
};

useEffect(() => {
updateDataSourceConnectionInfo();
}, [selectedDatasource]);

useEffect(() => {
if (databaseName !== undefined && tableName !== undefined) {
initiateColumnLoad(
Expand Down Expand Up @@ -236,6 +251,7 @@ export const CreateAcceleration = ({
<EuiSpacer size="xxl" />
<IndexTypeSelector
accelerationFormData={accelerationFormData}
isS3ConnectionWithLakeFormation={isS3ConnectionWithLakeFormation}
setAccelerationFormData={setAccelerationFormData}
initiateColumnLoad={initiateColumnLoad}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { EuiFormRow, EuiLink, EuiSpacer, EuiSuperSelect, EuiText } from '@elastic/eui';
import React, { Fragment, useEffect, useState } from 'react';
import React, { Fragment, useEffect, useState, useRef } from 'react';
import {
ACCELERATION_DEFUALT_SKIPPING_INDEX_NAME,
ACC_INDEX_TYPE_DOCUMENTATION_URL,
Expand All @@ -16,16 +16,27 @@ import {

interface IndexTypeSelectorProps {
accelerationFormData: CreateAccelerationForm;
isS3ConnectionWithLakeFormation: boolean;
setAccelerationFormData: React.Dispatch<React.SetStateAction<CreateAccelerationForm>>;
initiateColumnLoad: (dataSource: string, database: string, dataTable: string) => void;
}

export const IndexTypeSelector = ({
accelerationFormData,
isS3ConnectionWithLakeFormation,
setAccelerationFormData,
initiateColumnLoad,
}: IndexTypeSelectorProps) => {
const [value, setValue] = useState('skipping');
// This is used to track if user changed the value
// If so, we skip changing it based on 'isS3ConnectionWithLakeFormation' in the effect below
const valueSetAlready = useRef(false);

useEffect(() => {
if (!valueSetAlready.current) {
setValue(isS3ConnectionWithLakeFormation ? 'materialized' : 'skipping');
}
}, [isS3ConnectionWithLakeFormation]);

useEffect(() => {
initiateColumnLoad(
Expand All @@ -43,23 +54,30 @@ export const IndexTypeSelector = ({
indexType === 'skipping' ? ACCELERATION_DEFUALT_SKIPPING_INDEX_NAME : '',
});
setValue(indexType);
valueSetAlready.current = true;
};

const baseOptions = !isS3ConnectionWithLakeFormation
? [
{
value: 'skipping',
inputDisplay: 'Skipping index',
dropdownDisplay: (
<Fragment>
<strong>Skipping index</strong>
<EuiText size="s" color="subdued">
<p className="EuiTextColor--subdued">
Accelerate direct queries by storing table meta-data in OpenSearch.
</p>
</EuiText>
</Fragment>
),
},
]
: [];

const superSelectOptions = [
{
value: 'skipping',
inputDisplay: 'Skipping index',
dropdownDisplay: (
<Fragment>
<strong>Skipping index</strong>
<EuiText size="s" color="subdued">
<p className="EuiTextColor--subdued">
Accelerate direct queries by storing table meta-data in OpenSearch.
</p>
</EuiText>
</Fragment>
),
},
...baseOptions,
{
value: 'covering',
inputDisplay: 'Covering index',
Expand Down

0 comments on commit 5334641

Please sign in to comment.