diff options
author | Gusted <williamzijl7@hotmail.com> | 2021-12-28 13:28:27 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-28 21:28:27 +0800 |
commit | e4e3df6c66dbeac6ac5bceff8ac4f05dbea30d70 (patch) | |
tree | ea7ef42f8d34580b8ec1319f6bc2cd84c6fb973a /web_src/js | |
parent | d2fac636d16a596a36a3088ff05ffe812ba6eff2 (diff) | |
download | gitea-e4e3df6c66dbeac6ac5bceff8ac4f05dbea30d70.tar.gz gitea-e4e3df6c66dbeac6ac5bceff8ac4f05dbea30d70.zip |
Handle invalid issues (#18111)
* Handle invalid issues
- When you hover over a issue reference, and the issue doesn't exist, it
will just hang on the loading animation.
- This patch fixes that by showing them the pop-up with a "Error
occured" message.
* Add I18N
* refactor
* fix comment for lint
* fix unit test for i18n
* fix unit test for i18n
* add comments
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'web_src/js')
-rw-r--r-- | web_src/js/components/ContextPopup.vue | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/web_src/js/components/ContextPopup.vue b/web_src/js/components/ContextPopup.vue index efaa7be89e..c002a3d066 100644 --- a/web_src/js/components/ContextPopup.vue +++ b/web_src/js/components/ContextPopup.vue @@ -16,13 +16,17 @@ </div> </div> </div> + <div v-if="!loading && issue === null"> + <p><small>{{ i18nErrorOccurred }}</small></p> + <p>{{ i18nErrorMessage }}</p> + </div> </div> </template> <script> import {SvgIcon} from '../svg.js'; -const {appSubUrl} = window.config; +const {appSubUrl, i18n} = window.config; // NOTE: see models/issue_label.go for similar implementation const srgbToLinear = (color) => { @@ -49,7 +53,9 @@ export default { data: () => ({ loading: false, - issue: null + issue: null, + i18nErrorOccurred: i18n.error_occurred, + i18nErrorMessage: null, }), computed: { @@ -112,14 +118,20 @@ export default { methods: { load(data, callback) { this.loading = true; - $.get(`${appSubUrl}/api/v1/repos/${data.owner}/${data.repo}/issues/${data.index}`, (issue) => { + this.i18nErrorMessage = null; + $.get(`${appSubUrl}/api/v1/repos/${data.owner}/${data.repo}/issues/${data.index}`).done((issue) => { this.issue = issue; + }).fail((jqXHR) => { + if (jqXHR.responseJSON && jqXHR.responseJSON.message) { + this.i18nErrorMessage = jqXHR.responseJSON.message; + } else { + this.i18nErrorMessage = i18n.network_error; + } + }).always(() => { this.loading = false; - this.$nextTick(() => { - if (callback) { - callback(); - } - }); + if (callback) { + this.$nextTick(callback); + } }); } } |