Skip to content

Commit

Permalink
feat: convert table snake case to pascal case
Browse files Browse the repository at this point in the history
  • Loading branch information
danielstefanequilobe committed Dec 5, 2022
1 parent 146d64c commit 320dbfc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/components/blocks/DataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import styled, { withTheme, css } from 'styled-components';

import { TableCellHeaderText, TableCellText } from '../typography';
import {
convertPascalCaseToSentenceCase,
convertSnakeCaseToPascalCase,
isStringOfImageType,
isStringOfNoValueType,
} from '../../utils/stringUtils';
Expand Down Expand Up @@ -148,10 +148,7 @@ const DataTable = withTheme(
{headings.map((heading, index) => (
<Th selectedTheme={theme} key={index}>
<TableCellHeaderText>
{heading &&
convertPascalCaseToSentenceCase(
heading.replace(/_/g, ' '),
)}
{heading && convertSnakeCaseToPascalCase(heading)}
</TableCellHeaderText>
</Th>
))}
Expand Down
9 changes: 9 additions & 0 deletions src/utils/stringUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ export const formatValidationError = error => {
return errorStringArray.join(' ');
};

export const convertSnakeCaseToPascalCase = string => {
const wordsOfString = string.split('_');
const newString = wordsOfString.reduce(
(acc, cur) => acc + ' ' + cur[0].toUpperCase() + cur.substring(1),
'',
);
return newString;
};

export const isStringOfImageType = value =>
typeof value === 'string' && value.startsWith('data:image/png;base64');

Expand Down

0 comments on commit 320dbfc

Please sign in to comment.