Skip to content

Commit 7ae9d13

Browse files
committed
Show visible in stats label on posts
1 parent 747e6e2 commit 7ae9d13

33 files changed

+120
-51
lines changed

app/helpers/categories_helper.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22
module CategoriesHelper
33
include FormHelper
4+
include VisibleHelper
45

56
def new_category_props
67
new_form_props(category_form_inputs, categories_path)
@@ -40,7 +41,8 @@ def actions_setup(element, url_helper)
4041
name: t('common.actions.edit'),
4142
link: link
4243
},
43-
delete: action_delete(url_helper)
44+
delete: action_delete(url_helper),
45+
visible: get_visible(element.visible)
4446
}
4547
end
4648

@@ -89,7 +91,7 @@ def category_visible(visible)
8991
{
9092
id: 'category_visible',
9193
type: 'switch',
92-
label: t('shared.stats.visible_in_stats'),
94+
label: t('shared.stats.make_visible_in_stats'),
9395
dark: true,
9496
name: 'category[visible]',
9597
value: true,

app/helpers/moments_helper.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22
module MomentsHelper
33
include ViewersHelper
4+
include VisibleHelper
45

56
def moments_data_json
67
{
@@ -44,9 +45,13 @@ def secret_share_props(moment)
4445
def user_actions(element, present_object, signed_in)
4546
return { viewers: nil, edit: nil, delete: nil } unless signed_in
4647

48+
model_name = element.class.name.downcase
49+
is_strategy = model_name == 'strategy'
50+
4751
{ viewers: get_viewer_list(element.viewers, nil),
4852
edit: get_user_action('edit', present_object),
49-
delete: get_user_action('delete', present_object) }
53+
delete: get_user_action('delete', present_object),
54+
visible: is_strategy && get_visible(element.visible) }
5055
end
5156

5257
def present_moment_or_strategy(element)
@@ -82,7 +87,7 @@ def moment_or_strategy_actions(element, present_object)
8287
present_object,
8388
element.user_id == current_user&.id)
8489
{ edit: actions[:edit], delete: actions[:delete],
85-
viewers: actions[:viewers] }
90+
viewers: actions[:viewers], visible: actions[:visible] }
8691
end
8792

8893
def story_by(element)

app/helpers/moods_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def mood_visible
4444
{
4545
id: 'mood_visible',
4646
type: 'switch',
47-
label: t('shared.stats.visible_in_stats'),
47+
label: t('shared.stats.make_visible_in_stats'),
4848
dark: true,
4949
name: 'mood[visible]',
5050
value: true,

app/helpers/strategies_form_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def build_strategy_bookmarked(strategy)
8585
def build_strategy_visible(strategy)
8686
build_switch_input(true, strategy.visible, false).merge(
8787
id: 'strategy_visible', name: 'strategy[visible]',
88-
label: t('shared.stats.visible_in_stats')
88+
label: t('shared.stats.make_visible_in_stats')
8989
)
9090
end
9191

app/helpers/visible_helper.rb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# frozen_string_literal: true
2+
module VisibleHelper
3+
def get_visible(visible)
4+
return t('shared.stats.visible_in_stats') if visible
5+
end
6+
end

app/services/moment_keywords.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def collect_keywords(array)
3030
end
3131

3232
def extract(str)
33-
str = str || ''
33+
str ||= ''
3434
str = strip_html(str.tr('\\', '/'))
3535
str.gsub(/[^\p{Alpha} -]/, '').split.map(&:downcase)
3636
end

app/views/categories/show.html.erb

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
edit: {
2525
name: t('common.actions.edit'),
2626
link: edit_category_path(@category)
27-
}
27+
},
28+
visible: get_visible(@category.visible)
2829
}
2930
}) %>
3031
</div>

app/views/moods/show.html.erb

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
edit: {
2525
name: t('common.actions.edit'),
2626
link: edit_mood_path(@mood)
27-
}
27+
},
28+
visible: get_visible(@mood.visible)
2829
}
2930
}) %>
3031
</div>

