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

Tan 3487/screening status filter item #9994

Merged
merged 15 commits into from
Jan 15, 2025
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the original StatusFilter with all the prescreening status related code that I'd like to separate from all other status filters. Only changes where indicated. :)

Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import React from 'react';

import { IconTooltip, Box, Tooltip } from '@citizenlab/cl2-component-library';
import ColorIndicator from 'component-library/components/ColorIndicator';
import { useParams } from 'react-router-dom';
import styled from 'styled-components';

import { IIdeaStatusData } from 'api/idea_statuses/types';
import usePhase from 'api/phases/usePhase';

import useFeatureFlag from 'hooks/useFeatureFlag';

import T from 'components/T';

import { FormattedMessage } from 'utils/cl-intl';

import messages from '../../../messages';

import StatusButton from './StatusButton';

const StatusText = styled.div`
&:first-letter {
text-transform: uppercase;
}
`;

interface Props {
status: IIdeaStatusData;
active: boolean;
onClick: () => void;
}

const ScreeningStatusFilter = ({ status, active, onClick }: Props) => {
const { phaseId } = useParams();
const { data: phase } = usePhase(phaseId);

const preScreeningFeatureFlag =
phase?.data.attributes.participation_method === 'ideation'
? 'prescreening_ideation'
: 'prescreening';

const preScreeningFeatureAllowed = useFeatureFlag({
name: preScreeningFeatureFlag,
onlyCheckAllowed: true,
});
const phasePrescreeningEnabled =
phase?.data.attributes.prescreening_enabled === true;

const prescreeningButtonIsDisabled =
!phasePrescreeningEnabled || !preScreeningFeatureAllowed;

const prescreeningTooltipIsDisabled =
phasePrescreeningEnabled && preScreeningFeatureAllowed;
Comment on lines +49 to +53
Copy link
Contributor Author

@brentguf brentguf Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the status code checks here since we know code is always prescreening.


return (
// Div wrapping is needed to make the filter take full width.
<div>
<Tooltip
content={
<div>
{!preScreeningFeatureAllowed ? (
<FormattedMessage {...messages.prescreeningTooltipUpsell} />
) : (
<FormattedMessage
{...messages.prescreeningTooltipPhaseDisabled}
/>
)}
</div>
}
disabled={prescreeningTooltipIsDisabled}
>
<Box>
<StatusButton
onClick={onClick}
active={active}
disabled={prescreeningButtonIsDisabled}
>
<Box
display="flex"
alignItems="center"
justifyContent="flex-start"
w="100%"
>
<ColorIndicator bgColor={status.attributes.color} />
<Box display="flex" alignItems="center" gap="4px">
<StatusText>
<T value={status.attributes.title_multiloc} />
</StatusText>
<IconTooltip
theme="light"
iconSize="16px"
content={
<FormattedMessage
{...messages.automatedStatusTooltipText}
/>
}
/>
</Box>
</Box>
</StatusButton>
</Box>
</Tooltip>
</div>
);
};

export default ScreeningStatusFilter;
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import React from 'react';

import { IconTooltip, Box, Tooltip } from '@citizenlab/cl2-component-library';
import { IconTooltip, Box } from '@citizenlab/cl2-component-library';
import ColorIndicator from 'component-library/components/ColorIndicator';
import { useDrop } from 'react-dnd';
import { useParams } from 'react-router-dom';
import styled from 'styled-components';

import { IIdeaStatusData } from 'api/idea_statuses/types';
import usePhase from 'api/phases/usePhase';

import useFeatureFlag from 'hooks/useFeatureFlag';

import T from 'components/T';

Expand All @@ -32,21 +28,6 @@ interface Props {
}

const StatusFilter = ({ status, active, onClick }: Props) => {
const { phaseId } = useParams() as { phaseId: string };
const { data: phase } = usePhase(phaseId);

const preScreeningFeatureFlag =
phase?.data.attributes.participation_method === 'ideation'
? 'prescreening_ideation'
: 'prescreening';

const preScreeningFeatureAllowed = useFeatureFlag({
name: preScreeningFeatureFlag,
onlyCheckAllowed: true,
});
const phasePrescreeningEnabled =
phase?.data.attributes.prescreening_enabled === true;

const [{ canDrop, isOver }, drop] = useDrop({
accept: 'IDEA',
drop: () => ({
Expand All @@ -62,63 +43,33 @@ const StatusFilter = ({ status, active, onClick }: Props) => {
const showAutomaticStatusTooltip =
status.attributes.can_manually_transition_to === false;

const prescreeningButtonIsDisabled =
status.attributes.code === 'prescreening' &&
(!phasePrescreeningEnabled || !preScreeningFeatureAllowed);

const prescreeningTooltipIsDisabled =
status.attributes.code !== 'prescreening' ||
(phasePrescreeningEnabled && preScreeningFeatureAllowed);

return (
<div ref={drop}>
<Tooltip
content={
<div>
{!preScreeningFeatureAllowed ? (
<FormattedMessage {...messages.prescreeningTooltipUpsell} />
) : (
<FormattedMessage
{...messages.prescreeningTooltipPhaseDisabled}
<StatusButton onClick={onClick} active={active || (isOver && canDrop)}>
<Box
display="flex"
alignItems="center"
justifyContent="flex-start"
w="100%"
>
<ColorIndicator bgColor={status.attributes.color} />
<Box display="flex" alignItems="center" gap="4px">
<StatusText>
<T value={status.attributes.title_multiloc} />
</StatusText>
{/* You can't drop inputs on an "automatic status", for which we show this tooltip */}
{showAutomaticStatusTooltip && (
<IconTooltip
theme="light"
iconSize="16px"
content={
<FormattedMessage {...messages.automatedStatusTooltipText} />
}
/>
)}
</div>
}
disabled={prescreeningTooltipIsDisabled}
>
<Box>
<StatusButton
onClick={onClick}
active={active || (isOver && canDrop)}
disabled={prescreeningButtonIsDisabled}
>
<Box
display="flex"
alignItems="center"
justifyContent="flex-start"
w="100%"
>
<ColorIndicator bgColor={status.attributes.color} />
<Box display="flex" alignItems="center" gap="4px">
<StatusText>
<T value={status.attributes.title_multiloc} />
</StatusText>
{showAutomaticStatusTooltip && (
<IconTooltip
theme="light"
iconSize="16px"
content={
<FormattedMessage
{...messages.automatedStatusTooltipText}
/>
}
/>
)}
</Box>
</Box>
</StatusButton>
</Box>
</Box>
</Tooltip>
</StatusButton>
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { isAdmin } from 'utils/permissions/roles';
import { ManagerType } from '../../..';
import messages from '../../../messages';

import ScreeningStatusFilter from './ScreeningStatusFilter';
import StatusButton from './StatusButton';
import StatusFilter from './StatusFilter';

Expand Down Expand Up @@ -71,14 +72,23 @@ const StatusFilters = ({
</Button>
</Box>
)}
{statuses.map((status) => (
<StatusFilter
key={status.id}
status={status}
active={isActive(status.id)}
onClick={() => handleItemClick(status.id)}
/>
))}
{statuses.map((status) =>
status.attributes.code === 'prescreening' ? (
<ScreeningStatusFilter
key={status.id}
status={status}
brentguf marked this conversation as resolved.
Show resolved Hide resolved
active={isActive(status.id)}
onClick={() => handleItemClick(status.id)}
/>
) : (
<StatusFilter
key={status.id}
status={status}
active={isActive(status.id)}
onClick={() => handleItemClick(status.id)}
/>
)
)}
</Box>
);
};
Expand Down