From 12f1fd485e1734267ea400fb4488db9d287a6196 Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Date: Sat, 29 Nov 2025 16:04:29 +0000 Subject: [PATCH] Audit viewer making api call when shouldnt (#5069) # Description of Changes --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### Translations (if applicable) - [ ] I ran [`scripts/counter_translation.py`](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/docs/counter_translation.md) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details. --- frontend/src/core/hooks/useAuditFilters.ts | 8 +++++--- .../config/configSections/audit/AuditEventsTable.tsx | 2 +- .../config/configSections/audit/AuditExportSection.tsx | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/frontend/src/core/hooks/useAuditFilters.ts b/frontend/src/core/hooks/useAuditFilters.ts index ef8f0c7df..b650c3491 100644 --- a/frontend/src/core/hooks/useAuditFilters.ts +++ b/frontend/src/core/hooks/useAuditFilters.ts @@ -4,7 +4,7 @@ import auditService, { AuditFilters } from '@app/services/auditService'; /** * Shared hook for managing audit filters across components */ -export function useAuditFilters(initialFilters: Partial = {}) { +export function useAuditFilters(initialFilters: Partial = {}, loginEnabled: boolean = true) { const [eventTypes, setEventTypes] = useState([]); const [users, setUsers] = useState([]); const [filters, setFilters] = useState({ @@ -30,8 +30,10 @@ export function useAuditFilters(initialFilters: Partial = {}) { } }; - fetchMetadata(); - }, []); + if (loginEnabled) { + fetchMetadata(); + } + }, [loginEnabled]); const handleFilterChange = (key: keyof AuditFilters, value: any) => { setFilters((prev) => ({ ...prev, [key]: value })); diff --git a/frontend/src/proprietary/components/shared/config/configSections/audit/AuditEventsTable.tsx b/frontend/src/proprietary/components/shared/config/configSections/audit/AuditEventsTable.tsx index adad94388..d8bf714b0 100644 --- a/frontend/src/proprietary/components/shared/config/configSections/audit/AuditEventsTable.tsx +++ b/frontend/src/proprietary/components/shared/config/configSections/audit/AuditEventsTable.tsx @@ -35,7 +35,7 @@ const AuditEventsTable: React.FC = ({ loginEnabled = true const { filters, eventTypes, users, handleFilterChange, handleClearFilters } = useAuditFilters({ page: 0, pageSize: 20, - }); + }, loginEnabled); useEffect(() => { const fetchEvents = async () => { diff --git a/frontend/src/proprietary/components/shared/config/configSections/audit/AuditExportSection.tsx b/frontend/src/proprietary/components/shared/config/configSections/audit/AuditExportSection.tsx index 2b4e533f3..04cc260e9 100644 --- a/frontend/src/proprietary/components/shared/config/configSections/audit/AuditExportSection.tsx +++ b/frontend/src/proprietary/components/shared/config/configSections/audit/AuditExportSection.tsx @@ -23,7 +23,7 @@ const AuditExportSection: React.FC = ({ loginEnabled = const [exporting, setExporting] = useState(false); // Use shared filters hook - const { filters, eventTypes, users, handleFilterChange, handleClearFilters } = useAuditFilters(); + const { filters, eventTypes, users, handleFilterChange, handleClearFilters } = useAuditFilters({}, loginEnabled); const handleExport = async () => { if (!loginEnabled) return;