Skip to content

Commit

Permalink
[FIX JENKINS-42650] - notify when leaving pipeline page (#31)
Browse files Browse the repository at this point in the history
* JENKINS-42650 - notify when leaving pipeline page
  • Loading branch information
kzantow committed Mar 13, 2017
1 parent 8f043b5 commit 4872877
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
35 changes: 34 additions & 1 deletion src/main/js/EditorPage.jsx
Expand Up @@ -119,6 +119,38 @@ class PipelineLoader extends React.Component {
this.loadPipeline();
}

componentDidMount() {
this.context.router.setRouteLeaveHook(this.props.route, e => this.routerWillLeave(e));
this.priorUnload = window.onbeforeunload;
window.onbeforeunload = e => this.routerWillLeave(e);
pipelineStore.addListener(this.pipelineUpdated = p => this.checkForModification());
}

componentWillUnmount() {
window.onbeforeunload = this.priorUnload;
pipelineStore.removeListener(this.pipelineUpdated);
}

routerWillLeave(e) {
if (this.pipelineIsModified) {
const t = 'There are unsaved changes, discard them?';
if (e) {
e.returnValue = t;
}
return t;
}
}

checkForModification() {
if (!this.lastPipeline) {
this.lastPipeline = JSON.stringify(convertInternalModelToJson(pipelineStore.pipeline));
return;
}
if (!this.pipelineIsModified) {
this.pipelineIsModified = JSON.stringify(convertInternalModelToJson(pipelineStore.pipeline)) !== this.lastPipeline;
}
}

loadPipeline(onComplete) {
const { organization, pipeline, branch } = this.props.params;
this.opener = locationService.previous;
Expand Down Expand Up @@ -288,7 +320,6 @@ class PipelineLoader extends React.Component {
convertJsonToPipeline(JSON.stringify(pipelineJson), (pipelineScript, err) => {
if (!err) {
const body = {
"$class": "io.jenkins.blueocean.blueocean_github_pipeline.GithubScmSaveFileRequest",
"content": {
"message": saveMessage,
"path": "Jenkinsfile",
Expand All @@ -307,6 +338,8 @@ class PipelineLoader extends React.Component {
}
})
.then(data => {
this.pipelineIsModified = false;
this.lastPipeline = JSON.stringify(convertInternalModelToJson(pipelineStore.pipeline));
// If this is a save on the same branch that already has a Jenkinsfile, just re-run it
if (this.state.sha && branch === body.content.branch) {
RunApi.startRun({ _links: { self: { href: this.href + 'branches/' + branch + '/' }}})
Expand Down
1 change: 1 addition & 0 deletions src/main/js/jenkins-js-extension.yaml
Expand Up @@ -9,6 +9,7 @@ extensions:

- component: PipelineEditorLink
extensionPoint: jenkins.pipeline.branches.list.action
ordinal: 50

- component: components/editor/EditorCSS #Self-implemented, currently required to make the css load
extensionPoint: pipeline.editor.css
Expand Down
2 changes: 1 addition & 1 deletion src/main/js/services/PipelineValidator.js
Expand Up @@ -36,7 +36,7 @@ export class PipelineValidator {
if (window.isDevelopmentMode) console.error(data);
}
handler(data);
});
}, { disableLoadingIndicator: true });
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/main/less/editor.less
Expand Up @@ -792,3 +792,11 @@
font-weight: bold;
}
}

td .pipeline-editor-link .svg-icon:hover path {
fill: #1c436a;
}

.Header-topNav .pipeline-editor-link .svg-icon:hover path {
fill: #ccc;
}

0 comments on commit 4872877

Please sign in to comment.