Skip to content

Commit

Permalink
[#2101] fix(web): fix comment rendering as date error (#2114)
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

Fix comment rendering error as date.

### Why are the changes needed?

dayjs non-strict check error

```js
dayjs('my test catalog 2').isValid()
// returned `true`
```

Fix: #2101

### Does this PR introduce _any_ user-facing change?

N/A

### How was this patch tested?

N/A
  • Loading branch information
ch3yne authored Feb 6, 2024
1 parent a4a79aa commit 02d4ad3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions web/app/ui/metalakes/DetailsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ const DetailsView = props => {
}
})

const renderFieldText = (value, linkBreak = false) => {
const renderFieldText = ({ value, linkBreak = false, isDate = false }) => {
if (!value) {
return <EmptyText />
}

return (
<Typography sx={{ fontWeight: 500, wordBreak: 'break-all', whiteSpace: linkBreak ? 'pre-wrap' : 'normal' }}>
{isValidDate(value) ? formatToDateTime(value) : value}
{isDate && isValidDate(value) ? formatToDateTime(value) : value}
</Typography>
)
}
Expand All @@ -44,49 +44,49 @@ const DetailsView = props => {
<Typography variant='body2' sx={{ mb: 2 }}>
Type
</Typography>
{renderFieldText(activatedItem?.type)}
{renderFieldText({ value: activatedItem?.type })}
</Grid>
<Grid item xs={12} md={6} sx={{ mb: [0, 5] }}>
<Typography variant='body2' sx={{ mb: 2 }}>
Provider
</Typography>
{renderFieldText(activatedItem?.provider)}
{renderFieldText({ value: activatedItem?.provider })}
</Grid>
</>
) : null}
<Grid item xs={12} sx={{ mb: [0, 5] }}>
<Typography variant='body2' sx={{ mb: 2 }}>
Comment
</Typography>
{renderFieldText(activatedItem?.comment, true)}
{renderFieldText({ value: activatedItem?.comment, linkBreak: true })}
</Grid>

<Grid item xs={12} md={6} sx={{ mb: [0, 5] }}>
<Typography variant='body2' sx={{ mb: 2 }}>
Created by
</Typography>
{renderFieldText(audit.creator)}
{renderFieldText({ value: audit.creator })}
</Grid>

<Grid item xs={12} md={6} sx={{ mb: [0, 5] }}>
<Typography variant='body2' sx={{ mb: 2 }}>
Created at
</Typography>
{renderFieldText(audit.createTime)}
{renderFieldText({ value: audit.createTime, isDate: true })}
</Grid>

<Grid item xs={12} md={6} sx={{ mb: [0, 5] }}>
<Typography variant='body2' sx={{ mb: 2 }}>
Last modified by
</Typography>
{renderFieldText(audit.lastModifier)}
{renderFieldText({ value: audit.lastModifier })}
</Grid>

<Grid item xs={12} md={6} sx={{ mb: [0, 5] }}>
<Typography variant='body2' sx={{ mb: 2 }}>
Last modified at
</Typography>
{renderFieldText(audit.lastModifiedTime)}
{renderFieldText({ value: audit.lastModifiedTime, isDate: true })}
</Grid>

<Grid item xs={12} sx={{ mb: [0, 5] }}>
Expand Down
18 changes: 9 additions & 9 deletions web/components/DetailsDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ const DetailsDrawer = props => {
setOpenDrawer(false)
}

const renderFieldText = (value, linkBreak = false) => {
const renderFieldText = ({ value, linkBreak = false, isDate = false }) => {
if (!value) {
return <EmptyText />
}

return (
<Typography sx={{ fontWeight: 500, wordBreak: 'break-all', whiteSpace: linkBreak ? 'pre-wrap' : 'normal' }}>
{isValidDate(value) ? formatToDateTime(value) : value}
{isDate && isValidDate(value) ? formatToDateTime(value) : value}
</Typography>
)
}
Expand Down Expand Up @@ -118,13 +118,13 @@ const DetailsDrawer = props => {
<Typography variant='body2' sx={{ mb: 2 }}>
Type
</Typography>
{renderFieldText(drawerData.type)}
{renderFieldText({ value: drawerData.type })}
</Grid>
<Grid item xs={12} md={6} sx={{ mb: [0, 5] }}>
<Typography variant='body2' sx={{ mb: 2 }}>
Provider
</Typography>
{renderFieldText(drawerData.provider)}
{renderFieldText({ value: drawerData.provider })}
</Grid>
</>
) : null}
Expand All @@ -133,35 +133,35 @@ const DetailsDrawer = props => {
<Typography variant='body2' sx={{ mb: 2 }}>
Comment
</Typography>
{renderFieldText(drawerData.comment, true)}
{renderFieldText({ value: drawerData.comment, linkBreak: true })}
</Grid>

<Grid item xs={12} sx={{ mb: [0, 5] }}>
<Typography variant='body2' sx={{ mb: 2 }}>
Created by
</Typography>
{renderFieldText(audit.creator)}
{renderFieldText({ value: audit.creator })}
</Grid>

<Grid item xs={12} sx={{ mb: [0, 5] }}>
<Typography variant='body2' sx={{ mb: 2 }}>
Created at
</Typography>
{renderFieldText(audit.createTime)}
{renderFieldText({ value: audit.createTime, isDate: true })}
</Grid>

<Grid item xs={12} sx={{ mb: [0, 5] }}>
<Typography variant='body2' sx={{ mb: 2 }}>
Last modified by
</Typography>
{renderFieldText(audit.lastModifier)}
{renderFieldText({ value: audit.lastModifier })}
</Grid>

<Grid item xs={12} sx={{ mb: [0, 5] }}>
<Typography variant='body2' sx={{ mb: 2 }}>
Last modified at
</Typography>
{renderFieldText(audit.lastModifiedTime)}
{renderFieldText({ value: audit.lastModifiedTime, isDate: true })}
</Grid>

<Grid item xs={12} sx={{ mb: [0, 5] }}>
Expand Down

0 comments on commit 02d4ad3

Please sign in to comment.