Eev for communication between components

This commit is contained in:
piotrpekala7 2021-01-28 01:07:51 +01:00
parent 3cc84364ff
commit 5c1ed5de06
5 changed files with 34 additions and 17 deletions

View File

@ -68,6 +68,7 @@
"command-exists": "^1.2.9", "command-exists": "^1.2.9",
"core-js": "^3.8.2", "core-js": "^3.8.2",
"d3-ng2-service": "^2.1.0", "d3-ng2-service": "^2.1.0",
"eev": "^0.1.5",
"file-saver": "^2.0.5", "file-saver": "^2.0.5",
"ini": "^1.3.8", "ini": "^1.3.8",
"material-design-icons": "^3.0.1", "material-design-icons": "^3.0.1",

View File

@ -3,6 +3,7 @@ import Card from 'react-bootstrap/Card';
import Spinner from 'react-bootstrap/Spinner'; import Spinner from 'react-bootstrap/Spinner';
import IssueComponent from './issue'; import IssueComponent from './issue';
import FilterComponent from './filter'; import FilterComponent from './filter';
import e from '../../../event-bus';
const wrapperStyle = { const wrapperStyle = {
justifyContent: 'center' as 'center', justifyContent: 'center' as 'center',
@ -21,7 +22,7 @@ const cardStyle = {
const cardTitleStyle = { const cardTitleStyle = {
color: 'red' color: 'red'
}; };
const message = 'Thank you for reporting the issue!';
const apiUrl = 'https://api.github.com/repos/GNS3/gns3-web-ui/issues'; const apiUrl = 'https://api.github.com/repos/GNS3/gns3-web-ui/issues';
const newIssueLink = 'https://github.com/GNS3/gns3-web-ui/issues/new'; const newIssueLink = 'https://github.com/GNS3/gns3-web-ui/issues/new';
@ -45,8 +46,8 @@ class IssueListComponent extends Component<any, any> {
})); }));
} }
handleChange = (e) => { handleChange = (event) => {
let filter = e.target.value; let filter = event.target.value;
let filteredIssues = this.state.issues; let filteredIssues = this.state.issues;
filteredIssues = filteredIssues.filter((issue) => { filteredIssues = filteredIssues.filter((issue) => {
@ -58,6 +59,10 @@ class IssueListComponent extends Component<any, any> {
}); });
} }
newIssueOpened = (event) => {
e.emit('message', { text: message });
}
render() { render() {
return ( return (
<div> <div>
@ -77,7 +82,7 @@ class IssueListComponent extends Component<any, any> {
<Card style={cardStyle}> <Card style={cardStyle}>
<Card.Body> <Card.Body>
<Card.Title style={cardTitleStyle}>Don't see your issue here?</Card.Title> <Card.Title style={cardTitleStyle}>Don't see your issue here?</Card.Title>
<Card.Link href={newIssueLink} target = "_blank">Open new issue</Card.Link> <Card.Link onClick={this.newIssueOpened} href={newIssueLink} target = "_blank">Open new issue</Card.Link>
</Card.Body> </Card.Body>
</Card> </Card>
</div> </div>

View File

@ -11,34 +11,35 @@ import {
Output, Output,
SimpleChanges, SimpleChanges,
ViewChild, ViewChild,
ViewEncapsulation ViewEncapsulation,
AfterContentInit
} from '@angular/core'; } from '@angular/core';
import IssueListComponent from '../report-issue/issue-list'; import IssueListComponent from '../report-issue/issue-list';
import * as React from 'react'; import * as React from 'react';
import * as ReactDOM from 'react-dom'; import * as ReactDOM from 'react-dom';
import e from '../../../event-bus';
import { ToasterService } from '../../../services/toaster.service';
@Component({ @Component({
selector: 'app-report-issue', selector: 'app-report-issue',
templateUrl: './report-issue.component.html', templateUrl: './report-issue.component.html',
styleUrls: ['./report-issue.component.scss'] styleUrls: ['./report-issue.component.scss']
}) })
export class ReportIssueComponent implements OnInit, OnChanges, OnDestroy, AfterViewInit { export class ReportIssueComponent implements OnDestroy, AfterViewInit, AfterContentInit {
@ViewChild('issueListComponentContainer') containerRef: ElementRef; @ViewChild('issueListComponentContainer') containerRef: ElementRef;
constructor() {} constructor(private toasterService: ToasterService) {}
ngOnInit() {
//this.render();
}
ngOnChanges(changes: SimpleChanges): void {
//this.render();
}
ngAfterViewInit() { ngAfterViewInit() {
this.render(); this.render();
} }
ngAfterContentInit() {
e.on('message', message => {
this.toasterService.success(message.text);
});
}
ngOnDestroy() { ngOnDestroy() {
ReactDOM.unmountComponentAtNode(this.containerRef.nativeElement); ReactDOM.unmountComponentAtNode(this.containerRef.nativeElement);
} }

View File

@ -0,0 +1,5 @@
import Eev from 'eev'
export const e = new Eev()
export default e

View File

@ -5114,6 +5114,11 @@ ee-first@1.1.1:
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0= integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=
eev@^0.1.5:
version "0.1.5"
resolved "https://registry.yarnpkg.com/eev/-/eev-0.1.5.tgz#800c04d450b31972b02660b97182cd28a3058e06"
integrity sha512-U7+up/+0JaC+ffyrMicGDzb+j2Q04Fy22tKK1Xh6hHFWdVtXwoBF8M2DwFofwsJzJcs3W3NPDvmxcMak5/iQaA==
ejs@^3.1.5: ejs@^3.1.5:
version "3.1.5" version "3.1.5"
resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.1.5.tgz#aed723844dc20acb4b170cd9ab1017e476a0d93b" resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.1.5.tgz#aed723844dc20acb4b170cd9ab1017e476a0d93b"