Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GH-61]: Adding "Create Issue" and "Attach Comment to Issue" modals #306

Merged
merged 81 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
23015c1
[MI-1847] Created new branch for create-issue-modal
raghavaggarwal2308 Jun 16, 2022
10d90d9
[MI-1847] fixed error while running make check-style
raghavaggarwal2308 Jun 16, 2022
f6172d2
[MI-1847]Review fixes
raghavaggarwal2308 Jun 17, 2022
114774c
[MI-1847]Fixed initial srtate of milestone in create_issue.tsx
raghavaggarwal2308 Jun 17, 2022
a054a7d
[MI-1860]Added attach comment to gitlab issue button
raghavaggarwal2308 Jun 9, 2022
cc7f9cc
[MI-1860]Added "Attach to gilab issue" modal
raghavaggarwal2308 Jun 9, 2022
f7e864f
[MI-1860]Attach comment endpoint
raghavaggarwal2308 Jun 10, 2022
7f193d0
[MI-1860]Added post message
raghavaggarwal2308 Jun 11, 2022
af71d4e
[MI-1860]Handled error
raghavaggarwal2308 Jun 12, 2022
e3ca566
Code formatting
raghavaggarwal2308 Jun 12, 2022
bcaea3f
Merge branch 'MI-1847' of github.com:Brightscout/mattermost-plugin-gi…
raghavaggarwal2308 Jun 14, 2022
a753160
[MI-1860]Pull from MI-1847
raghavaggarwal2308 Jun 14, 2022
b5b12b1
removed //eslint-diable...
raghavaggarwal2308 Jun 14, 2022
6fd1907
[MI-1860]Review fixes
raghavaggarwal2308 Jun 15, 2022
a324c0a
Merge branch 'MI-1847' of github.com:Brightscout/mattermost-plugin-gi…
raghavaggarwal2308 Jun 16, 2022
b04d319
[MI-1860]Review Fixes
raghavaggarwal2308 Jun 17, 2022
08318e6
[MI-1860]Fixes
raghavaggarwal2308 Jun 17, 2022
1511295
[MI-1847] Review fixes
raghavaggarwal2308 Jun 20, 2022
395ead8
[MI-1847]Review Fixes
raghavaggarwal2308 Jun 20, 2022
78e2fe4
Merge pull request #9 from Brightscout/new-MI-1847
raghavaggarwal2308 Jun 20, 2022
be79e99
Merge branch 'create_issue_modal' of github.com:Brightscout/mattermos…
raghavaggarwal2308 Jun 21, 2022
f63ed27
Fixed CI error
raghavaggarwal2308 Jun 21, 2022
7280b93
Merge branch 'create_issue_modal' of github.com:Brightscout/mattermos…
raghavaggarwal2308 Jun 21, 2022
f444757
[MI-1847]Fixes
raghavaggarwal2308 Jun 21, 2022
612dae9
[MI-1847]Review FIxes
raghavaggarwal2308 Jun 23, 2022
53c2fc0
Merge branch 'MI-1847-component-fix' of github.com:Brightscout/matter…
raghavaggarwal2308 Jun 23, 2022
505ef61
[MI-1860]Review fixes
raghavaggarwal2308 Jun 24, 2022
e121b66
[MI-1847]Review fixes
raghavaggarwal2308 Jun 29, 2022
b514add
[MI-1847]Converted remaining class components to functional components
raghavaggarwal2308 Jun 29, 2022
71ba323
[MI-1860]Fixed variable names
raghavaggarwal2308 Jun 29, 2022
5891151
[MI-1847]Review fixes
raghavaggarwal2308 Jun 30, 2022
b311a0f
[MI-1847]Review fixes
raghavaggarwal2308 Jun 30, 2022
c441278
[MI-1847]Review fixes
raghavaggarwal2308 Jul 1, 2022
f98f996
Merge pull request #12 from Brightscout/MI-1847-component-fix
raghavaggarwal2308 Jul 1, 2022
b11a35e
Merge branch 'create_issue_modal' of github.com:Brightscout/mattermos…
raghavaggarwal2308 Jul 1, 2022
51ddddd
[MI-1860]Review fixes
raghavaggarwal2308 Jul 1, 2022
286de6f
[MI-1860]Review fixes
raghavaggarwal2308 Jul 5, 2022
d61b49b
[MI-1860]Review Fixes
raghavaggarwal2308 Jul 6, 2022
7e3bb1d
Merge pull request #10 from Brightscout/new-MI-1860
raghavaggarwal2308 Jul 6, 2022
1debe45
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gitl…
raghavaggarwal2308 Jul 13, 2022
77bd128
[MI-2221] Review fixes (#22)
raghavaggarwal2308 Oct 6, 2022
53f914c
[MI-2245] Fix failing "Code scanning / CodeQL" in gitlab create issue…
raghavaggarwal2308 Oct 12, 2022
79e82ae
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gitl…
raghavaggarwal2308 Nov 25, 2022
dd36a6f
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gitl…
raghavaggarwal2308 Dec 15, 2022
f88ea7a
Fix lint errors
raghavaggarwal2308 Dec 15, 2022
d869175
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gitl…
raghavaggarwal2308 Jan 13, 2023
e5b9082
[MI-2701]: Done the review fixes of a PR: Adding create issue modal #…
Nityanand13 Feb 3, 2023
aaf36e3
[MI-2947]: Did the review fixes of a gitlab PR #306 (#31)
Nityanand13 Mar 30, 2023
4da3919
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gitl…
raghavaggarwal2308 Mar 30, 2023
736c0ac
[MI-2967]: Did the review fixes of gitlab PR #306 (#33)
Nityanand13 Apr 4, 2023
bef1f23
[MI-2959] Review fixes on Gitlab PR #306(Add create issue modal)
raghavaggarwal2308 May 1, 2023
4cf4448
Merge pull request #36 from Brightscout/MI-2959
raghavaggarwal2308 May 1, 2023
17a962b
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gitl…
raghavaggarwal2308 May 10, 2023
c43dbe9
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gitl…
raghavaggarwal2308 Nov 28, 2023
cf26366
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gitl…
raghavaggarwal2308 Nov 29, 2023
a926c2c
[MI-3787] Fix reported issue:
raghavaggarwal2308 Nov 29, 2023
a264673
[MM-3] Removed "ussCallback" and "useMemo" hooks
raghavaggarwal2308 Dec 7, 2023
cf43d8e
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gitl…
raghavaggarwal2308 Dec 13, 2023
2666781
[MM-3] Removed useMemo/useCallabck and fixed lint error.
raghavaggarwal2308 Dec 14, 2023
ce8d613
[MM-3] Separated out form components for create issue modal
raghavaggarwal2308 Dec 14, 2023
0e35472
[MM-3] Seperate out form component for attach comment to issue modal
raghavaggarwal2308 Dec 14, 2023
c1bbf7e
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gitl…
raghavaggarwal2308 Dec 20, 2023
d5b52ff
Fix lint errors
raghavaggarwal2308 Dec 20, 2023
33dab04
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gitl…
raghavaggarwal2308 Jan 22, 2024
8e48d31
[MM-158] Review fixes
raghavaggarwal2308 Jan 22, 2024
96c60cd
[MM-158] Review fixes:
raghavaggarwal2308 Jan 22, 2024
2783352
[MM-158] Review fixes:
raghavaggarwal2308 Jan 22, 2024
3fd2c21
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gitl…
raghavaggarwal2308 Jan 31, 2024
1ae302f
[MM-146] Fixed lint errors
raghavaggarwal2308 Jan 31, 2024
ea29b31
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gitl…
raghavaggarwal2308 Feb 2, 2024
082a192
Merge branch 'master' into create_issue_modal
raghavaggarwal2308 Mar 18, 2024
e0e2765
[MM-289] Fix ci error
raghavaggarwal2308 Mar 18, 2024
fe33b33
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gitl…
raghavaggarwal2308 Apr 23, 2024
f01c791
Review fixes: Add new types, error state and some refactoring
ayusht2810 Jun 27, 2024
1f9fbc3
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gitl…
ayusht2810 Jun 27, 2024
c09c256
Fix package-lock.json file
ayusht2810 Jun 27, 2024
7216af6
[MM-527] Review fixes
raghavaggarwal2308 Jun 28, 2024
6758220
Create a new type
ayusht2810 Jul 1, 2024
625e227
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gitl…
raghavaggarwal2308 Jul 9, 2024
dbe16e3
Update package-lock.json file due to ci errors
ayusht2810 Jul 9, 2024
90a50a3
Fix type errors
ayusht2810 Jul 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[MI-1860]Added "Attach to gilab issue" modal
1. Button in context menu to open "Attach to gitlab issue" modal.
2. Created modal to attach comment to issue.
  • Loading branch information
raghavaggarwal2308 committed Jun 17, 2022
commit cc7f9cc7e6cc2d5f29c651106871376619a1d9f9
12 changes: 12 additions & 0 deletions server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (p *Plugin) initializeAPI() {
apiRouter.HandleFunc("/assignees", p.checkAuth(p.attachUserContext(p.getAssignees), ResponseTypePlain)).Methods(http.MethodGet)
apiRouter.HandleFunc("/milestones", p.checkAuth(p.attachUserContext(p.getMilestones), ResponseTypePlain)).Methods(http.MethodGet)
apiRouter.HandleFunc("/issue", p.checkAuth(p.attachUserContext(p.createIssue), ResponseTypePlain)).Methods(http.MethodPost)
apiRouter.HandleFunc("/searchissues", p.checkAuth(p.attachUserContext(p.searchIssues), ResponseTypePlain)).Methods(http.MethodGet)
apiRouter.HandleFunc("/settings", p.checkAuth(p.attachUserContext(p.updateSettings), ResponseTypePlain)).Methods(http.MethodPost)
}

Expand Down Expand Up @@ -631,6 +632,17 @@ func (p *Plugin) getPermaLink(postID string) string {
return fmt.Sprintf("%v/_redirect/pl/%v", siteURL, postID)
}

func (p *Plugin) searchIssues(c *UserContext, w http.ResponseWriter, r *http.Request) {
search := r.FormValue("search")
result, err := p.GitlabClient.SearchIssues(c.Ctx, c.GitlabInfo, search)
if err != nil {
c.Log.WithError(err).Warnf("Unable to search issues in GitLab API")
p.writeAPIError(w, &APIErrorResponse{ID: "", Message: fmt.Sprintf("Unable to search issues in GitLab API. Error: %d", err), StatusCode: http.StatusInternalServerError})
return
}

p.writeAPIResponse(w, result)
}
func (p *Plugin) getYourProjects(c *UserContext, w http.ResponseWriter, r *http.Request) {
result, err := p.GitlabClient.GetYourProjects(c.Ctx, c.GitlabInfo)
if err != nil {
Expand Down
20 changes: 20 additions & 0 deletions server/gitlab/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,26 @@ func (g *gitlab) CreateIssue(ctx context.Context, user *UserInfo, issue *IssueRe
return result, nil
}

func (g *gitlab) SearchIssues(ctx context.Context, user *UserInfo, search string) ([]*internGitlab.Issue, error) {
client, err := g.gitlabConnect(*user.Token)
if err != nil {
return nil, err
}

result, resp, err := client.Search.Issues(
search,
&internGitlab.SearchOptions{},
internGitlab.WithContext(ctx),
)
if respErr := checkResponse(resp); respErr != nil {
return nil, respErr
}
if err != nil {
return nil, errors.Wrap(err, "can't search issues in GitLab api")
}
return result, nil
}

func (g *gitlab) ResolveNamespaceAndProject(
ctx context.Context,
userInfo *UserInfo,
Expand Down
3 changes: 2 additions & 1 deletion server/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ type Gitlab interface {
GetCurrentUser(ctx context.Context, userID string, token oauth2.Token) (*UserInfo, error)
GetUserDetails(ctx context.Context, user *UserInfo) (*internGitlab.User, error)
GetProject(ctx context.Context, user *UserInfo, owner, repo string) (*internGitlab.Project, error)
CreateIssue(ctx context.Context, user *UserInfo, issue *IssueRequest) (*internGitlab.Issue, error)
SearchIssues(ctx context.Context, user *UserInfo, search string) ([]*internGitlab.Issue, error)
GetReviews(ctx context.Context, user *UserInfo) ([]*internGitlab.MergeRequest, error)
GetYourPrs(ctx context.Context, user *UserInfo) ([]*internGitlab.MergeRequest, error)
GetYourAssignments(ctx context.Context, user *UserInfo) ([]*internGitlab.Issue, error)
GetUnreads(ctx context.Context, user *UserInfo) ([]*internGitlab.Todo, error)
CreateIssue(ctx context.Context, user *UserInfo, issue *IssueRequest) (*internGitlab.Issue, error)
GetYourProjects(ctx context.Context, user *UserInfo) ([]*internGitlab.Project, error)
GetLabels(ctx context.Context, user *UserInfo, projectID string) ([]*internGitlab.Label, error)
GetAssignees(ctx context.Context, user *UserInfo, projectID string) ([]*internGitlab.ProjectMember, error)
Expand Down
15 changes: 15 additions & 0 deletions server/gitlab/mocks/mock_gitlab.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions server/mocks/mock_gitlab.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"core-js": "3.6.5",
"csstype": "3.0.3",
"debounce-promise": "3.1.2",
"mattermost-redux": "5.27.0",
"prop-types": "15.7.2",
"react": "16.13.1",
Expand Down
2 changes: 2 additions & 0 deletions webapp/src/action_types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ export default {
OPEN_CREATE_ISSUE_MODAL_WITHOUT_POST: `${id}_open_create_modal_without_post`,
CLOSE_CREATE_ISSUE_MODAL: `${id}_close_create_modal`,
RECEIVED_PROJECTS: `${id}_received_projects`,
CLOSE_ATTACH_COMMENT_TO_ISSUE_MODAL: `${id}_close_attach_modal`,
OPEN_ATTACH_COMMENT_TO_ISSUE_MODAL: `${id}_open_attach_modal`,
};
15 changes: 15 additions & 0 deletions webapp/src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,21 @@ export function createIssue(payload) {
};
}

export function openAttachCommentToIssueModal(postId) {
return {
type: ActionTypes.OPEN_ATTACH_COMMENT_TO_ISSUE_MODAL,
data: {
postId,
},
};
}

export function closeAttachCommentToIssueModal() {
return {
type: ActionTypes.CLOSE_ATTACH_COMMENT_TO_ISSUE_MODAL,
};
}

export function getProjects() {
return async (dispatch, getState) => {
let data;
Expand Down
4 changes: 4 additions & 0 deletions webapp/src/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export default class Client {
return this.doPost(`${this.url}/issue`, payload);
}

searchIssues = async (searchTerm) => {
return this.doGet(`${this.url}/searchissues?search=${searchTerm}`);
}

getProjects = async () => {
return this.doGet(`${this.url}/projects`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class AttachCommentToIssuePostMenuAction extends PureComponent {
handleClick = (e) => {
const {open, postId} = this.props;
e.preventDefault();
// open(postId);
open(postId);
};

render() {
Expand Down
152 changes: 152 additions & 0 deletions webapp/src/components/gitlab_issue_selector.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';

import debounce from 'debounce-promise';
import AsyncSelect from 'react-select/async';

import {getStyleForReactSelect} from 'utils/styles';
import Client from 'client';

const searchDebounceDelay = 400;

export default class GitlabIssueSelector extends PureComponent {
static propTypes = {
required: PropTypes.bool,
theme: PropTypes.object.isRequired,
onChange: PropTypes.func.isRequired,
error: PropTypes.string,
value: PropTypes.object,
};

constructor(props) {
super(props);

this.state = {invalid: false};
}

componentDidUpdate(prevProps, prevState) {
if (prevState.invalid && this.props.value !== prevProps.value) {
this.setState({invalid: false}); //eslint-disable-line react/no-did-update-set-state
}
}

handleIssueSearchTermChange = (inputValue) => {
return this.debouncedSearchIssues(inputValue);
};

searchIssues = async (text) => {
// const textEncoded = encodeURIComponent(text.trim().replace(/"/g, '\\"'));

let issues = await Client.searchIssues(text)

if (!Array.isArray(issues)) {
return [];
}

return issues.map((issue) => {
const projectParts = issue.web_url.split('/');
let prefix = '';
if (projectParts.length >= 5) {
prefix = `${projectParts[projectParts.length - 5]}/${projectParts[projectParts.length - 4]}`;
}
return ({value: issue, label: `${prefix}, #${issue.iid}: ${issue.title}`});
});
};

debouncedSearchIssues = debounce(this.searchIssues, searchDebounceDelay);

onChange = (e) => {
const value = e ? e.value : '';
this.props.onChange(value);
}

isValid = () => {
if (!this.props.required) {
return true;
}

const valid = this.props.value && this.props.value.toString().length !== 0;
this.setState({invalid: !valid});
return valid;
};

render() {
const {error} = this.props;
const requiredStar = (
<span
className={'error-text'}
style={{marginLeft: '3px'}}
>
{'*'}
</span>
);

let issueError = null;
if (error) {
issueError = (
<p className='help-text error-text'>
<span>{error}</span>
</p>
);
}

const serverError = this.state.error;
let errComponent;
if (this.state.error) {
errComponent = (
<p className='alert alert-danger'>
<i
className='fa fa-warning'
title='Warning Icon'
/>
<span>{serverError.toString()}</span>
</p>
);
}

const requiredMsg = 'This field is required.';
let validationError = null;
if (this.props.required && this.state.invalid) {
validationError = (
<p className='help-text error-text'>
<span>{requiredMsg}</span>
</p>
);
}

return (
<div className={'form-group margin-bottom x3'}>
{errComponent}
<label
className={'control-label'}
htmlFor={'issue'}
>
{'GitLab Issue'}
</label>
{this.props.required && requiredStar}
<AsyncSelect
name={'issue'}
placeholder={'Search for issues containing text...'}
onChange={this.onChange}
required={true}
disabled={false}
isMulti={false}
isClearable={true}
defaultOptions={true}
loadOptions={this.handleIssueSearchTermChange}
menuPortalTarget={document.body}
menuPlacement='auto'
styles={getStyleForReactSelect(this.props.theme)}
/>
{validationError}
{issueError}
<div className={'help-text'}>
{'Returns issues sorted by most recently created.'} <br/>
</div>
</div>
);
}
}
Loading