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

47 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-12-21 20:55:43 +05:30
import _ from 'underscore';
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 =
!_.isNull(descriptionSection) && descriptionSection.getElementsByTagName('details');
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);
}
}