File tree Expand file tree Collapse file tree 10 files changed +242
-217
lines changed Expand file tree Collapse file tree 10 files changed +242
-217
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import { activateBilling } from 'api/configs/activateBilling'
1111
1212import styles from './styles.module.scss'
1313
14- const AUTO_HIDE_DURATION = 1500
14+ const AUTO_HIDE_DURATION = 3000
1515
1616export const StickyTopBar = ( ) => {
1717 const useStyles = makeStyles (
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ import { Spinner } from '@postgres.ai/shared/components/Spinner'
3232import { StubSpinner } from '@postgres.ai/shared/components/StubSpinnerFlex'
3333import { Select } from '@postgres.ai/shared/components/Select'
3434
35- import { generateToken } from 'utils/utils'
35+ import { generateToken , validateDLEName } from 'utils/utils'
3636import urls from 'utils/urls'
3737
3838import { AnsibleInstance } from 'components/DbLabInstanceForm/DbLabFormSteps/AnsibleInstance'
@@ -483,6 +483,12 @@ const DbLabInstanceForm = (props: DbLabInstanceFormWithStylesProps) => {
483483 InputLabelProps = { {
484484 shrink : true ,
485485 } }
486+ helperText = {
487+ validateDLEName ( state . name )
488+ ? 'Name must be lowercase and contain only letters and numbers.'
489+ : ''
490+ }
491+ error = { validateDLEName ( state . name ) }
486492 onChange = { (
487493 event : React . ChangeEvent <
488494 HTMLTextAreaElement | HTMLInputElement
@@ -595,7 +601,10 @@ const DbLabInstanceForm = (props: DbLabInstanceFormWithStylesProps) => {
595601 </ div >
596602 < DbLabInstanceFormSidebar
597603 state = { state }
598- handleCreate = { ( ) => handleSetFormStep ( 'docker' ) }
604+ disabled = { validateDLEName ( state . name ) }
605+ handleCreate = { ( ) =>
606+ ! validateDLEName ( state . name ) && handleSetFormStep ( 'docker' )
607+ }
599608 />
600609 </ >
601610 ) : state . formStep === 'ansible' && permitted ? (
Original file line number Diff line number Diff line change @@ -88,9 +88,11 @@ const useStyles = makeStyles({
8888export const DbLabInstanceFormSidebar = ( {
8989 state,
9090 handleCreate,
91+ disabled,
9192} : {
9293 state : typeof initialState
9394 handleCreate : ( ) => void
95+ disabled : boolean
9496} ) => {
9597 const classes = useStyles ( )
9698
@@ -200,7 +202,7 @@ export const DbLabInstanceFormSidebar = ({
200202 variant = "contained"
201203 color = "primary"
202204 onClick = { handleCreate }
203- disabled = { ! state . name || ! state . verificationToken }
205+ disabled = { ! state . name || ! state . verificationToken || disabled }
204206 >
205207 Create DLE
206208 </ Button >
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ import { DockerInstance } from 'components/DbLabInstanceInstallForm/DbLabFormSte
2121import { availableTags } from 'components/DbLabInstanceForm/utils'
2222import { Select } from '@postgres.ai/shared/components/Select'
2323
24- import { generateToken } from 'utils/utils'
24+ import { generateToken , validateDLEName } from 'utils/utils'
2525import urls from 'utils/urls'
2626
2727interface DbLabInstanceFormWithStylesProps extends DbLabInstanceFormProps {
@@ -93,6 +93,12 @@ const DbLabInstanceInstallForm = (props: DbLabInstanceFormWithStylesProps) => {
9393 InputLabelProps = { {
9494 shrink : true ,
9595 } }
96+ helperText = {
97+ validateDLEName ( state . name )
98+ ? 'Name must be lowercase and contain only letters and numbers.'
99+ : ''
100+ }
101+ error = { validateDLEName ( state . name ) }
96102 onChange = { (
97103 event : React . ChangeEvent <
98104 HTMLTextAreaElement | HTMLInputElement
@@ -192,7 +198,10 @@ const DbLabInstanceInstallForm = (props: DbLabInstanceFormWithStylesProps) => {
192198 </ div >
193199 < DbLabInstanceFormInstallSidebar
194200 state = { state }
195- handleCreate = { ( ) => handleSetFormStep ( 'docker' ) }
201+ disabled = { validateDLEName ( state . name ) }
202+ handleCreate = { ( ) =>
203+ ! validateDLEName ( state . name ) && handleSetFormStep ( 'docker' )
204+ }
196205 />
197206 </ >
198207 ) : state . formStep === 'ansible' && permitted ? (
Original file line number Diff line number Diff line change @@ -72,9 +72,11 @@ const useStyles = makeStyles({
7272export const DbLabInstanceFormInstallSidebar = ( {
7373 state,
7474 handleCreate,
75+ disabled,
7576} : {
7677 state : typeof initialState
7778 handleCreate : ( ) => void
79+ disabled : boolean
7880} ) => {
7981 const classes = useStyles ( )
8082
@@ -97,7 +99,7 @@ export const DbLabInstanceFormInstallSidebar = ({
9799 variant = "contained"
98100 color = "primary"
99101 onClick = { handleCreate }
100- disabled = { ! state . name || ! state . verificationToken }
102+ disabled = { ! state . name || ! state . verificationToken || ! disabled }
101103 >
102104 Install DLE
103105 </ Button >
Original file line number Diff line number Diff line change @@ -24,3 +24,10 @@ export const isHttps = function (url: string | string[]) {
2424
2525export const snakeToCamel = ( str : string ) =>
2626 str . replace ( / ( [ - _ ] \w ) / g, ( g ) => g [ 1 ] . toUpperCase ( ) )
27+
28+ export const validateDLEName = ( name : string ) => {
29+ return (
30+ name . length > 0 &&
31+ ! name . match ( / ^ ( [ a - z ] (?: [ - a - z 0 - 9 ] { 0 , 61 } [ a - z 0 - 9 ] ) ? | [ 1 - 9 ] [ 0 - 9 ] { 0 , 19 } ) $ / )
32+ )
33+ }
You can’t perform that action at this time.
0 commit comments