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>
This commit is contained in:
Gusted 2021-12-28 13:28:27 +00:00 committed by GitHub
parent d2fac636d1
commit e4e3df6c66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 23 deletions

View file

@ -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);
}
});
}
}