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
64c4d1cd
Commit
64c4d1cd
authored
Aug 27, 2024
by
Max Alekseenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add rating count
parent
18eb8120
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
5 deletions
+11
-5
marketplace.ts
types/client/marketplace.ts
+1
-0
Rating.tsx
ui/marketplace/Rating/Rating.tsx
+2
-0
TriggerButton.tsx
ui/marketplace/Rating/TriggerButton.tsx
+5
-3
useRatings.tsx
ui/marketplace/Rating/useRatings.tsx
+3
-2
No files found.
types/client/marketplace.ts
View file @
64c4d1cd
...
@@ -29,6 +29,7 @@ export type MarketplaceAppOverview = MarketplaceAppPreview & MarketplaceAppSocia
...
@@ -29,6 +29,7 @@ export type MarketplaceAppOverview = MarketplaceAppPreview & MarketplaceAppSocia
export
type
AppRating
=
{
export
type
AppRating
=
{
recordId
:
string
;
recordId
:
string
;
value
:
number
|
undefined
;
value
:
number
|
undefined
;
count
?:
number
;
}
}
export
type
MarketplaceAppWithSecurityReport
=
MarketplaceAppOverview
&
{
export
type
MarketplaceAppWithSecurityReport
=
MarketplaceAppOverview
&
{
...
...
ui/marketplace/Rating/Rating.tsx
View file @
64c4d1cd
...
@@ -51,6 +51,7 @@ const Rating = ({
...
@@ -51,6 +51,7 @@ const Rating = ({
<>
<>
<
Stars
filledIndex=
{
(
rating
?.
value
||
0
)
-
1
}
/>
<
Stars
filledIndex=
{
(
rating
?.
value
||
0
)
-
1
}
/>
<
Text
fontSize=
"md"
ml=
{
2
}
>
{
rating
?.
value
}
</
Text
>
<
Text
fontSize=
"md"
ml=
{
2
}
>
{
rating
?.
value
}
</
Text
>
{
rating
?.
count
&&
<
Text
variant=
"secondary"
fontSize=
"md"
ml=
{
1
}
>
(
{
rating
?.
count
}
)
</
Text
>
}
</>
</>
)
}
)
}
<
Box
ref=
{
popoverRef
}
>
<
Box
ref=
{
popoverRef
}
>
...
@@ -58,6 +59,7 @@ const Rating = ({
...
@@ -58,6 +59,7 @@ const Rating = ({
<
PopoverTrigger
>
<
PopoverTrigger
>
<
TriggerButton
<
TriggerButton
rating=
{
rating
?.
value
}
rating=
{
rating
?.
value
}
count=
{
rating
?.
count
}
fullView=
{
fullView
}
fullView=
{
fullView
}
isActive=
{
isOpen
}
isActive=
{
isOpen
}
onClick=
{
onToggle
}
onClick=
{
onToggle
}
...
...
ui/marketplace/Rating/TriggerButton.tsx
View file @
64c4d1cd
import
{
Button
,
chakra
,
useColorModeValue
,
Tooltip
,
useDisclosure
}
from
'
@chakra-ui/react
'
;
import
{
Button
,
chakra
,
useColorModeValue
,
Tooltip
,
useDisclosure
,
Text
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
...
@@ -7,6 +7,7 @@ import IconSvg from 'ui/shared/IconSvg';
...
@@ -7,6 +7,7 @@ import IconSvg from 'ui/shared/IconSvg';
type
Props
=
{
type
Props
=
{
rating
?:
number
;
rating
?:
number
;
count
?:
number
;
fullView
?:
boolean
;
fullView
?:
boolean
;
isActive
:
boolean
;
isActive
:
boolean
;
onClick
:
()
=>
void
;
onClick
:
()
=>
void
;
...
@@ -24,7 +25,7 @@ const getTooltipText = (canRate: boolean | undefined) => {
...
@@ -24,7 +25,7 @@ const getTooltipText = (canRate: boolean | undefined) => {
};
};
const
TriggerButton
=
(
const
TriggerButton
=
(
{
rating
,
fullView
,
isActive
,
onClick
,
canRate
}:
Props
,
{
rating
,
count
,
fullView
,
isActive
,
onClick
,
canRate
}:
Props
,
ref
:
React
.
ForwardedRef
<
HTMLButtonElement
>
,
ref
:
React
.
ForwardedRef
<
HTMLButtonElement
>
,
)
=>
{
)
=>
{
const
textColor
=
useColorModeValue
(
'
blackAlpha.800
'
,
'
whiteAlpha.800
'
);
const
textColor
=
useColorModeValue
(
'
blackAlpha.800
'
,
'
whiteAlpha.800
'
);
...
@@ -75,8 +76,9 @@ const TriggerButton = (
...
@@ -75,8 +76,9 @@ const TriggerButton = (
/>
/>
)
}
)
}
{
(
rating
&&
!
fullView
)
?
(
{
(
rating
&&
!
fullView
)
?
(
<
chakra
.
span
color=
{
textColor
}
transition=
"inherit"
>
<
chakra
.
span
color=
{
textColor
}
transition=
"inherit"
display=
"inline-flex"
>
{
rating
}
{
rating
}
<
Text
variant=
"secondary"
ml=
{
1
}
>
(
{
count
}
)
</
Text
>
</
chakra
.
span
>
</
chakra
.
span
>
)
:
(
)
:
(
'
Rate it!
'
'
Rate it!
'
...
...
ui/marketplace/Rating/useRatings.tsx
View file @
64c4d1cd
...
@@ -28,11 +28,12 @@ export type RateFunction = (
...
@@ -28,11 +28,12 @@ export type RateFunction = (
function
formatRatings
(
data
:
Airtable
.
Records
<
Airtable
.
FieldSet
>
)
{
function
formatRatings
(
data
:
Airtable
.
Records
<
Airtable
.
FieldSet
>
)
{
return
data
.
reduce
((
acc
:
Record
<
string
,
AppRating
>
,
record
)
=>
{
return
data
.
reduce
((
acc
:
Record
<
string
,
AppRating
>
,
record
)
=>
{
const
fields
=
record
.
fields
as
{
appId
:
string
|
Array
<
string
>
;
rating
:
number
|
undefined
};
const
fields
=
record
.
fields
as
{
appId
:
string
|
Array
<
string
>
;
rating
:
number
|
undefined
;
count
?:
number
};
const
appId
=
Array
.
isArray
(
fields
.
appId
)
?
fields
.
appId
[
0
]
:
fields
.
appId
;
const
appId
=
Array
.
isArray
(
fields
.
appId
)
?
fields
.
appId
[
0
]
:
fields
.
appId
;
acc
[
appId
]
=
{
acc
[
appId
]
=
{
recordId
:
record
.
id
,
recordId
:
record
.
id
,
value
:
fields
.
rating
,
value
:
fields
.
rating
,
count
:
fields
.
count
,
};
};
return
acc
;
return
acc
;
},
{});
},
{});
...
@@ -63,7 +64,7 @@ export default function useRatings() {
...
@@ -63,7 +64,7 @@ export default function useRatings() {
return
;
return
;
}
}
try
{
try
{
const
data
=
await
airtable
(
'
apps_ratings
'
).
select
({
fields
:
[
'
appId
'
,
'
rating
'
]
}).
all
();
const
data
=
await
airtable
(
'
apps_ratings
'
).
select
({
fields
:
[
'
appId
'
,
'
rating
'
,
'
count
'
]
}).
all
();
const
ratings
=
formatRatings
(
data
);
const
ratings
=
formatRatings
(
data
);
setRatings
(
ratings
);
setRatings
(
ratings
);
}
catch
(
error
)
{
}
catch
(
error
)
{
...
...
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