Skip to content

Commit

Permalink
fix code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
anshgoyalevil committed Mar 14, 2024
1 parent 962075d commit d3675b4
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 100 deletions.
1 change: 1 addition & 0 deletions components/logos/Adidas.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @description Logo for Adidas
* @param {string} className - used to style the svg
*/
export default function AdidasLogo({ className }: { className?: string }) {
return (
Expand Down
1 change: 1 addition & 0 deletions components/logos/Axway.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @description Logo for Axway
* @param {string} className - used to style the svg
*/
export default function AxwayLogo({ className }: { className?: string }) {
return (
Expand Down
1 change: 1 addition & 0 deletions components/logos/SAP.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState } from 'react';

/**
* @description Logo for SAP
* @param {string} className - used to style the svg
*/
export default function SapLogo({ className }: { className?: string }) {
const [isHovered, setIsHovered] = useState(false);
Expand Down
1 change: 1 addition & 0 deletions components/logos/Salesforce.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @description Logo for Salesforce
* @param {string} className - used to style the svg
*/
export default function SalesforceLogo({ className }: { className?: string }) {
return (
Expand Down
1 change: 1 addition & 0 deletions components/logos/Slack.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @description Logo for Slack
* @param {string} className - used to style the svg
*/
export default function SlackLogo({ className }: { className?: string }) {
return (
Expand Down
102 changes: 7 additions & 95 deletions components/roadmap/RoadmapItem.tsx
Original file line number Diff line number Diff line change
@@ -1,82 +1,9 @@
import { useState } from 'react';

import IconArrowRight from '../icons/ArrowRight';
import Modal from '../Modal';
// Since a roadmap item can contain nested roadmap lists, we need to import RoadmapList to display them.
/* eslint-disable import/no-cycle*/
import RoadmapList from './RoadmapList';

interface IPillProps {
item: {
done?: boolean;
url?: string;
description?: string;
title: string;
};
colorClass?: string;
isCollapsible?: boolean;
isCollapsed?: boolean;
onClickCollapse?: () => void;
}

/**
* @description Pill is a component to display a roadmap item.
* @param {object} props.item - The roadmap item.
* @param {boolean} props.item.done - Whether the item is done.
* @param {string} props.item.url - The URL associated with the item.
* @param {string} props.item.description - The description of the item.
* @param {string} props.item.title - The title of the item.
* @param {string} props.colorClass - The color class for styling.
* @param {boolean} props.isCollapsible - Whether the item is collapsible.
* @param {boolean} props.isCollapsed - Whether the item is collapsed.
* @param {function} props.onClickCollapse - Function to handle click on collapse.
*/
function Pill({
item,
colorClass = '',
isCollapsible = false,
isCollapsed = false,
onClickCollapse = () => {}
}: IPillProps) {
const [isDescriptionVisible, setIsDescriptionVisible] = useState(false);

return (
<>
<div className={`w-full shadow-sm ${item.done && 'opacity-50'}`}>
<div className='flex flex-1'>
<div className={`flex w-4 shrink-0 items-center justify-center rounded-l-md text-sm font-medium ${colorClass}`}></div>
<div className={'flex flex-1 items-center justify-between rounded-r-md border-y border-r border-gray-200 bg-white'}>
<div className='px-4 py-2 text-sm'>
<a href={item.url} rel='noopener noreferrer' onClick={() => !item.url && item.description && setIsDescriptionVisible(true)} className={`block text-left font-medium text-gray-900 ${item.description || item.url ? 'cursor-pointer hover:text-gray-600' : 'cursor-default'}`}>
{
item.done && (
<span title='Done!'>
<svg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' strokeWidth={1.5} stroke='currentColor' className='-mt-0.5 mr-2 inline-block size-6 text-green-600'>
<path strokeLinecap='round' strokeLinejoin='round' d='M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z' />
</svg>
</span>
)
}
<span>{ item.title }</span>
</a>
</div>
{isCollapsible && (
<button className='mr-2' onClick={onClickCollapse} data-testid='RoadmapItem-button'>
<IconArrowRight className={`h-4${isCollapsed ? 'rotate-90' : '-rotate-90'}`} />
</button>
)}
</div>
</div>
</div>
{
isDescriptionVisible && (
<Modal title={item.title} onModalClose={() => setIsDescriptionVisible(false)}>
<div className='prose'>{item.description}</div>
</Modal>
)
}
</>
);
}
import Pill from './RoadmapPill';

export interface IRoadmapItemProps {
item: {
Expand All @@ -103,22 +30,17 @@ export interface IRoadmapItemProps {
* @param {boolean} props.showConnector - Whether to show the connector.
* @param {boolean} props.collapsed - Whether the list is collapsed.
*/
export default function RoadmapItem({
item,
colorClass,
showConnector = true,
collapsed = true
}: IRoadmapItemProps) {
export default function RoadmapItem({ item, colorClass, showConnector = true, collapsed = true }: IRoadmapItemProps) {
const [isCollapsed, setIsCollapsed] = useState(collapsed);
const isCollapsible = (item.solutions !== null) || (item.implementations !== null);
const isCollapsible = item.solutions !== null || item.implementations !== null;

const connectorClasses = 'border-l-2 border-dashed border-gray-300';
const classNames = `pt-2 ${showConnector && connectorClasses}`;

return (
<li className={classNames} data-testid='RoadmapItem-list'>
<div className='flex'>
{ showConnector && (
{showConnector && (
<div className='flex flex-col justify-center'>
<div className='my-2 ml-0 mr-2 h-1 w-5 border-b-2 border-dashed border-gray-300'></div>
</div>
Expand All @@ -133,21 +55,11 @@ export default function RoadmapItem({
</div>

{!isCollapsed && item?.solutions?.length && (
<RoadmapList
className='ml-2 pt-3'
colorClass='bg-blue-400'
items={item.solutions}
collapsed={false}
/>
<RoadmapList className='ml-2 pt-3' colorClass='bg-blue-400' items={item.solutions} collapsed={false} />
)}

{!isCollapsed && item?.implementations?.length && (
<RoadmapList
className='ml-9 pt-3'
colorClass='bg-black'
items={item.implementations}
collapsed={false}
/>
<RoadmapList className='ml-9 pt-3' colorClass='bg-black' items={item.implementations} collapsed={false} />
)}
</li>
);
Expand Down
10 changes: 5 additions & 5 deletions components/roadmap/RoadmapList.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Since a RoadmapList may contain other RoadmapItems, we need to import RoadmapItem to display them.
/* eslint-disable import/no-cycle*/
import RoadmapItem from './RoadmapItem';

Expand Down Expand Up @@ -36,9 +37,9 @@ export default function RoadmapList({
}: IRoadmapListProps) {
return (
<>
items && items.length && (
items && items.length && (
<ul className={className} data-testid='RoadmapList-list'>
{ !collapsed && (
{!collapsed &&
items.map((item, index) => (
<RoadmapItem
key={index}
Expand All @@ -47,10 +48,9 @@ export default function RoadmapList({
showConnector={showConnector}
collapsed={childrenCollapsed}
/>
))
)}
))}
</ul>
)
)
</>
);
}
104 changes: 104 additions & 0 deletions components/roadmap/RoadmapPill.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { useState } from 'react';

import IconArrowRight from '../icons/ArrowRight';
import Modal from '../Modal';

/**
* @description Icon for Done (Tick)
*/
function DoneIcon() {
return (
<svg
xmlns='http://www.w3.org/2000/svg'
fill='none'
viewBox='0 0 24 24'
strokeWidth={1.5}
stroke='currentColor'
className='-mt-0.5 mr-2 inline-block size-6 text-green-600'
>
<path
strokeLinecap='round'
strokeLinejoin='round'
d='M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z'
/>
</svg>
);
}

interface IPillProps {
item: {
done?: boolean;
url?: string;
description?: string;
title: string;
};
colorClass?: string;
isCollapsible?: boolean;
isCollapsed?: boolean;
onClickCollapse?: () => void;
}

/**
* @description Pill is a component to display a roadmap item.
* @param {object} props.item - The roadmap item.
* @param {boolean} props.item.done - Whether the item is done.
* @param {string} props.item.url - The URL associated with the item.
* @param {string} props.item.description - The description of the item.
* @param {string} props.item.title - The title of the item.
* @param {string} props.colorClass - The color class for styling.
* @param {boolean} props.isCollapsible - Whether the item is collapsible.
* @param {boolean} props.isCollapsed - Whether the item is collapsed.
* @param {function} props.onClickCollapse - Function to handle click on collapse.
*/
export default function Pill({
item,
colorClass = '',
isCollapsible = false,
isCollapsed = false,
onClickCollapse = () => {}
}: IPillProps) {
const [isDescriptionVisible, setIsDescriptionVisible] = useState(false);

return (
<>
<div className={`w-full shadow-sm ${item.done && 'opacity-50'}`}>
<div className='flex flex-1'>
<div
className={`flex w-4 shrink-0 items-center justify-center rounded-l-md text-sm font-medium ${colorClass}`}
></div>
<div
className={
'flex flex-1 items-center justify-between rounded-r-md border-y border-r border-gray-200 bg-white'
}
>
<div className='px-4 py-2 text-sm'>
<a
href={item.url}
rel='noopener noreferrer'
onClick={() => !item.url && item.description && setIsDescriptionVisible(true)}
className={`block text-left font-medium text-gray-900 ${item.description || item.url ? 'cursor-pointer hover:text-gray-600' : 'cursor-default'}`}
>
{item.done && (
<span title='Done!'>
<DoneIcon />
</span>
)}
<span>{item.title}</span>
</a>
</div>
{isCollapsible && (
<button className='mr-2' onClick={onClickCollapse} data-testid='RoadmapItem-button'>
<IconArrowRight className={`h-4${isCollapsed ? 'rotate-90' : '-rotate-90'}`} />
</button>
)}
</div>
</div>
</div>
{isDescriptionVisible && (
<Modal title={item.title} onModalClose={() => setIsDescriptionVisible(false)}>
<div className='prose'>{item.description}</div>
</Modal>
)}
</>
);
}

0 comments on commit d3675b4

Please sign in to comment.