diff options
author | Michael Foiani <sotech117@Michaels-MacBook-Pro-5.local> | 2022-08-18 00:47:30 +0200 |
---|---|---|
committer | Michael Foiani <sotech117@Michaels-MacBook-Pro-5.local> | 2022-08-18 00:47:30 +0200 |
commit | a41d3546cbf34313b1d0a2caa7050fd04e7eee0f (patch) | |
tree | c11322e56a9038817406a09327a2a4ef1f4c5ac5 /src/client/util/ReportManager.tsx | |
parent | 934f78eb90dd4aa16929e1b89c7c05f4f24b5c07 (diff) |
add button to create an issue - also can upload files.
Diffstat (limited to 'src/client/util/ReportManager.tsx')
-rw-r--r-- | src/client/util/ReportManager.tsx | 95 |
1 files changed, 72 insertions, 23 deletions
diff --git a/src/client/util/ReportManager.tsx b/src/client/util/ReportManager.tsx index fa9a0513b..75102ec8e 100644 --- a/src/client/util/ReportManager.tsx +++ b/src/client/util/ReportManager.tsx @@ -37,9 +37,11 @@ export class ReportManager extends React.Component<{}> { @observable public issues: any[] = []; @action setIssues = action((issues: any[]) => { this.issues = issues; }); - @observable public selectedIssue: any = null; + // undefined is the default - null is if the user is making an issue + @observable public selectedIssue: any = undefined; @action setSelectedIssue = action((issue: any) => { this.selectedIssue = issue; }); + // only get the open issues @observable public shownIssues = this.issues.filter(issue => issue.state === 'open'); public updateIssueSearch = action((query: string = '') => { @@ -98,11 +100,12 @@ export class ReportManager extends React.Component<{}> { public async reportIssue() { if (this.toGithub) { + const req = await this.octokit.request('POST /repos/{owner}/{repo}/issues', { owner: 'brown-dash', repo: 'Dash-Web', title: this.formatTitle(this.bugTitle, Doc.CurrentUserEmail), - body: this.bugDescription, + body: `${this.bugDescription} \n\nfileLinks:\n${(this.fileLinks ?? []).join('\n')}`, labels: [ 'from-dash-app', ] @@ -123,31 +126,85 @@ export class ReportManager extends React.Component<{}> { this.bugTitle = ''; this.bugDescription = ''; this.toGithub = false; + this.setFileLinks([]) this.close(); } + @observable public fileLinks: any = []; + @action setFileLinks = action((links: any) => { this.fileLinks = links; }); + + private getServerPath = (link: any) => { return link.result.accessPaths.agnostic.server } + + private uploadFiles = (input: any) => { + this.setFileLinks(null); + // upload the files to the server + if (input.files && input.files.length !== 0) { + const fileArray: File[] = Array.from(input.files); + Networking.UploadFilesToServer(fileArray).then(links => { + console.log('finshed uploading', links.map(this.getServerPath)); + this.setFileLinks(links.map(this.getServerPath)); + }) + } + + } + + private renderIssue = (issue: any) => { - const { title, body, number, html_url } = issue; - return ( + const isReportingIssue = issue === null; + + return isReportingIssue ? + // report issue + (<div className="settings-content"> + <h3 style={{ 'textDecoration': 'underline'}}>Report an Issue</h3> + <label>Please leave a title for the bug.</label><br /> + <input type="text" placeholder='title' onChange={(e) => this.bugTitle = e.target.value} required/> + <br /> + <label>Please leave a description for the bug and how it can be recreated.</label> + <textarea placeholder='description' onChange={(e) => this.bugDescription = e.target.value} required/> + <br /><br /> + {/* {<label>Send to github issues? </label> + <input type="checkbox" onChange={(e) => this.toGithub = e.target.checked} /> + <br /> } */} + + <div> + <label>Choose file(s) to upload to show the bug (optional)</label> + <input type="file" name="file" multiple accept='audio/*, video/*' onChange={e => this.uploadFiles(e.target)}/> + </div> + <br /> + <button onClick={() => this.reportIssue()} disabled={this.fileLinks === null}>{this.fileLinks === null ? 'Uploading...' : 'Submit'}</button> + </div>) + : + // view issue + ( <div className='issue-container'> - <h5 style={{'textAlign': "left"}}><a href={html_url} target="_blank">Issue #{number}</a></h5> + <h5 style={{'textAlign': "left"}}><a href={issue.html_url} target="_blank">Issue #{issue.number}</a></h5> <div className='issue-title'> - {title} + {issue.title} </div> - <ReactMarkdown children={body} className='issue-body' linkTarget={"_blank"} remarkPlugins={[remarkGfm]} rehypePlugins={[rehypeRaw]} /> + <ReactMarkdown children={issue.body} className='issue-body' linkTarget={"_blank"} remarkPlugins={[remarkGfm]} rehypePlugins={[rehypeRaw]} /> </div> ); } + private showReportIssueScreen = () => { + this.setSelectedIssue(null); + } + + private closeReportIssueScreen = () => { + this.setSelectedIssue(undefined); + } + private get reportInterface() { + const isReportingIssue = this.selectedIssue === null; + return ( <div className="settings-interface"> <div className='issue-list-wrapper'> <h3>Current Issues</h3> <input type="text" placeholder='search issues' onChange={(e => this.updateIssueSearch(e.target.value))}></input><br /> - {this.issues.length === 0 ? <ReactLoading/> : this.shownIssues.map(issue => <div className='issue-list' key={issue.number} onClick={() => this.setSelectedIssue(issue)}>{issue.title}</div>)} + {this.issues.length === 0 ? <ReactLoading className='loading-center'/> : this.shownIssues.map(issue => <div className='issue-list' key={issue.number} onClick={() => this.setSelectedIssue(issue)}>{issue.title}</div>)} {/* <div className="settings-user"> <button onClick={() => this.getAllIssues().then(issues => this.issues = issues)}>Poll Issues</button> @@ -158,23 +215,15 @@ export class ReportManager extends React.Component<{}> { <FontAwesomeIcon icon={'times'} color="black" size={'lg'} /> </div> - <div className="issue-content"> - {this.selectedIssue === null ? "no issue selected" : this.renderIssue(this.selectedIssue)} + <div className="issue-content" style={{'paddingTop' : this.selectedIssue === undefined ? '50px' : 'inherit'}}> + {this.selectedIssue === undefined ? "no issue selected" : this.renderIssue(this.selectedIssue)} </div> - {/* <div className="settings-content"> - <h3 style={{ 'textDecoration': 'underline'}}>Report an Issue</h3> - <label>Please leave a title for the bug.</label><br /> - <input type="text" placeholder='title' onChange={(e) => this.bugTitle = e.target.value} /> - <br /> - <label>Please leave a description for the bug and how it can be recreated.</label> - <textarea placeholder='description' onChange={(e) => this.bugDescription = e.target.value}/> - <br /><br /> - {/* <label>Send to github issues? </label> - <input type="checkbox" onChange={(e) => this.toGithub = e.target.checked} /> - <br /> } - <button onClick={() => this.reportIssue()}>Submit</button> - </div> */} + <div className='report-issue-fab'> + <button + onClick={() => isReportingIssue ? this.closeReportIssueScreen() : this.showReportIssueScreen()} + >{isReportingIssue ? 'Cancel' : 'Report New Issue'}</button> + </div> </div> |