Skip to content

Commit

Permalink
feat(GoalHistory): show criteria changes history
Browse files Browse the repository at this point in the history
  • Loading branch information
LamaEats committed Aug 3, 2023
1 parent 5d5fcb7 commit 433f2d9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 42 deletions.
1 change: 1 addition & 0 deletions src/components/GoalActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export const GoalActivity = forwardRef<HTMLDivElement, GoalActivityProps>(
)}
{value.subject === 'criteria' && (
<HistoryRecordCriteria
from={excludeString(value.previousValue)}
to={excludeString(value.nextValue)}
action={value.action as HistoryAction}
/>
Expand Down
93 changes: 51 additions & 42 deletions src/components/HistoryRecord/HistoryRecord.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -443,17 +443,46 @@ export const HistoryRecordParticipant: React.FC<HistoryChangeProps<Activity & {
/>
);

type CriteriaItem = GoalAchieveCriteria & {
goalAsCriteria: (Goal & { state: StateData | null }) | null;
strike?: boolean;
};

const HistoryRecordCriteriaItem: React.FC<CriteriaItem> = ({ goalAsCriteria, title, strike }) => {
if (goalAsCriteria) {
return (
<StyledIssueListItem
strike={strike}
size="xs"
issue={{
title: goalAsCriteria.title,
_shortId: `${goalAsCriteria.projectId}-${goalAsCriteria.scopeId}`,
id: goalAsCriteria.id,
}}
/>
);
}

return (
<StyledText size="xs" weight="bold" strike={strike}>
{title}
</StyledText>
);
};

export const HistoryRecordCriteria: React.FC<
HistoryChangeProps<GoalAchieveCriteria & { goalAsCriteria: Goal & { state: StateData | null } }> & {
HistoryChangeProps<CriteriaItem> & {
action: HistoryAction;
strike?: boolean;
}
> = ({ to, action }) => {
> = ({ from, to, action }) => {
const recordCtx = useContext(RecordCtx);

const isChangeAction = ['complete', 'uncomplete'].includes(action);

recordCtx.setSubjectText((prev) => {
if (to?.goalAsCriteria != null) {
const target = from || to;
if (target?.goalAsCriteria != null) {
if (isChangeAction) {
if (action === 'complete') {
return 'goalComplete';
Expand All @@ -470,43 +499,23 @@ export const HistoryRecordCriteria: React.FC<
return prev;
});

return nullable(to, (t) => {
if (t?.goalAsCriteria) {
return (
<HistorySimplifyRecord
withPretext={false}
to={
<>
<StyledIssueListItem
strike={action === 'remove'}
size="xs"
issue={{
title: t.goalAsCriteria.title,
_shortId: `${t.goalAsCriteria.projectId}-${t.goalAsCriteria.scopeId}`,
id: t.goalAsCriteria.id,
}}
/>
<Text size="xs">{tr('as criteria')}</Text>
</>
}
/>
);
}

return (
<HistorySimplifyRecord
withPretext={false}
to={
<>
<Text size="xs" weight="bold">
{t.title}
</Text>
{nullable(isChangeAction, () => (
<Text size="xs">{tr(action === 'complete' ? 'as completed' : 'as uncompleted')}</Text>
))}
</>
}
/>
);
});
return (
<HistorySimplifyRecord
withPretext={from != null}
from={nullable(from, (val) => (
<HistoryRecordCriteriaItem {...val} strike />
))}
to={nullable(to, (val) => (
<>
<HistoryRecordCriteriaItem {...val} strike={action === 'remove'} />
{val?.goalAsCriteria && <Text size="xs">{tr('as criteria')}</Text>}
{nullable(isChangeAction, () => (
<StyledText size="xs">
{tr(action === 'complete' ? 'as completed' : 'as uncompleted')}
</StyledText>
))}
</>
))}
/>
);
};

0 comments on commit 433f2d9

Please sign in to comment.