Преглед изворни кода

fix(app): lower threshold for diff hiding

Adam пре 1 месец
родитељ
комит
2611c35acc

+ 7 - 28
packages/ui/src/components/session-review.tsx

@@ -17,25 +17,7 @@ import { PreloadMultiFileDiffResult } from "@pierre/diffs/ssr"
 import { type SelectedLineRange } from "@pierre/diffs"
 import { Dynamic } from "solid-js/web"
 
-const MAX_DIFF_LINES = 20_000
-const MAX_DIFF_BYTES = 2_000_000
-
-function linesOver(text: string, max: number) {
-  let lines = 1
-  for (let i = 0; i < text.length; i++) {
-    if (text.charCodeAt(i) !== 10) continue
-    lines++
-    if (lines > max) return true
-  }
-  return lines > max
-}
-
-function formatBytes(bytes: number) {
-  if (!Number.isFinite(bytes) || bytes <= 0) return "0 B"
-  if (bytes < 1024) return `${bytes} B`
-  if (bytes < 1024 * 1024) return `${Math.round((bytes / 1024) * 10) / 10} KB`
-  return `${Math.round((bytes / (1024 * 1024)) * 10) / 10} MB`
-}
+const MAX_DIFF_CHANGED_LINES = 500
 
 export type SessionReviewDiffStyle = "unified" | "split"
 
