Skip to content

Commit 9404194

Browse files
authored
Merge pull request #940 from AppQuality/fix-action-bar
Fix-action-bar
2 parents 77d2446 + fceb676 commit 9404194

File tree

3 files changed

+77
-44
lines changed

3 files changed

+77
-44
lines changed

src/locales/en/translation.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,10 @@
772772
"__INSIGHTS_PAGE_ACTION_BAR_BUTTON_CANCEL": "Cancel",
773773
"__INSIGHTS_PAGE_ACTION_BAR_BUTTON_CREATE_INSIGHT": "Create insight",
774774
"__INSIGHTS_PAGE_ACTION_BAR_BUTTON_EDIT_INSIGHT": "Update insight",
775-
"__INSIGHTS_PAGE_ACTION_BAR_INSIGHTS_COUNT_LABEL_one": "Selected observation: <1>{{count}}</1>",
776-
"__INSIGHTS_PAGE_ACTION_BAR_INSIGHTS_COUNT_LABEL_other": "Selected observations: <1>{{count}}</1>",
775+
"__INSIGHTS_PAGE_ACTION_BAR_INSIGHTS_COUNT_OBSERVATIONS_LABEL_one": "Selected observations: <1>{{observations}}</1>",
776+
"__INSIGHTS_PAGE_ACTION_BAR_INSIGHTS_COUNT_OBSERVATIONS_LABEL_other": "Selected observations: <1>{{observations}}</1>",
777+
"__INSIGHTS_PAGE_ACTION_BAR_INSIGHTS_COUNT_THEMES_LABEL_one": "Selected themes: <1>{{themes}}</1>",
778+
"__INSIGHTS_PAGE_ACTION_BAR_INSIGHTS_COUNT_THEMES_LABEL_other": "Selected themes: <1>{{themes}}</1>",
777779
"__INSIGHTS_PAGE_CLOSE_DRAWER_BUTTON": "Close",
778780
"__INSIGHTS_PAGE_COLLECTION_GROUP_BY_USECASE": "Group by Use Case",
779781
"__INSIGHTS_PAGE_COLLECTION_UNGROUP": "Show all",

src/locales/it/translation.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -799,9 +799,12 @@
799799
"__INSIGHTS_PAGE_ACTION_BAR_BUTTON_CANCEL": "Annulla",
800800
"__INSIGHTS_PAGE_ACTION_BAR_BUTTON_CREATE_INSIGHT": "",
801801
"__INSIGHTS_PAGE_ACTION_BAR_BUTTON_EDIT_INSIGHT": "",
802-
"__INSIGHTS_PAGE_ACTION_BAR_INSIGHTS_COUNT_LABEL_one": "Osservazione selezionata: <1>{{count}}</1>",
803-
"__INSIGHTS_PAGE_ACTION_BAR_INSIGHTS_COUNT_LABEL_many": "Osservazioni selezionate: <1>{{count}}</1>",
804-
"__INSIGHTS_PAGE_ACTION_BAR_INSIGHTS_COUNT_LABEL_other": "Osservazioni selezionate: <1>{{count}}</1>",
802+
"__INSIGHTS_PAGE_ACTION_BAR_INSIGHTS_COUNT_OBSERVATIONS_LABEL_one": "Selected observations: <1>{{observations}}</1>",
803+
"__INSIGHTS_PAGE_ACTION_BAR_INSIGHTS_COUNT_OBSERVATIONS_LABEL_many": "Selected observations: <1>{{observations}}</1>",
804+
"__INSIGHTS_PAGE_ACTION_BAR_INSIGHTS_COUNT_OBSERVATIONS_LABEL_other": "Selected observations: <1>{{observations}}</1>",
805+
"__INSIGHTS_PAGE_ACTION_BAR_INSIGHTS_COUNT_THEMES_LABEL_one": "Selected themes: <1>{{themes}}</1>",
806+
"__INSIGHTS_PAGE_ACTION_BAR_INSIGHTS_COUNT_THEMES_LABEL_many": "Selected themes: <1>{{themes}}</1>",
807+
"__INSIGHTS_PAGE_ACTION_BAR_INSIGHTS_COUNT_THEMES_LABEL_other": "Selected themes: <1>{{themes}}</1>",
805808
"__INSIGHTS_PAGE_CLOSE_DRAWER_BUTTON": "Close drawer",
806809
"__INSIGHTS_PAGE_COLLECTION_GROUP_BY_USECASE": "Organizza per Use Case",
807810
"__INSIGHTS_PAGE_COLLECTION_UNGROUP": "",

src/pages/Insights/ActionBar.tsx

Lines changed: 67 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { useFormikContext } from 'formik';
22
import { 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';
44
import { appTheme } from 'src/app/theme';
55
import styled from 'styled-components';
6+
import { VideoTag } from 'src/features/api';
7+
import { useMemo } from 'react';
68
import { InsightFormValues } from './FormProvider';
79
import { useInsightContext } from './InsightContext';
810

911
const 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

Comments
 (0)