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
79ec74ef
Commit
79ec74ef
authored
Dec 14, 2022
by
Yuri Mikhin
Committed by
Yuri Mikhin
Dec 19, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move ChartWidget to ui/shared/chart.
parent
59c3d6f9
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
69 additions
and
41 deletions
+69
-41
stats.ts
types/api/stats.ts
+6
-4
ChartWidget.tsx
ui/shared/chart/ChartWidget.tsx
+5
-33
ChartWidgetGraph.tsx
ui/shared/chart/ChartWidgetGraph.tsx
+1
-1
ChartWidgetSkeleton.tsx
ui/shared/chart/ChartWidgetSkeleton.tsx
+0
-0
FullscreenChartModal.tsx
ui/shared/chart/FullscreenChartModal.tsx
+1
-1
ChartWidgetContainer.tsx
ui/stats/ChartWidgetContainer.tsx
+54
-0
ChartsWidgetsList.tsx
ui/stats/ChartsWidgetsList.tsx
+2
-2
No files found.
types/api/stats.ts
View file @
79ec74ef
...
@@ -24,8 +24,10 @@ export type Stats = {
...
@@ -24,8 +24,10 @@ export type Stats = {
}
}
export
type
Charts
=
{
export
type
Charts
=
{
'
chart
'
:
Array
<
{
chart
:
Array
<
ChartsItem
>
;
date
:
string
;
}
value
:
string
;
}
>
;
export
type
ChartsItem
=
{
date
:
string
;
value
:
string
;
}
}
ui/s
tats
/ChartWidget.tsx
→
ui/s
hared/chart
/ChartWidget.tsx
View file @
79ec74ef
import
{
Box
,
Grid
,
Heading
,
Icon
,
IconButton
,
Menu
,
MenuButton
,
MenuItem
,
MenuList
,
Text
,
useColorModeValue
,
VisuallyHidden
}
from
'
@chakra-ui/react
'
;
import
{
Box
,
Grid
,
Heading
,
Icon
,
IconButton
,
Menu
,
MenuButton
,
MenuItem
,
MenuList
,
Text
,
useColorModeValue
,
VisuallyHidden
}
from
'
@chakra-ui/react
'
;
import
{
useQuery
}
from
'
@tanstack/react-query
'
;
import
React
,
{
useCallback
,
useState
}
from
'
react
'
;
import
React
,
{
useCallback
,
useState
}
from
'
react
'
;
import
type
{
Charts
}
from
'
types/api/stats
'
;
import
type
{
TimeChartItem
}
from
'
./types
'
;
import
{
QueryKeys
}
from
'
types/client/queries
'
;
import
type
{
StatsIntervalIds
}
from
'
types/client/stats
'
;
import
repeatArrow
from
'
icons/repeat_arrow.svg
'
;
import
repeatArrow
from
'
icons/repeat_arrow.svg
'
;
import
dotsIcon
from
'
icons/vertical_dots.svg
'
;
import
dotsIcon
from
'
icons/vertical_dots.svg
'
;
import
useFetch
from
'
lib/hooks/useFetch
'
;
import
ChartWidgetGraph
from
'
./ChartWidgetGraph
'
;
import
ChartWidgetGraph
from
'
./ChartWidgetGraph
'
;
import
ChartWidgetSkeleton
from
'
./ChartWidgetSkeleton
'
;
import
ChartWidgetSkeleton
from
'
./ChartWidgetSkeleton
'
;
import
{
STATS_INTERVALS
}
from
'
./constants
'
;
import
FullscreenChartModal
from
'
./FullscreenChartModal
'
;
import
FullscreenChartModal
from
'
./FullscreenChartModal
'
;
type
Props
=
{
type
Props
=
{
i
d
:
string
;
i
tems
?:
Array
<
TimeChartItem
>
;
title
:
string
;
title
:
string
;
description
:
string
;
description
:
string
;
i
nterval
:
StatsIntervalIds
;
i
sLoading
:
boolean
;
}
}
function
formatDate
(
date
:
Date
)
{
const
ChartWidget
=
({
items
,
title
,
description
,
isLoading
}:
Props
)
=>
{
return
date
.
toISOString
().
substring
(
0
,
10
);
}
const
ChartWidget
=
({
id
,
title
,
description
,
interval
}:
Props
)
=>
{
const
fetch
=
useFetch
();
const
selectedInterval
=
STATS_INTERVALS
[
interval
];
const
[
isFullscreen
,
setIsFullscreen
]
=
useState
(
false
);
const
[
isFullscreen
,
setIsFullscreen
]
=
useState
(
false
);
const
[
isZoomResetInitial
,
setIsZoomResetInitial
]
=
React
.
useState
(
true
);
const
[
isZoomResetInitial
,
setIsZoomResetInitial
]
=
React
.
useState
(
true
);
const
endDate
=
selectedInterval
.
start
?
formatDate
(
new
Date
())
:
undefined
;
const
startDate
=
selectedInterval
.
start
?
formatDate
(
selectedInterval
.
start
)
:
undefined
;
const
menuButtonColor
=
useColorModeValue
(
'
black
'
,
'
white
'
);
const
menuButtonColor
=
useColorModeValue
(
'
black
'
,
'
white
'
);
const
borderColor
=
useColorModeValue
(
'
gray.200
'
,
'
gray.600
'
);
const
borderColor
=
useColorModeValue
(
'
gray.200
'
,
'
gray.600
'
);
const
url
=
`/node-api/stats/charts?name=
${
id
}${
startDate
?
`&from=
${
startDate
}
&to=
${
endDate
}
`
:
''
}
`
;
const
{
data
,
isLoading
}
=
useQuery
<
unknown
,
unknown
,
Charts
>
(
[
QueryKeys
.
charts
,
id
,
startDate
],
async
()
=>
await
fetch
(
url
),
);
const
handleZoom
=
useCallback
(()
=>
{
const
handleZoom
=
useCallback
(()
=>
{
setIsZoomResetInitial
(
false
);
setIsZoomResetInitial
(
false
);
},
[]);
},
[]);
...
@@ -75,12 +52,7 @@ const ChartWidget = ({ id, title, description, interval }: Props) => {
...
@@ -75,12 +52,7 @@ const ChartWidget = ({ id, title, description, interval }: Props) => {
return
<
ChartWidgetSkeleton
/>;
return
<
ChartWidgetSkeleton
/>;
}
}
if
(
data
)
{
if
(
items
)
{
const
items
=
data
.
chart
.
map
((
item
)
=>
{
return
{
date
:
new
Date
(
item
.
date
),
value
:
Number
(
item
.
value
)
};
});
return
(
return
(
<>
<>
<
Box
<
Box
...
...
ui/s
tats
/ChartWidgetGraph.tsx
→
ui/s
hared/chart
/ChartWidgetGraph.tsx
View file @
79ec74ef
...
@@ -78,7 +78,7 @@ const ChartWidgetGraph = ({ items, onZoom, isZoomResetInitial, title }: Props) =
...
@@ -78,7 +78,7 @@ const ChartWidgetGraph = ({ items, onZoom, isZoomResetInitial, title }: Props) =
xScale=
{
xScale
}
xScale=
{
xScale
}
yScale=
{
yScale
}
yScale=
{
yScale
}
stroke=
{
color
}
stroke=
{
color
}
animation=
"
left
"
animation=
"
none
"
strokeWidth=
{
3
}
strokeWidth=
{
3
}
/>
/>
...
...
ui/s
tats
/ChartWidgetSkeleton.tsx
→
ui/s
hared/chart
/ChartWidgetSkeleton.tsx
View file @
79ec74ef
File moved
ui/s
tats
/FullscreenChartModal.tsx
→
ui/s
hared/chart
/FullscreenChartModal.tsx
View file @
79ec74ef
import
{
Button
,
Flex
,
Heading
,
Modal
,
ModalBody
,
ModalCloseButton
,
ModalContent
,
ModalHeader
,
ModalOverlay
}
from
'
@chakra-ui/react
'
;
import
{
Button
,
Flex
,
Heading
,
Modal
,
ModalBody
,
ModalCloseButton
,
ModalContent
,
ModalHeader
,
ModalOverlay
}
from
'
@chakra-ui/react
'
;
import
React
,
{
useCallback
}
from
'
react
'
;
import
React
,
{
useCallback
}
from
'
react
'
;
import
type
{
TimeChartItem
}
from
'
.
./shared/chart
/types
'
;
import
type
{
TimeChartItem
}
from
'
./types
'
;
import
ChartWidgetGraph
from
'
./ChartWidgetGraph
'
;
import
ChartWidgetGraph
from
'
./ChartWidgetGraph
'
;
...
...
ui/stats/ChartWidgetContainer.tsx
0 → 100644
View file @
79ec74ef
import
{
useQuery
}
from
'
@tanstack/react-query
'
;
import
React
from
'
react
'
;
import
type
{
Charts
}
from
'
types/api/stats
'
;
import
{
QueryKeys
}
from
'
types/client/queries
'
;
import
type
{
StatsIntervalIds
}
from
'
types/client/stats
'
;
import
useFetch
from
'
lib/hooks/useFetch
'
;
import
ChartWidget
from
'
../shared/chart/ChartWidget
'
;
import
{
STATS_INTERVALS
}
from
'
./constants
'
;
type
Props
=
{
id
:
string
;
title
:
string
;
description
:
string
;
interval
:
StatsIntervalIds
;
}
function
formatDate
(
date
:
Date
)
{
return
date
.
toISOString
().
substring
(
0
,
10
);
}
const
ChartWidgetContainer
=
({
id
,
title
,
description
,
interval
}:
Props
)
=>
{
const
fetch
=
useFetch
();
const
selectedInterval
=
STATS_INTERVALS
[
interval
];
const
endDate
=
selectedInterval
.
start
?
formatDate
(
new
Date
())
:
undefined
;
const
startDate
=
selectedInterval
.
start
?
formatDate
(
selectedInterval
.
start
)
:
undefined
;
const
url
=
`/node-api/stats/charts?name=
${
id
}${
startDate
?
`&from=
${
startDate
}
&to=
${
endDate
}
`
:
''
}
`
;
const
{
data
,
isLoading
}
=
useQuery
<
unknown
,
unknown
,
Charts
>
(
[
QueryKeys
.
charts
,
id
,
startDate
],
async
()
=>
await
fetch
(
url
),
);
const
items
=
data
?.
chart
.
map
((
item
)
=>
{
return
{
date
:
new
Date
(
item
.
date
),
value
:
Number
(
item
.
value
)
};
});
return
(
<
ChartWidget
items=
{
items
}
title=
{
title
}
description=
{
description
}
isLoading=
{
isLoading
}
/>
);
};
export
default
ChartWidgetContainer
;
ui/stats/ChartsWidgetsList.tsx
View file @
79ec74ef
...
@@ -6,7 +6,7 @@ import type { StatsIntervalIds, StatsSection } from 'types/client/stats';
...
@@ -6,7 +6,7 @@ import type { StatsIntervalIds, StatsSection } from 'types/client/stats';
import
{
apos
}
from
'
lib/html-entities
'
;
import
{
apos
}
from
'
lib/html-entities
'
;
import
EmptySearchResult
from
'
../apps/EmptySearchResult
'
;
import
EmptySearchResult
from
'
../apps/EmptySearchResult
'
;
import
ChartWidget
from
'
./ChartWidget
'
;
import
ChartWidget
Container
from
'
./ChartWidgetContainer
'
;
type
Props
=
{
type
Props
=
{
charts
:
Array
<
StatsSection
>
;
charts
:
Array
<
StatsSection
>
;
...
@@ -46,7 +46,7 @@ const ChartsWidgetsList = ({ charts, interval }: Props) => {
...
@@ -46,7 +46,7 @@ const ChartsWidgetsList = ({ charts, interval }: Props) => {
<
GridItem
<
GridItem
key=
{
chart
.
id
}
key=
{
chart
.
id
}
>
>
<
ChartWidget
<
ChartWidget
Container
id=
{
chart
.
id
}
id=
{
chart
.
id
}
title=
{
chart
.
title
}
title=
{
chart
.
title
}
description=
{
chart
.
description
}
description=
{
chart
.
description
}
...
...
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