debian-mirror-gitlab/app/assets/javascripts/issue_show/stores/index.js

47 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-01-03 14:25:43 +05:30
import { sanitize } from '~/lib/dompurify';
2019-03-02 22:35:43 +05:30
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
2019-12-21 20:55:43 +05:30
import updateDescription from '../utils/update_description';
2019-03-02 22:35:43 +05:30
2017-09-10 17:25:29 +05:30
export default class Store {
constructor(initialState) {
this.state = initialState;
this.formState = {
title: '',
description: '',
lockedWarningVisible: false,
updateLoading: false,
2019-03-02 22:35:43 +05:30
lock_version: 0,
2021-04-17 20:07:23 +05:30
issuableTemplates: {},
2017-09-10 17:25:29 +05:30
};
}
updateState(data) {
if (this.stateShouldUpdate(data)) {
this.formState.lockedWarningVisible = true;
}
2019-03-02 22:35:43 +05:30
Object.assign(this.state, convertObjectPropsToCamelCase(data));
2019-12-21 20:55:43 +05:30
// find if there is an open details node inside of the issue description.
const descriptionSection = document.body.querySelector(
'.detail-page-description.content-block',
);
const details =
2020-04-08 14:13:33 +05:30
descriptionSection != null && descriptionSection.getElementsByTagName('details');
2019-12-21 20:55:43 +05:30
2020-11-24 15:15:51 +05:30
this.state.descriptionHtml = updateDescription(sanitize(data.description), details);
this.state.titleHtml = sanitize(data.title);
2019-03-02 22:35:43 +05:30
this.state.lock_version = data.lock_version;
2017-09-10 17:25:29 +05:30
}
stateShouldUpdate(data) {
2018-12-13 13:39:08 +05:30
return (
this.state.titleText !== data.title_text ||
this.state.descriptionText !== data.description_text
);
2017-09-10 17:25:29 +05:30
}
setFormState(state) {
this.formState = Object.assign(this.formState, state);
}
}