@@ -354,18 +336,13 @@ export const SessionReview = (props: SessionReviewProps) => {
 
                 const beforeText = () => (typeof diff.before === "string" ? diff.before : "")
                 const afterText = () => (typeof diff.after === "string" ? diff.after : "")
+                const changedLines = () => diff.additions + diff.deletions
 
                 const tooLarge = createMemo(() => {
                   if (!expanded()) return false
                   if (force()) return false
                   if (isImageFile(diff.file)) return false
-
-                  const before = beforeText()
-                  const after = afterText()
-
-                  if (before.length > MAX_DIFF_BYTES || after.length > MAX_DIFF_BYTES) return true
-                  if (linesOver(before, MAX_DIFF_LINES) || linesOver(after, MAX_DIFF_LINES)) return true
-                  return false
+                  return changedLines() > MAX_DIFF_CHANGED_LINES
                 })
 
                 const isAdded = () => diff.status === "added" || (beforeText().length === 0 && afterText().length > 0)
@@ -636,8 +613,10 @@ export const SessionReview = (props: SessionReviewProps) => {
                                   {i18n.t("ui.sessionReview.largeDiff.title")}
                                 </div>
                                 <div data-slot="session-review-large-diff-meta">
-                                  Limit: {MAX_DIFF_LINES.toLocaleString()} lines / {formatBytes(MAX_DIFF_BYTES)}.
-                                  Current: {formatBytes(Math.max(beforeText().length, afterText().length))}.
+                                  {i18n.t("ui.sessionReview.largeDiff.meta", {
+                                    limit: MAX_DIFF_CHANGED_LINES.toLocaleString(),
+                                    current: changedLines().toLocaleString(),
+                                  })}
                                 </div>
                                 <div data-slot="session-review-large-diff-actions">
                                   <Button size="normal" variant="secondary" onClick={() => setForce(true)}>

+ 1 - 1
packages/ui/src/i18n/ar.ts

@@ -11,7 +11,7 @@ export const dict = {
   "ui.sessionReview.image.loading": "جار التحميل...",
   "ui.sessionReview.image.placeholder": "صورة",
   "ui.sessionReview.largeDiff.title": "Diff كبير جدا لعرضه",
-  "ui.sessionReview.largeDiff.meta": "الحد: {{lines}} سطر / {{limit}}. الحالي: {{current}}.",
+  "ui.sessionReview.largeDiff.meta": "الحد: {{limit}} سطرًا متغيرًا. الحالي: {{current}} سطرًا متغيرًا.",
   "ui.sessionReview.largeDiff.renderAnyway": "اعرض على أي حال",
 
   "ui.lineComment.label.prefix": "تعليق على ",

+ 1 - 1
packages/ui/src/i18n/br.ts

@@ -11,7 +11,7 @@ export const dict = {
   "ui.sessionReview.image.loading": "Carregando...",
   "ui.sessionReview.image.placeholder": "Imagem",
   "ui.sessionReview.largeDiff.title": "Diff grande demais para renderizar",
-  "ui.sessionReview.largeDiff.meta": "Limite: {{lines}} linhas / {{limit}}. Atual: {{current}}.",
+  "ui.sessionReview.largeDiff.meta": "Limite: {{limit}} linhas alteradas. Atual: {{current}} linhas alteradas.",
   "ui.sessionReview.largeDiff.renderAnyway": "Renderizar mesmo assim",
 
   "ui.lineComment.label.prefix": "Comentar em ",

+ 1 - 1
packages/ui/src/i18n/bs.ts

@@ -15,7 +15,7 @@ export const dict = {
   "ui.sessionReview.image.loading": "Učitavanje...",
   "ui.sessionReview.image.placeholder": "Slika",
   "ui.sessionReview.largeDiff.title": "Diff je prevelik za prikaz",
-  "ui.sessionReview.largeDiff.meta": "Limit: {{lines}} linija / {{limit}}. Trenutno: {{current}}.",
+  "ui.sessionReview.largeDiff.meta": "Limit: {{limit}} izmijenjenih linija. Trenutno: {{current}} izmijenjenih linija.",
   "ui.sessionReview.largeDiff.renderAnyway": "Prikaži svejedno",
 
   "ui.lineComment.label.prefix": "Komentar na ",

+ 1 - 1
packages/ui/src/i18n/da.ts

@@ -12,7 +12,7 @@ export const dict = {
   "ui.sessionReview.image.loading": "Indlæser...",
   "ui.sessionReview.image.placeholder": "Billede",
   "ui.sessionReview.largeDiff.title": "Diff er for stor til at blive vist",
-  "ui.sessionReview.largeDiff.meta": "Grænse: {{lines}} linjer / {{limit}}. Nuværende: {{current}}.",
+  "ui.sessionReview.largeDiff.meta": "Grænse: {{limit}} ændrede linjer. Nuværende: {{current}} ændrede linjer.",
   "ui.sessionReview.largeDiff.renderAnyway": "Vis alligevel",
   "ui.lineComment.label.prefix": "Kommenter på ",
   "ui.lineComment.label.suffix": "",

+ 1 - 1
packages/ui/src/i18n/de.ts

@@ -16,7 +16,7 @@ export const dict = {
   "ui.sessionReview.image.loading": "Wird geladen...",
   "ui.sessionReview.image.placeholder": "Bild",
   "ui.sessionReview.largeDiff.title": "Diff zu groß zum Rendern",
-  "ui.sessionReview.largeDiff.meta": "Limit: {{lines}} Zeilen / {{limit}}. Aktuell: {{current}}.",
+  "ui.sessionReview.largeDiff.meta": "Limit: {{limit}} geänderte Zeilen. Aktuell: {{current}} geänderte Zeilen.",
   "ui.sessionReview.largeDiff.renderAnyway": "Trotzdem rendern",
   "ui.lineComment.label.prefix": "Kommentar zu ",
   "ui.lineComment.label.suffix": "",

+ 1 - 1
packages/ui/src/i18n/en.ts

@@ -11,7 +11,7 @@ export const dict = {
   "ui.sessionReview.image.loading": "Loading...",
   "ui.sessionReview.image.placeholder": "Image",
   "ui.sessionReview.largeDiff.title": "Diff too large to render",
-  "ui.sessionReview.largeDiff.meta": "Limit: {{lines}} lines / {{limit}}. Current: {{current}}.",
+  "ui.sessionReview.largeDiff.meta": "Limit: {{limit}} changed lines. Current: {{current}} changed lines.",
   "ui.sessionReview.largeDiff.renderAnyway": "Render anyway",
 
   "ui.lineComment.label.prefix": "Comment on ",

+ 1 - 1
packages/ui/src/i18n/es.ts

@@ -11,7 +11,7 @@ export const dict = {
   "ui.sessionReview.image.loading": "Cargando...",
   "ui.sessionReview.image.placeholder": "Imagen",
   "ui.sessionReview.largeDiff.title": "Diff demasiado grande para renderizar",
-  "ui.sessionReview.largeDiff.meta": "Límite: {{lines}} líneas / {{limit}}. Actual: {{current}}.",
+  "ui.sessionReview.largeDiff.meta": "Límite: {{limit}} líneas modificadas. Actual: {{current}} líneas modificadas.",
   "ui.sessionReview.largeDiff.renderAnyway": "Renderizar de todos modos",
 
   "ui.lineComment.label.prefix": "Comentar en ",

+ 1 - 1
packages/ui/src/i18n/fr.ts

@@ -11,7 +11,7 @@ export const dict = {
   "ui.sessionReview.image.loading": "Chargement...",
   "ui.sessionReview.image.placeholder": "Image",
   "ui.sessionReview.largeDiff.title": "Diff trop volumineux pour être affiché",
-  "ui.sessionReview.largeDiff.meta": "Limite : {{lines}} lignes / {{limit}}. Actuel : {{current}}.",
+  "ui.sessionReview.largeDiff.meta": "Limite : {{limit}} lignes modifiées. Actuel : {{current}} lignes modifiées.",
   "ui.sessionReview.largeDiff.renderAnyway": "Afficher quand même",
 
   "ui.lineComment.label.prefix": "Commenter sur ",

+ 1 - 1
packages/ui/src/i18n/ja.ts

@@ -12,7 +12,7 @@ export const dict = {
   "ui.sessionReview.image.loading": "読み込み中...",
   "ui.sessionReview.image.placeholder": "画像",
   "ui.sessionReview.largeDiff.title": "差分が大きすぎて表示できません",
-  "ui.sessionReview.largeDiff.meta": "上限: {{lines}} 行 / {{limit}}。現在: {{current}}。",
+  "ui.sessionReview.largeDiff.meta": "上限: {{limit}} 変更行。現在: {{current}} 変更行。",
   "ui.sessionReview.largeDiff.renderAnyway": "それでも表示する",
   "ui.lineComment.label.prefix": "",
   "ui.lineComment.label.suffix": "へのコメント",

+ 1 - 1
packages/ui/src/i18n/ko.ts

@@ -11,7 +11,7 @@ export const dict = {
   "ui.sessionReview.image.loading": "로딩 중...",
   "ui.sessionReview.image.placeholder": "이미지",
   "ui.sessionReview.largeDiff.title": "차이가 너무 커서 렌더링할 수 없습니다",
-  "ui.sessionReview.largeDiff.meta": "제한: {{lines}}줄 / {{limit}}. 현재: {{current}}.",
+  "ui.sessionReview.largeDiff.meta": "제한: {{limit}} 변경 줄. 현재: {{current}} 변경 줄.",
   "ui.sessionReview.largeDiff.renderAnyway": "그래도 렌더링",
 
   "ui.lineComment.label.prefix": "",

+ 1 - 1
packages/ui/src/i18n/no.ts

@@ -14,7 +14,7 @@ export const dict: Record<Keys, string> = {
   "ui.sessionReview.image.loading": "Laster...",
   "ui.sessionReview.image.placeholder": "Bilde",
   "ui.sessionReview.largeDiff.title": "Diff er for stor til å gjengi",
-  "ui.sessionReview.largeDiff.meta": "Grense: {{lines}} linjer / {{limit}}. Nåværende: {{current}}.",
+  "ui.sessionReview.largeDiff.meta": "Grense: {{limit}} endrede linjer. Nåværende: {{current}} endrede linjer.",
   "ui.sessionReview.largeDiff.renderAnyway": "Gjengi likevel",
 
   "ui.lineComment.label.prefix": "Kommenter på ",

+ 1 - 1
packages/ui/src/i18n/pl.ts

@@ -12,7 +12,7 @@ export const dict = {
   "ui.sessionReview.image.loading": "Ładowanie...",
   "ui.sessionReview.image.placeholder": "Obraz",
   "ui.sessionReview.largeDiff.title": "Diff jest zbyt duży, aby go wyrenderować",
-  "ui.sessionReview.largeDiff.meta": "Limit: {{lines}} linii / {{limit}}. Obecnie: {{current}}.",
+  "ui.sessionReview.largeDiff.meta": "Limit: {{limit}} zmienionych linii. Obecnie: {{current}} zmienionych linii.",
   "ui.sessionReview.largeDiff.renderAnyway": "Renderuj mimo to",
   "ui.lineComment.label.prefix": "Komentarz do ",
   "ui.lineComment.label.suffix": "",

+ 1 - 1
packages/ui/src/i18n/ru.ts

@@ -12,7 +12,7 @@ export const dict = {
   "ui.sessionReview.image.loading": "Загрузка...",
   "ui.sessionReview.image.placeholder": "Изображение",
   "ui.sessionReview.largeDiff.title": "Diff слишком большой для отображения",
-  "ui.sessionReview.largeDiff.meta": "Лимит: {{lines}} строк / {{limit}}. Текущий: {{current}}.",
+  "ui.sessionReview.largeDiff.meta": "Лимит: {{limit}} изменённых строк. Текущий: {{current}} изменённых строк.",
   "ui.sessionReview.largeDiff.renderAnyway": "Отобразить всё равно",
   "ui.lineComment.label.prefix": "Комментарий к ",
   "ui.lineComment.label.suffix": "",

+ 2 - 1
packages/ui/src/i18n/th.ts

@@ -11,7 +11,8 @@ export const dict = {
   "ui.sessionReview.image.loading": "กำลังโหลด...",
   "ui.sessionReview.image.placeholder": "รูปภาพ",
   "ui.sessionReview.largeDiff.title": "Diff มีขนาดใหญ่เกินไปจนไม่สามารถแสดงผลได้",
-  "ui.sessionReview.largeDiff.meta": "ขีดจำกัด: {{lines}} บรรทัด / {{limit}}. ปัจจุบัน: {{current}}.",
+  "ui.sessionReview.largeDiff.meta":
+    "ขีดจำกัด: {{limit}} บรรทัดที่เปลี่ยนแปลง. ปัจจุบัน: {{current}} บรรทัดที่เปลี่ยนแปลง.",
   "ui.sessionReview.largeDiff.renderAnyway": "แสดงผลต่อไป",
 
   "ui.lineComment.label.prefix": "แสดงความคิดเห็นบน ",

+ 1 - 1
packages/ui/src/i18n/zh.ts

@@ -15,7 +15,7 @@ export const dict = {
   "ui.sessionReview.image.loading": "加载中...",
   "ui.sessionReview.image.placeholder": "图片",
   "ui.sessionReview.largeDiff.title": "差异过大,无法渲染",
-  "ui.sessionReview.largeDiff.meta": "限制:{{lines}} 行 / {{limit}}。当前:{{current}}。",
+  "ui.sessionReview.largeDiff.meta": "限制:{{limit}} 行变更。当前:{{current}} 行变更。",
   "ui.sessionReview.largeDiff.renderAnyway": "仍然渲染",
 
   "ui.lineComment.label.prefix": "评论 ",

+ 1 - 1
packages/ui/src/i18n/zht.ts

@@ -15,7 +15,7 @@ export const dict = {
   "ui.sessionReview.image.loading": "載入中...",
   "ui.sessionReview.image.placeholder": "圖片",
   "ui.sessionReview.largeDiff.title": "差異過大,無法渲染",
-  "ui.sessionReview.largeDiff.meta": "限制:{{lines}} 行 / {{limit}}。目前:{{current}}。",
+  "ui.sessionReview.largeDiff.meta": "限制:{{limit}} 行變更。目前:{{current}} 行變更。",
   "ui.sessionReview.largeDiff.renderAnyway": "仍然渲染",
 
   "ui.lineComment.label.prefix": "評論 ",