Bläddra i källkod

fix: reactive blocks refs count

Tienson Qin 2 år sedan
förälder
incheckning
646975cef7
3 ändrade filer med 21 tillägg och 19 borttagningar
  1. 4 2
      e2e-tests/editor.spec.ts
  2. 15 16
      src/main/frontend/components/block.cljs
  3. 2 1
      src/main/frontend/db/model.cljs

+ 4 - 2
e2e-tests/editor.spec.ts

@@ -825,7 +825,8 @@ test('copy blocks should remove all ref-related values', async ({ page, block })
   await block.mustFill('test')
   await page.keyboard.press(modKey + '+c', { delay: 10 })
   await block.clickNext()
-  await page.keyboard.press(modKey + '+v')
+  await page.keyboard.press(modKey + '+v', { delay: 10 })
+  await block.clickNext()
   await expect(page.locator('.open-block-ref-link')).toHaveCount(1)
 
   await page.keyboard.press('ArrowUp', { delay: 10 })
@@ -845,7 +846,8 @@ test('undo cut block should recover refs', async ({ page, block }) => {
   await block.mustFill('test')
   await page.keyboard.press(modKey + '+c', { delay: 10 })
   await block.clickNext()
-  await page.keyboard.press(modKey + '+v')
+  await page.keyboard.press(modKey + '+v', { delay: 10 })
+  await block.clickNext()
   await expect(page.locator('.open-block-ref-link')).toHaveCount(1)
 
   await page.keyboard.press('ArrowUp', { delay: 10 })

+ 15 - 16
src/main/frontend/components/block.cljs

@@ -2405,21 +2405,20 @@
         nil)]]))
 
 (rum/defc block-refs-count < rum/static
-  [block *hide-block-refs?]
-  (let [block-refs-count (count (:block/_refs block))]
-    (when (> block-refs-count 0)
-      [:div
-       [:a.open-block-ref-link.bg-base-2.text-sm.ml-2.fade-link
-        {:title "Open block references"
-         :style {:margin-top -1}
-         :on-click (fn [e]
-                     (if (gobj/get e "shiftKey")
-                       (state/sidebar-add-block!
-                        (state/get-current-repo)
-                        (:db/id block)
-                        :block-ref)
-                       (swap! *hide-block-refs? not)))}
-        block-refs-count]])))
+  [block block-refs-count *hide-block-refs?]
+  (when (> block-refs-count 0)
+    [:div
+     [:a.open-block-ref-link.bg-base-2.text-sm.ml-2.fade-link
+      {:title "Open block references"
+       :style {:margin-top -1}
+       :on-click (fn [e]
+                   (if (gobj/get e "shiftKey")
+                     (state/sidebar-add-block!
+                      (state/get-current-repo)
+                      (:db/id block)
+                      :block-ref)
+                     (swap! *hide-block-refs? not)))}
+      block-refs-count]]))
 
 (rum/defc block-left-menu < rum/reactive
   [_config {:block/keys [uuid] :as _block}]
@@ -2517,7 +2516,7 @@
                                    (editor-handler/edit-block! block :max (:block/uuid block)))}
                  svg/edit])
 
-              (block-refs-count block *hide-block-refs?)])]
+              (block-refs-count block refs-count *hide-block-refs?)])]
 
           (when (and (not hide-block-refs?) (> refs-count 0)
                      (not (:in-property? config)))

+ 2 - 1
src/main/frontend/db/model.cljs

@@ -447,7 +447,8 @@ independent of format as format specific heading characters are stripped"
                                  :tags (:block/tags e)
                                  :children children
                                  :collapsed? (:block/collapsed? e)
-                                 :collapsed-properties (:block/collapsed-properties e)}]))}
+                                 :collapsed-properties (:block/collapsed-properties e)
+                                 :refs-count (count (:block/_refs e))}]))}
               nil)
      react
      first)))