-
Notifications
You must be signed in to change notification settings - Fork 991
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move formatting functions to a separate file
- Loading branch information
Showing
5 changed files
with
89 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/cli/src/commands/generate/scaffold/templates/lib/formattingFunctions.tsx.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from 'react' | ||
|
||
import humanize from 'humanize-string' | ||
|
||
const MAX_STRING_LENGTH = 150 | ||
|
||
export const formatEnum = (values: string | string[] | null | undefined) => { | ||
if (values) { | ||
if (Array.isArray(values)) { | ||
const humanizedValues = values.map((value) => humanize(value)) | ||
return humanizedValues.join(', ') | ||
} else { | ||
return humanize(values as string) | ||
} | ||
} | ||
|
||
return '' | ||
} | ||
|
||
export const truncate = (value: string | number) => { | ||
const output = value?.toString() | ||
if (output?.length > MAX_STRING_LENGTH) { | ||
return output.substring(0, MAX_STRING_LENGTH) + '...' | ||
} | ||
return output ?? '' | ||
} | ||
|
||
export const jsonTruncate = (obj: unknown) => { | ||
return truncate(JSON.stringify(obj, null, 2)) | ||
} | ||
|
||
export const timeTag = (datetime?: string) => { | ||
return datetime ? ( | ||
<time dateTime={datetime} title={datetime}> | ||
{new Date(datetime).toUTCString()} | ||
</time> | ||
) : ( | ||
'' | ||
) | ||
} | ||
|
||
export const checkboxInputTag = (checked: boolean) => { | ||
return <input type="checkbox" checked={checked} disabled /> | ||
} |