Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide redundant action status visualisation #210

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions components/actions/ActionPhase.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ function Phase(props) {
const theme = useTheme();

let blockColor = theme.themeColors.light;
const color = getStatusColorForAction(action, plan, theme);
const color = statusSummary
? getStatusColorForAction(action, plan, theme)
: theme.graphColors.grey050;

let labelClass = 'disabled';

Expand All @@ -85,7 +87,7 @@ function Phase(props) {
} else if (active) {
blockColor = color;
labelClass = 'active';
} else if (statusSummary.isCompleted) {
} else if (statusSummary?.isCompleted) {
blockColor = color;
labelClass = 'disabled';
}
Expand Down Expand Up @@ -115,9 +117,10 @@ function ActionPhase(props) {
}
// Override phase name in special case statuses
const inactive = ['cancelled', 'merged', 'postponed', 'completed'].includes(
status.identifier
status?.identifier
);
if (inactive) {

if (status && inactive) {
activePhaseName =
status.identifier === ActionStatusSummaryIdentifier.Merged
? `${t('actions:action-status-merged', getActionTermContext(plan))}`
Expand All @@ -141,7 +144,7 @@ function ActionPhase(props) {
/>
))}
</ul>
{!compact && status.identifier !== 'UNDEFINED' && (
{!compact && !!status && status.identifier !== 'UNDEFINED' && (
<>
<strong>{status.label}</strong>
{reason && (
Expand All @@ -158,7 +161,8 @@ function ActionPhase(props) {
}

ActionPhase.propTypes = {
status: PropTypes.shape().isRequired,
/** If status is undefined, status colors and labels will be hidden */
status: PropTypes.shape(),
activePhase: PropTypes.shape(),
reason: PropTypes.string,
phases: PropTypes.arrayOf(
Expand Down
35 changes: 32 additions & 3 deletions components/dashboard/ActionStatusTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactNode, useState } from 'react';
import React, { ReactNode, useState, createContext } from 'react';
import { Table, Button } from 'reactstrap';
import styled from 'styled-components';

Expand All @@ -16,6 +16,21 @@ import {
import { PlanContextFragment } from 'common/__generated__/graphql';
import { COLUMN_CONFIG } from './dashboard.constants';

type TActionTableContext = {
plan?: PlanContextFragment;
planViewUrl?: string | null;
/** Custom configuration for cell components */
config: {
hasPhaseAndStatusColumns?: boolean;
};
};

export const ActionTableContext = createContext<TActionTableContext>({
plan: undefined,
planViewUrl: undefined,
config: {},
});

const TableWrapper = styled.div`
width: 100%;
display: flex;
Expand Down Expand Up @@ -163,6 +178,12 @@ const preprocessForSorting = (
}
};

const hasPhaseAndStatusColumns = (columns: ColumnConfig[]) =>
!!(
columns.find((c) => c.__typename === 'ImplementationPhaseColumnBlock') &&
columns.find((c) => c.__typename === 'StatusColumnBlock')
);

interface Props {
actions: ActionListAction[];
orgs: ActionListOrganization[];
Expand Down Expand Up @@ -232,7 +253,15 @@ const ActionStatusTable = (props: Props) => {
: columns;

return (
<>
<ActionTableContext.Provider
value={{
plan,
planViewUrl,
config: {
hasPhaseAndStatusColumns: hasPhaseAndStatusColumns(filteredColumns),
},
}}
>
<ToolBar>
<ResetSorting>
{sort.key && (
Expand Down Expand Up @@ -294,7 +323,7 @@ const ActionStatusTable = (props: Props) => {
</tbody>
</DashTable>
</TableWrapper>
</>
</ActionTableContext.Provider>
);
};

Expand Down
19 changes: 15 additions & 4 deletions components/dashboard/ActionTableTooltips.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useContext } from 'react';
import styled from 'styled-components';
import dayjs from 'common/dayjs';
import {
Expand All @@ -11,6 +11,7 @@ import { ActionListAction } from './dashboard.types';
import { PlanContextFragment } from 'common/__generated__/graphql';
import { getTaskCounts } from './cells/TasksStatusCell';
import { useTheme } from 'common/theme';
import { ActionTableContext } from './ActionStatusTable';

const TooltipTitle = styled.p`
font-weight: ${(props) => props.theme.fontWeightBold};
Expand Down Expand Up @@ -126,14 +127,18 @@ export const TasksTooltipContent = ({ action, plan }: TooltipWithPlanProps) => {
// TODO: Should we split implementation phase and status?
export const ImplementationPhaseTooltipContent = ({
action,
plan,
}: TooltipWithPlanProps) => {
const { t } = useTranslation(['common', 'actions']);
const { plan, config } = useContext(ActionTableContext);

const activePhase = action.implementationPhase;
const merged = action.mergedWith;
const status = action.statusSummary;

if (!plan) {
return null;
}

const getMergedName = (mergedWith, planId) => {
if (mergedWith.plan.id !== planId) {
return `${mergedWith.plan.shortName} ${mergedWith.identifier}`;
Expand All @@ -145,6 +150,7 @@ export const ImplementationPhaseTooltipContent = ({
const statusDisplay = (
<StatusLabel $color={status?.color}>{status.label}</StatusLabel>
);

// If action is merged, display merged status
if (merged) {
return (
Expand All @@ -156,15 +162,20 @@ export const ImplementationPhaseTooltipContent = ({
</TooltipTitle>
);
}

// If action has no active phase or it's cancelled, or plan has no implementation phases : display only status
if (!activePhase || status?.identifier === 'cancelled') {
return statusDisplay;
}

return (
<div>
{statusDisplay}
<Divider />
{!config.hasPhaseAndStatusColumns && (
<>
{statusDisplay}
<Divider />
</>
)}
<TooltipTitle>{t('actions:action-implementation-phase')}:</TooltipTitle>
<PhasesTooltipList>
{plan.actionImplementationPhases.map((phase) => (
Expand Down
38 changes: 25 additions & 13 deletions components/dashboard/cells/ImplementationPhaseCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { ActionListAction } from '../dashboard.types';
import styled from 'styled-components';
import { PlanContextFragment } from 'common/__generated__/graphql';
import ActionPhase from 'components/actions/ActionPhase';
import { useContext } from 'react';
import { ActionTableContext } from '../ActionStatusTable';

interface Props {
action: ActionListAction;
Expand All @@ -13,18 +15,28 @@ const StatusDisplay = styled.div`
height: 100%;
`;

const ImplementationPhaseCell = ({ action, plan }: Props) => (
<StatusDisplay>
<ActionPhase
action={action}
status={action.statusSummary}
activePhase={action.implementationPhase}
reason={action.manualStatusReason}
mergedWith={action.mergedWith?.identifier}
phases={plan.actionImplementationPhases}
compact
/>
</StatusDisplay>
);
const ImplementationPhaseCell = ({ action }: Props) => {
const { plan, config } = useContext(ActionTableContext);

if (!plan) {
return null;
}

return (
<StatusDisplay>
<ActionPhase
action={action}
status={
config.hasPhaseAndStatusColumns ? undefined : action.statusSummary
}
activePhase={action.implementationPhase}
reason={action.manualStatusReason}
mergedWith={action.mergedWith?.identifier}
phases={plan.actionImplementationPhases}
compact
/>
</StatusDisplay>
);
};

export default ImplementationPhaseCell;
Loading