Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Disable stop button immediately after click (#5079)
Browse files Browse the repository at this point in the history
  • Loading branch information
debuggy authored Nov 13, 2020
1 parent 9764169 commit f4e4b47
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 37 deletions.
72 changes: 36 additions & 36 deletions src/webportal/src/app/job/job-view/fabric/JobList/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import React, {
useEffect,
useRef,
} from 'react';
import { debounce, isEmpty } from 'lodash';
import { debounce, isEmpty, cloneDeep } from 'lodash';

import { ColorClassNames, getTheme } from '@uifabric/styling';
import { Fabric } from 'office-ui-fabric-react/lib/Fabric';
Expand All @@ -39,7 +39,6 @@ export default function JobList() {
const admin = userAuth.checkAdmin();
const username = cookies.get('user');

const [allJobs, setAllJobs] = useState(null);
const [selectedJobs, setSelectedJobs] = useState([]);
const [error, setError] = useState(null);

Expand Down Expand Up @@ -164,42 +163,43 @@ export default function JobList() {
applyOrdering(ordering);
}, [applyOrdering, ordering]);

const stopJob = useCallback(
(...jobs) => {
userAuth.checkToken(token => {
jobs.forEach(job => {
const { name, username } = job;
const client = new PAIV2.OpenPAIClient({
rest_server_uri: new URL(
webportalConfig.restServerUri,
window.location.href,
),
username: username,
token: token,
https: window.location.protocol === 'https:',
});
client.job
.updateJobExecutionType(username, name, 'STOP')
.then(() => {
job.executionType = 'STOP';
delete job._statusText;
delete job._statusIndex;
setAllJobs(allJobs.slice());
})
.catch(err => {
if (err.data.code === 'UnauthorizedUserError') {
alert(err.data.message);
clearToken();
} else {
alert(err.data.message || err.message);
throw new Error(err.data.message || err.message);
}
});
const stopJob = (...jobs) => {
userAuth.checkToken(token => {
jobs.forEach(job => {
const { name, username } = job;
const client = new PAIV2.OpenPAIClient({
rest_server_uri: new URL(
webportalConfig.restServerUri,
window.location.href,
),
username: username,
token: token,
https: window.location.protocol === 'https:',
});
client.job
.updateJobExecutionType(username, name, 'STOP')
.then(() => {
job.executionType = 'STOP';
delete job._statusText;
delete job._statusIndex;
const newFilteredJobsInfo = cloneDeep(filteredJobsInfo);
setFilteredJobsInfo(newFilteredJobsInfo);
})
.catch(err => {
if (err.data && err.data.code === 'UnauthorizedUserError') {
alert(err.data.message);
clearToken();
} else if (err.data) {
alert(err.data.message);
throw new Error(err.data.message);
} else {
alert(err.message);
throw new Error(err.message);
}
});
});
},
[allJobs],
);
});
};

const getJobs = async query => {
const token = userAuth.checkToken();
Expand Down
7 changes: 6 additions & 1 deletion src/webportal/src/app/job/job-view/fabric/job-detail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import { capitalize, isEmpty, isNil, get } from 'lodash';
import { capitalize, isEmpty, isNil, get, cloneDeep } from 'lodash';
import { DateTime, Interval } from 'luxon';
import {
MessageBar,
Expand Down Expand Up @@ -162,6 +162,11 @@ class JobDetail extends React.Component {

async stop() {
await stopJob();
const newJobInfo = cloneDeep(this.state.jobInfo);
newJobInfo.jobStatus.executionType = 'STOP';
this.setState({
jobInfo: newJobInfo,
});
await this.reload();
}

Expand Down

0 comments on commit f4e4b47

Please sign in to comment.