11import { useFormikContext } from 'formik' ;
22import { Trans , useTranslation } from 'react-i18next' ;
3- import { Button , MD , Span } from '@appquality/unguess-design-system' ;
3+ import { Button , MD , SM , Span } from '@appquality/unguess-design-system' ;
44import { appTheme } from 'src/app/theme' ;
55import styled from 'styled-components' ;
6+ import { VideoTag } from 'src/features/api' ;
7+ import { useMemo } from 'react' ;
68import { InsightFormValues } from './FormProvider' ;
79import { useInsightContext } from './InsightContext' ;
810
911const FloatingContainer = styled . div `
1012 position: fixed;
11- bottom: 100px ;
13+ bottom: ${ ( { theme } ) => theme . space . xxl } ;
1214 left: 50%;
1315 transform: translateX(-50%);
1416 z-index: ${ ( { theme } ) => theme . levels . front } ;
@@ -31,6 +33,21 @@ const ActionBar = () => {
3133 useFormikContext < InsightFormValues > ( ) ;
3234 const { isDrawerOpen, setIsDrawerOpen } = useInsightContext ( ) ;
3335
36+ const themesCount = useMemo ( ( ) => {
37+ const tags = values . observations . flatMap ( ( obs ) => obs . tags ) ;
38+ const titles = tags . filter ( ( tag ) => tag . group . name === 'title' ) ;
39+
40+ // Get count of unique titles (tag.name)
41+ const uniqueTitles = titles . reduce ( ( acc , tag ) => {
42+ if ( ! acc . find ( ( _t ) => _t . tag . name === tag . tag . name ) ) {
43+ acc . push ( tag ) ;
44+ }
45+ return acc ;
46+ } , [ ] as VideoTag [ ] ) ;
47+
48+ return uniqueTitles . length ;
49+ } , [ values . observations ] ) ;
50+
3451 // Do not show action bar cta if in editing or creating mode
3552 const hideCta = ( values . id > 0 || values . id === - 1 ) && isDrawerOpen ;
3653
@@ -40,51 +57,62 @@ const ActionBar = () => {
4057 < FloatingContainer >
4158 < Container >
4259 < div style = { { marginRight : appTheme . space . md } } >
43- < MD style = { { marginRight : appTheme . space . md } } >
60+ < MD >
4461 < Trans
4562 count = { values . observations . length }
46- i18nKey = "__INSIGHTS_PAGE_ACTION_BAR_INSIGHTS_COUNT_LABEL "
63+ i18nKey = "__INSIGHTS_PAGE_ACTION_BAR_INSIGHTS_COUNT_OBSERVATIONS_LABEL "
4764 >
4865 Selected observations:
49- < Span isBold > { { count : values . observations . length } } </ Span >
66+ < Span isBold > { { observations : values . observations . length } } </ Span >
5067 </ Trans >
5168 </ MD >
69+ < SM style = { { marginTop : appTheme . space . xs } } >
70+ < Trans
71+ count = { values . observations . length }
72+ i18nKey = "__INSIGHTS_PAGE_ACTION_BAR_INSIGHTS_COUNT_THEMES_LABEL"
73+ >
74+ Selected themes:
75+ < Span isBold > { { themes : themesCount } } </ Span >
76+ </ Trans >
77+ </ SM >
5278 </ div >
53- < Button
54- isLink
55- size = "small"
56- onClick = { ( ) => {
57- resetForm ( ) ;
58- } }
59- style = { {
60- marginRight : appTheme . space . md ,
61- color : appTheme . palette . white ,
62- } }
63- >
64- { t ( '__INSIGHTS_PAGE_ACTION_BAR_BUTTON_CANCEL' ) }
65- </ Button >
6679 { ! hideCta && (
67- < Button
68- isPrimary
69- isAccent
70- size = "small"
71- onClick = { ( ) => {
72- setIsDrawerOpen ( true ) ;
73- if ( values . id === 0 ) {
74- setValues ( {
75- ...values ,
76- id : - 1 ,
77- } ) ;
78- }
79- if ( values . id > 0 ) {
80- setValues ( values ) ;
81- }
82- } }
83- >
84- { values . id === 0 || values . id === - 1
85- ? t ( '__INSIGHTS_PAGE_ACTION_BAR_BUTTON_CREATE_INSIGHT' )
86- : t ( '__INSIGHTS_PAGE_ACTION_BAR_BUTTON_EDIT_INSIGHT' ) }
87- </ Button >
80+ < div style = { { marginLeft : appTheme . space . md } } >
81+ < Button
82+ isLink
83+ size = "small"
84+ onClick = { ( ) => {
85+ resetForm ( ) ;
86+ } }
87+ style = { {
88+ marginRight : appTheme . space . md ,
89+ color : appTheme . palette . white ,
90+ } }
91+ >
92+ { t ( '__INSIGHTS_PAGE_ACTION_BAR_BUTTON_CANCEL' ) }
93+ </ Button >
94+ < Button
95+ isPrimary
96+ isAccent
97+ size = "small"
98+ onClick = { ( ) => {
99+ setIsDrawerOpen ( true ) ;
100+ if ( values . id === 0 ) {
101+ setValues ( {
102+ ...values ,
103+ id : - 1 ,
104+ } ) ;
105+ }
106+ if ( values . id > 0 ) {
107+ setValues ( values ) ;
108+ }
109+ } }
110+ >
111+ { values . id === 0 || values . id === - 1
112+ ? t ( '__INSIGHTS_PAGE_ACTION_BAR_BUTTON_CREATE_INSIGHT' )
113+ : t ( '__INSIGHTS_PAGE_ACTION_BAR_BUTTON_EDIT_INSIGHT' ) }
114+ </ Button >
115+ </ div >
88116 ) }
89117 </ Container >
90118 </ FloatingContainer >
0 commit comments