From 22a7a0b436b8fcf023add385af03f2c3350b73b1 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Thu, 18 Aug 2022 22:51:56 -0400 Subject: [PATCH] fix(striker-ui): allow skip domain pattern validation --- striker-ui/components/GeneralInitForm.tsx | 80 +++++++++++++++++++---- 1 file changed, 67 insertions(+), 13 deletions(-) diff --git a/striker-ui/components/GeneralInitForm.tsx b/striker-ui/components/GeneralInitForm.tsx index 2e68954b..0068a3dc 100644 --- a/striker-ui/components/GeneralInitForm.tsx +++ b/striker-ui/components/GeneralInitForm.tsx @@ -1,4 +1,4 @@ -import { Grid as MUIGrid } from '@mui/material'; +import { Checkbox as MUICheckbox, Grid as MUIGrid } from '@mui/material'; import { forwardRef, ReactNode, @@ -106,6 +106,7 @@ const GeneralInitForm = forwardRef< useState(false); const [isConfirmAdminPassword, setIsConfirmAdminPassword] = useState(true); + const [isValidateDomain, setIsValidateDomain] = useState(true); const adminPasswordInputRef = useRef>({}); const confirmAdminPasswordInputRef = useRef< @@ -228,6 +229,7 @@ const GeneralInitForm = forwardRef< }, [IT_IDS.domainName]: { defaults: { + compare: [!isValidateDomain], getValue: () => domainNameInputRef.current.getValue?.call(null), onSuccess: () => { setDomainNameInputMessage(undefined); @@ -246,13 +248,15 @@ const GeneralInitForm = forwardRef< ), }); }, - test: ({ value }) => REP_DOMAIN.test(value as string), + test: ({ compare, value }) => + (compare[0] as boolean) || REP_DOMAIN.test(value as string), }, { test: testNotBlank }, ], }, [IT_IDS.hostName]: { defaults: { + compare: [!isValidateDomain], getValue: () => hostNameInputRef.current.getValue?.call(null), onSuccess: () => { setHostNameInputMessage(undefined); @@ -271,7 +275,8 @@ const GeneralInitForm = forwardRef< ), }); }, - test: ({ value }) => REP_DOMAIN.test(value as string), + test: ({ compare, value }) => + (compare[0] as boolean) || REP_DOMAIN.test(value as string), }, { test: testNotBlank }, ], @@ -287,7 +292,7 @@ const GeneralInitForm = forwardRef< { onFailure: () => { setHostNumberInputMessage({ - children: 'Host number can only contain digits.', + children: 'Striker number can only contain digits.', }); }, test: ({ value }) => /^\d+$/.test(value as string), @@ -325,6 +330,7 @@ const GeneralInitForm = forwardRef< }, }), [ + isValidateDomain, setAdminPasswordInputMessage, setConfirmAdminPasswordInputMessage, setDomainNameInputMessage, @@ -342,8 +348,12 @@ const GeneralInitForm = forwardRef< ({ excludeTestIds = [], inputs, + isContinueOnFailure, isExcludeConfirmAdminPassword = !isConfirmAdminPassword, - }: Pick & { + }: Pick< + TestInputFunctionOptions, + 'inputs' | 'excludeTestIds' | 'isContinueOnFailure' + > & { isExcludeConfirmAdminPassword?: boolean; } = {}) => { if (isExcludeConfirmAdminPassword) { @@ -355,6 +365,7 @@ const GeneralInitForm = forwardRef< testInput({ excludeTestIds, inputs, + isContinueOnFailure, isIgnoreOnCallbacks: true, isTestAll: true, }), @@ -373,16 +384,19 @@ const GeneralInitForm = forwardRef< organizationPrefix, ); - testInput({ - inputs: { [IT_IDS.organizationPrefix]: { value: organizationPrefix } }, - }); testInputToToggleSubmitDisabled({ - excludeTestIds: [IT_IDS.organizationPrefix], + inputs: { + [IT_IDS.organizationPrefix]: { + isIgnoreOnCallbacks: false, + value: organizationPrefix, + }, + }, + isContinueOnFailure: true, }); return organizationPrefix; }, - [testInput, testInputToToggleSubmitDisabled], + [testInputToToggleSubmitDisabled], ); const populateHostNameInput = useCallback( ({ @@ -400,12 +414,16 @@ const GeneralInitForm = forwardRef< hostNameInputRef.current.setValue?.call(null, hostName); - testInput({ inputs: { [IT_IDS.hostName]: { value: hostName } } }); - testInputToToggleSubmitDisabled({ excludeTestIds: [IT_IDS.hostName] }); + testInputToToggleSubmitDisabled({ + inputs: { + [IT_IDS.hostName]: { isIgnoreOnCallbacks: false, value: hostName }, + }, + isContinueOnFailure: true, + }); return hostName; }, - [testInput, testInputToToggleSubmitDisabled], + [testInputToToggleSubmitDisabled], ); const isOrganizationPrefixPrereqFilled = useCallback( () => @@ -460,6 +478,32 @@ const GeneralInitForm = forwardRef< [], ); + const validateDomainCheckbox = useMemo( + () => ( + { + setIsValidateDomain(checked); + testInputToToggleSubmitDisabled({ + inputs: { + [IT_IDS.domainName]: { + compare: [!checked], + isIgnoreOnCallbacks: false, + }, + [IT_IDS.hostName]: { + compare: [!checked], + isIgnoreOnCallbacks: false, + }, + }, + isContinueOnFailure: true, + }); + }} + sx={{ padding: '.2em' }} + /> + ), + [isValidateDomain, testInputToToggleSubmitDisabled], + ); + useImperativeHandle(ref, () => ({ get: () => ({ adminPassword: adminPasswordInputRef.current.getValue?.call(null), @@ -775,6 +819,16 @@ const GeneralInitForm = forwardRef< defaultMessageType="warning" ref={messageGroupRef} /> + + :last-child': { flexGrow: 1 } }}> + {validateDomainCheckbox} + + {isValidateDomain + ? 'Uncheck to skip domain and host name pattern validation.' + : 'Check to re-enable domain and host name pattern validation.'} + + + {helpMessage && ( {