Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
c27b97a2
Commit
c27b97a2
authored
Sep 26, 2024
by
isstuev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add url params for resolution and interval
parent
e22db695
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
6 deletions
+46
-6
Chart.tsx
ui/pages/Chart.tsx
+46
-6
No files found.
ui/pages/Chart.tsx
View file @
c27b97a2
import
{
Button
,
Flex
,
IconButton
,
Link
,
Text
}
from
'
@chakra-ui/react
'
;
import
{
Button
,
Flex
,
IconButton
,
Link
,
Text
}
from
'
@chakra-ui/react
'
;
import
type
{
NextRouter
}
from
'
next/router
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
{
Resolution
}
from
'
@blockscout/stats-types
'
;
import
{
Resolution
}
from
'
@blockscout/stats-types
'
;
import
type
{
StatsIntervalIds
}
from
'
types/client/stats
'
;
import
type
{
StatsIntervalIds
}
from
'
types/client/stats
'
;
import
{
StatsIntervalId
}
from
'
types/client/stats
'
;
import
config
from
'
configs/app
'
;
import
config
from
'
configs/app
'
;
import
{
useAppContext
}
from
'
lib/contexts/app
'
;
import
{
useAppContext
}
from
'
lib/contexts/app
'
;
...
@@ -41,11 +43,33 @@ const getIntervalByResolution = (resolution: Resolution): StatsIntervalIds => {
...
@@ -41,11 +43,33 @@ const getIntervalByResolution = (resolution: Resolution): StatsIntervalIds => {
}
}
};
};
const
getIntervalFromQuery
=
(
router
:
NextRouter
):
StatsIntervalIds
|
undefined
=>
{
const
intervalFromQuery
=
getQueryParamString
(
router
.
query
.
interval
);
if
(
!
intervalFromQuery
||
!
Object
.
values
(
StatsIntervalId
).
includes
(
intervalFromQuery
as
StatsIntervalIds
))
{
return
undefined
;
}
return
intervalFromQuery
as
StatsIntervalIds
;
};
const
getResolutionFromQuery
=
(
router
:
NextRouter
)
=>
{
const
resolutionFromQuery
=
getQueryParamString
(
router
.
query
.
resolution
);
if
(
!
resolutionFromQuery
||
!
Resolution
[
resolutionFromQuery
as
keyof
typeof
Resolution
])
{
return
DEFAULT_RESOLUTION
;
}
return
resolutionFromQuery
as
Resolution
;
};
const
Chart
=
()
=>
{
const
Chart
=
()
=>
{
const
router
=
useRouter
();
const
router
=
useRouter
();
const
id
=
getQueryParamString
(
router
.
query
.
id
);
const
id
=
getQueryParamString
(
router
.
query
.
id
);
const
[
intervalState
,
setIntervalState
]
=
React
.
useState
<
StatsIntervalIds
|
undefined
>
();
const
intervalFromQuery
=
getIntervalFromQuery
(
router
);
const
[
resolution
,
setResolution
]
=
React
.
useState
<
Resolution
>
(
DEFAULT_RESOLUTION
);
const
resolutionFromQuery
=
getResolutionFromQuery
(
router
);
const
[
intervalState
,
setIntervalState
]
=
React
.
useState
<
StatsIntervalIds
|
undefined
>
(
intervalFromQuery
);
const
[
resolution
,
setResolution
]
=
React
.
useState
<
Resolution
>
(
resolutionFromQuery
||
DEFAULT_RESOLUTION
);
const
{
zoomRange
,
handleZoom
,
handleZoomReset
}
=
useZoom
();
const
{
zoomRange
,
handleZoom
,
handleZoomReset
}
=
useZoom
();
const
interval
=
intervalState
||
getIntervalByResolution
(
resolution
);
const
interval
=
intervalState
||
getIntervalByResolution
(
resolution
);
...
@@ -69,10 +93,26 @@ const Chart = () => {
...
@@ -69,10 +93,26 @@ const Chart = () => {
};
};
},
[
appProps
.
referrer
]);
},
[
appProps
.
referrer
]);
const
onIntervalChange
=
React
.
useCallback
((
interval
:
StatsIntervalIds
)
=>
{
setIntervalState
(
interval
);
router
.
push
({
pathname
:
router
.
pathname
,
query
:
{
...
router
.
query
,
interval
},
});
},
[
setIntervalState
,
router
]);
const
onResolutionChange
=
React
.
useCallback
((
resolution
:
Resolution
)
=>
{
setResolution
(
resolution
);
router
.
push
({
pathname
:
router
.
pathname
,
query
:
{
...
router
.
query
,
resolution
},
});
},
[
setResolution
,
router
]);
const
handleReset
=
React
.
useCallback
(()
=>
{
const
handleReset
=
React
.
useCallback
(()
=>
{
handleZoomReset
();
handleZoomReset
();
setResolution
(
DEFAULT_RESOLUTION
);
onResolutionChange
(
DEFAULT_RESOLUTION
);
},
[
handleZoomReset
]);
},
[
handleZoomReset
,
onResolutionChange
]);
const
{
items
,
info
,
lineQuery
}
=
useChartQuery
(
id
,
resolution
,
interval
);
const
{
items
,
info
,
lineQuery
}
=
useChartQuery
(
id
,
resolution
,
interval
);
...
@@ -179,14 +219,14 @@ const Chart = () => {
...
@@ -179,14 +219,14 @@ const Chart = () => {
<
Flex
alignItems=
"center"
gap=
{
{
base
:
3
,
lg
:
6
}
}
maxW=
"100%"
overflow=
"hidden"
>
<
Flex
alignItems=
"center"
gap=
{
{
base
:
3
,
lg
:
6
}
}
maxW=
"100%"
overflow=
"hidden"
>
<
Flex
alignItems=
"center"
gap=
{
3
}
>
<
Flex
alignItems=
"center"
gap=
{
3
}
>
<
Text
>
Period
</
Text
>
<
Text
>
Period
</
Text
>
<
ChartIntervalSelect
interval=
{
interval
}
onIntervalChange=
{
setIntervalStat
e
}
/>
<
ChartIntervalSelect
interval=
{
interval
}
onIntervalChange=
{
onIntervalChang
e
}
/>
</
Flex
>
</
Flex
>
{
lineQuery
.
data
?.
info
?.
resolutions
&&
lineQuery
.
data
?.
info
?.
resolutions
.
length
>
1
&&
(
{
lineQuery
.
data
?.
info
?.
resolutions
&&
lineQuery
.
data
?.
info
?.
resolutions
.
length
>
1
&&
(
<
Flex
alignItems=
"center"
gap=
{
3
}
>
<
Flex
alignItems=
"center"
gap=
{
3
}
>
<
Text
>
{
isMobile
?
'
Res.
'
:
'
Resolution
'
}
</
Text
>
<
Text
>
{
isMobile
?
'
Res.
'
:
'
Resolution
'
}
</
Text
>
<
ChartResolutionSelect
<
ChartResolutionSelect
resolution=
{
resolution
}
resolution=
{
resolution
}
onResolutionChange=
{
setResolution
}
onResolutionChange=
{
onResolutionChange
}
resolutions=
{
lineQuery
.
data
?.
info
?.
resolutions
||
[]
}
resolutions=
{
lineQuery
.
data
?.
info
?.
resolutions
||
[]
}
/>
/>
</
Flex
>
</
Flex
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment