2019-01-29 13:50:22 +00:00
|
|
|
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
|
|
|
|
|
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,
|
2019-09-18 14:02:45 +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));
|
2017-05-10 11:29:33 +00:00
|
|
|
this.state.titleHtml = data.title;
|
|
|
|
this.state.descriptionHtml = data.description;
|
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
|
|
|
}
|