From 75fb7f3135f307bcf16634e12effee40108c170f Mon Sep 17 00:00:00 2001 From: Sam Chau Date: Sun, 19 Jan 2025 18:02:19 +1030 Subject: [PATCH] style: visual overhaul for format cards --- frontend/src/components/format/FormatCard.jsx | 243 ++++++++++-------- 1 file changed, 134 insertions(+), 109 deletions(-) diff --git a/frontend/src/components/format/FormatCard.jsx b/frontend/src/components/format/FormatCard.jsx index 453aedd..a2703b2 100644 --- a/frontend/src/components/format/FormatCard.jsx +++ b/frontend/src/components/format/FormatCard.jsx @@ -1,7 +1,8 @@ -import React from 'react'; +import React, {useState} from 'react'; import PropTypes from 'prop-types'; -import {Copy, Check} from 'lucide-react'; +import {Copy, Check, FlaskConical, FileText, ListFilter} from 'lucide-react'; import Tooltip from '@ui/Tooltip'; +import ReactMarkdown from 'react-markdown'; function FormatCard({ format, @@ -13,6 +14,7 @@ function FormatCard({ willBeSelected, onSelect }) { + const [showDescription, setShowDescription] = useState(true); const {content} = format; const totalTests = content.tests?.length || 0; const passedTests = content.tests?.filter(t => t.passes)?.length || 0; @@ -20,37 +22,12 @@ function FormatCard({ const getConditionStyle = condition => { if (condition.negate) { - return 'bg-red-100 border-red-200 text-red-700 dark:bg-red-900/30 dark:border-red-700 dark:text-red-300'; + return 'bg-red-500/20 text-red-400 border border-red-500/20'; } if (condition.required) { - return 'bg-green-100 border-green-200 text-green-700 dark:bg-green-900/30 dark:border-green-700 dark:text-green-300'; + return 'bg-green-500/20 text-green-400 border border-green-500/20'; } - return 'bg-blue-100 border-blue-200 text-blue-700 dark:bg-blue-900/30 dark:border-blue-700 dark:text-blue-300'; - }; - - const getDisplayConditions = conditions => { - if (!conditions?.length) return []; - - // Sort conditions: required first, then non-required - const sortedConditions = [...conditions].sort((a, b) => { - if (a.required && !b.required) return -1; - if (!a.required && b.required) return 1; - return 0; - }); - - if (sortedConditions.length <= 5) return sortedConditions; - - // Take first 6 conditions and add a count of remaining ones - const displayConditions = sortedConditions.slice(0, 6); - const remainingCount = sortedConditions.length - 6; - - // Add a virtual condition for the count - displayConditions.push({ - name: `+${remainingCount} more...`, - isCounter: true - }); - - return displayConditions; + return 'bg-blue-500/20 text-blue-400 border border-blue-500/20'; }; const handleClick = e => { @@ -66,8 +43,12 @@ function FormatCard({ onClone(format); }; + const handleViewToggle = e => { + e.stopPropagation(); + setShowDescription(!showDescription); + }; + const handleMouseDown = e => { - // Prevent text selection when shift-clicking if (e.shiftKey) { e.preventDefault(); } @@ -75,39 +56,66 @@ function FormatCard({ return (
-
+
{/* Header Section */} -
-
-

+
+
+

{content.name}

- {sortBy === 'dateModified' && format.modified_date && ( -

- Modified:{' '} - {new Date( - format.modified_date - ).toLocaleString()} -

- )} +
+
+ {content.tags?.map(tag => ( + + {tag} + + ))} +
+
-
- {isSelectionMode ? ( + +
+ + + + {!isSelectionMode && ( + + )} + {isSelectionMode && (
{isSelected && ( - ) : ( - )}
- {/* Description */} - {content.description && ( -

- {content.description} -

- )} +
- {/* Conditions and Test Results */} -
-
- {getDisplayConditions(content.conditions)?.map( - (condition, index) => ( - - {condition.name} - - ) - )} + {/* Content Area with Slide Animation */} +
+
+ {/* Conditions */} +
+
+ {content.conditions?.map((condition, index) => ( + + {condition.name} + + ))} +
+
+
+ {/* Description */} +
+ {content.description ? ( +
+ + {content.description} + +
+ ) : ( + + No description provided + + )} +
+
+
- {totalTests > 0 && ( -
- = 80 - ? 'text-yellow-600 dark:text-yellow-400' - : 'text-red-600 dark:text-red-400' - }`}> - {passRate}% Pass Rate - - - ({passedTests}/{totalTests}) +
+ + {/* Footer - Tests */} +
+ {totalTests > 0 ? ( +
= 80 + ? 'bg-yellow-500/10 text-yellow-400' + : 'bg-red-500/10 text-red-400' + }`}> + + + {passedTests}/{totalTests} passing
+ ) : ( +
+ + No tests +
+ )} + {sortBy === 'dateModified' && format.modified_date && ( + + Modified:{' '} + {new Date(format.modified_date).toLocaleString()} + )}
- - {/* Tags */} - {content.tags?.length > 0 && ( -
- {content.tags.map(tag => ( - - {tag} - - ))} -
- )}
);