filters fixed for all pages of planner writer
This commit is contained in:
@@ -9,6 +9,7 @@ import TablePageTemplate from '../../templates/TablePageTemplate';
|
||||
import {
|
||||
fetchContent,
|
||||
fetchImages,
|
||||
fetchWriterContentFilterOptions,
|
||||
Content,
|
||||
ContentListResponse,
|
||||
ContentFilters,
|
||||
@@ -69,38 +70,44 @@ export default function Approved() {
|
||||
const [sortDirection, setSortDirection] = useState<'asc' | 'desc'>('desc');
|
||||
const [showContent, setShowContent] = useState(false);
|
||||
|
||||
// Load dynamic filter options with cascading
|
||||
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;
|
||||
site_status?: string;
|
||||
content_type?: string;
|
||||
content_structure?: string;
|
||||
search?: string;
|
||||
}) => {
|
||||
if (!activeSite) return;
|
||||
|
||||
try {
|
||||
const params = new URLSearchParams();
|
||||
params.append('site_id', activeSite.id.toString());
|
||||
if (statusFilter) params.append('status', statusFilter);
|
||||
if (siteStatusFilter) params.append('site_status', siteStatusFilter);
|
||||
if (contentTypeFilter) params.append('content_type', contentTypeFilter);
|
||||
if (contentStructureFilter) params.append('content_structure', contentStructureFilter);
|
||||
if (searchTerm) params.append('search', searchTerm);
|
||||
|
||||
const response = await fetch(`/api/v1/writer/content/filter_options/?${params.toString()}`, {
|
||||
credentials: 'include',
|
||||
});
|
||||
const result = await response.json();
|
||||
if (result.success && result.data) {
|
||||
setStatusOptions(result.data.statuses || []);
|
||||
setSiteStatusOptions(result.data.site_statuses || []);
|
||||
setContentTypeOptions(result.data.content_types || []);
|
||||
setContentStructureOptions(result.data.content_structures || []);
|
||||
}
|
||||
const options = await fetchWriterContentFilterOptions(activeSite.id, currentFilters);
|
||||
setStatusOptions(options.statuses || []);
|
||||
setSiteStatusOptions(options.site_statuses || []);
|
||||
setContentTypeOptions(options.content_types || []);
|
||||
setContentStructureOptions(options.content_structures || []);
|
||||
} catch (error) {
|
||||
console.error('Error loading filter options:', error);
|
||||
}
|
||||
}, [activeSite, statusFilter, siteStatusFilter, contentTypeFilter, contentStructureFilter, searchTerm]);
|
||||
}, [activeSite]);
|
||||
|
||||
// Load filter options when dependencies change
|
||||
// Load filter options when site changes (initial load with no filters)
|
||||
useEffect(() => {
|
||||
loadFilterOptions();
|
||||
}, [loadFilterOptions]);
|
||||
}, [activeSite]);
|
||||
|
||||
// Reload filter options when any filter changes (cascading filters)
|
||||
useEffect(() => {
|
||||
loadFilterOptions({
|
||||
status: statusFilter || undefined,
|
||||
site_status: siteStatusFilter || undefined,
|
||||
content_type: contentTypeFilter || undefined,
|
||||
content_structure: contentStructureFilter || undefined,
|
||||
search: searchTerm || undefined,
|
||||
});
|
||||
}, [statusFilter, siteStatusFilter, contentTypeFilter, contentStructureFilter, searchTerm, loadFilterOptions]);
|
||||
|
||||
// Load total metrics for footer widget and header metrics (not affected by pagination)
|
||||
const loadTotalMetrics = useCallback(async () => {
|
||||
|
||||
Reference in New Issue
Block a user