app/views/strategies/show.html.erb

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
dataMethod: 'delete',
4040
dataConfirm: t('common.actions.confirm')
4141
},
42-
viewers: get_viewer_list(@strategy.viewers, nil)
42+
viewers: get_viewer_list(@strategy.viewers, nil),
43+
visible: get_visible(@strategy.visible)
4344
}
4445
}) %>
4546
</div>

client/app/components/Story/StoryActions.jsx

+26-12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
faExclamationTriangle,
1313
faCalendarPlus,
1414
faCalendarMinus,
15+
faChartLine,
1516
} from '@fortawesome/free-solid-svg-icons';
1617
import { Tooltip } from 'components/Tooltip';
1718
import css from './Story.scss';
@@ -33,6 +34,7 @@ export type Actions = {
3334
add_to_google_cal?: Action,
3435
remove_from_google_cal?: Action,
3536
viewers?: string,
37+
visible?: string,
3638
};
3739

3840
export type Props = {
@@ -47,6 +49,7 @@ const JOIN = 'join';
4749
const LEAVE = 'leave';
4850
const REPORT = 'report';
4951
const VIEWERS = 'viewers';
52+
const VISIBLE = 'visible';
5053
const ADD_TO_G_CAL = 'add_to_google_cal';
5154
const REMOVE_FROM_G_CAL = 'remove_from_google_cal';
5255

@@ -68,6 +71,14 @@ const classMap = (dark: ?boolean) => {
6871
aria-label={I18n.t('shared.viewers.plural')}
6972
/>
7073
),
74+
visible: (
75+
<FontAwesomeIcon
76+
icon={faChartLine}
77+
className={className}
78+
tabIndex={0}
79+
aria-label={I18n.t('shared.stats.visible_in_stats')}
80+
/>
81+
),
7182
add_to_google_cal: (
7283
<FontAwesomeIcon icon={faCalendarPlus} className={className} />
7384
),
@@ -77,21 +88,23 @@ const classMap = (dark: ?boolean) => {
7788
};
7889
};
7990

80-
const displayViewers = (
91+
const displayNonLink = (
8192
actions: Actions,
8293
item: string,
8394
hasStory: ?boolean,
8495
dark: ?boolean,
85-
) => (
86-
<div key={item} className="storyActionsViewers">
87-
<Tooltip
88-
className="storyActionsViewer"
89-
element={classMap(dark)[item]}
90-
text={actions[item]}
91-
right={!!hasStory}
92-
/>
93-
</div>
94-
);
96+
) => {
97+
const capitalizeItem = item.charAt(0).toUpperCase() + item.slice(1);
98+
return (
99+
<div key={item} className={`storyActions${capitalizeItem}`}>
100+
<Tooltip
101+
element={classMap(dark)[item]}
102+
text={actions[item]}
103+
right={!!hasStory}
104+
/>
105+
</div>
106+
);
107+
};
95108

96109
const titleItem = (item: string) => item.charAt(0).toUpperCase() + item.slice(1);
97110

@@ -137,7 +150,7 @@ const displayItem = (
137150
hasStory: ?boolean,
138151
dark: ?boolean,
139152
) => {
140-
if (item === VIEWERS) return displayViewers(actions, item, hasStory, dark);
153+
if (item === VIEWERS || item === VISIBLE) return displayNonLink(actions, item, hasStory, dark);
141154
return displayLink(actions, item, hasStory, dark);
142155
};
143156

@@ -153,6 +166,7 @@ export const StoryActions = (props: Props): Node => {
153166
LEAVE,
154167
DELETE,
155168
REPORT,
169+
VISIBLE,
156170
VIEWERS,
157171
].map((item: string) => (actions[item] ? displayItem(actions, item, hasStory, dark) : null))}
158172
</div>

