diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-25 06:10:18 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-25 06:10:18 +0000 |
commit | 4ae91e9f5004d78168b5b50f9ce51db045e479d0 (patch) | |
tree | 5b19e0ee9302696df06bbf980133d44883ba89ba /app/assets/javascripts/related_issues/stores | |
parent | c9c77a8466e7cc2b88b6c8ae54365b4123caa2d0 (diff) | |
download | gitlab-ce-4ae91e9f5004d78168b5b50f9ce51db045e479d0.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/related_issues/stores')
-rw-r--r-- | app/assets/javascripts/related_issues/stores/related_issues_store.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/app/assets/javascripts/related_issues/stores/related_issues_store.js b/app/assets/javascripts/related_issues/stores/related_issues_store.js new file mode 100644 index 00000000000..14d71628cad --- /dev/null +++ b/app/assets/javascripts/related_issues/stores/related_issues_store.js @@ -0,0 +1,50 @@ +import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; + +class RelatedIssuesStore { + constructor() { + this.state = { + // Stores issue objects of the known related issues + relatedIssues: [], + // Stores references of the "staging area" related issues that are planned to be added + pendingReferences: [], + }; + } + + setRelatedIssues(issues = []) { + this.state.relatedIssues = convertObjectPropsToCamelCase(issues, { deep: true }); + } + + addRelatedIssues(issues = []) { + this.setRelatedIssues(this.state.relatedIssues.concat(issues)); + } + + removeRelatedIssue(issue) { + this.state.relatedIssues = this.state.relatedIssues.filter(x => x.id !== issue.id); + } + + updateIssueOrder(oldIndex, newIndex) { + if (this.state.relatedIssues.length > 0) { + const updatedIssue = this.state.relatedIssues.splice(oldIndex, 1)[0]; + this.state.relatedIssues.splice(newIndex, 0, updatedIssue); + } + } + + setPendingReferences(issues) { + // Remove duplicates but retain order. + // If you don't do this, Vue will be confused by duplicates and refuse to delete them all. + this.state.pendingReferences = issues.filter((ref, idx) => issues.indexOf(ref) === idx); + } + + addPendingReferences(references = []) { + const issues = this.state.pendingReferences.concat(references); + this.setPendingReferences(issues); + } + + removePendingRelatedIssue(indexToRemove) { + this.state.pendingReferences = this.state.pendingReferences.filter( + (reference, index) => index !== indexToRemove, + ); + } +} + +export default RelatedIssuesStore; |