2024-08-12 05:50:54 -04:00
|
|
|
import { memo } from 'react'
|
|
|
|
import { useRangesActionsContext } from '../context/ranges-context'
|
|
|
|
import {
|
|
|
|
Change,
|
|
|
|
DeleteOperation,
|
|
|
|
EditOperation,
|
|
|
|
} from '../../../../../types/change'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import classnames from 'classnames'
|
|
|
|
import { usePermissionsContext } from '@/features/ide-react/context/permissions-context'
|
|
|
|
import { Button } from 'react-bootstrap'
|
|
|
|
import Tooltip from '@/shared/components/tooltip'
|
|
|
|
import MaterialIcon from '@/shared/components/material-icon'
|
|
|
|
import { formatTimeBasedOnYear } from '@/features/utils/format-date'
|
|
|
|
import { useChangesUsersContext } from '../context/changes-users-context'
|
|
|
|
import { ReviewPanelChangeUser } from './review-panel-change-user'
|
2024-08-15 06:07:40 -04:00
|
|
|
import { ReviewPanelEntry } from './review-panel-entry'
|
2024-08-12 05:50:54 -04:00
|
|
|
|
|
|
|
export const ReviewPanelChange = memo<{
|
|
|
|
change: Change<EditOperation>
|
|
|
|
aggregate?: Change<DeleteOperation>
|
|
|
|
top?: number
|
2024-09-24 04:54:14 -04:00
|
|
|
editable?: boolean
|
2024-09-26 10:13:54 -04:00
|
|
|
docId: string
|
|
|
|
hoverRanges?: boolean
|
2024-10-02 07:58:46 -04:00
|
|
|
hovered?: boolean
|
|
|
|
onEnter?: () => void
|
|
|
|
onLeave?: () => void
|
|
|
|
}>(
|
|
|
|
({
|
|
|
|
change,
|
|
|
|
aggregate,
|
|
|
|
top,
|
|
|
|
docId,
|
|
|
|
hoverRanges,
|
|
|
|
editable = true,
|
|
|
|
hovered,
|
|
|
|
onEnter,
|
|
|
|
onLeave,
|
|
|
|
}) => {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const { acceptChanges, rejectChanges } = useRangesActionsContext()
|
|
|
|
const permissions = usePermissionsContext()
|
|
|
|
const changesUsers = useChangesUsersContext()
|
2024-08-12 05:50:54 -04:00
|
|
|
|
2024-10-02 07:58:46 -04:00
|
|
|
if (!changesUsers) {
|
|
|
|
// if users are not loaded yet, do not show "Unknown" user
|
|
|
|
return null
|
|
|
|
}
|
2024-08-12 05:50:54 -04:00
|
|
|
|
2024-10-02 07:58:46 -04:00
|
|
|
return (
|
|
|
|
<ReviewPanelEntry
|
|
|
|
className={classnames('review-panel-entry-change', {
|
|
|
|
'review-panel-entry-insert': 'i' in change.op,
|
|
|
|
'review-panel-entry-delete': 'd' in change.op,
|
|
|
|
'review-panel-entry-hover': hovered,
|
|
|
|
// TODO: aggregate
|
|
|
|
})}
|
|
|
|
top={top}
|
|
|
|
op={change.op}
|
|
|
|
position={change.op.p}
|
|
|
|
docId={docId}
|
|
|
|
hoverRanges={hoverRanges}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
className="review-panel-entry-indicator"
|
|
|
|
onMouseEnter={onEnter}
|
|
|
|
onMouseLeave={onLeave}
|
|
|
|
>
|
|
|
|
<MaterialIcon type="edit" className="review-panel-entry-icon" />
|
|
|
|
</div>
|
2024-08-12 05:50:54 -04:00
|
|
|
|
2024-10-02 07:58:46 -04:00
|
|
|
<div
|
|
|
|
className="review-panel-entry-content"
|
|
|
|
onMouseEnter={onEnter}
|
|
|
|
onMouseLeave={onLeave}
|
|
|
|
>
|
|
|
|
<div className="review-panel-entry-header">
|
|
|
|
<div>
|
|
|
|
<div className="review-panel-entry-user">
|
|
|
|
<ReviewPanelChangeUser change={change} />
|
|
|
|
</div>
|
|
|
|
<div className="review-panel-entry-time">
|
|
|
|
{formatTimeBasedOnYear(change.metadata?.ts)}
|
|
|
|
</div>
|
2024-08-12 05:50:54 -04:00
|
|
|
</div>
|
2024-10-02 07:58:46 -04:00
|
|
|
{editable && permissions.write && (
|
|
|
|
<div className="review-panel-entry-actions">
|
|
|
|
<Tooltip
|
|
|
|
id="accept-change"
|
|
|
|
overlayProps={{ placement: 'bottom' }}
|
|
|
|
description={t('accept_change')}
|
|
|
|
tooltipProps={{ className: 'review-panel-tooltip' }}
|
2024-08-12 05:50:54 -04:00
|
|
|
>
|
2024-10-02 07:58:46 -04:00
|
|
|
<Button
|
|
|
|
onClick={() =>
|
|
|
|
aggregate
|
|
|
|
? acceptChanges(change.id, aggregate.id)
|
|
|
|
: acceptChanges(change.id)
|
|
|
|
}
|
|
|
|
bsStyle={null}
|
|
|
|
>
|
|
|
|
<MaterialIcon
|
|
|
|
type="check"
|
|
|
|
className="review-panel-entry-actions-icon"
|
|
|
|
accessibilityLabel={t('accept_change')}
|
|
|
|
/>
|
|
|
|
</Button>
|
|
|
|
</Tooltip>
|
2024-08-12 05:50:54 -04:00
|
|
|
|
2024-10-02 07:58:46 -04:00
|
|
|
<Tooltip
|
|
|
|
id="reject-change"
|
|
|
|
description={t('reject_change')}
|
|
|
|
overlayProps={{ placement: 'bottom' }}
|
|
|
|
tooltipProps={{ className: 'review-panel-tooltip' }}
|
2024-08-12 05:50:54 -04:00
|
|
|
>
|
2024-10-02 07:58:46 -04:00
|
|
|
<Button
|
|
|
|
bsStyle={null}
|
|
|
|
onClick={() =>
|
|
|
|
aggregate
|
|
|
|
? rejectChanges(change.id, aggregate.id)
|
|
|
|
: rejectChanges(change.id)
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<MaterialIcon
|
|
|
|
className="review-panel-entry-actions-icon"
|
|
|
|
accessibilityLabel={t('reject_change')}
|
|
|
|
type="close"
|
|
|
|
/>
|
|
|
|
</Button>
|
|
|
|
</Tooltip>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="review-panel-change-body">
|
|
|
|
{'i' in change.op && (
|
|
|
|
<>
|
|
|
|
{aggregate ? (
|
2024-08-12 05:50:54 -04:00
|
|
|
<MaterialIcon
|
2024-10-04 05:15:57 -04:00
|
|
|
className="review-panel-entry-icon review-panel-entry-change-icon review-panel-entry-icon-changed"
|
2024-10-02 07:58:46 -04:00
|
|
|
type="edit"
|
2024-08-12 05:50:54 -04:00
|
|
|
/>
|
2024-10-02 07:58:46 -04:00
|
|
|
) : (
|
|
|
|
<MaterialIcon
|
2024-10-04 05:15:57 -04:00
|
|
|
className="review-panel-entry-icon review-panel-entry-change-icon review-panel-entry-icon-accept"
|
2024-10-02 07:58:46 -04:00
|
|
|
type="add_circle"
|
|
|
|
/>
|
|
|
|
)}
|
2024-08-12 05:50:54 -04:00
|
|
|
|
2024-10-02 07:58:46 -04:00
|
|
|
{aggregate ? (
|
|
|
|
<span>
|
|
|
|
{t('aggregate_changed')}:{' '}
|
|
|
|
<del className="review-panel-content-highlight">
|
|
|
|
{aggregate.op.d}
|
|
|
|
</del>{' '}
|
|
|
|
{t('aggregate_to')}{' '}
|
|
|
|
<ins className="review-panel-content-highlight">
|
|
|
|
{change.op.i}
|
|
|
|
</ins>
|
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
<span>
|
|
|
|
{t('tracked_change_added')}:
|
|
|
|
<ins className="review-panel-content-highlight">
|
|
|
|
{change.op.i}
|
|
|
|
</ins>
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{'d' in change.op && (
|
|
|
|
<>
|
2024-08-12 05:50:54 -04:00
|
|
|
<MaterialIcon
|
2024-10-04 05:15:57 -04:00
|
|
|
className="review-panel-entry-icon review-panel-entry-change-icon review-panel-entry-icon-reject"
|
2024-10-02 07:58:46 -04:00
|
|
|
type="delete"
|
2024-08-12 05:50:54 -04:00
|
|
|
/>
|
|
|
|
|
|
|
|
<span>
|
2024-10-02 07:58:46 -04:00
|
|
|
{t('tracked_change_deleted')}:
|
2024-08-12 05:50:54 -04:00
|
|
|
<del className="review-panel-content-highlight">
|
2024-10-02 07:58:46 -04:00
|
|
|
{change.op.d}
|
|
|
|
</del>
|
2024-08-12 05:50:54 -04:00
|
|
|
</span>
|
2024-10-02 07:58:46 -04:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
2024-08-12 05:50:54 -04:00
|
|
|
</div>
|
2024-10-02 07:58:46 -04:00
|
|
|
</ReviewPanelEntry>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
2024-08-12 05:50:54 -04:00
|
|
|
ReviewPanelChange.displayName = 'ReviewPanelChange'
|