client/app/components/Story/__tests__/StoryActions.spec.jsx

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ describe('storyActions', () => {
2525
},
2626
report: { link: 'some-url', name: 'Report' },
2727
viewers: 'testViewer',
28+
visible: 'testVisible',
2829
}}
2930
/>,
3031
);
@@ -33,6 +34,7 @@ describe('storyActions', () => {
3334
expect(getByText('Delete')).toBeInTheDocument();
3435
expect(getByText('Report')).toBeInTheDocument();
3536
expect(getByText('testViewer')).toBeInTheDocument();
37+
expect(getByText('testVisible')).toBeInTheDocument();
3638
});
3739
});
3840
describe('with remove google calendar action', () => {
@@ -54,6 +56,7 @@ describe('storyActions', () => {
5456
},
5557
report: { link: 'some-url', name: 'Report' },
5658
viewers: 'testViewer',
59+
visible: 'testVisible',
5760
}}
5861
/>,
5962
);
@@ -62,6 +65,7 @@ describe('storyActions', () => {
6265
expect(getByText('Delete')).toBeInTheDocument();
6366
expect(getByText('Report')).toBeInTheDocument();
6467
expect(getByText('testViewer')).toBeInTheDocument();
68+
expect(getByText('testVisible')).toBeInTheDocument();
6569
});
6670
});
6771
});

config/locales/de.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,8 @@ de:
919919
stats:
920920
you_are_focusing: Du konzentrierst dich am meisten auf
921921
user_is_focusing: '%{name} konzentriert sich am meisten auf'
922-
visible_in_stats: In Statistiken sichtbar?
922+
visible_in_stats: Sichtbar in Statistiken
923+
make_visible_in_stats: In Statistiken sichtbar machen?
923924
viewers:
924925
plural: Betrachter
925926
you: Nur du

config/locales/en.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,8 @@ en:
819819
stats:
820820
you_are_focusing: You are focusing the most on
821821
user_is_focusing: '%{name} is focusing the most on'
822-
visible_in_stats: Visible in stats?
822+
visible_in_stats: Visible in stats
823+
make_visible_in_stats: Make visible in stats?
823824
viewers:
824825
plural: Viewers
825826
you: Only you

config/locales/es.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,8 @@ es:
865865
stats:
866866
you_are_focusing: Te concentrás principalmente en
867867
user_is_focusing: '%{name} se concentra principalmente en'
868-
visible_in_stats: ¿Visible en las estadísticas?
868+
visible_in_stats: Visible en las estadísticas
869+
make_visible_in_stats: ¿Hacer visible en las estadísticas?
869870
viewers:
870871
plural: Personas observando
871872
you: Sólo tú

config/locales/fr.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,8 @@ fr:
878878
stats:
879879
you_are_focusing: Vous vous concentrez le plus
880880
user_is_focusing: '%{name} se concentre le plus'
881-
visible_in_stats: Visible dans les statistiques?
881+
visible_in_stats: Visible dans les statistiques
882+
make_visible_in_stats: Rendre visible dans les statistiques ?
882883
viewers:
883884
plural: lecteurs
884885
you: Seulment vous

config/locales/hi.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,8 @@ hi:
842842
stats:
843843
you_are_focusing: आप सबसे अधिक ध्यान केंद्रित कर रहे हैं
844844
user_is_focusing: '%{name} सबसे अधिक ध्यान केंद्रित कर रहा है'
845-
visible_in_stats: आँकड़ों में दृश्यमान?
845+
visible_in_stats: आँकड़ों में दृश्यमान
846+
make_visible_in_stats: आँकड़ों में दृश्यमान बनाएं?
846847
viewers:
847848
plural: दर्शक
848849
you: केवल आप

config/locales/id.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,8 @@ id:
846846
stats:
847847
you_are_focusing: Anda paling fokus pada
848848
user_is_focusing: '%{name} paling fokus pada'
849-
visible_in_stats: Terlihat di statistik?
849+
visible_in_stats: Terlihat di statistik
850+
make_visible_in_stats: Buat terlihat di statistik?
850851
viewers:
851852
plural: Penonton
852853
you: Hanya Anda

