fix(striker-ui): isolate disassemble camel string

main
Tsu-ba-me 11 months ago
parent 47a84a86e8
commit 96be4a41b2
  1. 13
      striker-ui/components/FormSummary.tsx
  2. 9
      striker-ui/lib/disassembleCamel.ts
  3. 8
      striker-ui/lib/getFormikErrorMessages.ts

@ -1,16 +1,9 @@
import { Box, List as MUIList, ListItem as MUIListItem } from '@mui/material'; import { Box, List as MUIList, ListItem as MUIListItem } from '@mui/material';
import { capitalize } from 'lodash';
import { FC, ReactElement } from 'react'; import { FC, ReactElement } from 'react';
import FlexBox from './FlexBox'; import FlexBox from './FlexBox';
import { BodyText, MonoText, SensitiveText } from './Text'; import { BodyText, MonoText, SensitiveText } from './Text';
import disassembleCamel from '../lib/disassembleCamel';
const capEntryLabel: CapFormEntryLabel = (value) => {
const spaced = value.replace(/([a-z\d])([A-Z])/g, '$1 $2');
const lcased = spaced.toLowerCase();
return capitalize(lcased);
};
const renderEntryValueWithMono: RenderFormValueFunction = ({ entry }) => ( const renderEntryValueWithMono: RenderFormValueFunction = ({ entry }) => (
<MonoText whiteSpace="nowrap">{String(entry)}</MonoText> <MonoText whiteSpace="nowrap">{String(entry)}</MonoText>
@ -128,7 +121,9 @@ const FormSummary = <T extends FormEntries>({
maxDepth = 3, maxDepth = 3,
renderEntry = ({ depth, entry, getLabel, key, nest, renderValue }) => ( renderEntry = ({ depth, entry, getLabel, key, nest, renderValue }) => (
<FlexBox fullWidth growFirst row maxWidth="100%"> <FlexBox fullWidth growFirst row maxWidth="100%">
<BodyText>{getLabel({ cap: capEntryLabel, depth, entry, key })}</BodyText> <BodyText>
{getLabel({ cap: disassembleCamel, depth, entry, key })}
</BodyText>
<Box sx={{ maxWidth: '100%', overflowX: 'scroll' }}> <Box sx={{ maxWidth: '100%', overflowX: 'scroll' }}>
{!nest && renderValue({ depth, entry, key })} {!nest && renderValue({ depth, entry, key })}
</Box> </Box>

@ -0,0 +1,9 @@
import { capitalize } from 'lodash';
const disassembleCamel = (value: string) => {
const spaced = value.replace(/([a-z\d])([A-Z])/g, '$1 $2');
return capitalize(spaced);
};
export default disassembleCamel;

@ -1,4 +1,4 @@
import { capitalize } from 'lodash'; import disassembleCamel from './disassembleCamel';
const getFormikErrorMessages = ( const getFormikErrorMessages = (
errors: object, errors: object,
@ -7,7 +7,11 @@ const getFormikErrorMessages = (
let children = error; let children = error;
if (typeof children === 'string') { if (typeof children === 'string') {
children = capitalize(children.replace(/^[^\s]+\.([^.]+)/, '$1')); const [first, ...rest] = children.split(/\s+/);
const name = disassembleCamel(first.replace(/^[^\s]+\.([^.]+)/, '$1'));
children = [name, ...rest].join(' ');
} }
return { children, type: 'warning' }; return { children, type: 'warning' };

Loading…
Cancel
Save