Skip to content

Commit a93a338

Browse files
committed
Load commenting components based on seed flag
Set loadCommenting in the seed config for preview mode so the frontend dynamically imports commenting components after hydration. Review translations are now derived from the same flag. This allows server-side gating of commenting via the seed options. REDMINE-21261
1 parent 227b3c1 commit a93a338

File tree

13 files changed

+171
-13
lines changed

13 files changed

+171
-13
lines changed

entry_types/scrolled/app/controllers/pageflow_scrolled/entries_controller.rb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,30 @@ class EntriesController < ActionController::Base
1515

1616
def show
1717
entry = get_published_entry_from_env
18+
mode = get_entry_mode_from_env
1819

1920
I18n.locale = entry.locale
2021

2122
render(
2223
locals: {
2324
entry:,
24-
entry_mode: get_entry_mode_from_env,
25-
seed_options: {
26-
embed: get_embed_from_env,
27-
origin_url: request.original_url
28-
}
25+
entry_mode: mode,
26+
seed_options: seed_options(mode)
2927
}
3028
)
3129
end
30+
31+
private
32+
33+
def seed_options(mode)
34+
options = {
35+
embed: get_embed_from_env,
36+
origin_url: request.original_url
37+
}
38+
39+
options[:load_commenting] = true if mode == :preview
40+
41+
options
42+
end
3243
end
3344
end

entry_types/scrolled/app/helpers/pageflow_scrolled/i18n_helper.rb

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
module PageflowScrolled
22
# @api private
33
module I18nHelper
4-
def scrolled_i18n_translations(entry, include_inline_editing: false)
4+
def scrolled_i18n_translations(entry,
5+
include_inline_editing: false,
6+
include_review: false)
57
result = scrolled_i18n_public_translations(entry)
68

7-
return result unless include_inline_editing
9+
if include_inline_editing
10+
result = result.deep_merge(I18n.locale.to_s => {
11+
pageflow_scrolled: {
12+
inline_editing: I18n.t('pageflow_scrolled.inline_editing')
13+
}
14+
})
15+
end
816

9-
result.deep_merge(I18n.locale.to_s => {
10-
pageflow_scrolled: {
11-
inline_editing: I18n.t('pageflow_scrolled.inline_editing')
12-
}
13-
})
17+
if include_review
18+
result = result.deep_merge(I18n.locale.to_s => {
19+
pageflow_scrolled: {
20+
review: I18n.t('pageflow_scrolled.review')
21+
}
22+
})
23+
end
24+
25+
result
1426
end
1527

1628
private

entry_types/scrolled/app/views/pageflow_scrolled/entry_json_seed/_entry.json.jbuilder

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ json.config do
5454
json.embed options.fetch(:embed, false)
5555
json.origin_url options[:origin_url] if options[:origin_url]
5656
json.load_inline_editing true if options[:load_inline_editing]
57+
json.load_commenting true if options[:load_commenting]
5758
end
5859

5960
unless options[:skip_i18n]
@@ -62,7 +63,8 @@ unless options[:skip_i18n]
6263
json.locale I18n.locale
6364
json.translations scrolled_i18n_translations(
6465
entry,
65-
include_inline_editing: !!options[:load_inline_editing]
66+
include_inline_editing: !!options[:load_inline_editing],
67+
include_review: !!options[:load_commenting]
6668
)
6769
end
6870
end

entry_types/scrolled/config/locales/de.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,3 +1909,5 @@ de:
19091909
content_element_margin_top: Oberer Außenabstand
19101910
content_element_margin_bottom: Unterer Außenabstand
19111911
expose_motif_area: Motiv freilegen
1912+
review:
1913+
toolbar_label: Kommentare

entry_types/scrolled/config/locales/en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,3 +1738,5 @@ en:
17381738
content_element_margin_top: Top margin
17391739
content_element_margin_bottom: Bottom margin
17401740
expose_motif_area: Expose motif
1741+
review:
1742+
toolbar_label: Comments
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
3+
import {FloatingToolbar} from './FloatingToolbar';
4+
5+
export function EntryDecorator(props) {
6+
return (
7+
<>
8+
{props.children}
9+
<FloatingToolbar />
10+
</>
11+
);
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
3+
import {useI18n} from '../i18n';
4+
import styles from './FloatingToolbar.module.css';
5+
6+
export function FloatingToolbar() {
7+
const {t} = useI18n({locale: 'ui'});
8+
9+
return (
10+
<div className={styles.toolbar}>
11+
{t('pageflow_scrolled.review.toolbar_label')}
12+
</div>
13+
);
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.toolbar {
2+
position: fixed;
3+
bottom: 20px;
4+
left: 50%;
5+
transform: translateX(-50%);
6+
z-index: 100;
7+
padding: 8px 16px;
8+
background: #ffd24d;
9+
color: #795f0f;
10+
border-radius: 20px;
11+
font-family: sans-serif;
12+
font-size: 14px;
13+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
14+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {registerDecorators} from '../decoratorRegistry';
2+
import {EntryDecorator} from './EntryDecorator';
3+
4+
export function loadCommentingComponents() {
5+
registerDecorators('commenting', {
6+
EntryDecorator
7+
});
8+
}

entry_types/scrolled/package/src/frontend/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ global.pageflowScrolledRender = async function(seed) {
169169
}
170170

171171
render(seed);
172+
173+
if (seed.config.loadCommenting) {
174+
import(/* webpackPreload: true */ './commenting').then(
175+
({loadCommentingComponents}) => loadCommentingComponents()
176+
);
177+
}
172178
}
173179

174180
global.pageflowScrolledRegisterUpdateSeedHandler = function() {

0 commit comments

Comments
 (0)