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

Enhanced Styling Updates: Conditional 'Completed' Tags and Export Button Design #9499

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
8 changes: 6 additions & 2 deletions src/components/Common/Export.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const ExportButton = ({
...props
}: ExportButtonProps) => {
const { isExporting, exportFile } = useExport();

const isCompleted = props.tooltip?.toLowerCase() === "completed";
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using a dedicated prop for completion status

Using the tooltip text to determine completion status mixes presentation with business logic. This approach is fragile and could break if tooltip text changes.

Consider adding a dedicated prop:

- const isCompleted = props.tooltip?.toLowerCase() === "completed";
+ interface ExportButtonProps {
+   // ... existing props
+   isCompleted?: boolean;
+ }
+ 
+ export const ExportButton = ({
+   isCompleted = false,
+   // ... other props
+ }: ExportButtonProps)

Committable suggestion skipped: line range outside the PR's diff.

return (
<>
<ButtonV2
Expand All @@ -130,7 +130,11 @@ export const ExportButton = ({
exportFile(action, props.filenamePrefix, type, parse);
}
}}
className="tooltip mx-2 p-4 text-lg text-secondary-800 disabled:bg-transparent disabled:text-secondary-500"
className={`tooltip mx-2 p-4 text-lg ${
isCompleted
? "text-white"
: "text-secondary-800 disabled:bg-transparent disabled:text-secondary-500"
}`}
variant="secondary"
ghost
circle
Expand Down
16 changes: 14 additions & 2 deletions src/components/Kanban/Board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,20 @@ export function KanbanSection<T extends { id: string }>(
}
>
<div className="sticky top-0 rounded-xl bg-secondary-200 pt-2">
<div className="mx-2 flex items-center justify-between rounded-lg border border-secondary-300 bg-white p-4">
<div>{section.title}</div>
<div
className={`mx-2 flex items-center justify-between rounded-lg border p-4 ${
section.id === "COMPLETED"
? "border-green-500 bg-green-500 "
: "border-secondary-300 bg-white"
}`}
>
<div>
{section.id === "COMPLETED" ? (
<span className="font-bold text-white">{section.title}</span>
) : (
section.title
)}
</div>
Comment on lines +153 to +166
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Extract status constants and simplify conditional rendering

The current implementation has several areas for improvement:

  1. Hardcoded "COMPLETED" string
  2. Complex nested conditional rendering
  3. Multiple nested divs

Consider this refactor:

+ const SECTION_STATUS = {
+   COMPLETED: 'COMPLETED'
+ } as const;
+
+ const getSectionHeaderClass = (status: string) => 
+   status === SECTION_STATUS.COMPLETED
+     ? "border-green-500 bg-green-500"
+     : "border-secondary-300 bg-white";

- <div
-   className={`mx-2 flex items-center justify-between rounded-lg border p-4 ${
-     section.id === "COMPLETED"
-       ? "border-green-500 bg-green-500 "
-       : "border-secondary-300 bg-white"
-   }`}
- >
-   <div>
-     {section.id === "COMPLETED" ? (
-       <span className="font-bold text-white">{section.title}</span>
-     ) : (
-       section.title
-     )}
-   </div>
+ <div className={`mx-2 flex items-center justify-between rounded-lg border p-4 ${getSectionHeaderClass(section.id)}`}>
+   <span className={section.id === SECTION_STATUS.COMPLETED ? "font-bold text-white" : ""}>
+     {section.title}
+   </span>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<div
className={`mx-2 flex items-center justify-between rounded-lg border p-4 ${
section.id === "COMPLETED"
? "border-green-500 bg-green-500 "
: "border-secondary-300 bg-white"
}`}
>
<div>
{section.id === "COMPLETED" ? (
<span className="font-bold text-white">{section.title}</span>
) : (
section.title
)}
</div>
const SECTION_STATUS = {
COMPLETED: 'COMPLETED'
} as const;
const getSectionHeaderClass = (status: string) =>
status === SECTION_STATUS.COMPLETED
? "border-green-500 bg-green-500"
: "border-secondary-300 bg-white";
<div className={`mx-2 flex items-center justify-between rounded-lg border p-4 ${getSectionHeaderClass(section.id)}`}>
<span className={section.id === SECTION_STATUS.COMPLETED ? "font-bold text-white" : ""}>
{section.title}
</span>

<div>
<span className="ml-2 rounded-lg bg-secondary-300 px-2">
{typeof totalCount === "undefined" ? "..." : totalCount}
Expand Down
1 change: 1 addition & 0 deletions src/components/Resource/ResourceBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default function BoardView() {
<h3 className="flex h-8 items-center text-xs">
{board}{" "}
<ExportButton
tooltip={`${board}`}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add translation and improve accessibility for tooltips

The tooltip text should be translated and accessible.

- tooltip={`${board}`}
+ tooltip={t(`resource_board_export_tooltip`, { board: t(board.toLowerCase()) })}
+ aria-label={t(`resource_board_export_aria_label`, { board: t(board.toLowerCase()) })}

Also, ensure these translation keys are added to your i18n files:

{
  "resource_board_export_tooltip": "Export {{board}} resources",
  "resource_board_export_aria_label": "Export resources from {{board}} board"
}

action={async () => {
const { data } = await request(
routes.downloadResourceRequests,
Expand Down
1 change: 1 addition & 0 deletions src/components/Shifting/ShiftingBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export default function BoardView() {
<h3 className="flex h-8 items-center text-xs">
{board.label || board.text}{" "}
<ExportButton
tooltip={`${board.text}`}
action={async () => {
const { data } = await request(
routes.downloadShiftRequests,
Expand Down
Loading