Skip to content

Commit d1bda6f

Browse files
authored
Merge pull request #32 from whale4113/feat/lujunji/bug-report
feat(chrome-extension): support bug report
2 parents 862d08e + a2e001d commit d1bda6f

File tree

8 files changed

+223
-6
lines changed

8 files changed

+223
-6
lines changed

.changeset/brown-suits-rhyme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@dolphin/chrome-extension': minor
3+
---
4+
5+
feat: support bug report

apps/chrome-extension/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@dolphin/typescript-config": "workspace:^",
2121
"@rollup/plugin-babel": "^6.0.4",
2222
"@rollup/plugin-commonjs": "^25.0.8",
23+
"@rollup/plugin-json": "^6.1.0",
2324
"@rollup/plugin-node-resolve": "^15.3.0",
2425
"@rollup/plugin-terser": "^0.4.4",
2526
"@rollup/plugin-typescript": "^11.1.6",
@@ -37,6 +38,7 @@
3738
"browser-fs-access": "^0.35.0",
3839
"filenamify": "^6.0.0",
3940
"i18next": "^23.16.4",
40-
"radash": "^12.1.0"
41+
"radash": "^12.1.0",
42+
"serialize-error": "^12.0.0"
4143
}
4244
}

apps/chrome-extension/rollup.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { defineConfig } from 'rollup'
22
import { nodeResolve } from '@rollup/plugin-node-resolve'
33
import typescript from '@rollup/plugin-typescript'
4+
import json from '@rollup/plugin-json'
45
import commonjs from '@rollup/plugin-commonjs'
56
import { babel } from '@rollup/plugin-babel'
67
import terser from '@rollup/plugin-terser'
@@ -21,6 +22,7 @@ const createSharedPlugins = (options = {}) => {
2122
exclude: [/node_modules\/core-js/],
2223
}),
2324
commonjs(),
25+
json(),
2426
...(isDev ? [] : [terser()]),
2527
]
2628

