Skip to content

A platform for community discussion. Free, open, simple.

FIX: Prevent duplicate table edit buttons on quoted tables (#38689)

Régis Hanolb3eb3c7a7085
diff --git a/frontend/discourse/app/instance-initializers/post-decorations.js b/frontend/discourse/app/instance-initializers/post-decorations.js
index 6da55d46bd6..b9e41464e37 100644
--- a/frontend/discourse/app/instance-initializers/post-decorations.js
+++ b/frontend/discourse/app/instance-initializers/post-decorations.js
@@ -183,6 +183,12 @@ export default {
function generatePopups(tables, post) {
tables.forEach((table, index) => {
+ if (
+ table.parentNode.querySelector(".fullscreen-table-wrapper__buttons")
+ ) {
+ return;
+ }
+
const buttonWrapper = document.createElement("div");
buttonWrapper.classList.add("fullscreen-table-wrapper__buttons");
diff --git a/spec/system/table_builder_spec.rb b/spec/system/table_builder_spec.rb
index 09172d0874f..61fd6f74aff 100644
--- a/spec/system/table_builder_spec.rb
+++ b/spec/system/table_builder_spec.rb
@@ -166,9 +166,6 @@ describe "Table Builder", type: :system do
end
it "should not accept default Discourse keyboard shortcuts" do
- # Some default keyboard shortcuts like Shift + S bring up a modal overriding
- # the table builder modal and therefore should not be accepted
-
topic_page.visit_topic(topic)
topic_page.find(".btn-edit-table", visible: :all).click
insert_table_modal.find_cell(0, 0)
@@ -176,5 +173,22 @@ describe "Table Builder", type: :system do
expect(page).to have_css(".insert-table-modal")
expect(page).to have_no_css(".share-topic-modal")
end
+
+ it "does not show duplicate edit buttons on quoted tables" do
+ raw = <<~MD
+ [quote="#{user.username}, post:#{post1.post_number}, topic:#{topic.id}"]
+ |Make | Model | Year|
+ | - | - | - |
+ | Toyota | Supra | 1998 |
+ [/quote]
+ MD
+
+ quoting_post = create_post(user:, topic:, raw:)
+ topic_page.visit_topic(topic)
+
+ within "#post_#{quoting_post.post_number}" do
+ expect(page).to have_css(".btn-edit-table", count: 1, visible: :all)
+ end
+ end
end
end