mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 08:51:16 -05:00
Refactor: Approve lovable tool use
This commit is contained in:
@@ -43,7 +43,18 @@ export function TestDataGenerator() {
|
||||
});
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [results, setResults] = useState<any>(null);
|
||||
const [stats, setStats] = useState<{ total: number; pending: number; approved: number } | null>(null);
|
||||
const [stats, setStats] = useState<{
|
||||
total: number;
|
||||
pending: number;
|
||||
approved: number;
|
||||
operators: number;
|
||||
property_owners: number;
|
||||
manufacturers: number;
|
||||
designers: number;
|
||||
parks: number;
|
||||
rides: number;
|
||||
ride_models: number;
|
||||
} | null>(null);
|
||||
|
||||
const selectedEntityTypes = Object.entries(entityTypes)
|
||||
.filter(([_, enabled]) => enabled)
|
||||
@@ -141,10 +152,35 @@ export function TestDataGenerator() {
|
||||
</Alert>
|
||||
|
||||
{stats && (
|
||||
<div className="flex gap-4 text-sm text-muted-foreground">
|
||||
<span>Total Test Data: {stats.total}</span>
|
||||
<span>Pending: {stats.pending}</span>
|
||||
<span>Approved: {stats.approved}</span>
|
||||
<div className="space-y-2">
|
||||
<div className="flex gap-4 text-sm text-muted-foreground">
|
||||
<span>Total Test Data: {stats.total}</span>
|
||||
<span>Pending: {stats.pending}</span>
|
||||
<span>Approved: {stats.approved}</span>
|
||||
</div>
|
||||
|
||||
{(stats.operators > 0 || stats.property_owners > 0 || stats.manufacturers > 0 ||
|
||||
stats.designers > 0 || stats.parks > 0 || stats.rides > 0 || stats.ride_models > 0) && (
|
||||
<Alert>
|
||||
<AlertDescription>
|
||||
<div className="text-sm">
|
||||
<p className="font-medium mb-2">Available Test Dependencies:</p>
|
||||
<ul className="space-y-1">
|
||||
{stats.operators > 0 && <li>• {stats.operators} test operator{stats.operators > 1 ? 's' : ''}</li>}
|
||||
{stats.property_owners > 0 && <li>• {stats.property_owners} test property owner{stats.property_owners > 1 ? 's' : ''}</li>}
|
||||
{stats.manufacturers > 0 && <li>• {stats.manufacturers} test manufacturer{stats.manufacturers > 1 ? 's' : ''}</li>}
|
||||
{stats.designers > 0 && <li>• {stats.designers} test designer{stats.designers > 1 ? 's' : ''}</li>}
|
||||
{stats.parks > 0 && <li>• {stats.parks} test park{stats.parks > 1 ? 's' : ''}</li>}
|
||||
{stats.rides > 0 && <li>• {stats.rides} test ride{stats.rides > 1 ? 's' : ''}</li>}
|
||||
{stats.ride_models > 0 && <li>• {stats.ride_models} test ride model{stats.ride_models > 1 ? 's' : ''}</li>}
|
||||
</ul>
|
||||
<p className="text-xs text-muted-foreground mt-2">
|
||||
Enable "Include Dependencies" to link new entities to these existing test entities.
|
||||
</p>
|
||||
</div>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
@@ -2226,6 +2226,36 @@ export type Database = {
|
||||
},
|
||||
]
|
||||
}
|
||||
test_data_registry: {
|
||||
Row: {
|
||||
created_at: string
|
||||
entity_id: string
|
||||
entity_slug: string
|
||||
entity_type: string
|
||||
id: string
|
||||
metadata: Json | null
|
||||
test_session_id: string | null
|
||||
}
|
||||
Insert: {
|
||||
created_at?: string
|
||||
entity_id: string
|
||||
entity_slug: string
|
||||
entity_type: string
|
||||
id?: string
|
||||
metadata?: Json | null
|
||||
test_session_id?: string | null
|
||||
}
|
||||
Update: {
|
||||
created_at?: string
|
||||
entity_id?: string
|
||||
entity_slug?: string
|
||||
entity_type?: string
|
||||
id?: string
|
||||
metadata?: Json | null
|
||||
test_session_id?: string | null
|
||||
}
|
||||
Relationships: []
|
||||
}
|
||||
user_blocks: {
|
||||
Row: {
|
||||
blocked_id: string
|
||||
|
||||
@@ -220,35 +220,57 @@ export async function clearTestData(): Promise<{ deleted: number }> {
|
||||
.eq('content->metadata->>is_test_data', 'true');
|
||||
|
||||
if (fetchError) throw fetchError;
|
||||
if (!testSubmissions || testSubmissions.length === 0) {
|
||||
return { deleted: 0 };
|
||||
|
||||
const submissionCount = testSubmissions?.length || 0;
|
||||
|
||||
// Delete submissions if found
|
||||
if (submissionCount > 0) {
|
||||
const batchSize = 100;
|
||||
let totalDeleted = 0;
|
||||
|
||||
for (let i = 0; i < testSubmissions.length; i += batchSize) {
|
||||
const batch = testSubmissions.slice(i, i + batchSize);
|
||||
const ids = batch.map(s => s.id);
|
||||
|
||||
const { error: deleteError } = await supabase
|
||||
.from('content_submissions')
|
||||
.delete()
|
||||
.in('id', ids);
|
||||
|
||||
if (deleteError) throw deleteError;
|
||||
totalDeleted += ids.length;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete in batches of 100
|
||||
const batchSize = 100;
|
||||
let totalDeleted = 0;
|
||||
|
||||
for (let i = 0; i < testSubmissions.length; i += batchSize) {
|
||||
const batch = testSubmissions.slice(i, i + batchSize);
|
||||
const ids = batch.map(s => s.id);
|
||||
|
||||
const { error: deleteError } = await supabase
|
||||
.from('content_submissions')
|
||||
.delete()
|
||||
.in('id', ids);
|
||||
|
||||
if (deleteError) throw deleteError;
|
||||
totalDeleted += ids.length;
|
||||
// Clear the test data registry
|
||||
const { error: registryError } = await supabase
|
||||
.from('test_data_registry')
|
||||
.delete()
|
||||
.neq('id', '00000000-0000-0000-0000-000000000000'); // Delete all records
|
||||
|
||||
if (registryError) {
|
||||
console.error('Error clearing test data registry:', registryError);
|
||||
}
|
||||
|
||||
return { deleted: totalDeleted };
|
||||
return { deleted: submissionCount };
|
||||
} catch (error) {
|
||||
console.error('Error clearing test data:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getTestDataStats(): Promise<{ total: number; pending: number; approved: number }> {
|
||||
export async function getTestDataStats(): Promise<{
|
||||
total: number;
|
||||
pending: number;
|
||||
approved: number;
|
||||
operators: number;
|
||||
property_owners: number;
|
||||
manufacturers: number;
|
||||
designers: number;
|
||||
parks: number;
|
||||
rides: number;
|
||||
ride_models: number;
|
||||
}> {
|
||||
// Use proper JSON path query for nested metadata
|
||||
const { data, error } = await supabase
|
||||
.from('content_submissions')
|
||||
@@ -257,10 +279,27 @@ export async function getTestDataStats(): Promise<{ total: number; pending: numb
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
// Get registry counts for available dependencies
|
||||
const { data: registryData } = await supabase
|
||||
.from('test_data_registry')
|
||||
.select('entity_type');
|
||||
|
||||
const registryCounts = registryData?.reduce((acc, row) => {
|
||||
acc[row.entity_type] = (acc[row.entity_type] || 0) + 1;
|
||||
return acc;
|
||||
}, {} as Record<string, number>) || {};
|
||||
|
||||
const stats = {
|
||||
total: data?.length || 0,
|
||||
pending: data?.filter(s => s.status === 'pending').length || 0,
|
||||
approved: data?.filter(s => s.status === 'approved').length || 0
|
||||
approved: data?.filter(s => s.status === 'approved').length || 0,
|
||||
operators: registryCounts['operator'] || 0,
|
||||
property_owners: registryCounts['property_owner'] || 0,
|
||||
manufacturers: registryCounts['manufacturer'] || 0,
|
||||
designers: registryCounts['designer'] || 0,
|
||||
parks: registryCounts['park'] || 0,
|
||||
rides: registryCounts['ride'] || 0,
|
||||
ride_models: registryCounts['ride_model'] || 0
|
||||
};
|
||||
|
||||
return stats;
|
||||
|
||||
Reference in New Issue
Block a user