config/locales/it.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,8 @@ it:
855855
stats:
856856
you_are_focusing: Ti stai concentrando specialmente su
857857
user_is_focusing: '%{name} si sta concentrando specialmente su'
858-
visible_in_stats: Visibile nelle statistiche?
858+
visible_in_stats: Visibile nelle statistiche
859+
make_visible_in_stats: Rendi visibile nelle statistiche?
859860
viewers:
860861
plural: Visualizzatori
861862
you: Solo tu

config/locales/ko.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,8 @@ ko:
745745
stats:
746746
you_are_focusing: 당신이 가장 집중하고 있는것은
747747
user_is_focusing: '%{name} (이)가 가장 집중하고 있는것은'
748-
visible_in_stats: 통계를 표시하겠습니까?
748+
visible_in_stats: 통계에서 볼 수 있음
749+
make_visible_in_stats: 통계에 표시하시겠습니까?
749750
viewers:
750751
plural: 조회자들
751752
you: 당신만

config/locales/nb.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,8 @@ nb:
829829
stats:
830830
you_are_focusing: Du fokuserer mest på
831831
user_is_focusing: '%{name} fokuserer mest på'
832-
visible_in_stats: Synlig i statistikk?
832+
visible_in_stats: Synlig i statistikk
833+
make_visible_in_stats: Gjøre synlig i statistikk?
833834
viewers:
834835
plural: Seere
835836
you: Kun deg

config/locales/nl.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,8 @@ nl:
866866
stats:
867867
you_are_focusing: Je focust het meest op
868868
user_is_focusing: '%{name} is het meest gefocust op'
869-
visible_in_stats: Zichtbaar in statistieken?
869+
visible_in_stats: Zichtbaar in statistieken
870+
make_visible_in_stats: Zichtbaar maken in statistieken?
870871
viewers:
871872
plural: Kijkers
872873
you: Alleen jij

config/locales/pt-BR.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,8 @@ pt-BR:
868868
stats:
869869
you_are_focusing: Você está focando demais em
870870
user_is_focusing: '%{name} está focando demais em'
871-
visible_in_stats: Visível nas estatísticas?
871+
visible_in_stats: Visível nas estatísticas
872+
make_visible_in_stats: Tornar visível nas estatísticas?
872873
viewers:
873874
plural: Visualizadores
874875
you: Apenas você

config/locales/sv.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,8 @@ sv:
833833
stats:
834834
you_are_focusing: Du fokuserar mest på
835835
user_is_focusing: '%{name} fokuserar mest på'
836-
visible_in_stats: Synlig i statistik?
836+
visible_in_stats: Syns i statistik
837+
make_visible_in_stats: Visas i statistik?
837838
viewers:
838839
plural: Tittare
839840
you: Bara du

config/locales/vi.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,8 @@ vi:
847847
stats:
848848
you_are_focusing: Bạn tập trung vào nhất
849849
user_is_focusing: '%{name} đang tập trung nhiều nhất vào'
850-
visible_in_stats: Hiển thị trong số liệu thống kê?
850+
visible_in_stats: Hiển thị trong số liệu thống kê
851+
make_visible_in_stats: Hiển thị trong số liệu thống kê?
851852
viewers:
852853
plural: Người xem
853854
you: Duy nhất có bạn

config/locales/zh-CN.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,8 @@ zh-CN:
714714
stats:
715715
you_are_focusing: 你最关注的是
716716
user_is_focusing: '%{name}最关注'
717-
visible_in_stats: 统计参考资料中显示?
717+
visible_in_stats: 在統計中可見
718+
make_visible_in_stats: 在統計數據中顯示?
718719
viewers:
719720
plural: 读者
720721
you: 只有你

spec/features/user_creates_a_draft_strategy_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
expect(page).to have_content 'Daily reminder email'
6868
expect(page).not_to have_css('#comments')
6969
expect(page).to have_selector '.storyDraft'
70+
find('.storyActionsVisible').hover
71+
expect(page).to have_content 'Visible in stats'
7072
back = current_url
7173

7274
# TRYING TO VIEW AS ALLY

0 commit comments

Comments
 (0)