filters fixed for all pages of planner writer
This commit is contained in:
@@ -107,12 +107,20 @@ export default function Ideas() {
|
||||
loadClusters();
|
||||
}, []);
|
||||
|
||||
// Load dynamic filter options based on current site's data
|
||||
const loadFilterOptions = useCallback(async () => {
|
||||
// Load dynamic filter options based on current site's data and applied filters
|
||||
// This implements cascading filters - each filter's options reflect what's available
|
||||
// given the other currently applied filters
|
||||
const loadFilterOptions = useCallback(async (currentFilters?: {
|
||||
status?: string;
|
||||
content_type?: string;
|
||||
content_structure?: string;
|
||||
cluster?: string;
|
||||
search?: string;
|
||||
}) => {
|
||||
if (!activeSite) return;
|
||||
|
||||
try {
|
||||
const options = await fetchPlannerIdeasFilterOptions(activeSite.id);
|
||||
const options = await fetchPlannerIdeasFilterOptions(activeSite.id, currentFilters);
|
||||
setStatusOptions(options.statuses || []);
|
||||
setContentTypeOptions(options.content_types || []);
|
||||
setContentStructureOptions(options.content_structures || []);
|
||||
@@ -122,42 +130,21 @@ export default function Ideas() {
|
||||
}
|
||||
}, [activeSite]);
|
||||
|
||||
// Load filter options when site changes
|
||||
// Load filter options when site changes (initial load with no filters)
|
||||
useEffect(() => {
|
||||
loadFilterOptions();
|
||||
}, [loadFilterOptions]);
|
||||
}, [activeSite]);
|
||||
|
||||
// Reload filter options when filters change (cascading)
|
||||
// Reload filter options when any filter changes (cascading filters)
|
||||
useEffect(() => {
|
||||
if (!activeSite) return;
|
||||
|
||||
const loadCascadingOptions = async () => {
|
||||
try {
|
||||
const params = new URLSearchParams();
|
||||
params.append('site_id', activeSite.id.toString());
|
||||
if (statusFilter) params.append('status', statusFilter);
|
||||
if (typeFilter) params.append('content_type', typeFilter);
|
||||
if (structureFilter) params.append('content_structure', structureFilter);
|
||||
if (clusterFilter) params.append('cluster', clusterFilter);
|
||||
if (searchTerm) params.append('search', searchTerm);
|
||||
|
||||
const response = await fetch(`/api/v1/planner/ideas/filter_options/?${params.toString()}`, {
|
||||
credentials: 'include',
|
||||
});
|
||||
const result = await response.json();
|
||||
if (result.success && result.data) {
|
||||
setStatusOptions(result.data.statuses || []);
|
||||
setContentTypeOptions(result.data.content_types || []);
|
||||
setContentStructureOptions(result.data.content_structures || []);
|
||||
setClusterOptions(result.data.clusters || []);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error loading cascading filter options:', error);
|
||||
}
|
||||
};
|
||||
|
||||
loadCascadingOptions();
|
||||
}, [activeSite, statusFilter, typeFilter, structureFilter, clusterFilter, searchTerm]);
|
||||
loadFilterOptions({
|
||||
status: statusFilter || undefined,
|
||||
content_type: typeFilter || undefined,
|
||||
content_structure: structureFilter || undefined,
|
||||
cluster: clusterFilter || undefined,
|
||||
search: searchTerm || undefined,
|
||||
});
|
||||
}, [statusFilter, typeFilter, structureFilter, clusterFilter, searchTerm, loadFilterOptions]);
|
||||
|
||||
// Load total metrics for footer widget (site-wide totals, no sector filter)
|
||||
const loadTotalMetrics = useCallback(async () => {
|
||||
|
||||
Reference in New Issue
Block a user