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 { capitalize } from 'lodash';
import { FC, ReactElement } from 'react';
import FlexBox from './FlexBox';
import { BodyText, MonoText, SensitiveText } from './Text';
const capEntryLabel: CapFormEntryLabel = (value) => {
const spaced = value.replace(/([a-z\d])([A-Z])/g, '$1 $2');
const lcased = spaced.toLowerCase();
return capitalize(lcased);
};
import disassembleCamel from '../lib/disassembleCamel';
const renderEntryValueWithMono: RenderFormValueFunction = ({ entry }) => (
<MonoText whiteSpace="nowrap">{String(entry)}</MonoText>
@ -128,7 +121,9 @@ const FormSummary = <T extends FormEntries>({
maxDepth = 3,
renderEntry = ({ depth, entry, getLabel, key, nest, renderValue }) => (
<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' }}>
{!nest && renderValue({ depth, entry, key })}
</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 = (
errors: object,
@ -7,7 +7,11 @@ const getFormikErrorMessages = (
let children = error;
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' };

Loading…
Cancel
Save