forked from opensearch-project/dashboards-query-workbench
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Shenoy Pratik <[email protected]>
- Loading branch information
Showing
15 changed files
with
696 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export const isTimePlural = (timeWindow: number) => { | ||
return timeWindow > 1 ? 's' : ''; | ||
}; | ||
|
||
export const validateIndexName = (value: string) => { | ||
const lowercaseUnderscoreHyphenRegex = /^[a-z_\-]+$/; | ||
|
||
if (!lowercaseUnderscoreHyphenRegex.test(value)) { | ||
return false; | ||
} | ||
|
||
// Check if the value does not begin with underscores or hyphens | ||
if (value.startsWith('_') || value.startsWith('-')) { | ||
return false; | ||
} | ||
|
||
// Check if the value does not contain disallowed characters | ||
const disallowedCharacters = /[\s,:"*+\/|?#><]/; | ||
if (disallowedCharacters.test(value)) { | ||
return false; | ||
} | ||
|
||
// If all checks pass, the value is valid | ||
return true; | ||
}; |
66 changes: 66 additions & 0 deletions
66
public/components/acceleration/selectors/define_index_options.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { ChangeEvent, useEffect, useState } from 'react'; | ||
import { CreateAccelerationForm } from '../../../../common/types'; | ||
import { EuiFieldText, EuiFormRow, EuiSpacer, EuiText, EuiToolTip } from '@elastic/eui'; | ||
import { validateIndexName } from '../create/utils'; | ||
|
||
interface DefineIndexOptionsProps { | ||
accelerationFormData: CreateAccelerationForm; | ||
setAccelerationFormData: React.Dispatch<React.SetStateAction<CreateAccelerationForm>>; | ||
} | ||
|
||
export const DefineIndexOptions = ({ | ||
accelerationFormData, | ||
setAccelerationFormData, | ||
}: DefineIndexOptionsProps) => { | ||
const [indexName, setIndexName] = useState(''); | ||
|
||
const onChangeIndexName = (e: ChangeEvent<HTMLInputElement>) => { | ||
setAccelerationFormData({ ...accelerationFormData, accelerationIndexName: e.target.value }); | ||
setIndexName(e.target.value); | ||
}; | ||
|
||
useEffect(() => { | ||
accelerationFormData.accelerationIndexType === 'skipping' | ||
? setIndexName('skipping') | ||
: setIndexName(''); | ||
}, [accelerationFormData.accelerationIndexType]); | ||
|
||
return ( | ||
<> | ||
<EuiText data-test-subj="define-index-header"> | ||
<h3>Index settings</h3> | ||
</EuiText> | ||
<EuiSpacer size="s" /> | ||
<EuiFormRow | ||
label="Index name" | ||
helpText='Must be in lowercase letters. Cannot begin with underscores or hyphens. Spaces, commas, and characters :, ", *, +, /, \, |, ?, #, >, or < are not allowed. | ||
Prefix and suffix are added to the name of generated OpenSearch index.' | ||
> | ||
<EuiToolTip | ||
position="right" | ||
content={ | ||
accelerationFormData.accelerationIndexType === 'skipping' | ||
? 'Skipping Index name follows a pre-defined in the format `flint_datasource_datatable_skipping_index` and cannot be changed.' | ||
: 'Generated OpenSearch index names follow the format `flint_datasource_datatable_<covering_index_name>_index` and `flint_datasource_datatable_<materialized_view>`' | ||
} | ||
> | ||
<EuiFieldText | ||
placeholder="Enter Index Name" | ||
value={indexName} | ||
onChange={onChangeIndexName} | ||
aria-label="Enter Index Name" | ||
prepend={`flint_${accelerationFormData.dataSource}_${accelerationFormData.database}_`} | ||
append={accelerationFormData.accelerationIndexType === 'materialized' ? '' : '_index'} | ||
disabled={accelerationFormData.accelerationIndexType === 'skipping'} | ||
isInvalid={validateIndexName(indexName)} | ||
/> | ||
</EuiToolTip> | ||
</EuiFormRow> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.