From 96e82e7d05ba9c318ae45a08f88df6ac5932bdde Mon Sep 17 00:00:00 2001 From: DonOmalVindula Date: Thu, 5 Sep 2024 14:15:39 +0530 Subject: [PATCH 1/3] Fix bugs in the infinite scrolling mechanism in logs section --- .../pages/diagnostic-logs-page.tsx | 71 ++++++++----------- 1 file changed, 28 insertions(+), 43 deletions(-) diff --git a/features/admin.logs.v1/pages/diagnostic-logs-page.tsx b/features/admin.logs.v1/pages/diagnostic-logs-page.tsx index aec36be6cf6..9daf889c050 100644 --- a/features/admin.logs.v1/pages/diagnostic-logs-page.tsx +++ b/features/admin.logs.v1/pages/diagnostic-logs-page.tsx @@ -59,6 +59,8 @@ const DiagnosticLogsPage = (props: DiagnosticPagePropsInterface) : ReactElement ["data-componentid"]: componentId } = props; + const scrollRef: MutableRefObject = useRef(null); + const [ isPreviousEmpty, setIsPreviousEmpty ] = useState(false); const [ isNextEmpty, setIsNextEmpty ] = useState(false); const [ searchQuery, setSearchQuery ] = useState(""); @@ -78,9 +80,31 @@ const DiagnosticLogsPage = (props: DiagnosticPagePropsInterface) : ReactElement const [ timerRunning, setTimerRunning ] = useState(false); const [ diagnosticLogList, setDiagnosticLogList ] = useState([]); - const { t } = useTranslation(); const timeZone: string = "GMT+0000 UTC"; + const { t } = useTranslation(); + + const { error, list, loading, next, previous } = useFetch(requestPayload); + + useEffect(() => { + const current: number = getDateTimeWithOffset(timeZone); + const currentEndTime: string = current.toString(); + const currentStartTime: string = (current - 3600*1000*timeRange).toString(); + + setEndTime(currentEndTime); + setStartTime(currentStartTime); + setLastDiagnosticLogRequestTime(currentEndTime); + + // Fetch logs automatically during the first render. + setRequestPayload({ + endTime: currentEndTime, + filter: "", + limit: LogsConstants.LOG_FETCH_COUNT, + logType: TabIndex.DIAGNOSTIC_LOGS, + startTime: currentStartTime + }); + }, []); + useEffect(() => { // Display a message if the logs are not fetched within 15 seconds of the request. setTimeout(() => { @@ -107,33 +131,9 @@ const DiagnosticLogsPage = (props: DiagnosticPagePropsInterface) : ReactElement setShowRefreshButton(false); }, [ endTime, startTime, inputQuery, filterQuery ]); - useEffect(() => { - const current: number = getDateTimeWithOffset(timeZone); - const currentEndTime: string = current.toString(); - const currentStartTime: string = (current - 3600*1000*timeRange).toString(); - - setEndTime(currentEndTime); - setStartTime(currentStartTime); - setLastDiagnosticLogRequestTime(currentEndTime); - - // Fetch logs automatically during the first render. - setRequestPayload({ - endTime: currentEndTime, - filter: "", - limit: LogsConstants.LOG_FETCH_COUNT, - logType: TabIndex.DIAGNOSTIC_LOGS, - startTime: currentStartTime - }); - }, []); - - const scrollRef: MutableRefObject = useRef(null); - - const { error, list, loading, next, previous } = useFetch(requestPayload); - - useEffect (() => { if (!loading && list.length > 0) { - setDiagnosticLogList(list); + setDiagnosticLogList([ ...diagnosticLogList, ...list ]); } }, [ list, loading ]); @@ -144,24 +144,7 @@ const DiagnosticLogsPage = (props: DiagnosticPagePropsInterface) : ReactElement const element: any = e.target; setShowDelayMessage(false); - /** - * When the at the top of the log container - */ - if (element.scrollTop === 0) { - if (previous) { - setRequestPayload({ - filter: searchQuery, - limit: LogsConstants.LOG_FETCH_COUNT, - logType: TabIndex.DIAGNOSTIC_LOGS, - previousToken: previous - }); - setIsPreviousEmpty(false); - setIsNextEmpty(false); - } else { - setIsPreviousEmpty(true); - } - } /** * When at the bottom of the log container */ @@ -258,6 +241,8 @@ const DiagnosticLogsPage = (props: DiagnosticPagePropsInterface) : ReactElement * @param query - search query with filters */ const handleSearch = () => { + setDiagnosticLogList([]); + let currentQuery: string = ""; if (inputQuery.length === 0) { From 0d88f811734b358df236fc1b98d799266da27d38 Mon Sep 17 00:00:00 2001 From: DonOmalVindula Date: Thu, 5 Sep 2024 14:27:29 +0530 Subject: [PATCH 2/3] Add changeset --- .changeset/eleven-suns-nail.md | 5 +++++ features/admin.logs.v1/pages/diagnostic-logs-page.tsx | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/eleven-suns-nail.md diff --git a/.changeset/eleven-suns-nail.md b/.changeset/eleven-suns-nail.md new file mode 100644 index 00000000000..51971af7ddf --- /dev/null +++ b/.changeset/eleven-suns-nail.md @@ -0,0 +1,5 @@ +--- +"@wso2is/admin.logs.v1": patch +--- + +Fix bugs in the infinite scrolling mechanism in logs section diff --git a/features/admin.logs.v1/pages/diagnostic-logs-page.tsx b/features/admin.logs.v1/pages/diagnostic-logs-page.tsx index 9daf889c050..4e036d7f09d 100644 --- a/features/admin.logs.v1/pages/diagnostic-logs-page.tsx +++ b/features/admin.logs.v1/pages/diagnostic-logs-page.tsx @@ -133,7 +133,7 @@ const DiagnosticLogsPage = (props: DiagnosticPagePropsInterface) : ReactElement useEffect (() => { if (!loading && list.length > 0) { - setDiagnosticLogList([ ...diagnosticLogList, ...list ]); + setDiagnosticLogList((previousLogs: InterfaceLogEntry[]) => [ ...previousLogs, ...list ]); } }, [ list, loading ]); From 996f92de0a2115e4a31ec952a901705988c1cf86 Mon Sep 17 00:00:00 2001 From: DonOmalVindula Date: Thu, 5 Sep 2024 15:01:22 +0530 Subject: [PATCH 3/3] Refactor search query logic --- .../pages/diagnostic-logs-page.tsx | 117 +++++++++--------- 1 file changed, 58 insertions(+), 59 deletions(-) diff --git a/features/admin.logs.v1/pages/diagnostic-logs-page.tsx b/features/admin.logs.v1/pages/diagnostic-logs-page.tsx index 4e036d7f09d..1ef428b81a5 100644 --- a/features/admin.logs.v1/pages/diagnostic-logs-page.tsx +++ b/features/admin.logs.v1/pages/diagnostic-logs-page.tsx @@ -164,61 +164,6 @@ const DiagnosticLogsPage = (props: DiagnosticPagePropsInterface) : ReactElement } }; - const renderDiagnosticLogContent = () : ReactElement => { - - return ( -
-
- { advancedSearchFilter() } - setStartTime(value) } - setToTime={ (value: string): void => setEndTime(value) } - setTimeRange={ (value: number): void => setTimeRange(value) } - data-componentid={ componentId } - /> - { showRefreshButton - ? ( - fetchLatestLogs() } - data-componentid={ `${ componentId }-refresh-button` } - > - - { t("extensions:develop.monitor.filter.refreshButton.label") } - - ) : ( - handleSearch() } - data-componentid={ `${ componentId }-search-button` } - > - - { t("extensions:develop.monitor.filter.queryButton.label") } - - ) - } -
-
- <> -
- { renderRefreshTime() } - - { filterList && filterList.map( - (value: { key: string, value:string }, index: number) => - () - ) } - { resolveClearAllFilters() } - -
- { resolveDiagnosticLogs() } - -
-
- ); - }; - /** * Build filter query */ @@ -240,7 +185,7 @@ const DiagnosticLogsPage = (props: DiagnosticPagePropsInterface) : ReactElement * * @param query - search query with filters */ - const handleSearch = () => { + const handleSearch = (overrideQuery?: string) => { setDiagnosticLogList([]); let currentQuery: string = ""; @@ -253,7 +198,7 @@ const DiagnosticLogsPage = (props: DiagnosticPagePropsInterface) : ReactElement currentQuery = ` and ${currentQuery}`; } } - setSearchQuery(currentQuery); + setSearchQuery(overrideQuery === undefined ? currentQuery : overrideQuery); // If the custom time range is not defined, // start, end times needs to be updated to account for the time it takes to click the search button. @@ -271,7 +216,7 @@ const DiagnosticLogsPage = (props: DiagnosticPagePropsInterface) : ReactElement setRequestPayload({ endTime: currentEndTime, - filter: `${filterQuery}${currentQuery}`, + filter: `${filterQuery}${overrideQuery === undefined ? currentQuery : overrideQuery}`, limit: LogsConstants.LOG_FETCH_COUNT, logType: TabIndex.DIAGNOSTIC_LOGS, startTime: currentStartTime @@ -285,7 +230,7 @@ const DiagnosticLogsPage = (props: DiagnosticPagePropsInterface) : ReactElement setSearchQuery(""); setInputQuery(""); setShowRefreshButton(false); - + handleSearch(""); }; /** @@ -339,6 +284,60 @@ const DiagnosticLogsPage = (props: DiagnosticPagePropsInterface) : ReactElement setFilterList([]); }; + const renderDiagnosticLogContent = () : ReactElement => { + return ( +
+
+ { advancedSearchFilter() } + setStartTime(value) } + setToTime={ (value: string): void => setEndTime(value) } + setTimeRange={ (value: number): void => setTimeRange(value) } + data-componentid={ componentId } + /> + { showRefreshButton + ? ( + fetchLatestLogs() } + data-componentid={ `${ componentId }-refresh-button` } + > + + { t("extensions:develop.monitor.filter.refreshButton.label") } + + ) : ( + handleSearch() } + data-componentid={ `${ componentId }-search-button` } + > + + { t("extensions:develop.monitor.filter.queryButton.label") } + + ) + } +
+
+ <> +
+ { renderRefreshTime() } + + { filterList && filterList.map( + (value: { key: string, value:string }, index: number) => + () + ) } + { resolveClearAllFilters() } + +
+ { resolveDiagnosticLogs() } + +
+
+ ); + }; + /** * Returns search component */