fix(striker-ui): remove isEmpty()

main
Tsu-ba-me 2 years ago
parent f9c9855462
commit 9ba521839e
  1. 15
      striker-ui/components/GeneralInitForm.tsx
  2. 35
      striker-ui/lib/isEmpty.ts

@ -14,7 +14,6 @@ import { REP_DOMAIN } from '../lib/consts/REG_EXP_PATTERNS';
import FlexBox from './FlexBox'; import FlexBox from './FlexBox';
import InputWithRef, { InputForwardedRefContent } from './InputWithRef'; import InputWithRef, { InputForwardedRefContent } from './InputWithRef';
import isEmpty from '../lib/isEmpty';
import MessageBox, { Message } from './MessageBox'; import MessageBox, { Message } from './MessageBox';
import MessageGroup, { MessageGroupForwardedRefContent } from './MessageGroup'; import MessageGroup, { MessageGroupForwardedRefContent } from './MessageGroup';
import OutlinedInputWithLabel, { import OutlinedInputWithLabel, {
@ -87,7 +86,7 @@ const buildHostName = ({
hostNumber?: number; hostNumber?: number;
domainName?: string; domainName?: string;
}) => }) =>
isEmpty([organizationPrefix, hostNumber, domainName], { not: true }) [organizationPrefix, hostNumber, domainName].every((value) => Boolean(value))
? `${organizationPrefix}-striker${pad(hostNumber)}.${domainName}` ? `${organizationPrefix}-striker${pad(hostNumber)}.${domainName}`
: ''; : '';
@ -422,24 +421,16 @@ const GeneralInitForm = forwardRef<
[testInputToToggleSubmitDisabled], [testInputToToggleSubmitDisabled],
); );
const isOrganizationPrefixPrereqFilled = useCallback( const isOrganizationPrefixPrereqFilled = useCallback(
() => () => Boolean(organizationNameInputRef.current.getValue?.call(null)),
isEmpty([organizationNameInputRef.current.getValue?.call(null)], {
not: true,
}),
[], [],
); );
const isHostNamePrereqFilled = useCallback( const isHostNamePrereqFilled = useCallback(
() => () =>
isEmpty(
[ [
organizationPrefixInputRef.current.getValue?.call(null), organizationPrefixInputRef.current.getValue?.call(null),
hostNumberInputRef.current.getValue?.call(null), hostNumberInputRef.current.getValue?.call(null),
domainNameInputRef.current.getValue?.call(null), domainNameInputRef.current.getValue?.call(null),
], ].every((value) => Boolean(value)),
{
not: true,
},
),
[], [],
); );
const populateOrganizationPrefixInputOnBlur: OutlinedInputWithLabelOnBlur = const populateOrganizationPrefixInputOnBlur: OutlinedInputWithLabelOnBlur =

@ -1,35 +0,0 @@
type IsEmptyTypeMap = Pick<
MapToType,
'number' | 'object' | 'string' | 'undefined'
>;
type MapToValueIsEmptyFunction = {
[TypeName in keyof IsEmptyTypeMap]: (
value: IsEmptyTypeMap[TypeName],
) => boolean;
};
const MAP_TO_VALUE_IS_EMPTY_FUNCTION: MapToValueIsEmptyFunction = {
number: (value = 0) => value === 0,
object: (value) => Object.keys(value).length === 0,
string: (value = '') => value.trim().length === 0,
undefined: () => true,
};
const isEmpty = <TypeName extends keyof IsEmptyTypeMap>(
values: Array<IsEmptyTypeMap[TypeName]>,
{ not, fn = 'every' }: { not?: boolean; fn?: 'every' | 'some' } = {},
): boolean =>
values[fn]((value) => {
const type = typeof value as TypeName;
let result = MAP_TO_VALUE_IS_EMPTY_FUNCTION[type](value);
if (not) {
result = !result;
}
return result;
});
export default isEmpty;
Loading…
Cancel
Save