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,
|
2019-12-21 20:55:43 +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
|
|
|
|
|
|
|
this.state.descriptionHtml = updateDescription(data.description, details);
|
2017-09-10 17:25:29 +05:30
|
|
|
this.state.titleHtml = 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);
|
|
|
|
}
|
|
|
|
}
|