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
c6293a41
Commit
c6293a41
authored
Jul 09, 2024
by
Max Alekseenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
split the rating component into multiple files
parent
273f5dca
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
201 additions
and
3 deletions
+201
-3
MarketplaceAppCard.tsx
ui/marketplace/MarketplaceAppCard.tsx
+1
-1
MarketplaceAppModal.tsx
ui/marketplace/MarketplaceAppModal.tsx
+1
-1
PopoverContent.tsx
ui/marketplace/Rating/PopoverContent.tsx
+73
-0
Rating.tsx
ui/marketplace/Rating/Rating.tsx
+93
-0
Stars.tsx
ui/marketplace/Rating/Stars.tsx
+32
-0
useRatings.tsx
ui/marketplace/Rating/useRatings.tsx
+0
-0
useMarketplaceApps.tsx
ui/marketplace/useMarketplaceApps.tsx
+1
-1
No files found.
ui/marketplace/MarketplaceAppCard.tsx
View file @
c6293a41
...
...
@@ -10,7 +10,7 @@ import IconSvg from 'ui/shared/IconSvg';
import
AppSecurityReport
from
'
./AppSecurityReport
'
;
import
MarketplaceAppCardLink
from
'
./MarketplaceAppCardLink
'
;
import
MarketplaceAppIntegrationIcon
from
'
./MarketplaceAppIntegrationIcon
'
;
import
Rating
from
'
./Rating
'
;
import
Rating
from
'
./Rating
/Rating
'
;
interface
Props
extends
MarketplaceAppWithSecurityReport
{
onInfoClick
:
(
id
:
string
)
=>
void
;
...
...
ui/marketplace/MarketplaceAppModal.tsx
View file @
c6293a41
...
...
@@ -15,7 +15,7 @@ import IconSvg from 'ui/shared/IconSvg';
import
AppSecurityReport
from
'
./AppSecurityReport
'
;
import
MarketplaceAppModalLink
from
'
./MarketplaceAppModalLink
'
;
import
Rating
from
'
./Rating
'
;
import
Rating
from
'
./Rating
/Rating
'
;
type
Props
=
{
onClose
:
()
=>
void
;
...
...
ui/marketplace/Rating/PopoverContent.tsx
0 → 100644
View file @
c6293a41
import
{
Text
,
Flex
,
Spinner
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
import
Stars
from
'
./Stars
'
;
const
ratingDescriptions
=
[
'
Terrible
'
,
'
Poor
'
,
'
Average
'
,
'
Very good
'
,
'
Outstanding
'
];
type
Props
=
{
appId
:
string
;
recordId
?:
string
;
isRatedByUser
?:
boolean
;
rate
:
(
appId
:
string
,
recordId
:
string
|
undefined
,
rating
:
number
)
=>
void
;
isSending
?:
boolean
;
};
const
PopoverContent
=
({
appId
,
recordId
,
isRatedByUser
,
rate
,
isSending
}:
Props
)
=>
{
const
[
hovered
,
setHovered
]
=
React
.
useState
(
-
1
);
const
handleMouseOverFactory
=
React
.
useCallback
((
index
:
number
)
=>
()
=>
{
setHovered
(
index
);
},
[]);
const
handleMouseOut
=
React
.
useCallback
(()
=>
{
setHovered
(
-
1
);
},
[]);
const
handleRateFactory
=
React
.
useCallback
((
index
:
number
)
=>
()
=>
{
rate
(
appId
,
recordId
,
index
+
1
);
},
[
appId
,
recordId
,
rate
]);
if
(
isRatedByUser
)
{
return
(
<
Flex
alignItems=
"center"
>
<
IconSvg
name=
"check_circle"
color=
"green.500"
boxSize=
{
8
}
/>
<
Text
fontSize=
"md"
ml=
{
3
}
>
App is already rated
</
Text
>
</
Flex
>
);
}
if
(
isSending
)
{
return
(
<
Flex
alignItems=
"center"
>
<
Spinner
size=
"md"
/>
<
Text
fontSize=
"md"
ml=
{
3
}
>
Sending your feedback
</
Text
>
</
Flex
>
);
}
return
(
<>
<
Text
fontWeight=
"500"
fontSize=
"xs"
lineHeight=
"30px"
variant=
"secondary"
>
How was your experience?
</
Text
>
<
Flex
alignItems=
"center"
h=
"32px"
>
<
Stars
filledIndex=
{
hovered
}
onMouseOverFactory=
{
handleMouseOverFactory
}
onMouseOut=
{
handleMouseOut
}
onClickFactory=
{
handleRateFactory
}
/>
{
hovered
>=
0
&&
(
<
Text
fontSize=
"md"
ml=
{
2
}
>
{
ratingDescriptions
[
hovered
]
}
</
Text
>
)
}
</
Flex
>
</>
);
};
export
default
PopoverContent
;
ui/marketplace/Rating.tsx
→
ui/marketplace/Rating
/Rating
.tsx
View file @
c6293a41
import
{
Text
,
Popover
,
PopoverTrigger
,
PopoverBody
,
PopoverContent
,
useDisclosure
,
Button
,
Flex
,
Spinner
,
Skeleton
,
chakra
,
useColorModeValue
,
Text
,
Popover
,
PopoverTrigger
,
PopoverBody
,
PopoverContent
,
useDisclosure
,
Button
,
Skeleton
,
chakra
,
useColorModeValue
,
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
type
{
MouseEventHandler
}
from
'
react
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
const
ratingDescriptions
=
[
'
Terrible
'
,
'
Poor
'
,
'
Average
'
,
'
Very good
'
,
'
Outstanding
'
];
import
Content
from
'
./PopoverContent
'
;
import
Stars
from
'
./Stars
'
;
type
StarsProps
=
{
filledIndex
:
number
;
onMouseOverFactory
?:
(
index
:
number
)
=>
MouseEventHandler
<
HTMLDivElement
>
;
onMouseOut
?:
()
=>
void
;
onClickFactory
?:
(
index
:
number
)
=>
MouseEventHandler
<
HTMLDivElement
>
;
};
const
Stars
=
({
filledIndex
,
onMouseOverFactory
,
onMouseOut
,
onClickFactory
}:
StarsProps
)
=>
(
<>
{
Array
(
5
).
fill
(
null
).
map
((
_
,
index
)
=>
(
<
IconSvg
key=
{
index
}
name=
{
filledIndex
>=
index
?
'
star_filled
'
:
'
star_outline
'
}
color=
{
filledIndex
>=
index
?
'
yellow.400
'
:
'
gray.400
'
}
w=
{
6
}
// 5 + 1 padding
h=
{
5
}
pr=
{
1
}
// use padding intead of margin so that there are no empty spaces between stars without hover effect
cursor=
{
onMouseOverFactory
?
'
pointer
'
:
'
default
'
}
onMouseOver=
{
onMouseOverFactory
?.(
index
)
}
onMouseOut=
{
onMouseOut
}
onClick=
{
onClickFactory
?.(
index
)
}
/>
))
}
</>
);
type
ContentProps
=
{
appId
:
string
;
recordId
?:
string
;
isRatedByUser
?:
boolean
;
rate
:
(
appId
:
string
,
recordId
:
string
|
undefined
,
rating
:
number
)
=>
void
;
isSending
?:
boolean
;
};
const
Content
=
({
appId
,
recordId
,
isRatedByUser
,
rate
,
isSending
}:
ContentProps
)
=>
{
const
[
hovered
,
setHovered
]
=
React
.
useState
(
-
1
);
const
handleMouseOverFactory
=
React
.
useCallback
((
index
:
number
)
=>
()
=>
{
setHovered
(
index
);
},
[]);
const
handleMouseOut
=
React
.
useCallback
(()
=>
{
setHovered
(
-
1
);
},
[]);
const
handleRateFactory
=
React
.
useCallback
((
index
:
number
)
=>
()
=>
{
rate
(
appId
,
recordId
,
index
+
1
);
},
[
appId
,
recordId
,
rate
]);
if
(
isRatedByUser
)
{
return
(
<
Flex
alignItems=
"center"
>
<
IconSvg
name=
"check_circle"
color=
"green.500"
boxSize=
{
8
}
/>
<
Text
fontSize=
"md"
ml=
{
3
}
>
App is already rated
</
Text
>
</
Flex
>
);
}
if
(
isSending
)
{
return
(
<
Flex
alignItems=
"center"
>
<
Spinner
size=
"md"
/>
<
Text
fontSize=
"md"
ml=
{
3
}
>
Sending your feedback
</
Text
>
</
Flex
>
);
}
return
(
<>
<
Text
fontWeight=
"500"
fontSize=
"xs"
lineHeight=
"30px"
variant=
"secondary"
>
How was your experience?
</
Text
>
<
Flex
alignItems=
"center"
h=
"32px"
>
<
Stars
filledIndex=
{
hovered
}
onMouseOverFactory=
{
handleMouseOverFactory
}
onMouseOut=
{
handleMouseOut
}
onClickFactory=
{
handleRateFactory
}
/>
{
hovered
>=
0
&&
(
<
Text
fontSize=
"md"
ml=
{
2
}
>
{
ratingDescriptions
[
hovered
]
}
</
Text
>
)
}
</
Flex
>
</>
);
};
type
RatingProps
=
{
type
Props
=
{
appId
:
string
;
rating
?:
number
;
recordId
?:
string
;
...
...
@@ -109,7 +20,7 @@ type RatingProps = {
fullView
?:
boolean
;
};
const
Rating
=
({
appId
,
rating
,
recordId
,
isRatedByUser
,
rate
,
isSending
,
isLoading
,
fullView
}:
Rating
Props
)
=>
{
const
Rating
=
({
appId
,
rating
,
recordId
,
isRatedByUser
,
rate
,
isSending
,
isLoading
,
fullView
}:
Props
)
=>
{
const
{
isOpen
,
onToggle
,
onClose
}
=
useDisclosure
();
const
textColor
=
useColorModeValue
(
'
blackAlpha.800
'
,
'
whiteAlpha.800
'
);
...
...
ui/marketplace/Rating/Stars.tsx
0 → 100644
View file @
c6293a41
import
React
from
'
react
'
;
import
type
{
MouseEventHandler
}
from
'
react
'
;
import
IconSvg
from
'
ui/shared/IconSvg
'
;
type
Props
=
{
filledIndex
:
number
;
onMouseOverFactory
?:
(
index
:
number
)
=>
MouseEventHandler
<
HTMLDivElement
>
;
onMouseOut
?:
()
=>
void
;
onClickFactory
?:
(
index
:
number
)
=>
MouseEventHandler
<
HTMLDivElement
>
;
};
const
Stars
=
({
filledIndex
,
onMouseOverFactory
,
onMouseOut
,
onClickFactory
}:
Props
)
=>
(
<>
{
Array
(
5
).
fill
(
null
).
map
((
_
,
index
)
=>
(
<
IconSvg
key=
{
index
}
name=
{
filledIndex
>=
index
?
'
star_filled
'
:
'
star_outline
'
}
color=
{
filledIndex
>=
index
?
'
yellow.400
'
:
'
gray.400
'
}
w=
{
6
}
// 5 + 1 padding
h=
{
5
}
pr=
{
1
}
// use padding intead of margin so that there are no empty spaces between stars without hover effect
cursor=
{
onMouseOverFactory
?
'
pointer
'
:
'
default
'
}
onMouseOver=
{
onMouseOverFactory
?.(
index
)
}
onMouseOut=
{
onMouseOut
}
onClick=
{
onClickFactory
?.(
index
)
}
/>
))
}
</>
);
export
default
Stars
;
ui/marketplace/useRatings.tsx
→
ui/marketplace/
Rating/
useRatings.tsx
View file @
c6293a41
File moved
ui/marketplace/useMarketplaceApps.tsx
View file @
c6293a41
...
...
@@ -10,7 +10,7 @@ import useApiFetch from 'lib/api/useApiFetch';
import
useFetch
from
'
lib/hooks/useFetch
'
;
import
{
MARKETPLACE_APP
}
from
'
stubs/marketplace
'
;
import
useRatings
from
'
./useRatings
'
;
import
useRatings
from
'
./
Rating/
useRatings
'
;
import
useSecurityReports
from
'
./useSecurityReports
'
;
import
type
{
SortValue
}
from
'
./utils
'
;
...
...
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