Skip to content

Commit 0e8dc55

Browse files
authored
[Announcement] Migrate block JSON types to use Ruby identifiers (#11035)
1 parent 9435691 commit 0e8dc55

File tree

7 files changed

+36
-8
lines changed

7 files changed

+36
-8
lines changed

app/javascript/controllers/tiptap/nodes/donation_goal_node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Node } from '@tiptap/core'
22

33
export const DonationGoalNode = Node.create({
4-
name: 'donationGoal',
4+
name: 'Announcement::Block::DonationGoal',
55
atom: true,
66
group: 'block',
77
priority: 2000,

app/javascript/controllers/tiptap/nodes/donation_summary_node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Node } from '@tiptap/core'
22

33
export const DonationSummaryNode = Node.create({
4-
name: 'donationSummary',
4+
name: 'Announcement::Block::DonationSummary',
55
atom: true,
66
group: 'block',
77
priority: 2000,

app/javascript/controllers/tiptap/nodes/hcb_code_node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Node } from '@tiptap/core'
22

33
export const HcbCodeNode = Node.create({
4-
name: 'hcbCode',
4+
name: 'Announcement::Block::HcbCode',
55
atom: true,
66
group: 'block',
77
priority: 2000,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# frozen_string_literal: true
2+
3+
module OneTimeJobs
4+
class MigrateBlockTypes
5+
def self.perform
6+
Announcement.find_each do |announcement|
7+
new_content = ProsemirrorService::Renderer.map_nodes announcement.content do |node|
8+
new_type = case node["type"]
9+
when "donationGoal"
10+
"Announcement::Block::DonationGoal"
11+
when "donationSummary"
12+
"Announcement::Block::DonationSummary"
13+
when "hcbCode"
14+
"Announcement::Block::HcbCode"
15+
else
16+
node["type"]
17+
end
18+
19+
node["type"] = new_type
20+
end
21+
22+
announcement.content = new_content
23+
24+
announcement.save!
25+
end
26+
27+
end
28+
29+
end
30+
end

app/services/prosemirror_service/donation_goal_node.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
module ProsemirrorService
44
class DonationGoalNode < ProsemirrorToHtml::Nodes::Node
5-
include ApplicationHelper
6-
7-
@node_type = "donationGoal"
5+
@node_type = "Announcement::Block::DonationGoal"
86
@tag_name = "div"
97

108
def tag

app/services/prosemirror_service/donation_summary_node.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module ProsemirrorService
44
class DonationSummaryNode < ProsemirrorToHtml::Nodes::Node
5-
@node_type = "donationSummary"
5+
@node_type = "Announcement::Block::DonationSummary"
66
@tag_name = "div"
77

88
def tag

app/services/prosemirror_service/hcb_code_node.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module ProsemirrorService
44
class HcbCodeNode < ProsemirrorToHtml::Nodes::Node
5-
@node_type = "hcbCode"
5+
@node_type = "Announcement::Block::HcbCode"
66
@tag_name = "div"
77

88
def tag

0 commit comments

Comments
 (0)