1- import React , { useEffect , useState , useCallback } from 'react'
1+ import React , { useEffect , useState , useCallback , useRef } from 'react'
22import {
33 Alert ,
44 Box ,
@@ -68,6 +68,7 @@ export const ActionBar = ({
6868 const [ maxDepthNonFull , setMaxDepthNonFull ] = useState < number | null > ( null )
6969 const [ prevObjectsCount , setPrevObjectsCount ] = useState < number | null > ( null )
7070 const [ prevDepth , setPrevDepth ] = useState < number | null > ( null )
71+ const snackbarTimeoutRef = useRef < NodeJS . Timeout | null > ( null )
7172
7273 useEffect ( ( ) => {
7374 const resetLimitState = ( ) => {
@@ -134,21 +135,50 @@ export const ActionBar = ({
134135 const requestedDepth = parseInt ( e . target . value , 10 ) || 0 ;
135136 const currentMaxDepth = isFull ? maxDepthFull : maxDepthNonFull ;
136137
137- // Verifica se o usuário está tentando ultrapassar o limite conhecido
138- if ( currentMaxDepth !== null && requestedDepth > currentMaxDepth ) {
139- setDepth ( currentMaxDepth ) ;
140- searchParams . set ( 'depth' , currentMaxDepth . toString ( ) ) ;
141- setSearchParams ( searchParams ) ;
142- setSnackbarMessage ( "You've reached the maximum depth" ) ;
138+ if ( ! namespace || ! name ) {
139+ setSnackbarMessage ( "Namespace or name is missing" ) ;
140+
143141 setOpenSnackbar ( true ) ;
142+ if ( snackbarTimeoutRef . current ) clearTimeout ( snackbarTimeoutRef . current ) ;
143+ snackbarTimeoutRef . current = setTimeout ( ( ) => {
144+ setOpenSnackbar ( false ) ;
145+ setLoading ( false ) ;
146+ } , 2000 ) ;
147+
148+ return ;
149+ }
150+
151+
152+ if ( currentMaxDepth !== null && requestedDepth <= currentMaxDepth ) {
153+ setDepth ( requestedDepth ) ;
154+ searchParams . set ( 'depth' , requestedDepth . toString ( ) ) ;
155+ setSearchParams ( searchParams ) ;
144156 setLoading ( false ) ;
145157 return ;
146158 }
147159
148- if ( ! namespace || ! name ) {
149- setSnackbarMessage ( "Namespace or name is missing" ) ;
160+ if ( currentMaxDepth !== null && requestedDepth > currentMaxDepth ) {
161+ setSnackbarMessage ( "You've reached the maximum depth" ) ;
162+
150163 setOpenSnackbar ( true ) ;
151- setLoading ( false ) ;
164+ if ( snackbarTimeoutRef . current ) clearTimeout ( snackbarTimeoutRef . current ) ;
165+ snackbarTimeoutRef . current = setTimeout ( ( ) => {
166+ setOpenSnackbar ( false ) ;
167+ setLoading ( false ) ;
168+ } , 2000 ) ;
169+
170+ if ( isFull && maxDepthFull === null ) {
171+ setMaxDepthFull ( currentMaxDepth ) ;
172+ localStorage . setItem ( 'maxDepthFull' , currentMaxDepth . toString ( ) ) ;
173+ } else if ( ! isFull && maxDepthNonFull === null ) {
174+ setMaxDepthNonFull ( currentMaxDepth ) ;
175+ localStorage . setItem ( 'maxDepthNonFull' , currentMaxDepth . toString ( ) ) ;
176+ }
177+
178+ setDepth ( currentMaxDepth ) ;
179+ searchParams . set ( 'depth' , currentMaxDepth . toString ( ) ) ;
180+ setSearchParams ( searchParams ) ;
181+
152182 return ;
153183 }
154184
@@ -162,44 +192,60 @@ export const ActionBar = ({
162192
163193 const objectsCount = isFull ? totalObjects : visibleObjectsCount ;
164194
165- if ( currentMaxDepth === null && requestedDepth > depth ) { // Calcula o maxDepth apenas uma vez
166- if ( prevObjectsCount !== null && objectsCount <= prevObjectsCount ) {
167- const newMaxDepth = requestedDepth - 1 ;
168-
169- if ( isFull ) {
170- setMaxDepthFull ( newMaxDepth ) ;
171- localStorage . setItem ( 'maxDepthFull' , newMaxDepth . toString ( ) ) ;
172- } else {
173- setMaxDepthNonFull ( newMaxDepth ) ;
174- localStorage . setItem ( 'maxDepthNonFull' , newMaxDepth . toString ( ) ) ;
175- }
176-
177- setDepth ( newMaxDepth ) ;
178- searchParams . set ( 'depth' , newMaxDepth . toString ( ) ) ;
179- setSearchParams ( searchParams ) ;
195+ setDepth ( requestedDepth ) ;
196+ searchParams . set ( 'depth' , requestedDepth . toString ( ) ) ;
197+ setSearchParams ( searchParams ) ;
198+ setPrevObjectsCount ( objectsCount ) ;
199+
200+ if ( prevObjectsCount !== null && objectsCount <= prevObjectsCount ) {
201+ const newMaxDepth = requestedDepth - 1 ;
202+
203+ if ( isFull && maxDepthFull === null ) {
204+ setMaxDepthFull ( newMaxDepth ) ;
180205 setSnackbarMessage ( "You've reached the maximum depth" ) ;
181206 setOpenSnackbar ( true ) ;
182- } else {
183- setDepth ( requestedDepth ) ;
184- searchParams . set ( 'depth' , requestedDepth . toString ( ) ) ;
185- setSearchParams ( searchParams ) ;
186- setPrevObjectsCount ( objectsCount ) ;
207+
208+ if ( snackbarTimeoutRef . current ) clearTimeout ( snackbarTimeoutRef . current ) ;
209+ snackbarTimeoutRef . current = setTimeout ( ( ) => {
210+ setOpenSnackbar ( false ) ;
211+ } , 2000 ) ;
212+
213+ localStorage . setItem ( 'maxDepthFull' , newMaxDepth . toString ( ) ) ;
214+ } else if ( ! isFull && maxDepthNonFull === null ) {
215+ setMaxDepthNonFull ( newMaxDepth ) ;
216+ setSnackbarMessage ( "You've reached the maximum depth" ) ;
217+ setOpenSnackbar ( true ) ;
218+
219+ if ( snackbarTimeoutRef . current ) clearTimeout ( snackbarTimeoutRef . current ) ;
220+ snackbarTimeoutRef . current = setTimeout ( ( ) => {
221+ setOpenSnackbar ( false ) ;
222+ } , 2000 ) ;
223+
224+ localStorage . setItem ( 'maxDepthNonFull' , newMaxDepth . toString ( ) ) ;
187225 }
188- } else {
189- // Permite alterar o depth livremente dentro do limite
190- setDepth ( requestedDepth ) ;
191- searchParams . set ( 'depth' , requestedDepth . toString ( ) ) ;
192- setSearchParams ( searchParams ) ;
193- setPrevObjectsCount ( objectsCount ) ;
194226 }
195227 } else {
196228 setSnackbarMessage ( "Failed to fetch lineage data" ) ;
229+
197230 setOpenSnackbar ( true ) ;
231+ if ( snackbarTimeoutRef . current ) clearTimeout ( snackbarTimeoutRef . current ) ;
232+ snackbarTimeoutRef . current = setTimeout ( ( ) => {
233+ setOpenSnackbar ( false ) ;
234+ setLoading ( false ) ;
235+ } , 2000 ) ;
236+
198237 console . error ( 'Failed to fetch lineage data' ) ;
199238 }
200239 } catch ( error ) {
201240 setSnackbarMessage ( "Error fetching lineage data" ) ;
241+
202242 setOpenSnackbar ( true ) ;
243+ if ( snackbarTimeoutRef . current ) clearTimeout ( snackbarTimeoutRef . current ) ;
244+ snackbarTimeoutRef . current = setTimeout ( ( ) => {
245+ setOpenSnackbar ( false ) ;
246+ setLoading ( false ) ;
247+ } , 2000 ) ;
248+
203249 console . error ( 'Error fetching lineage data:' , error ) ;
204250 }
205251
@@ -208,8 +254,12 @@ export const ActionBar = ({
208254 } ;
209255
210256 const handleCloseSnackbar = useCallback ( ( ) => {
211- setOpenSnackbar ( false )
212- } , [ ] )
257+ setOpenSnackbar ( false ) ;
258+ if ( snackbarTimeoutRef . current ) {
259+ clearTimeout ( snackbarTimeoutRef . current )
260+ snackbarTimeoutRef . current = null
261+ }
262+ } , [ ] ) ;
213263
214264 const handleAllDependenciesToggle = useCallback ( ( checked : boolean ) => {
215265 setIsFull ( checked )
@@ -320,7 +370,7 @@ export const ActionBar = ({
320370 </ MQTooltip >
321371 </ Box >
322372 </ Box >
323- < Snackbar open = { openSnackbar } autoHideDuration = { 1500 } onClose = { handleCloseSnackbar } >
373+ < Snackbar open = { openSnackbar } onClose = { handleCloseSnackbar } >
324374 < Alert
325375 onClose = { handleCloseSnackbar }
326376 severity = 'info'
0 commit comments