apps/chrome-extension/src/common/i18n.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,102 @@ export enum Namespace {
77
export enum CommonTranslationKey {
88
CONTINUE = 'continue',
99
CONFIRM_TEXT = 'confirm_text',
10+
CONFIRM_REPORT_BUG = 'confirm_report_bug',
11+
ISSUE_TEMPLATE_BODY = 'issue_template_body',
1012
}
1113

1214
export const en: ResourceLanguage = {
1315
common: {
1416
[CommonTranslationKey.CONTINUE]: 'Please click Confirm to continue',
1517
[CommonTranslationKey.CONFIRM_TEXT]: 'Confirm',
18+
[CommonTranslationKey.CONFIRM_REPORT_BUG]: 'Report Bug',
19+
[CommonTranslationKey.ISSUE_TEMPLATE_BODY]: `
20+
**Description**
21+
22+
A clear and concise description of what the bug is.
23+
24+
**Recording**
25+
26+
A GIF or video showing the issue happening. (If you don't include this, there's a very good chance your issue will be closed, because it's much too hard to figure out exactly what is going wrong, and it makes maintenance much harder.)
27+
28+
**Example Document**
29+
30+
A link to a Lark Document where the error can be reproduced. (Please ensure that the documentation is publicly accessible.)
31+
32+
**Steps**
33+
34+
To reproduce the behavior:
35+
36+
1. Go to '...'
37+
2. Click on '....'
38+
3. Scroll down to '....'
39+
4. See error
40+
41+
**Expectation**
42+
43+
A clear and concise description of what you expected to happen.
44+
45+
**Environment**
46+
47+
- Extension Version: {{version}}
48+
- Browser: [e.g. Chrome, Edge]
49+
50+
**Context**
51+
52+
Add any other context about the problem here. (The fastest way to have an issue fixed is to create a pull request with working, tested code and we'll help merge it.)
53+
54+
**Error Information**
55+
\`\`\`json
56+
{{errorInfo}}
57+
\`\`\`
58+
`,
1659
},
1760
}
1861

1962
export const zh: ResourceLanguage = {
2063
common: {
2164
[CommonTranslationKey.CONTINUE]: '请点击确认以继续',
2265
[CommonTranslationKey.CONFIRM_TEXT]: '确认',
66+
[CommonTranslationKey.CONFIRM_REPORT_BUG]: '报告错误',
67+
[CommonTranslationKey.ISSUE_TEMPLATE_BODY]: `
68+
**问题描述**
69+
70+
清晰简洁地描述这个 Bug 是什么。
71+
72+
**录屏**
73+
74+
展示问题发生的 GIF 或视频。(如果不包含这个,你的问题很可能会被关闭,因为很难准确了解问题出在哪里,这会使维护变得更加困难。)
75+
76+
**示例文档**
77+
78+
一个可以重现错误的飞书文档链接。(请确保文档是公开可访问的。)
79+
80+
**复现步骤**
81+
82+
重现该行为的步骤:
83+
84+
1. 前往 '...'
85+
2. 点击 '....'
86+
3. 滚动到 '....'
87+
4. 看到错误
88+
89+
**期望行为**
90+
91+
清晰简洁地描述你期望发生的情况。
92+
93+
**环境信息**
94+
95+
- 扩展版本:{{version}}
96+
- 浏览器:[例如 Chrome、Edge]
97+
98+
**上下文**
99+
100+
在此添加关于该问题的任何其他上下文。(修复问题最快的方法是创建一个包含已经过测试的可用代码的 Pull Request,我们会协助合并。)
101+
102+
**错误信息**
103+
\`\`\`json
104+
{{errorInfo}}
105+
\`\`\`
106+
`,
23107
},
24108
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import i18next from 'i18next'
2+
import { serializeError } from 'serialize-error'
3+
import { CommonTranslationKey, Namespace } from './i18n'
4+
import { version } from '../../package.json'
5+
6+
interface Issue {
7+
/**
8+
* Title
9+
*/
10+
title: string
11+
/**
12+
* Description
13+
*/
14+
body: string
15+
/**
16+
* Labels
17+
*/
18+
labels?: Label[]
19+
/**
20+
* Issue template
21+
*/
22+
template: string
23+
}
24+
25+
enum Label {
26+
/**
27+
* Something isn't working
28+
*/
29+
Bug = 'bug',
30+
}
31+
32+
function generateIssueUrl(issue: Issue): string {
33+
const { title, body, labels = [], template } = issue
34+
35+
const baseUrl =
36+
'https://github.com/whale4113/cloud-document-converter/issues/new'
37+
const params = new URLSearchParams({
38+
title: title,
39+
body: body,
40+
labels: labels.join(','),
41+
template,
42+
})
43+
44+
return `${baseUrl}?${params.toString()}`
45+
}
46+
47+
export const reportBug = (error: unknown) => {
48+
const url = generateIssueUrl({
49+
title: '',
50+
body: i18next.t(CommonTranslationKey.ISSUE_TEMPLATE_BODY, {
51+
version,
52+
errorInfo: JSON.stringify(serializeError(error), null, 2),
53+
ns: Namespace.COMMON,
54+
interpolation: { escapeValue: false },
55+
}),
56+
labels: [Label.Bug],
57+
template: 'bug.md',
58+
})
59+
60+
window.open(url, '__blank')
61+
}

apps/chrome-extension/src/scripts/copy-lark-docx-as-markdown.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import i18next from 'i18next'
22
import { Docx, docx, Toast } from '@dolphin/lark'
33
import { generatePublicUrl, makePublicUrlEffective } from '@dolphin/lark/image'
44
import { isDefined } from '@dolphin/common'
5-
import { en, zh } from '../common/i18n'
5+
import { CommonTranslationKey, en, Namespace, zh } from '../common/i18n'
66
import { confirm } from '../common/notification'
7+
import { reportBug } from '../common/issue'
78

89
const enum TranslationKey {
910
FAILED_TO_COPY_IMAGES = 'failed_to_copy_images',
@@ -102,8 +103,14 @@ const main = async () => {
102103
}
103104
}
104105

105-
main().catch(() => {
106+
main().catch(error => {
106107
Toast.error({
107108
content: i18next.t(TranslationKey.UNKNOWN_ERROR),
109+
actionText: i18next.t(CommonTranslationKey.CONFIRM_REPORT_BUG, {
110+
ns: Namespace.COMMON,
111+
}),
112+
onActionClick: () => {
113+
reportBug(error)
114+
},
108115
})
109116
})

apps/chrome-extension/src/scripts/download-lark-docx-as-markdown.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { fileSave, supported } from 'browser-fs-access'
44
import { fs } from '@zip.js/zip.js'
55
import normalizeFileName from 'filenamify/browser'
66
import { cluster } from 'radash'
7-
import { en, zh } from '../common/i18n'
7+
import { CommonTranslationKey, en, Namespace, zh } from '../common/i18n'
88
import { confirm } from '../common/notification'
99
import { legacyFileSave } from '../common/legacy'
10+
import { reportBug } from '../common/issue'
1011

1112
const DOWNLOAD_ABORTED = 'Download aborted'
1213

@@ -212,11 +213,17 @@ const downloadImage = async (
212213
}
213214

214215
return null
215-
} catch {
216+
} catch (error) {
216217
Toast.error({
217218
content: i18next.t(TranslationKey.FAILED_TO_DOWNLOAD, {
218219
name: originName,
219220
}),
221+
actionText: i18next.t(CommonTranslationKey.CONFIRM_REPORT_BUG, {
222+
ns: Namespace.COMMON,
223+
}),
224+
onActionClick: () => {
225+
reportBug(error)
226+
},
220227
})
221228

222229
return null
@@ -274,6 +281,12 @@ const downloadFile = async (
274281
content: i18next.t(TranslationKey.FAILED_TO_DOWNLOAD, {
275282
name,
276283
}),
284+
actionText: i18next.t(CommonTranslationKey.CONFIRM_REPORT_BUG, {
285+
ns: Namespace.COMMON,
286+
}),
287+
onActionClick: () => {
288+
reportBug(error)
289+
},
277290
})
278291

279292
return null
@@ -450,7 +463,15 @@ main()
450463
})
451464
.catch((error: DOMException | TypeError | Error) => {
452465
if (error.name !== 'AbortError' && error.message !== DOWNLOAD_ABORTED) {
453-
Toast.error({ content: String(error) })
466+
Toast.error({
467+
content: String(error),
468+
actionText: i18next.t(CommonTranslationKey.CONFIRM_REPORT_BUG, {
469+
ns: Namespace.COMMON,
470+
}),
471+
onActionClick: () => {
472+
reportBug(error)
473+
},
474+
})
454475
}
455476
})
456477
.finally(() => {

pnpm-lock.yaml

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)