mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 06:31:13 -05:00
Refactor History component
This commit is contained in:
81
src/components/history/EntityHistoryTabs.tsx
Normal file
81
src/components/history/EntityHistoryTabs.tsx
Normal file
@@ -0,0 +1,81 @@
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import { EntityHistoryTimeline, HistoryEvent } from './EntityHistoryTimeline';
|
||||
import { EntityVersionHistory } from '@/components/versioning/EntityVersionHistory';
|
||||
import { FormerNamesSection } from './FormerNamesSection';
|
||||
import { RideNameHistory } from '@/types/database';
|
||||
|
||||
interface EntityHistoryTabsProps {
|
||||
entityType: 'park' | 'ride' | 'company';
|
||||
entityId: string;
|
||||
entityName: string;
|
||||
events: HistoryEvent[];
|
||||
formerNames?: RideNameHistory[];
|
||||
currentName?: string;
|
||||
}
|
||||
|
||||
const getHistoryLabel = (entityType: string) => {
|
||||
switch (entityType) {
|
||||
case 'park':
|
||||
return 'Park History';
|
||||
case 'ride':
|
||||
return 'Ride History';
|
||||
case 'company':
|
||||
return 'Company History';
|
||||
default:
|
||||
return 'History';
|
||||
}
|
||||
};
|
||||
|
||||
const getHistoryValue = (entityType: string) => {
|
||||
switch (entityType) {
|
||||
case 'park':
|
||||
return 'park-history';
|
||||
case 'ride':
|
||||
return 'ride-history';
|
||||
case 'company':
|
||||
return 'company-history';
|
||||
default:
|
||||
return 'entity-history';
|
||||
}
|
||||
};
|
||||
|
||||
export function EntityHistoryTabs({
|
||||
entityType,
|
||||
entityId,
|
||||
entityName,
|
||||
events,
|
||||
formerNames,
|
||||
currentName,
|
||||
}: EntityHistoryTabsProps) {
|
||||
const historyValue = getHistoryValue(entityType);
|
||||
const historyLabel = getHistoryLabel(entityType);
|
||||
|
||||
return (
|
||||
<Tabs defaultValue={historyValue} className="w-full">
|
||||
<TabsList className="grid w-full grid-cols-2">
|
||||
<TabsTrigger value={historyValue}>{historyLabel}</TabsTrigger>
|
||||
<TabsTrigger value="version-history">Version History</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value={historyValue} className="mt-6 space-y-6">
|
||||
{formerNames && formerNames.length > 0 && currentName && (
|
||||
<FormerNamesSection
|
||||
currentName={currentName}
|
||||
formerNames={formerNames}
|
||||
entityType={entityType}
|
||||
/>
|
||||
)}
|
||||
|
||||
<EntityHistoryTimeline events={events} entityName={entityName} />
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="version-history" className="mt-6">
|
||||
<EntityVersionHistory
|
||||
entityType={entityType}
|
||||
entityId={entityId}
|
||||
entityName={entityName}
|
||||
/>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
);
|
||||
}
|
||||
@@ -16,9 +16,7 @@ import { useUserRole } from '@/hooks/useUserRole';
|
||||
import { toast } from '@/hooks/use-toast';
|
||||
import { submitCompanyUpdate } from '@/lib/companyHelpers';
|
||||
import { VersionIndicator } from '@/components/versioning/VersionIndicator';
|
||||
import { EntityVersionHistory } from '@/components/versioning/EntityVersionHistory';
|
||||
import { EntityHistoryTimeline, HistoryEvent } from '@/components/history/EntityHistoryTimeline';
|
||||
import { FormerNamesSection } from '@/components/history/FormerNamesSection';
|
||||
import { EntityHistoryTabs } from '@/components/history/EntityHistoryTabs';
|
||||
|
||||
export default function DesignerDetail() {
|
||||
const { slug } = useParams<{ slug: string }>();
|
||||
@@ -276,34 +274,19 @@ export default function DesignerDetail() {
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="history" className="mt-6">
|
||||
<Tabs defaultValue="company-history" className="w-full">
|
||||
<TabsList className="w-full max-w-md">
|
||||
<TabsTrigger value="company-history">Company History</TabsTrigger>
|
||||
<TabsTrigger value="version-history">Version History</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value="company-history" className="mt-6 space-y-6">
|
||||
<EntityHistoryTimeline
|
||||
events={[
|
||||
...(designer.founded_year ? [{
|
||||
date: `${designer.founded_year}`,
|
||||
title: `${designer.name} Founded`,
|
||||
description: `${designer.name} was established`,
|
||||
type: 'milestone' as const
|
||||
}] : []),
|
||||
]}
|
||||
entityName={designer.name}
|
||||
/>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="version-history" className="mt-6">
|
||||
<EntityVersionHistory
|
||||
entityType="company"
|
||||
entityId={designer.id}
|
||||
entityName={designer.name}
|
||||
/>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
<EntityHistoryTabs
|
||||
entityType="company"
|
||||
entityId={designer.id}
|
||||
entityName={designer.name}
|
||||
events={[
|
||||
...(designer.founded_year ? [{
|
||||
date: `${designer.founded_year}`,
|
||||
title: `${designer.name} Founded`,
|
||||
description: `${designer.name} was established`,
|
||||
type: 'milestone' as const
|
||||
}] : []),
|
||||
]}
|
||||
/>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</main>
|
||||
|
||||
@@ -16,9 +16,7 @@ import { useUserRole } from '@/hooks/useUserRole';
|
||||
import { toast } from '@/hooks/use-toast';
|
||||
import { submitCompanyUpdate } from '@/lib/companyHelpers';
|
||||
import { VersionIndicator } from '@/components/versioning/VersionIndicator';
|
||||
import { EntityVersionHistory } from '@/components/versioning/EntityVersionHistory';
|
||||
import { EntityHistoryTimeline, HistoryEvent } from '@/components/history/EntityHistoryTimeline';
|
||||
import { FormerNamesSection } from '@/components/history/FormerNamesSection';
|
||||
import { EntityHistoryTabs } from '@/components/history/EntityHistoryTabs';
|
||||
|
||||
export default function ManufacturerDetail() {
|
||||
const { slug } = useParams<{ slug: string }>();
|
||||
@@ -298,34 +296,19 @@ export default function ManufacturerDetail() {
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="history" className="mt-6">
|
||||
<Tabs defaultValue="company-history" className="w-full">
|
||||
<TabsList className="w-full max-w-md">
|
||||
<TabsTrigger value="company-history">Company History</TabsTrigger>
|
||||
<TabsTrigger value="version-history">Version History</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value="company-history" className="mt-6 space-y-6">
|
||||
<EntityHistoryTimeline
|
||||
events={[
|
||||
...(manufacturer.founded_year ? [{
|
||||
date: `${manufacturer.founded_year}`,
|
||||
title: `${manufacturer.name} Founded`,
|
||||
description: `${manufacturer.name} was established`,
|
||||
type: 'milestone' as const
|
||||
}] : []),
|
||||
]}
|
||||
entityName={manufacturer.name}
|
||||
/>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="version-history" className="mt-6">
|
||||
<EntityVersionHistory
|
||||
entityType="company"
|
||||
entityId={manufacturer.id}
|
||||
entityName={manufacturer.name}
|
||||
/>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
<EntityHistoryTabs
|
||||
entityType="company"
|
||||
entityId={manufacturer.id}
|
||||
entityName={manufacturer.name}
|
||||
events={[
|
||||
...(manufacturer.founded_year ? [{
|
||||
date: `${manufacturer.founded_year}`,
|
||||
title: `${manufacturer.name} Founded`,
|
||||
description: `${manufacturer.name} was established`,
|
||||
type: 'milestone' as const
|
||||
}] : []),
|
||||
]}
|
||||
/>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</main>
|
||||
|
||||
@@ -17,9 +17,7 @@ import { useUserRole } from '@/hooks/useUserRole';
|
||||
import { toast } from '@/hooks/use-toast';
|
||||
import { submitCompanyUpdate } from '@/lib/companyHelpers';
|
||||
import { VersionIndicator } from '@/components/versioning/VersionIndicator';
|
||||
import { EntityVersionHistory } from '@/components/versioning/EntityVersionHistory';
|
||||
import { EntityHistoryTimeline, HistoryEvent } from '@/components/history/EntityHistoryTimeline';
|
||||
import { FormerNamesSection } from '@/components/history/FormerNamesSection';
|
||||
import { EntityHistoryTabs } from '@/components/history/EntityHistoryTabs';
|
||||
|
||||
export default function OperatorDetail() {
|
||||
const { slug } = useParams<{ slug: string }>();
|
||||
@@ -321,34 +319,19 @@ export default function OperatorDetail() {
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="history" className="mt-6">
|
||||
<Tabs defaultValue="company-history" className="w-full">
|
||||
<TabsList className="w-full max-w-md">
|
||||
<TabsTrigger value="company-history">Company History</TabsTrigger>
|
||||
<TabsTrigger value="version-history">Version History</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value="company-history" className="mt-6 space-y-6">
|
||||
<EntityHistoryTimeline
|
||||
events={[
|
||||
...(operator.founded_year ? [{
|
||||
date: `${operator.founded_year}`,
|
||||
title: `${operator.name} Founded`,
|
||||
description: `${operator.name} was established`,
|
||||
type: 'milestone' as const
|
||||
}] : []),
|
||||
]}
|
||||
entityName={operator.name}
|
||||
/>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="version-history" className="mt-6">
|
||||
<EntityVersionHistory
|
||||
entityType="company"
|
||||
entityId={operator.id}
|
||||
entityName={operator.name}
|
||||
/>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
<EntityHistoryTabs
|
||||
entityType="company"
|
||||
entityId={operator.id}
|
||||
entityName={operator.name}
|
||||
events={[
|
||||
...(operator.founded_year ? [{
|
||||
date: `${operator.founded_year}`,
|
||||
title: `${operator.name} Founded`,
|
||||
description: `${operator.name} was established`,
|
||||
type: 'milestone' as const
|
||||
}] : []),
|
||||
]}
|
||||
/>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</main>
|
||||
|
||||
@@ -21,9 +21,7 @@ import { toast } from '@/hooks/use-toast';
|
||||
import { useUserRole } from '@/hooks/useUserRole';
|
||||
import { Edit } from 'lucide-react';
|
||||
import { VersionIndicator } from '@/components/versioning/VersionIndicator';
|
||||
import { EntityVersionHistory } from '@/components/versioning/EntityVersionHistory';
|
||||
import { EntityHistoryTimeline, HistoryEvent } from '@/components/history/EntityHistoryTimeline';
|
||||
import { FormerNamesSection } from '@/components/history/FormerNamesSection';
|
||||
import { EntityHistoryTabs } from '@/components/history/EntityHistoryTabs';
|
||||
|
||||
export default function ParkDetail() {
|
||||
const {
|
||||
@@ -593,40 +591,25 @@ export default function ParkDetail() {
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="history" className="mt-6">
|
||||
<Tabs defaultValue="park-history" className="w-full">
|
||||
<TabsList className="w-full max-w-md">
|
||||
<TabsTrigger value="park-history">Park History</TabsTrigger>
|
||||
<TabsTrigger value="version-history">Version History</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value="park-history" className="mt-6 space-y-6">
|
||||
<EntityHistoryTimeline
|
||||
events={[
|
||||
...(park.opening_date ? [{
|
||||
date: park.opening_date,
|
||||
title: `${park.name} Opened`,
|
||||
description: `${park.name} opened to the public`,
|
||||
type: 'milestone' as const
|
||||
}] : []),
|
||||
...(park.closing_date ? [{
|
||||
date: park.closing_date,
|
||||
title: `${park.name} Closed`,
|
||||
description: `${park.name} ceased operation`,
|
||||
type: 'status_change' as const
|
||||
}] : []),
|
||||
]}
|
||||
entityName={park.name}
|
||||
/>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="version-history" className="mt-6">
|
||||
<EntityVersionHistory
|
||||
entityType="park"
|
||||
entityId={park.id}
|
||||
entityName={park.name}
|
||||
/>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
<EntityHistoryTabs
|
||||
entityType="park"
|
||||
entityId={park.id}
|
||||
entityName={park.name}
|
||||
events={[
|
||||
...(park.opening_date ? [{
|
||||
date: park.opening_date,
|
||||
title: `${park.name} Opened`,
|
||||
description: `${park.name} opened to the public`,
|
||||
type: 'milestone' as const
|
||||
}] : []),
|
||||
...(park.closing_date ? [{
|
||||
date: park.closing_date,
|
||||
title: `${park.name} Closed`,
|
||||
description: `${park.name} ceased operation`,
|
||||
type: 'status_change' as const
|
||||
}] : []),
|
||||
]}
|
||||
/>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
|
||||
|
||||
@@ -17,9 +17,7 @@ import { useUserRole } from '@/hooks/useUserRole';
|
||||
import { toast } from '@/hooks/use-toast';
|
||||
import { submitCompanyUpdate } from '@/lib/companyHelpers';
|
||||
import { VersionIndicator } from '@/components/versioning/VersionIndicator';
|
||||
import { EntityVersionHistory } from '@/components/versioning/EntityVersionHistory';
|
||||
import { EntityHistoryTimeline, HistoryEvent } from '@/components/history/EntityHistoryTimeline';
|
||||
import { FormerNamesSection } from '@/components/history/FormerNamesSection';
|
||||
import { EntityHistoryTabs } from '@/components/history/EntityHistoryTabs';
|
||||
|
||||
export default function PropertyOwnerDetail() {
|
||||
const { slug } = useParams<{ slug: string }>();
|
||||
@@ -321,34 +319,19 @@ export default function PropertyOwnerDetail() {
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="history" className="mt-6">
|
||||
<Tabs defaultValue="company-history" className="w-full">
|
||||
<TabsList className="w-full max-w-md">
|
||||
<TabsTrigger value="company-history">Company History</TabsTrigger>
|
||||
<TabsTrigger value="version-history">Version History</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value="company-history" className="mt-6 space-y-6">
|
||||
<EntityHistoryTimeline
|
||||
events={[
|
||||
...(owner.founded_year ? [{
|
||||
date: `${owner.founded_year}`,
|
||||
title: `${owner.name} Founded`,
|
||||
description: `${owner.name} was established`,
|
||||
type: 'milestone' as const
|
||||
}] : []),
|
||||
]}
|
||||
entityName={owner.name}
|
||||
/>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="version-history" className="mt-6">
|
||||
<EntityVersionHistory
|
||||
entityType="company"
|
||||
entityId={owner.id}
|
||||
entityName={owner.name}
|
||||
/>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
<EntityHistoryTabs
|
||||
entityType="company"
|
||||
entityId={owner.id}
|
||||
entityName={owner.name}
|
||||
events={[
|
||||
...(owner.founded_year ? [{
|
||||
date: `${owner.founded_year}`,
|
||||
title: `${owner.name} Founded`,
|
||||
description: `${owner.name} was established`,
|
||||
type: 'milestone' as const
|
||||
}] : []),
|
||||
]}
|
||||
/>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</main>
|
||||
|
||||
@@ -44,9 +44,7 @@ import { useAuth } from '@/hooks/useAuth';
|
||||
import { useUserRole } from '@/hooks/useUserRole';
|
||||
import { toast } from '@/hooks/use-toast';
|
||||
import { VersionIndicator } from '@/components/versioning/VersionIndicator';
|
||||
import { EntityVersionHistory } from '@/components/versioning/EntityVersionHistory';
|
||||
import { EntityHistoryTimeline, HistoryEvent } from '@/components/history/EntityHistoryTimeline';
|
||||
import { FormerNamesSection } from '@/components/history/FormerNamesSection';
|
||||
import { EntityHistoryTabs } from '@/components/history/EntityHistoryTabs';
|
||||
|
||||
export default function RideDetail() {
|
||||
const { parkSlug, rideSlug } = useParams<{ parkSlug: string; rideSlug: string }>();
|
||||
@@ -661,48 +659,27 @@ export default function RideDetail() {
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="history" className="mt-6">
|
||||
<Tabs defaultValue="ride-history" className="w-full">
|
||||
<TabsList className="grid w-full grid-cols-2">
|
||||
<TabsTrigger value="ride-history">Ride History</TabsTrigger>
|
||||
<TabsTrigger value="version-history">Version History</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value="ride-history" className="mt-6 space-y-6">
|
||||
{ride.name_history && ride.name_history.length > 0 && (
|
||||
<FormerNamesSection
|
||||
currentName={ride.name}
|
||||
formerNames={ride.name_history}
|
||||
entityType="ride"
|
||||
/>
|
||||
)}
|
||||
|
||||
<EntityHistoryTimeline
|
||||
events={[
|
||||
...(ride.opening_date ? [{
|
||||
date: ride.opening_date,
|
||||
title: `${ride.name} Opened`,
|
||||
description: `${ride.name} opened to the public at ${ride.park.name}`,
|
||||
type: 'milestone' as const
|
||||
}] : []),
|
||||
...(ride.closing_date ? [{
|
||||
date: ride.closing_date,
|
||||
title: `${ride.name} Closed`,
|
||||
description: `${ride.name} ceased operation`,
|
||||
type: 'status_change' as const
|
||||
}] : []),
|
||||
]}
|
||||
entityName={ride.name}
|
||||
/>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="version-history" className="mt-6">
|
||||
<EntityVersionHistory
|
||||
entityType="ride"
|
||||
entityId={ride.id}
|
||||
entityName={ride.name}
|
||||
/>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
<EntityHistoryTabs
|
||||
entityType="ride"
|
||||
entityId={ride.id}
|
||||
entityName={ride.name}
|
||||
currentName={ride.name}
|
||||
formerNames={ride.name_history}
|
||||
events={[
|
||||
...(ride.opening_date ? [{
|
||||
date: ride.opening_date,
|
||||
title: `${ride.name} Opened`,
|
||||
description: `${ride.name} opened to the public at ${ride.park.name}`,
|
||||
type: 'milestone' as const
|
||||
}] : []),
|
||||
...(ride.closing_date ? [{
|
||||
date: ride.closing_date,
|
||||
title: `${ride.name} Closed`,
|
||||
description: `${ride.name} ceased operation`,
|
||||
type: 'status_change' as const
|
||||
}] : []),
|
||||
]}
|
||||
/>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user