fitlers fixes
This commit is contained in:
@@ -52,10 +52,11 @@ export default function Ideas() {
|
||||
const [totalImagesCount, setTotalImagesCount] = useState(0);
|
||||
|
||||
// Dynamic filter options
|
||||
const [statusOptions, setStatusOptions] = useState<FilterOption[]>([]);
|
||||
const [contentTypeOptions, setContentTypeOptions] = useState<FilterOption[]>([]);
|
||||
const [contentStructureOptions, setContentStructureOptions] = useState<FilterOption[]>([]);
|
||||
const [clusterOptions, setClusterOptions] = useState<FilterOption[]>([]);
|
||||
// Initialize as undefined to distinguish "not loaded yet" from "loaded but empty array"
|
||||
const [statusOptions, setStatusOptions] = useState<FilterOption[] | undefined>(undefined);
|
||||
const [contentTypeOptions, setContentTypeOptions] = useState<FilterOption[] | undefined>(undefined);
|
||||
const [contentStructureOptions, setContentStructureOptions] = useState<FilterOption[] | undefined>(undefined);
|
||||
const [clusterOptions, setClusterOptions] = useState<FilterOption[] | undefined>(undefined);
|
||||
|
||||
// Filter state
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
@@ -126,6 +127,38 @@ export default function Ideas() {
|
||||
loadFilterOptions();
|
||||
}, [loadFilterOptions]);
|
||||
|
||||
// Reload filter options when filters change (cascading)
|
||||
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]);
|
||||
|
||||
// Load total metrics for footer widget (site-wide totals, no sector filter)
|
||||
const loadTotalMetrics = useCallback(async () => {
|
||||
try {
|
||||
@@ -185,6 +218,7 @@ export default function Ideas() {
|
||||
...(clusterFilter && { keyword_cluster_id: clusterFilter }),
|
||||
...(structureFilter && { content_structure: structureFilter }),
|
||||
...(typeFilter && { content_type: typeFilter }),
|
||||
...(activeSector?.id && { sector_id: activeSector.id }),
|
||||
page: currentPage,
|
||||
page_size: pageSize,
|
||||
ordering,
|
||||
|
||||
Reference in New Issue
Block a user