From 1f7ee0af0ccb254ee99e5cc759bb232de9c6cefe Mon Sep 17 00:00:00 2001 From: Shenoy Pratik Date: Wed, 17 Apr 2024 19:32:19 -0700 Subject: [PATCH] Remove auto refresh option in create acceleration flyout (#1716) * remove auto refresh option, update tests Signed-off-by: Shenoy Pratik * update error on blur Signed-off-by: Shenoy Pratik --------- Signed-off-by: Shenoy Pratik --- common/constants/data_sources.ts | 6 + common/types/data_connections.ts | 2 +- .../create_acceleration.test.tsx.snap | 220 ++++++++++- .../create/__tests__/utils.test.tsx | 30 +- .../create/create_acceleration.tsx | 7 +- .../create/utils.tsx | 16 +- .../index_setting_options.test.tsx.snap | 350 +++++++++++++++++- .../__tests__/index_setting_options.test.tsx | 2 +- .../selectors/index_setting_options.tsx | 41 +- test/accelerations.ts | 43 ++- 10 files changed, 649 insertions(+), 68 deletions(-) diff --git a/common/constants/data_sources.ts b/common/constants/data_sources.ts index ad36822b4..98c910b3a 100644 --- a/common/constants/data_sources.ts +++ b/common/constants/data_sources.ts @@ -33,6 +33,12 @@ export const ACCELERATION_TIME_INTERVAL = [ { text: 'day(s)', value: 'day' }, { text: 'week(s)', value: 'week' }, ]; +export const ACCELERATION_REFRESH_TIME_INTERVAL = [ + { text: 'minutes(s)', value: 'minute' }, + { text: 'hour(s)', value: 'hour' }, + { text: 'day(s)', value: 'day' }, + { text: 'week(s)', value: 'week' }, +]; export const ACCELERATION_ADD_FIELDS_TEXT = '(add fields here)'; export const ACCELERATION_INDEX_NAME_REGEX = /^[a-z0-9_]+$/; diff --git a/common/types/data_connections.ts b/common/types/data_connections.ts index f7901e051..66c756d3a 100644 --- a/common/types/data_connections.ts +++ b/common/types/data_connections.ts @@ -217,7 +217,7 @@ export interface FormErrorsType { watermarkDelayError: string[]; } -export type AccelerationRefreshType = 'auto' | 'autoInterval' | 'manual' | 'manualIncrement'; +export type AccelerationRefreshType = 'autoInterval' | 'manual' | 'manualIncrement'; export interface CreateAccelerationForm { dataSource: string; diff --git a/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/__tests__/__snapshots__/create_acceleration.test.tsx.snap b/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/__tests__/__snapshots__/create_acceleration.test.tsx.snap index d5b4b8e5c..19fcd741b 100644 --- a/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/__tests__/__snapshots__/create_acceleration.test.tsx.snap +++ b/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/__tests__/__snapshots__/create_acceleration.test.tsx.snap @@ -583,7 +583,7 @@ Array [
- Select an option: Auto, is selected + Select an option: Auto (Interval), is selected
+
+
+ +
+
+
+
+ +
+
+
+ +
+ + + +
+
+
+
+
+ Specify how frequent the index gets updated when performing the refresh job. +
+
+
,
- Select an option: Auto, is selected + Select an option: Auto (Interval), is selected
, +
+
+ +
+
+
+
+ +
+
+
+ +
+ + + + + +
+
+
+
+
+ Specify how frequent the index gets updated when performing the refresh job. +
+
+
,
{ describe('validateRefreshInterval', () => { it('should return an array with an error message when refreshType is "interval" and refreshWindow is less than 1', () => { - expect(validateRefreshInterval('autoInterval', 0)).toEqual([ + expect(validateRefreshInterval('autoInterval', 0, 'hour')).toEqual([ 'refresh window should be greater than 0', ]); - expect(validateRefreshInterval('autoInterval', -1)).toEqual([ + expect(validateRefreshInterval('autoInterval', -1, 'day')).toEqual([ 'refresh window should be greater than 0', ]); - expect(validateRefreshInterval('autoInterval', -10)).toEqual([ + expect(validateRefreshInterval('autoInterval', -10, 'week')).toEqual([ 'refresh window should be greater than 0', ]); + expect(validateRefreshInterval('autoInterval', 14, 'minute')).toEqual([ + 'refresh window should be greater than 15 minutes', + ]); + expect(validateRefreshInterval('autoInterval', 10, 'minute')).toEqual([ + 'refresh window should be greater than 15 minutes', + ]); + expect(validateRefreshInterval('autoInterval', 0, 'minute')).toEqual([ + 'refresh window should be greater than 15 minutes', + ]); }); it('should return an empty array when refreshType is not "interval" or when refreshWindow is greater than or equal to 1', () => { - expect(validateRefreshInterval('auto', 0)).toEqual([]); - expect(validateRefreshInterval('auto', 1)).toEqual([]); - expect(validateRefreshInterval('autoInterval', 1)).toEqual([]); - expect(validateRefreshInterval('autoInterval', 5)).toEqual([]); - expect(validateRefreshInterval('manual', 0)).toEqual([]); - expect(validateRefreshInterval('manualIncrement', 0)).toEqual([]); + expect(validateRefreshInterval('auto', 0, 'minute')).toEqual([]); + expect(validateRefreshInterval('auto', 1, 'minute')).toEqual([]); + expect(validateRefreshInterval('autoInterval', 15, 'minute')).toEqual([]); + expect(validateRefreshInterval('autoInterval', 20, 'minute')).toEqual([]); + expect(validateRefreshInterval('manual', 0, 'minute')).toEqual([]); + expect(validateRefreshInterval('manualIncrement', 0, 'minute')).toEqual([]); + expect(validateRefreshInterval('autoInterval', 1, 'hour')).toEqual([]); + expect(validateRefreshInterval('autoInterval', 2, 'day')).toEqual([]); + expect(validateRefreshInterval('autoInterval', 3, 'week')).toEqual([]); }); }); diff --git a/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/create_acceleration.tsx b/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/create_acceleration.tsx index 5f0998d8e..582307b33 100644 --- a/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/create_acceleration.tsx +++ b/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/create_acceleration.tsx @@ -18,6 +18,7 @@ import { import React, { useEffect, useState } from 'react'; import { ACCELERATION_DEFUALT_SKIPPING_INDEX_NAME, + ACCELERATION_REFRESH_TIME_INTERVAL, ACCELERATION_TIME_INTERVAL, } from '../../../../../../../../common/constants/data_sources'; import { @@ -75,15 +76,15 @@ export const CreateAcceleration = ({ accelerationIndexName: ACCELERATION_DEFUALT_SKIPPING_INDEX_NAME, primaryShardsCount: 1, replicaShardsCount: 1, - refreshType: 'auto', + refreshType: 'autoInterval', checkpointLocation: undefined, watermarkDelay: { delayWindow: 1, delayInterval: ACCELERATION_TIME_INTERVAL[2].value, // minutes }, refreshIntervalOptions: { - refreshWindow: 1, - refreshInterval: ACCELERATION_TIME_INTERVAL[2].value, // minutes + refreshWindow: 15, + refreshInterval: ACCELERATION_REFRESH_TIME_INTERVAL[0].value, // minutes }, formErrors: { dataSourceError: [], diff --git a/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/utils.tsx b/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/utils.tsx index 297397315..725a4ffe6 100644 --- a/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/utils.tsx +++ b/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/create/utils.tsx @@ -47,11 +47,16 @@ export const validateReplicaCount = (replicaCount: number) => { export const validateRefreshInterval = ( refreshType: AccelerationRefreshType, - refreshWindow: number + refreshWindow: number, + refreshInterval: string ) => { - return refreshType === 'autoInterval' && refreshWindow < 1 - ? ['refresh window should be greater than 0'] - : []; + if (refreshType === 'autoInterval' && refreshInterval === 'minute' && refreshWindow < 15) + return ['refresh window should be greater than 15 minutes']; + + if (refreshType === 'autoInterval' && refreshWindow < 1) + return ['refresh window should be greater than 0']; + + return []; }; export const validateWatermarkDelay = ( @@ -147,7 +152,8 @@ export const formValidator = (accelerationformData: CreateAccelerationForm) => { replicaShardsError: validateReplicaCount(replicaShardsCount), refreshIntervalError: validateRefreshInterval( refreshType, - refreshIntervalOptions.refreshWindow + refreshIntervalOptions.refreshWindow, + refreshIntervalOptions.refreshInterval ), checkpointLocationError: validateCheckpointLocation(refreshType, checkpointLocation), watermarkDelayError: validateWatermarkDelay(accelerationIndexType, watermarkDelay.delayWindow), diff --git a/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/selectors/__tests__/__snapshots__/index_setting_options.test.tsx.snap b/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/selectors/__tests__/__snapshots__/index_setting_options.test.tsx.snap index d4b97ea70..c3755c2ea 100644 --- a/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/selectors/__tests__/__snapshots__/index_setting_options.test.tsx.snap +++ b/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/selectors/__tests__/__snapshots__/index_setting_options.test.tsx.snap @@ -46,7 +46,7 @@ Array [ ,
- Select an option: Auto, is selected + Select an option: Auto (Interval), is selected
, +
+
+ +
+
+
+
+ +
+
+
+ +
+ + + + + +
+
+
+
+
+ Specify how frequent the index gets updated when performing the refresh job. +
+
+
,
,
- Select an option: Auto, is selected + Select an option: Auto (Interval), is selected
, +
+
+ +
+
+
+
+ +
+
+
+ +
+ + + + + +
+
+
+
+
+ Specify how frequent the index gets updated when performing the refresh job. +
+
+
,
,
- Select an option: Auto, is selected + Select an option: Auto (Interval), is selected
, +
+
+ +
+
+
+
+ +
+
+
+ +
+ + + + + +
+
+
+
+
+ Specify how frequent the index gets updated when performing the refresh job. +
+
+
,
{ ...createAccelerationEmptyDataMock, primaryShardsCount: 1, replicaShardsCount: 5, - refreshType: 'auto', + refreshType: 'manual', }; const setAccelerationFormData = jest.fn(); const wrapper = mount( diff --git a/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/selectors/index_setting_options.tsx b/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/selectors/index_setting_options.tsx index 7da778d9f..22a030894 100644 --- a/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/selectors/index_setting_options.tsx +++ b/public/components/datasources/components/manage/accelerations/create_accelerations_flyout/selectors/index_setting_options.tsx @@ -17,6 +17,7 @@ import producer from 'immer'; import React, { ChangeEvent, Fragment, useState } from 'react'; import { ACC_CHECKPOINT_DOCUMENTATION_URL, + ACCELERATION_REFRESH_TIME_INTERVAL, ACCELERATION_TIME_INTERVAL, } from '../../../../../../../../common/constants/data_sources'; import { @@ -41,20 +42,6 @@ export const IndexSettingOptions = ({ setAccelerationFormData, }: IndexSettingOptionsProps) => { const refreshOptions = [ - { - value: 'auto', - inputDisplay: 'Auto', - dropdownDisplay: ( - - Auto - -

- Automatically refreshes the index when new data is available. -

-
-
- ), - }, { value: 'autoInterval', inputDisplay: 'Auto (Interval)', @@ -97,9 +84,13 @@ export const IndexSettingOptions = ({ }, ]; - const [refreshTypeSelected, setRefreshTypeSelected] = useState('auto'); - const [refreshWindow, setRefreshWindow] = useState(1); - const [refreshInterval, setRefreshInterval] = useState(ACCELERATION_TIME_INTERVAL[2].value); + const [refreshTypeSelected, setRefreshTypeSelected] = useState( + 'autoInterval' + ); + const [refreshWindow, setRefreshWindow] = useState(15); + const [refreshInterval, setRefreshInterval] = useState( + ACCELERATION_REFRESH_TIME_INTERVAL[0].value + ); const [delayWindow, setDelayWindow] = useState(1); const [delayInterval, setDelayInterval] = useState(ACCELERATION_TIME_INTERVAL[2].value); const [checkpoint, setCheckpoint] = useState(''); @@ -204,7 +195,8 @@ export const IndexSettingOptions = ({ producer((accData) => { accData.formErrors.refreshIntervalError = validateRefreshInterval( refreshTypeSelected, - parseInt(e.target.value, 10) + parseInt(e.target.value, 10), + refreshInterval ); }) ); @@ -213,7 +205,18 @@ export const IndexSettingOptions = ({ { + setAccelerationFormData( + producer((accData) => { + accData.formErrors.refreshIntervalError = validateRefreshInterval( + refreshTypeSelected, + refreshWindow, + e.target.value + ); + }) + ); + }} /> } /> diff --git a/test/accelerations.ts b/test/accelerations.ts index 519a2b02a..3eb143968 100644 --- a/test/accelerations.ts +++ b/test/accelerations.ts @@ -5,6 +5,7 @@ import { ACCELERATION_DEFUALT_SKIPPING_INDEX_NAME, + ACCELERATION_REFRESH_TIME_INTERVAL, ACCELERATION_TIME_INTERVAL, } from '../common/constants/data_sources'; import { @@ -102,11 +103,11 @@ export const createAccelerationEmptyDataMock: CreateAccelerationForm = { accelerationIndexName: ACCELERATION_DEFUALT_SKIPPING_INDEX_NAME, primaryShardsCount: 5, replicaShardsCount: 1, - refreshType: 'auto', + refreshType: 'autoInterval', checkpointLocation: undefined, refreshIntervalOptions: { - refreshWindow: 1, - refreshInterval: ACCELERATION_TIME_INTERVAL[1].value, + refreshWindow: 15, + refreshInterval: ACCELERATION_REFRESH_TIME_INTERVAL[0].value, }, watermarkDelay: { delayWindow: 1, @@ -132,12 +133,17 @@ export const indexOptionsMock1: CreateAccelerationForm = { ...createAccelerationEmptyDataMock, primaryShardsCount: 3, replicaShardsCount: 2, - refreshType: 'auto', + refreshType: 'autoInterval', + refreshIntervalOptions: { + refreshWindow: 15, + refreshInterval: ACCELERATION_REFRESH_TIME_INTERVAL[0].value, + }, }; export const indexOptionsMockResult1 = `WITH ( index_settings = '{"number_of_shards":3,"number_of_replicas":2}', -auto_refresh = true +auto_refresh = true, +refresh_interval = '15 minutes' )`; export const indexOptionsMock2: CreateAccelerationForm = { @@ -147,27 +153,32 @@ export const indexOptionsMock2: CreateAccelerationForm = { refreshType: 'autoInterval', refreshIntervalOptions: { refreshWindow: 10, - refreshInterval: 'minute', + refreshInterval: ACCELERATION_REFRESH_TIME_INTERVAL[1].value, }, }; export const indexOptionsMockResult2 = `WITH ( index_settings = '{"number_of_shards":3,"number_of_replicas":2}', auto_refresh = true, -refresh_interval = '10 minutes' +refresh_interval = '10 hours' )`; export const indexOptionsMock3: CreateAccelerationForm = { ...createAccelerationEmptyDataMock, primaryShardsCount: 3, replicaShardsCount: 2, - refreshType: 'auto', + refreshType: 'autoInterval', + refreshIntervalOptions: { + refreshWindow: 10, + refreshInterval: ACCELERATION_REFRESH_TIME_INTERVAL[1].value, + }, checkpointLocation: 's3://path/to/checkpoint', }; export const indexOptionsMockResult3 = `WITH ( index_settings = '{"number_of_shards":3,"number_of_replicas":2}', auto_refresh = true, +refresh_interval = '10 hours', checkpoint_location = 's3://path/to/checkpoint' )`; @@ -294,7 +305,7 @@ export const skippingIndexBuilderMock2: CreateAccelerationForm = { ], primaryShardsCount: 5, replicaShardsCount: 3, - refreshType: 'auto', + refreshType: 'manual', checkpointLocation: 's3://test/', }; @@ -303,8 +314,8 @@ ON datasource.database.table ( \`field1\` PARTITION ) WITH ( index_settings = '{"number_of_shards":5,"number_of_replicas":3}', -auto_refresh = true, -checkpoint_location = 's3://test/' +auto_refresh = false, +incremental_refresh = false )`; export const coveringIndexBuilderMock1: CreateAccelerationForm = { @@ -345,7 +356,7 @@ export const coveringIndexBuilderMock2: CreateAccelerationForm = { coveringIndexQueryData: ['field1'], primaryShardsCount: 5, replicaShardsCount: 3, - refreshType: 'auto', + refreshType: 'manualIncrement', checkpointLocation: 's3://test/', }; @@ -354,7 +365,8 @@ ON datasource.database.table ( \`field1\` ) WITH ( index_settings = '{"number_of_shards":5,"number_of_replicas":3}', -auto_refresh = true, +auto_refresh = false, +incremental_refresh = true, checkpoint_location = 's3://test/' )`; @@ -427,7 +439,7 @@ export const materializedViewBuilderMock2: CreateAccelerationForm = { }, primaryShardsCount: 5, replicaShardsCount: 3, - refreshType: 'auto', + refreshType: 'manualIncrement', checkpointLocation: 's3://test/', watermarkDelay: { delayWindow: 2, @@ -442,7 +454,8 @@ FROM datasource.database.table GROUP BY TUMBLE (\`timestamp\`, '2 hours') WITH ( index_settings = '{"number_of_shards":5,"number_of_replicas":3}', -auto_refresh = true, +auto_refresh = false, +incremental_refresh = true, watermark_delay = '2 minutes', checkpoint_location = 's3://test/' )`;