From 1c7bb608c1a752f4beeaeb508badbac3bc9fce97 Mon Sep 17 00:00:00 2001 From: erinz Date: Mon, 28 Aug 2023 23:28:29 +0000 Subject: [PATCH 01/12] add change log component --- locale/en.json | 3 +- src/AuthenticatedSwitch.jsx | 4 +++ src/pages/changeLog/ChangeLog.jsx | 48 +++++++++++++++++++++++++ src/pages/controlPanel/ControlPanel.jsx | 16 +++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 src/pages/changeLog/ChangeLog.jsx diff --git a/locale/en.json b/locale/en.json index 003b5d9e..a81cdb1d 100644 --- a/locale/en.json +++ b/locale/en.json @@ -1256,5 +1256,6 @@ "CODEX_ID" : "Codex ID", "SPECIES_CONSISTENT_ERROR" : "Selected Codex ID does not match the species.", "CODEX_ID_CREATION" : "Codex ID Creation", - "CODEX_ID_CREATION_DESCRIPTION" : "Codex ID will be assigned based on the species." + "CODEX_ID_CREATION_DESCRIPTION" : "Codex ID will be assigned based on the species.", + "CHANGE_LOG" : "Change Log" } diff --git a/src/AuthenticatedSwitch.jsx b/src/AuthenticatedSwitch.jsx index f2ea5e73..87818cf5 100644 --- a/src/AuthenticatedSwitch.jsx +++ b/src/AuthenticatedSwitch.jsx @@ -48,6 +48,7 @@ import Footer from './components/Footer'; import { defaultCrossfadeDuration } from './constants/defaults'; import Requests from './pages/setup/Requests'; import SpeciesManagement from './pages/fieldManagement/SpeciesManagement'; +import ChangeLog from './pages/changeLog/ChangeLog'; export default function AuthenticatedSwitch({ emailNeedsVerification, @@ -132,6 +133,9 @@ export default function AuthenticatedSwitch({ + + + diff --git a/src/pages/changeLog/ChangeLog.jsx b/src/pages/changeLog/ChangeLog.jsx new file mode 100644 index 00000000..49e744a9 --- /dev/null +++ b/src/pages/changeLog/ChangeLog.jsx @@ -0,0 +1,48 @@ +import React, { useEffect, useState, useMemo } from 'react'; +import { get, has } from 'lodash-es'; + +import Grid from '@material-ui/core/Grid'; +import Paper from '@material-ui/core/Paper'; + +import useDocumentTitle from '../../hooks/useDocumentTitle'; +import MainColumn from '../../components/MainColumn'; +import Button from '../../components/Button'; +import SettingsBreadcrumbs from '../../components/SettingsBreadcrumbs'; +import Text from '../../components/Text'; +import Link from '../../components/Link'; +import ArrowBackIcon from '@material-ui/icons/ArrowBack'; +import useTheme from '@material-ui/core/styles/useTheme'; + + +export default function ChangeLog() { + + useDocumentTitle('CHANGE_LOG'); + const theme = useTheme(); + + return ( + + + + {'Change Log'} + + + {/* */} + + + ); +} diff --git a/src/pages/controlPanel/ControlPanel.jsx b/src/pages/controlPanel/ControlPanel.jsx index 59085412..1709495d 100644 --- a/src/pages/controlPanel/ControlPanel.jsx +++ b/src/pages/controlPanel/ControlPanel.jsx @@ -11,6 +11,7 @@ import SiteStatusIcon from '@material-ui/icons/Speed'; import UserManagementIcon from '@material-ui/icons/People'; import AdministrationIcon from '@material-ui/icons/Gavel'; import GroupWorkIcon from '@material-ui/icons/GroupWork'; +import AssignmentOutlinedIcon from '@material-ui/icons/AssignmentOutlined'; import useDocumentTitle from '../../hooks/useDocumentTitle'; import useGetMe from '../../models/users/useGetMe'; @@ -88,6 +89,21 @@ const adminPages = [ 'is_contributor', ], }, + { + icon: AssignmentOutlinedIcon, + name: 'change-log', + labelId: 'CHANGE_LOG', + href: '/settings/change-log', + roles: [ + 'is_admin', + 'is_exporter', + 'is_internal', + 'is_staff', + 'is_user_manager', + 'is_researcher', + 'is_contributor', + ], + }, ]; export default function ControlPanel() { From 85a5144d19dbef8142cf773becfaee88d64e3915 Mon Sep 17 00:00:00 2001 From: erinz Date: Tue, 29 Aug 2023 00:15:15 +0000 Subject: [PATCH 02/12] add change log table --- locale/en.json | 3 +- src/pages/changeLog/ChangeLog.jsx | 59 ++++++++++++++++++++++++++++--- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/locale/en.json b/locale/en.json index a81cdb1d..b98af691 100644 --- a/locale/en.json +++ b/locale/en.json @@ -1257,5 +1257,6 @@ "SPECIES_CONSISTENT_ERROR" : "Selected Codex ID does not match the species.", "CODEX_ID_CREATION" : "Codex ID Creation", "CODEX_ID_CREATION_DESCRIPTION" : "Codex ID will be assigned based on the species.", - "CHANGE_LOG" : "Change Log" + "CHANGE_LOG" : "Change Log", + "TIME_CHANGE_OCCURRED" : "Time Change occurred" } diff --git a/src/pages/changeLog/ChangeLog.jsx b/src/pages/changeLog/ChangeLog.jsx index 49e744a9..ffd4afc2 100644 --- a/src/pages/changeLog/ChangeLog.jsx +++ b/src/pages/changeLog/ChangeLog.jsx @@ -12,12 +12,34 @@ import Text from '../../components/Text'; import Link from '../../components/Link'; import ArrowBackIcon from '@material-ui/icons/ArrowBack'; import useTheme from '@material-ui/core/styles/useTheme'; - +import { useIntl, FormattedMessage } from 'react-intl'; +import DataDisplay from '../../components/dataDisplays/DataDisplay'; +import SearchIcon from '@material-ui/icons/Search'; export default function ChangeLog() { useDocumentTitle('CHANGE_LOG'); const theme = useTheme(); + const intl = useIntl(); + + + const tableColumns = [ + { + name: 'labelId', + label: intl.formatMessage({ id: 'TIME_CHANGE_OCCURRED' }), + options: { + customBodyRender: labelId => ( + + ), + }, + }, + { + name: 'type', + label: intl.formatMessage({ id: 'MESSAGE' }), + // options: { cellRenderer: cellRendererTypes.capitalizedString }, + }, + ]; + return ( @@ -26,14 +48,14 @@ export default function ChangeLog() { display:'flex', alignItems:'center', color: theme.palette.text.primary, - fontSize: 32, + fontSize: 22, fontWeight: 'bold', textDecoration: 'none', - marginTop: 500, + marginTop: 80, }} > - {'Change Log'} + {} {/* */} + + +
+ +
+ +
); } From a89f6068aeb6d5090b3e6a7d6067fa37a04f2744 Mon Sep 17 00:00:00 2001 From: erinz Date: Tue, 29 Aug 2023 22:14:02 +0000 Subject: [PATCH 03/12] add api call for all logs --- src/models/auditLogs/useGetAuditLogs.js | 10 +++++ src/pages/changeLog/ChangeLog.jsx | 53 ++++++++++++++++++------- src/pages/controlPanel/ControlPanel.jsx | 3 +- src/pages/devTools/AuditLog.jsx | 2 +- 4 files changed, 52 insertions(+), 16 deletions(-) diff --git a/src/models/auditLogs/useGetAuditLogs.js b/src/models/auditLogs/useGetAuditLogs.js index 7c845330..b07689ea 100644 --- a/src/models/auditLogs/useGetAuditLogs.js +++ b/src/models/auditLogs/useGetAuditLogs.js @@ -11,3 +11,13 @@ export default function useGetAuditLogs(entity_guid) { }, }); } + +export function useGetAllAuditLogs() { + return useFetch({ + queryKey: getAuditLogQueryKey(), + url: '/audit_logs', + queryOptions: { + retry: 1, + }, + }); +} diff --git a/src/pages/changeLog/ChangeLog.jsx b/src/pages/changeLog/ChangeLog.jsx index ffd4afc2..0c36837c 100644 --- a/src/pages/changeLog/ChangeLog.jsx +++ b/src/pages/changeLog/ChangeLog.jsx @@ -2,7 +2,6 @@ import React, { useEffect, useState, useMemo } from 'react'; import { get, has } from 'lodash-es'; import Grid from '@material-ui/core/Grid'; -import Paper from '@material-ui/core/Paper'; import useDocumentTitle from '../../hooks/useDocumentTitle'; import MainColumn from '../../components/MainColumn'; @@ -15,6 +14,8 @@ import useTheme from '@material-ui/core/styles/useTheme'; import { useIntl, FormattedMessage } from 'react-intl'; import DataDisplay from '../../components/dataDisplays/DataDisplay'; import SearchIcon from '@material-ui/icons/Search'; +import { useGetAllAuditLogs } from '../../models/auditLogs/useGetAuditLogs'; +import Paginator from '../../components/dataDisplays/Paginator'; export default function ChangeLog() { @@ -22,19 +23,42 @@ export default function ChangeLog() { const theme = useTheme(); const intl = useIntl(); + const { data, isLoading, error } = useGetAllAuditLogs(); + console.log('data', data); + + const [searchParams, setSearchParams] = useState({ + limit: 20, + offset: 0, + sort: 'time', + reverse: true, + }); + + const tableRows = data?.map((row) => { + + return { + id: row.guid, + time: row.created, + message: `MODULE NAME: ${row.module_name}, ITEM GUID: ${row.item_guid}, AUDIT TYPE: ${row.audit_type}, DETAILS: ${row.message}`, + } + + }) + + // module_name + item_guid + audit_type + message + + console.log('tableRows', tableRows); const tableColumns = [ { - name: 'labelId', + name: 'time', label: intl.formatMessage({ id: 'TIME_CHANGE_OCCURRED' }), options: { customBodyRender: labelId => ( - + ), }, }, { - name: 'type', + name: 'message', label: intl.formatMessage({ id: 'MESSAGE' }), // options: { cellRenderer: cellRendererTypes.capitalizedString }, }, @@ -57,13 +81,7 @@ export default function ChangeLog() { {} - - {/* */} + @@ -82,7 +100,7 @@ export default function ChangeLog() { /> + setInputValue(e.target.value)} + onKeyDown={event => { + if (event.key === 'Enter') { + setAuditLogId(inputValue); + } + }} + style={{ width: 420 }} + /> + + + -

Manage Requests

+ diff --git a/src/pages/sighting/SearchSightings.jsx b/src/pages/sighting/SearchSightings.jsx index 16a68063..1221f424 100644 --- a/src/pages/sighting/SearchSightings.jsx +++ b/src/pages/sighting/SearchSightings.jsx @@ -8,7 +8,7 @@ import SearchFilterList from '../../components/SearchFilterList'; import ElasticsearchSightingsDisplay from '../../components/dataDisplays/ElasticsearchSightingsDisplay'; import Paginator from '../../components/dataDisplays/Paginator'; -const rowsPerPage = 100; +const rowsPerPage = 10; export default function SearchSightings() { const [formFilters, setFormFilters] = useState([]); From 0588b3b7a58be831993a45cffd8aaa51eb6af02d Mon Sep 17 00:00:00 2001 From: erinz Date: Wed, 30 Aug 2023 20:55:53 +0000 Subject: [PATCH 05/12] update useGetAllAuditLogs hook --- src/pages/changeLog/ChangeLog.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/changeLog/ChangeLog.jsx b/src/pages/changeLog/ChangeLog.jsx index c6568bec..32295458 100644 --- a/src/pages/changeLog/ChangeLog.jsx +++ b/src/pages/changeLog/ChangeLog.jsx @@ -25,7 +25,7 @@ export default function ChangeLog() { const intl = useIntl(); const [inputValue, setInputValue] = useState(''); - const [auditLogId, setAuditLogId] = useState(undefined); + const [auditLogId, setAuditLogId] = useState(null); const [searchParams, setSearchParams] = useState({ limit: 20, @@ -148,7 +148,7 @@ export default function ChangeLog() { noTitleBar variant="secondary" columns={tableColumns} - data={searchedTableRows} + data={searchedTableRows || tableRows} tableContainerStyles={{ maxHeight: 700 }} searchParams={searchParams} setSearchParams={setSearchParams} From 7a92ff455b3c0d8939fb76f8e8c9e622618feb30 Mon Sep 17 00:00:00 2001 From: erinz Date: Wed, 30 Aug 2023 21:29:55 +0000 Subject: [PATCH 06/12] update query --- locale/en.json | 3 ++- src/models/auditLogs/useGetAuditLogs.js | 1 + src/pages/changeLog/ChangeLog.jsx | 35 +++++++++---------------- src/pages/controlPanel/ControlPanel.jsx | 6 ----- 4 files changed, 15 insertions(+), 30 deletions(-) diff --git a/locale/en.json b/locale/en.json index ec452d20..bd3aae8c 100644 --- a/locale/en.json +++ b/locale/en.json @@ -1259,5 +1259,6 @@ "CODEX_ID_CREATION_DESCRIPTION" : "Codex ID will be assigned based on the species.", "CHANGE_LOG" : "Change Log", "TIME_CHANGE_OCCURRED" : "Time Change occurred", - "MANAGE_REQUESTS" : "Manage Requests" + "MANAGE_REQUESTS" : "Manage Requests", + "NO_SEARCH_RESULT" : "Your search did not match any records." } diff --git a/src/models/auditLogs/useGetAuditLogs.js b/src/models/auditLogs/useGetAuditLogs.js index 13a747ec..1c21e8dd 100644 --- a/src/models/auditLogs/useGetAuditLogs.js +++ b/src/models/auditLogs/useGetAuditLogs.js @@ -17,6 +17,7 @@ export function useGetAllAuditLogs() { queryKey: getAuditLogQueryKey(), url: '/audit_logs', queryOptions: { + enabled: true, retry: 1, }, }); diff --git a/src/pages/changeLog/ChangeLog.jsx b/src/pages/changeLog/ChangeLog.jsx index 32295458..832cabe4 100644 --- a/src/pages/changeLog/ChangeLog.jsx +++ b/src/pages/changeLog/ChangeLog.jsx @@ -1,6 +1,4 @@ import React, { useEffect, useState, useMemo } from 'react'; -import { get, has } from 'lodash-es'; - import Grid from '@material-ui/core/Grid'; import useDocumentTitle from '../../hooks/useDocumentTitle'; @@ -33,32 +31,22 @@ export default function ChangeLog() { sort: 'time', reverse: true, }); - console.log(auditLogId); - - const { data, isLoading, error } = useGetAllAuditLogs(); - const { data: searchedData, isLoading: isSearchedLoading, error: searchedError } = useGetAuditLogs(auditLogId); - // const { data, isLoading, error } = useGetAuditLogs(auditLogId); - console.log('isSearchedLoading',isSearchedLoading); - console.log('searchedError',searchedError); - console.log('searchedData',searchedData); - - const searchedTableRows = (searchedData?.map((row) => { - return { - id: row.guid, - time: row.created, - message: `MODULE NAME: ${row.module_name}, ITEM GUID: ${row.item_guid}, AUDIT TYPE: ${row.audit_type}, DETAILS: ${row.message}`, - } - }) || [])?.sort((a, b) => new Date(b.created) - new Date(a.created)); - - const tableRows = (data?.map((row) => { + const buildAndSortTableRows = (data) => { + return data?.map((row) => { return { id: row.guid, time: row.created, message: `MODULE NAME: ${row.module_name}, ITEM GUID: ${row.item_guid}, AUDIT TYPE: ${row.audit_type}, DETAILS: ${row.message}`, } - }) || [])?.sort((a, b) => new Date(b.created) - new Date(a.created)); + })?.sort((a, b) => new Date(b.created) - new Date(a.created)); + } + + const { data, isLoading, error } = useGetAllAuditLogs(); + const { data: searchedData, isLoading: isSearchedLoading, error: searchedError } = useGetAuditLogs(auditLogId); + const searchedTableRows = searchedError ? [] : buildAndSortTableRows(searchedData); + const tableRows = buildAndSortTableRows(data); const tableColumns = [ { name: 'time', @@ -121,7 +109,7 @@ export default function ChangeLog() { setInputValue(e.target.value)} onKeyDown={event => { diff --git a/src/pages/controlPanel/ControlPanel.jsx b/src/pages/controlPanel/ControlPanel.jsx index d21294c2..5e6ae38e 100644 --- a/src/pages/controlPanel/ControlPanel.jsx +++ b/src/pages/controlPanel/ControlPanel.jsx @@ -94,7 +94,7 @@ const adminPages = [ icon: ListAltIcon, name: 'change-log', labelId: 'CHANGE_LOG', - href: '/settings/change-log', + href: '/settings/changelog', roles: [ 'is_admin', ], From 7811bf60bba13cc6567f5de6d8a03eb61ea0235d Mon Sep 17 00:00:00 2001 From: erinz Date: Fri, 1 Sep 2023 22:53:08 +0000 Subject: [PATCH 11/12] remove logs --- src/models/auditLogs/useFilterAuditLogs.js | 1 - src/models/auditLogs/useGetAuditLogs.js | 15 ++------------- src/pages/sighting/SearchSightings.jsx | 2 +- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/models/auditLogs/useFilterAuditLogs.js b/src/models/auditLogs/useFilterAuditLogs.js index 5e0c6a68..10caae3b 100644 --- a/src/models/auditLogs/useFilterAuditLogs.js +++ b/src/models/auditLogs/useFilterAuditLogs.js @@ -18,7 +18,6 @@ export default function useFilterAuditLogs({ queries, params = {} }) { ...params, }, dataAccessor: result => { - console.log('result', result); const resultCountString = get(result, [ 'data', 'headers', diff --git a/src/models/auditLogs/useGetAuditLogs.js b/src/models/auditLogs/useGetAuditLogs.js index 1c21e8dd..13e16f6f 100644 --- a/src/models/auditLogs/useGetAuditLogs.js +++ b/src/models/auditLogs/useGetAuditLogs.js @@ -3,22 +3,11 @@ import useFetch from '../../hooks/useFetch'; export default function useGetAuditLogs(entity_guid) { return useFetch({ - queryKey: entity_guid ? getAuditLogQueryKey(entity_guid) : getAuditLogQueryKey(), - url: entity_guid ? `/audit_logs/${entity_guid}` : '/audit_logs', + queryKey: getAuditLogQueryKey(entity_guid), + url: `/audit_logs/${entity_guid}`, queryOptions: { enabled: Boolean(entity_guid), retry: 1, }, }); } - -export function useGetAllAuditLogs() { - return useFetch({ - queryKey: getAuditLogQueryKey(), - url: '/audit_logs', - queryOptions: { - enabled: true, - retry: 1, - }, - }); -} diff --git a/src/pages/sighting/SearchSightings.jsx b/src/pages/sighting/SearchSightings.jsx index 63bb2054..16a68063 100644 --- a/src/pages/sighting/SearchSightings.jsx +++ b/src/pages/sighting/SearchSightings.jsx @@ -8,7 +8,7 @@ import SearchFilterList from '../../components/SearchFilterList'; import ElasticsearchSightingsDisplay from '../../components/dataDisplays/ElasticsearchSightingsDisplay'; import Paginator from '../../components/dataDisplays/Paginator'; -const rowsPerPage = 3; +const rowsPerPage = 100; export default function SearchSightings() { const [formFilters, setFormFilters] = useState([]); From 7ed1d0afefac7cc373d0ddd1266065718cb41ddf Mon Sep 17 00:00:00 2001 From: erinz Date: Tue, 5 Sep 2023 14:45:12 +0000 Subject: [PATCH 12/12] update date/time string to make it human readable --- src/pages/changeLog/ChangeLog.jsx | 2 +- src/pages/match/MatchSighting.jsx | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/changeLog/ChangeLog.jsx b/src/pages/changeLog/ChangeLog.jsx index ba4e4951..a4083cb4 100644 --- a/src/pages/changeLog/ChangeLog.jsx +++ b/src/pages/changeLog/ChangeLog.jsx @@ -77,7 +77,7 @@ export default function ChangeLog() { return data?.map((row) => { return { id: row.guid, - time: row.created, + time: new Date(row.created).toLocaleString(), message: `MODULE NAME: ${row.module_name}, ITEM GUID: ${row.item_guid}, AUDIT TYPE: ${row.audit_type}, DETAILS: ${row.message}`, } })?.sort((a, b) => new Date(b.time) - new Date(a.time)); diff --git a/src/pages/match/MatchSighting.jsx b/src/pages/match/MatchSighting.jsx index 5c1987a6..63a19a2d 100644 --- a/src/pages/match/MatchSighting.jsx +++ b/src/pages/match/MatchSighting.jsx @@ -135,7 +135,6 @@ export default function MatchSighting() { ['algorithms', 'hotspotter_nosv', 'scores_by_individual'], [] ); const annotation = scoresByIndividual.find((score) => score.guid === selectedMatchCandidateGuid); const heatmapUrl = annotation?.heatmap_src; - console.log(heatmapUrl); setHeatMapUrl(heatmapUrl); const checkHeatMap = async () => { try {