LayoutSectionCard.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. "use client";
  2. import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
  3. import { Badge } from "@/components/ui/badge";
  4. import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
  5. interface LayoutSection {
  6. id: number;
  7. name: string;
  8. type: string;
  9. sheetName: string;
  10. startingRow?: number | null;
  11. endingRow?: number | null;
  12. tableName: string;
  13. fields: LayoutSectionField[];
  14. }
  15. interface LayoutSectionField {
  16. id: number;
  17. name: string;
  18. dataType: string;
  19. dataTypeFormat: string | null;
  20. cellPosition: string;
  21. importTableColumnName: string;
  22. importColumnOrderNumber: number;
  23. }
  24. interface LayoutSectionCardProps {
  25. section: LayoutSection;
  26. }
  27. export function LayoutSectionCard({ section }: LayoutSectionCardProps) {
  28. const getTypeColor = (type: string) => {
  29. switch (type.toLowerCase()) {
  30. case "properties":
  31. return "bg-blue-100 text-blue-800";
  32. case "grid":
  33. return "bg-green-100 text-green-800";
  34. default:
  35. return "bg-gray-100 text-gray-800";
  36. }
  37. };
  38. return (
  39. <Card
  40. className="cursor-pointer hover:shadow-lg transition-shadow"
  41. onClick={() => window.location.href = `/layout-configurations/sections/${section.id}/fields`}
  42. >
  43. <CardHeader>
  44. <div className="flex justify-between items-start">
  45. <div>
  46. <CardTitle className="text-lg">{section.name}</CardTitle>
  47. <CardDescription>
  48. Sheet: {section.sheetName} | Table: {section.tableName}
  49. </CardDescription>
  50. </div>
  51. <Badge className={getTypeColor(section.type)}>
  52. {section.type}
  53. </Badge>
  54. </div>
  55. </CardHeader>
  56. <CardContent>
  57. <div className="space-y-4">
  58. <div className="flex gap-4 text-sm">
  59. {section.startingRow && (
  60. <span>
  61. <strong>Rows:</strong> {section.startingRow} - {section.endingRow || "end"}
  62. </span>
  63. )}
  64. <span>
  65. <strong>Fields:</strong> {section.fields.length}
  66. </span>
  67. </div>
  68. {section.fields.length > 0 && (
  69. <div>
  70. <h4 className="font-medium mb-2">Fields</h4>
  71. <div className="overflow-x-auto">
  72. <Table>
  73. <TableHeader>
  74. <TableRow>
  75. <TableHead>Name</TableHead>
  76. <TableHead>Type</TableHead>
  77. <TableHead>Position</TableHead>
  78. <TableHead>Column</TableHead>
  79. <TableHead>Order</TableHead>
  80. </TableRow>
  81. </TableHeader>
  82. <TableBody>
  83. {section.fields.map((field) => (
  84. <TableRow key={field.id}>
  85. <TableCell className="font-medium">{field.name}</TableCell>
  86. <TableCell>
  87. <Badge variant="outline" className="text-xs">
  88. {field.dataType}
  89. </Badge>
  90. </TableCell>
  91. <TableCell>{field.cellPosition}</TableCell>
  92. <TableCell>{field.importTableColumnName}</TableCell>
  93. <TableCell>{field.importColumnOrderNumber}</TableCell>
  94. </TableRow>
  95. ))}
  96. </TableBody>
  97. </Table>
  98. </div>
  99. </div>
  100. )}
  101. </div>
  102. </CardContent>
  103. </Card>
  104. );
  105. }