2020-09-23 06:09:45 +00:00
|
|
|
import { sanitize } from '~/lib/dompurify';
|
2019-01-29 13:50:22 +00:00
|
|
|
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
|
2019-09-25 15:06:16 +00:00
|
|
|
import updateDescription from '../utils/update_description';
|
2019-01-29 13:50:22 +00:00
|
|
|
|
2017-05-10 11:29:33 +00:00
|
|
|
export default class Store {
|
2017-06-20 09:56:18 +00:00
|
|
|
constructor(initialState) {
|
|
|
|
this.state = initialState;
|
2017-05-12 11:54:10 +00:00
|
|
|
this.formState = {
|
|
|
|
title: '',
|
2017-05-12 14:52:45 +00:00
|
|
|
description: '',
|
2017-05-18 15:51:51 +00:00
|
|
|
lockedWarningVisible: false,
|
2017-05-26 08:29:06 +00:00
|
|
|
updateLoading: false,
|
2018-12-21 00:19:41 +00:00
|
|
|
lock_version: 0,
|
2021-02-18 12:09:34 +00:00
|
|
|
issuableTemplates: {},
|
2017-05-12 11:54:10 +00:00
|
|
|
};
|
2017-05-10 11:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
updateState(data) {
|
2017-06-22 00:34:15 +00:00
|
|
|
if (this.stateShouldUpdate(data)) {
|
|
|
|
this.formState.lockedWarningVisible = true;
|
|
|
|
}
|
|
|
|
|
2019-01-29 13:50:22 +00:00
|
|
|
Object.assign(this.state, convertObjectPropsToCamelCase(data));
|
2019-09-25 15:06:16 +00:00
|
|
|
// 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-02-20 09:09:13 +00:00
|
|
|
descriptionSection != null && descriptionSection.getElementsByTagName('details');
|
2019-09-25 15:06:16 +00:00
|
|
|
|
2020-09-14 12:09:34 +00:00
|
|
|
this.state.descriptionHtml = updateDescription(sanitize(data.description), details);
|
|
|
|
this.state.titleHtml = sanitize(data.title);
|
2018-12-21 00:19:41 +00:00
|
|
|
this.state.lock_version = data.lock_version;
|
2017-05-10 11:29:33 +00:00
|
|
|
}
|
2017-05-18 15:51:51 +00:00
|
|
|
|
|
|
|
stateShouldUpdate(data) {
|
2018-10-10 06:23:54 +00:00
|
|
|
return (
|
|
|
|
this.state.titleText !== data.title_text ||
|
|
|
|
this.state.descriptionText !== data.description_text
|
|
|
|
);
|
2017-05-18 15:51:51 +00:00
|
|
|
}
|
2017-05-30 10:58:50 +00:00
|
|
|
|
|
|
|
setFormState(state) {
|
|
|
|
this.formState = Object.assign(this.formState, state);
|
|
|
|
}
|
2017-05-10 11:29:33 +00:00
|
|
|
}
|