From 3f38594fd50175b6375e05765c27cb7b5580a787 Mon Sep 17 00:00:00 2001 From: svetaStrech Date: Tue, 23 Jan 2024 11:56:51 +0200 Subject: [PATCH] partition-default-view --- .../src/components/partitionsFilter/index.js | 32 ++-- ui_src/src/components/sideBar/index.js | 2 +- ui_src/src/domain/stationOverview/index.js | 152 +++++++++--------- .../components/functionCard/index.js | 4 +- .../components/functionData/index.js | 2 +- .../components/functionsOverview/index.js | 30 ++-- .../stationObservabilty/index.js | 6 +- .../stationObservabilty/messages/index.js | 64 ++++---- .../stationObservabilty/messages/style.scss | 5 + .../stationOverviewHeader/index.js | 3 +- 10 files changed, 161 insertions(+), 139 deletions(-) diff --git a/ui_src/src/components/partitionsFilter/index.js b/ui_src/src/components/partitionsFilter/index.js index 4f6a84ade..aa81e38d6 100644 --- a/ui_src/src/components/partitionsFilter/index.js +++ b/ui_src/src/components/partitionsFilter/index.js @@ -12,8 +12,8 @@ import './style.scss'; -import React, { useContext, useState } from 'react'; -import { Divider, Popover } from 'antd'; +import React, { useContext, useState, useEffect } from 'react'; +import { Popover } from 'antd'; import { ReactComponent as PartitionIcon } from 'assets/images/partitionIcon.svg'; import { ReactComponent as CollapseArrowIcon } from 'assets/images/collapseArrow.svg'; import { StationStoreContext } from 'domain/stationOverview'; @@ -21,11 +21,14 @@ import { StationStoreContext } from 'domain/stationOverview'; const PartitionsFilter = ({ partitions_number }) => { const [stationState, stationDispatch] = useContext(StationStoreContext); const [isOpen, setIsOpen] = useState(false); - const [selectedPartition, setSelectedPartition] = useState(-1); + const [selectedPartition, setSelectedPartition] = useState(1); + useEffect(() => { + setSelectedPartition(stationState?.stationPartition); + }, [stationState?.stationPartition]); const handleApply = (i) => { - setSelectedPartition(i === 0 ? -1 : i); - stationDispatch({ type: 'SET_STATION_PARTITION', payload: i === 0 ? -1 : i }); + setSelectedPartition(i); + stationDispatch({ type: 'SET_STATION_PARTITION', payload: i }); setIsOpen(false); }; @@ -34,17 +37,14 @@ const PartitionsFilter = ({ partitions_number }) => { }; const getItems = () => { - let elements = []; - for (let i = 0; i <= partitions_number; i++) { - elements.push( -
handleApply(i)}> - - -
- ); - } - return elements; + return Array.apply(null, { length: partitions_number }).map((_, index) => ( +
handleApply(index + 1)}> + + +
+ )); }; + const getContent = () => { return
{getItems()}
; }; @@ -54,7 +54,7 @@ const PartitionsFilter = ({ partitions_number }) => {
-
{selectedPartition == -1 ? `All partitions` : `Partition ${selectedPartition}`}
+
{`Partition ${selectedPartition}`}
diff --git a/ui_src/src/components/sideBar/index.js b/ui_src/src/components/sideBar/index.js index d05690f04..ddb3336d3 100644 --- a/ui_src/src/components/sideBar/index.js +++ b/ui_src/src/components/sideBar/index.js @@ -464,7 +464,6 @@ function SideBar() { return (
- {state.route !== 'overview' && }
+ {state.route !== 'overview' && } { const history = useHistory(); const [state, dispatch] = useContext(Context); const [isLoading, setisLoading] = useState(false); + const [isReloading, setisReloading] = useState(false); const [socketOn, setSocketOn] = useState(false); const location = useLocation(); + const [referredFunction, setReferredFunction] = useState(null); + + useEffect(() => { + location?.selectedFunction && setReferredFunction(location?.selectedFunction); + }, [location?.selectedFunction]); const sortData = (data) => { data.audit_logs?.sort((a, b) => new Date(b.created_at) - new Date(a.created_at)); @@ -68,98 +74,100 @@ const StationOverview = () => { }; const getStationDetails = async () => { + setisReloading(true); try { - const data = await httpRequest( - 'GET', - `${ApiEndpoints.GET_STATION_DATA}?station_name=${stationName}&partition_number=${stationState?.stationPartition || -1}` - ); + const data = await httpRequest('GET', `${ApiEndpoints.GET_STATION_DATA}?station_name=${stationName}&partition_number=${stationState?.stationPartition || 1}`); await sortData(data); stationDispatch({ type: 'SET_SOCKET_DATA', payload: data }); stationDispatch({ type: 'SET_SCHEMA_TYPE', payload: data.schema.schema_type }); setisLoading(false); + setisReloading(false); } catch (error) { setisLoading(false); + setisReloading(false); if (error.status === 404) { history.push(pathDomains.stations); } } }; + useEffect(() => { - if (socketOn) { - getStationDetails(); - } + // if (socketOn) { + // getStationDetails(); + // } + getStationDetails(); }, [stationState?.stationPartition || stationState?.stationSocketData?.total_messages || stationState?.stationSocketData?.total_dls_messages, stationName]); + // const startListen = async () => { + // const jc = JSONCodec(); + // const sc = StringCodec(); + + // const listenForUpdates = async () => { + // try { + // if (sub) { + // for await (const msg of sub) { + // let data = jc.decode(msg.data); + // sortData(data); + // stationDispatch({ type: 'SET_SOCKET_DATA', payload: data }); + // if (!socketOn) { + // setSocketOn(true); + // } + // } + // } + // } catch (err) { + // console.error(`Error receiving data updates for station overview:`, err); + // } + // }; + + // try { + // const rawBrokerName = await state.socket?.request( + // `$memphis_ws_subs.station_overview_data.${stationName}.${stationState?.stationPartition || -1}`, + // sc.encode('SUB') + // ); + // if (rawBrokerName) { + // const brokerName = JSON.parse(sc.decode(rawBrokerName?._rdata))['name']; + // sub = state.socket?.subscribe(`$memphis_ws_pubs.station_overview_data.${stationName}.${stationState?.stationPartition || -1}.${brokerName}`); + // listenForUpdates(); + // } + // } catch (err) { + // console.error('Error subscribing to station overview data:', err); + // } + // }; + + // const stopListen = async () => { + // if (sub) { + // try { + // await sub.unsubscribe(); + // } catch (err) { + // console.error('Error unsubscribing from station overview data:', err); + // } + // } + // }; + + // useEffect(() => { + // if (state.socket) { + // startListen(); + // } + // return () => { + // stopListen(); + // }; + // }, [state.socket, stationName]); + + // useEffect(() => { + // if (sub && socketOn) { + // stopListen(); + // startListen(); + // } + // }, [stationState?.stationPartition, stationName]); + useEffect(() => { setisLoading(true); dispatch({ type: 'SET_ROUTE', payload: 'stations' }); getStaionMetaData(); getStationDetails(); - stationDispatch({ type: 'SET_STATION_PARTITION', payload: -1 }); + stationDispatch({ type: 'SET_STATION_PARTITION', payload: 1 }); }, [stationName]); - const startListen = async () => { - const jc = JSONCodec(); - const sc = StringCodec(); - - const listenForUpdates = async () => { - try { - if (sub) { - for await (const msg of sub) { - let data = jc.decode(msg.data); - sortData(data); - stationDispatch({ type: 'SET_SOCKET_DATA', payload: data }); - if (!socketOn) { - setSocketOn(true); - } - } - } - } catch (err) { - console.error(`Error receiving data updates for station overview:`, err); - } - }; - - try { - const rawBrokerName = await state.socket?.request( - `$memphis_ws_subs.station_overview_data.${stationName}.${stationState?.stationPartition || -1}`, - sc.encode('SUB') - ); - if (rawBrokerName) { - const brokerName = JSON.parse(sc.decode(rawBrokerName?._rdata))['name']; - sub = state.socket?.subscribe(`$memphis_ws_pubs.station_overview_data.${stationName}.${stationState?.stationPartition || -1}.${brokerName}`); - listenForUpdates(); - } - } catch (err) { - console.error('Error subscribing to station overview data:', err); - } - }; - - const stopListen = async () => { - if (sub) { - try { - await sub.unsubscribe(); - } catch (err) { - console.error('Error unsubscribing from station overview data:', err); - } - } - }; - - useEffect(() => { - if (state.socket) { - startListen(); - } - return () => { - stopListen(); - }; - }, [state.socket, stationName]); - - useEffect(() => { - if (sub && socketOn) { - stopListen(); - startListen(); - } - }, [stationState?.stationPartition, stationName]); - return ( @@ -174,7 +182,7 @@ const StationOverview = () => { getStationDetails()} />
- +
)} diff --git a/ui_src/src/domain/stationOverview/stationObservabilty/components/functionCard/index.js b/ui_src/src/domain/stationOverview/stationObservabilty/components/functionCard/index.js index d2c16aa52..8febd0f17 100644 --- a/ui_src/src/domain/stationOverview/stationObservabilty/components/functionCard/index.js +++ b/ui_src/src/domain/stationOverview/stationObservabilty/components/functionCard/index.js @@ -23,7 +23,7 @@ import { httpRequest } from 'services/http'; import { convertLongNumbers } from 'services/valueConvertor'; import { StationStoreContext } from 'domain/stationOverview'; import FunctionDetails from 'domain/functions/components/functionDetails'; -import Drawer from "components/drawer"; +import Drawer from 'components/drawer'; import Tooltip from 'components/tooltip/tooltip'; export default function FunctionCard({ @@ -77,7 +77,7 @@ export default function FunctionCard({ try { const data = await httpRequest( 'GET', - `${ApiEndpoints.GET_FUNCTIONS_OVERVIEW}?station_name=${stationState?.stationMetaData?.name}&partition=${stationState?.stationPartition || -1}` + `${ApiEndpoints.GET_FUNCTIONS_OVERVIEW}?station_name=${stationState?.stationMetaData?.name}&partition=${stationState?.stationPartition || 1}` ); stationDispatch({ type: 'SET_STATION_FUNCTIONS', payload: data }); } catch (e) { diff --git a/ui_src/src/domain/stationOverview/stationObservabilty/components/functionData/index.js b/ui_src/src/domain/stationOverview/stationObservabilty/components/functionData/index.js index a365d76dc..bac3dbd0b 100644 --- a/ui_src/src/domain/stationOverview/stationObservabilty/components/functionData/index.js +++ b/ui_src/src/domain/stationOverview/stationObservabilty/components/functionData/index.js @@ -30,7 +30,7 @@ import { ReactComponent as CodeGrayIcon } from 'assets/images/codeGrayIcon.svg'; import { ReactComponent as PurpleQuestionMark } from 'assets/images/purpleQuestionMark.svg'; import { parsingDate, messageParser } from 'services/valueConvertor'; import Spinner from 'components/spinner'; -import Drawer from "components/drawer"; +import Drawer from 'components/drawer'; import { IoClose } from 'react-icons/io5'; import OverflowTip from 'components/tooltip/overflowtip'; diff --git a/ui_src/src/domain/stationOverview/stationObservabilty/components/functionsOverview/index.js b/ui_src/src/domain/stationOverview/stationObservabilty/components/functionsOverview/index.js index 02f11416b..79d74c95b 100644 --- a/ui_src/src/domain/stationOverview/stationObservabilty/components/functionsOverview/index.js +++ b/ui_src/src/domain/stationOverview/stationObservabilty/components/functionsOverview/index.js @@ -21,7 +21,7 @@ import { ReactComponent as AddFunctionIcon } from 'assets/images/addFunction.svg import { ReactComponent as PlusIcon } from 'assets/images/plusIcon.svg'; import { ReactComponent as ProcessedIcon } from 'assets/images/processIcon.svg'; import { IoClose } from 'react-icons/io5'; -import Drawer from "components/drawer"; +import Drawer from 'components/drawer'; import dataPassLineLottie from 'assets/lotties/dataPassLine.json'; import dataPassLineEmptyLottie from 'assets/lotties/dataPassLineEmpty.json'; import Lottie from 'lottie-react'; @@ -34,7 +34,7 @@ import Spinner from 'components/spinner'; let sub; -const FunctionsOverview = ({ referredFunction, dismissFunction, moveToGenralView }) => { +const FunctionsOverview = ({ referredFunction, dismissFunction, moveToGenralView, loading }) => { const [stationState, stationDispatch] = useContext(StationStoreContext); const [currentFunction, setCurrentFunction] = useState(null); const [functionDetails, setFunctionDetails] = useState(null); @@ -129,7 +129,7 @@ const FunctionsOverview = ({ referredFunction, dismissFunction, moveToGenralView try { const data = await httpRequest( 'GET', - `${ApiEndpoints.GET_FUNCTIONS_OVERVIEW}?station_name=${stationState?.stationMetaData?.name}&partition=${stationState?.stationPartition || -1}` + `${ApiEndpoints.GET_FUNCTIONS_OVERVIEW}?station_name=${stationState?.stationMetaData?.name}&partition=${stationState?.stationPartition || 1}` ); stationDispatch({ type: 'SET_STATION_FUNCTIONS', payload: data }); setLoading(false); @@ -154,7 +154,7 @@ const FunctionsOverview = ({ referredFunction, dismissFunction, moveToGenralView const handleAddFunction = async (requestBody) => { requestBody.station_name = stationState?.stationMetaData?.name; - requestBody.partition = stationState?.stationPartition || -1; + requestBody.partition = stationState?.stationPartition || 1; try { await httpRequest('POST', ApiEndpoints.ADD_FUNCTION, requestBody); getFunctionsOverview(); @@ -212,12 +212,11 @@ const FunctionsOverview = ({ referredFunction, dismissFunction, moveToGenralView - {isLoading && ( + {isLoading || loading ? (
- )} - {stationState?.stationFunctions?.functions && stationState?.stationFunctions?.functions?.length > 0 && ( + ) : stationState?.stationFunctions?.functions && stationState?.stationFunctions?.functions?.length > 0 ? (
@@ -225,7 +224,7 @@ const FunctionsOverview = ({ referredFunction, dismissFunction, moveToGenralView { setCurrentFunction(functionItem); setOpenBottomDetails(true); @@ -251,14 +250,15 @@ const FunctionsOverview = ({ referredFunction, dismissFunction, moveToGenralView
- )} - {stationState?.stationFunctions?.functions?.length === 0 && ( -
-
setOpenFunctionsModal(true)}> - - Add Function + ) : ( + stationState?.stationFunctions?.functions?.length === 0 && ( +
+
setOpenFunctionsModal(true)}> + + Add Function +
-
+ ) )}
diff --git a/ui_src/src/domain/stationOverview/stationObservabilty/index.js b/ui_src/src/domain/stationOverview/stationObservabilty/index.js index 5c81e8670..304d67998 100644 --- a/ui_src/src/domain/stationOverview/stationObservabilty/index.js +++ b/ui_src/src/domain/stationOverview/stationObservabilty/index.js @@ -24,7 +24,7 @@ import ProduceConsumList from './ProduceConsumList'; import { StationStoreContext } from '..'; import Messages from './messages'; -const StationObservabilty = ({ referredFunction }) => { +const StationObservabilty = ({ referredFunction, loading }) => { const [stationState, stationDispatch] = useContext(StationStoreContext); return ( @@ -46,7 +46,9 @@ const StationObservabilty = ({ referredFunction }) => { )} - + + +
{stationState?.stationMetaData?.is_native ? ( <> diff --git a/ui_src/src/domain/stationOverview/stationObservabilty/messages/index.js b/ui_src/src/domain/stationOverview/stationObservabilty/messages/index.js index ece08ac45..da456290e 100644 --- a/ui_src/src/domain/stationOverview/stationObservabilty/messages/index.js +++ b/ui_src/src/domain/stationOverview/stationObservabilty/messages/index.js @@ -47,9 +47,10 @@ import { ReactComponent as DisableIcon } from 'assets/images/disableIcon.svg'; import { Divider } from 'antd'; import FunctionsOverview from '../components/functionsOverview'; import CloudModal from 'components/cloudModal'; +import Spinner from 'components/spinner'; import { ReactComponent as CleanDisconnectedProducersIcon } from 'assets/images/clean_disconnected_producers.svg'; -const Messages = ({ referredFunction }) => { +const Messages = ({ referredFunction, loading }) => { const [stationState, stationDispatch] = useContext(StationStoreContext); const [selectedRowIndex, setSelectedRowIndex] = useState(null); const [selectedRowPartition, setSelectedRowPartition] = useState(null); @@ -106,6 +107,10 @@ const Messages = ({ referredFunction }) => { }; }, []); + useEffect(() => { + activeTab === 'functions' && setSelectedRowIndex(null); + }, [activeTab]); + useEffect(() => { referredFunction && setActiveTab('functions'); setChoseReferredFunction(referredFunction); @@ -135,10 +140,7 @@ const Messages = ({ referredFunction }) => { const getStationDetails = async () => { try { - const data = await httpRequest( - 'GET', - `${ApiEndpoints.GET_STATION_DATA}?station_name=${stationName}&partition_number=${stationState?.stationPartition || -1}` - ); + const data = await httpRequest('GET', `${ApiEndpoints.GET_STATION_DATA}?station_name=${stationName}&partition_number=${stationState?.stationPartition || 1}`); stationDispatch({ type: 'SET_SOCKET_DATA', payload: data }); stationDispatch({ type: 'SET_SCHEMA_TYPE', payload: data.schema.schema_type }); } catch (error) {} @@ -243,7 +245,6 @@ const Messages = ({ referredFunction }) => { return item.id !== messageId; }); }); - console.log(messages); } setTimeout(() => { setIgnoreProcced(false); @@ -310,9 +311,9 @@ const Messages = ({ referredFunction }) => { > {selectedRowIndex === id && selectedRowPartition === partition &&
} - {tabValue === tabs[1] ? message?.id : message?.message_seq} - {tabValue === tabs[1] ? parsingDate(message?.message?.time_sent, true) : parsingDate(message?.created_at, true)} - {tabValue === tabs[1] ? messageParser('string', message?.message?.data) : messageParser('string', message?.data)} + + +
@@ -343,23 +344,29 @@ const Messages = ({ referredFunction }) => { -
- handleScroll()} - overscan={100} - itemContent={(index, message) => listGenerator(index, message)} - /> -
+ {loading ? ( +
+ +
+ ) : ( +
+ handleScroll()} + overscan={100} + itemContent={(index, message) => listGenerator(index, message)} + /> +
+ )} ); }; @@ -597,7 +604,7 @@ const Messages = ({ referredFunction }) => { showDivider > - {!isCloud() && stationState?.stationPartition !== -1 && ( + {!isCloud() && stationState?.stationPartition !== 1 && ( <> } @@ -616,7 +623,7 @@ const Messages = ({ referredFunction }) => { )} - {stationState?.stationSocketData?.followers?.length > 0 && !isCloud() && stationState?.stationPartition !== -1 && ( + {stationState?.stationSocketData?.followers?.length > 0 && !isCloud() && stationState?.stationPartition !== 1 && ( <> } @@ -702,6 +709,7 @@ const Messages = ({ referredFunction }) => { referredFunction={choseReferredFunction} dismissFunction={() => setChoseReferredFunction(null)} moveToGenralView={() => setActiveTab('general')} + loading={loading} /> )} diff --git a/ui_src/src/domain/stationOverview/stationObservabilty/messages/style.scss b/ui_src/src/domain/stationOverview/stationObservabilty/messages/style.scss index 3f722e732..48ba012a3 100644 --- a/ui_src/src/domain/stationOverview/stationObservabilty/messages/style.scss +++ b/ui_src/src/domain/stationOverview/stationObservabilty/messages/style.scss @@ -216,6 +216,11 @@ display: flex; flex-direction: column; position: relative; + .loading { + display: flex; + justify-content: center; + padding-top: 50px; + } .coulmns-table { border-bottom: 1px solid #e9e9e9; diff --git a/ui_src/src/domain/stationOverview/stationOverviewHeader/index.js b/ui_src/src/domain/stationOverview/stationOverviewHeader/index.js index 2a705d0c3..338e12d07 100644 --- a/ui_src/src/domain/stationOverview/stationOverviewHeader/index.js +++ b/ui_src/src/domain/stationOverview/stationOverviewHeader/index.js @@ -45,7 +45,6 @@ import Button from 'components/button'; import Modal from 'components/modal'; import Auditing from '../components/auditing'; import RefreshButton from 'components/refreshButton'; -import AsyncTasks from 'components/asyncTasks'; import pathDomains from 'router'; import { StationStoreContext } from '..'; import { TIERED_STORAGE_UPLOAD_INTERVAL, LOCAL_STORAGE_ACCOUNT_ID, LOCAL_STORAGE_ENV, LOCAL_STORAGE_BROKER_HOST } from 'const/localStorageConsts'; @@ -234,7 +233,7 @@ const StationOverviewHeader = ({ refresh }) => {
handleRefreshStationData()} isLoading={isLoading} /> {stationState?.stationMetaData?.partitions_number > 1 && ( - + )}