fitlers fixes
This commit is contained in:
@@ -45,6 +45,12 @@ export default function Approved() {
|
||||
const [totalPublished, setTotalPublished] = useState(0);
|
||||
const [totalImagesCount, setTotalImagesCount] = useState(0);
|
||||
|
||||
// Dynamic filter options (loaded from backend)
|
||||
const [statusOptions, setStatusOptions] = useState<Array<{value: string; label: string}> | undefined>(undefined);
|
||||
const [siteStatusOptions, setSiteStatusOptions] = useState<Array<{value: string; label: string}> | undefined>(undefined);
|
||||
const [contentTypeOptions, setContentTypeOptions] = useState<Array<{value: string; label: string}> | undefined>(undefined);
|
||||
const [contentStructureOptions, setContentStructureOptions] = useState<Array<{value: string; label: string}> | undefined>(undefined);
|
||||
|
||||
// Filter state
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
const [statusFilter, setStatusFilter] = useState(''); // Status filter (draft/review/approved/published)
|
||||
@@ -63,6 +69,39 @@ 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 () => {
|
||||
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 || []);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error loading filter options:', error);
|
||||
}
|
||||
}, [activeSite, statusFilter, siteStatusFilter, contentTypeFilter, contentStructureFilter, searchTerm]);
|
||||
|
||||
// Load filter options when dependencies change
|
||||
useEffect(() => {
|
||||
loadFilterOptions();
|
||||
}, [loadFilterOptions]);
|
||||
|
||||
// Load total metrics for footer widget and header metrics (not affected by pagination)
|
||||
const loadTotalMetrics = useCallback(async () => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user