fix(striker-ui): add IPv4 CSV input test to network config in manage manifest

main
Tsu-ba-me 2 years ago
parent fea0657119
commit 16ac5a4e6d
  1. 33
      striker-ui/components/ManageManifest/AnNetworkConfigInputGroup.tsx
  2. 25
      striker-ui/lib/test_input/buildIpCsvTestBatch.tsx
  3. 2
      striker-ui/lib/test_input/index.ts

@ -9,7 +9,10 @@ import Grid from '../Grid';
import IconButton from '../IconButton'; import IconButton from '../IconButton';
import InputWithRef from '../InputWithRef'; import InputWithRef from '../InputWithRef';
import OutlinedInputWithLabel from '../OutlinedInputWithLabel'; import OutlinedInputWithLabel from '../OutlinedInputWithLabel';
import { buildNumberTestBatch } from '../../lib/test_input'; import {
buildIpCsvTestBatch,
buildNumberTestBatch,
} from '../../lib/test_input';
const INPUT_ID_PREFIX_AN_NETWORK_CONFIG = 'an-network-config-input'; const INPUT_ID_PREFIX_AN_NETWORK_CONFIG = 'an-network-config-input';
@ -300,6 +303,20 @@ const AnNetworkConfigInputGroup = <
value={previousDnsCsv} value={previousDnsCsv}
/> />
} }
inputTestBatch={buildIpCsvTestBatch(
INPUT_LABEL_ANC_DNS,
() => {
setMessage(INPUT_ID_ANC_DNS);
},
{
onFinishBatch:
buildFinishInputTestBatchFunction(INPUT_ID_ANC_DNS),
},
(message) => {
setMessage(INPUT_ID_ANC_DNS, { children: message });
},
)}
onFirstRender={buildInputFirstRenderFunction(INPUT_ID_ANC_DNS)}
required required
/> />
), ),
@ -314,6 +331,20 @@ const AnNetworkConfigInputGroup = <
value={previousNtpCsv} value={previousNtpCsv}
/> />
} }
inputTestBatch={buildIpCsvTestBatch(
INPUT_LABEL_ANC_NTP,
() => {
setMessage(INPUT_ID_ANC_NTP);
},
{
onFinishBatch:
buildFinishInputTestBatchFunction(INPUT_ID_ANC_NTP),
},
(message) => {
setMessage(INPUT_ID_ANC_NTP, { children: message });
},
)}
onFirstRender={buildInputFirstRenderFunction(INPUT_ID_ANC_NTP)}
/> />
), ),
}, },

@ -0,0 +1,25 @@
import { REP_IPV4_CSV } from '../consts/REG_EXP_PATTERNS';
const buildIpCsvTestBatch: BuildInputTestBatchFunction = (
inputName,
onSuccess,
{ isRequired, onFinishBatch, ...defaults } = {},
onIpCsvTestFailure,
) => ({
defaults: { ...defaults, onSuccess },
isRequired,
onFinishBatch,
tests: [
{
onFailure: (...args) => {
onIpCsvTestFailure(
`${inputName} must be one or more valid IPv4 addresses separated by comma; without trailing comma.`,
...args,
);
},
test: ({ value }) => REP_IPV4_CSV.test(value as string),
},
],
});
export default buildIpCsvTestBatch;

@ -1,5 +1,6 @@
import buildDomainTestBatch from './buildDomainTestBatch'; import buildDomainTestBatch from './buildDomainTestBatch';
import buildIPAddressTestBatch from './buildIPAddressTestBatch'; import buildIPAddressTestBatch from './buildIPAddressTestBatch';
import buildIpCsvTestBatch from './buildIpCsvTestBatch';
import buildNumberTestBatch from './buildNumberTestBatch'; import buildNumberTestBatch from './buildNumberTestBatch';
import buildPeacefulStringTestBatch from './buildPeacefulStringTestBatch'; import buildPeacefulStringTestBatch from './buildPeacefulStringTestBatch';
import buildUUIDTestBatch from './buildUUIDTestBatch'; import buildUUIDTestBatch from './buildUUIDTestBatch';
@ -13,6 +14,7 @@ import testRange from './testRange';
export { export {
buildDomainTestBatch, buildDomainTestBatch,
buildIPAddressTestBatch, buildIPAddressTestBatch,
buildIpCsvTestBatch,
buildNumberTestBatch, buildNumberTestBatch,
buildPeacefulStringTestBatch, buildPeacefulStringTestBatch,
buildUUIDTestBatch, buildUUIDTestBatch,

Loading…
Cancel
Save