Skip to content

Commit

Permalink
Merge pull request #677 from nasa/harmony-1960
Browse files Browse the repository at this point in the history
Harmony 1960 - fix job counter refresh on job table reload
  • Loading branch information
vinnyinverso authored Dec 18, 2024
2 parents 0791a75 + dc0a609 commit e9b3d3e
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 10 deletions.
27 changes: 19 additions & 8 deletions services/harmony/public/js/workflow-ui/jobs/jobs-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,22 @@ function initSelectAllHandler() {
});
}

/**
* Replace the HTML of the jobs table. Reinitialize event handlers and formatting.
* @param {*} htmlRes - The HTML from the successful Jobs table response
*/
function handleSuccessResponse(htmlRes) {
const tmp = document.createElement('div');
tmp.innerHTML = `<div class="col-10" id="jobs-table-container">${htmlRes}</div>`;
document.getElementById('jobs-table-container').replaceWith(...tmp.childNodes);
initSelectHandler('.select-job');
initSelectAllHandler();
initCopyHandler('.copy-request');
formatDates('.date-td');
refreshSelected();
setJobCounterDisplay(jobIDs.length);
}

/**
* Query Harmony for up to date version of particular HTML rows of the jobs table.
* @param {object} params - parameters that define what will appear in the table row
Expand All @@ -186,14 +202,7 @@ async function loadRows(params) {
});
if (res.status === 200) {
const htmlRes = await res.text();
const tmp = document.createElement('div');
tmp.innerHTML = `<div class="col-10" id="jobs-table-container">${htmlRes}</div>`;
document.getElementById('jobs-table-container').replaceWith(...tmp.childNodes);
initSelectHandler('.select-job');
initSelectAllHandler();
initCopyHandler('.copy-request');
formatDates('.date-td');
refreshSelected();
handleSuccessResponse(htmlRes);
}
}

Expand Down Expand Up @@ -259,6 +268,8 @@ const jobsTable = {
getJobStatus(jobID) {
return document.querySelector(`#select-${jobID}`).getAttribute('data-status');
},

handleSuccessResponse,
};

export default jobsTable;
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('JobsStatusChangeLinks', function () {
const runningJobID = '058184f7-498c-4aa5-a3df-96a3a49b7d19';
const pausedJobID = '38d2b820-0b52-475d-8cb0-0b9f7775f767';
beforeEach(async () => {
const dom = await JSDOM.fromFile(path.resolve(__dirname, 'labels.html'), { url: 'http://localhost' });
const dom = await JSDOM.fromFile(path.resolve(__dirname, 'jobs.html'), { url: 'http://localhost' });
global.window = dom.window as unknown as Window & typeof globalThis;
global.document = dom.window.document;
});
Expand Down
24 changes: 24 additions & 0 deletions services/harmony/test/workflow-ui/jobs-table-js.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { JSDOM } from 'jsdom';
import { expect } from 'chai';
import path from 'path';
import JobsTable from '../../public/js/workflow-ui/jobs/jobs-table';
import * as fs from 'fs';

beforeEach(async () => {
const dom = await JSDOM.fromFile(path.resolve(__dirname, 'jobs.html'), { url: 'http://localhost' });
global.window = dom.window as unknown as Window & typeof globalThis;
global.document = dom.window.document;
});

describe('jobs-table.js', () => {
describe('handleSuccessResponse', () => {
it('resets the jobs counter display to reflect the new set of selected rows', () => {
const tableHtml = fs.readFileSync(path.resolve(__dirname, 'jobs-table.html'), 'utf-8');
const count = document.getElementById('job-counter').textContent;
expect(count).to.equal('0');
JobsTable.handleSuccessResponse(tableHtml);
const newCount = document.getElementById('job-counter').textContent;
expect(newCount).to.equal('2');
});
});
});
128 changes: 128 additions & 0 deletions services/harmony/test/workflow-ui/jobs-table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@

<table id="workflow-ui-jobs-table" class="table table-sm">
<thead class="sticky-top bg-white">
<tr class="align-middle">
<th scope="col"><input id="select-jobs" type="checkbox" title="select/deselect all jobs" autocomplete="off"></th>
<th scope="col">jobID</th>
<th scope="col">service</th>
<th scope="col">status</th>
<th scope="col">message</th>
<th scope="col">
<div class="d-flex flex-row align-items-center">
<div>granules</div>&nbsp;
<div class="d-flex flex-column">
<a href="#" onclick="document.getElementById('sort-granules').value='asc';document.getElementById('jobs-query-form').submit();" class="" style="height:12px;">
<i class="bi bi-caret-up-fill" title="apply ascending sort"></i>
</a>
<a href="#" onclick="document.getElementById('sort-granules').value='desc';document.getElementById('jobs-query-form').submit();" class="">
<i class="bi bi-caret-down-fill" title="apply descending sort"></i>
</a>
</div>
</div>
</th>
<th scope="col">progress</th>
<th scope="col">createdAt</th>
<th scope="col">updatedAt</th>
</tr>
</thead>
<tbody>
<tr id="job-3f94ec65-baa6-446d-bb11-bfd3890ea7c6" class="job-table-row">
<td><input id="select-3f94ec65-baa6-446d-bb11-bfd3890ea7c6" class="select-job" type="checkbox" data-id="3f94ec65-baa6-446d-bb11-bfd3890ea7c6" data-status="running" autocomplete="off" checked></td>
<th scope="row"><a href="workflow-ui/3f94ec65-baa6-446d-bb11-bfd3890ea7c6?fromDateTime=&amp;toDateTime=&amp;dateKind=createdAt&amp;tzOffsetMinutes=&amp;jobsLink=http%3A%2F%2Flocalhost%3A3000%2Fworkflow-ui%3Fpage%3D1%26limit%3D10">3f94ec65-baa6-446d-bb11-bfd3890ea7c6</a></th>
<td>harmony/service-example</td>
<td><span class="badge rounded-pill bg-info">running</span></td>
<td id="message-td" title="The job is being processed">The job is being processed</td>
<td>1</td>
<td>9%</td>
<td class="date-td" data-time="1734364907924">12/16/2024, 11:01:47 AM</td>
<td class="date-td" data-time="1734364909789">12/16/2024, 11:01:49 AM</td>
</tr>
<tr><th id="copy-3f94ec65-baa6-446d-bb11-bfd3890ea7c6" class="job-url-th" colspan="12">
<div class="d-flex flex-row justify-content-between">
<div>
<i class="bi bi-copy text-primary copy-request" data-text="http://localhost:3000/C1233800302-EEDTEST/ogc-api-coverages/1.0.0/collections/all/coverage/rangeset?granuleId=G1233800343-EEDTEST&amp;format=image%2Ftiff" data-truncated="false"></i>
<span title="http://localhost:3000/C1233800302-EEDTEST/ogc-api-coverages/1.0.0/collections/all/coverage/rangeset?granuleId=G1233800343-EEDTEST&amp;format=image/tiff" class="text-muted job-url-text">/C1233800302-EEDTEST/ogc-api-coverages/.../all/...?granuleId=G1233800343-EEDTEST&amp;format=image/tiff</span>
</div>
<div class="ml-1" id="job-labels-display-3f94ec65-baa6-446d-bb11-bfd3890ea7c6" data-labels="">

</div>
</div> </th> </tr><tr id="job-be304c5d-0968-49c1-a1e6-eefde5dd6eab" class="job-table-row">
<td><input id="select-be304c5d-0968-49c1-a1e6-eefde5dd6eab" class="select-job" type="checkbox" data-id="be304c5d-0968-49c1-a1e6-eefde5dd6eab" data-status="successful" autocomplete="off"></td>
<th scope="row"><a href="workflow-ui/be304c5d-0968-49c1-a1e6-eefde5dd6eab?fromDateTime=&amp;toDateTime=&amp;dateKind=createdAt&amp;tzOffsetMinutes=&amp;jobsLink=http%3A%2F%2Flocalhost%3A3000%2Fworkflow-ui%3Fpage%3D1%26limit%3D10">be304c5d-0968-49c1-a1e6-eefde5dd6eab</a></th>
<td>harmony/service-example</td>
<td><span class="badge rounded-pill bg-success">successful</span></td>
<td id="message-td" title="The job has completed successfully">The job has completed successfully</td>
<td>1</td>
<td>100%</td>
<td class="date-td" data-time="1734364907559">12/16/2024, 11:01:47 AM</td>
<td class="date-td" data-time="1734364923623">12/16/2024, 11:02:03 AM</td>
</tr>
<tr><th id="copy-be304c5d-0968-49c1-a1e6-eefde5dd6eab" class="job-url-th" colspan="12">
<div class="d-flex flex-row justify-content-between">
<div>
<i class="bi bi-copy text-primary copy-request" data-text="http://localhost:3000/C1233800302-EEDTEST/ogc-api-coverages/1.0.0/collections/all/coverage/rangeset?granuleId=G1233800343-EEDTEST&amp;format=image%2Ftiff" data-truncated="false"></i>
<span title="http://localhost:3000/C1233800302-EEDTEST/ogc-api-coverages/1.0.0/collections/all/coverage/rangeset?granuleId=G1233800343-EEDTEST&amp;format=image/tiff" class="text-muted job-url-text">/C1233800302-EEDTEST/ogc-api-coverages/.../all/...?granuleId=G1233800343-EEDTEST&amp;format=image/tiff</span>
</div>
<div class="ml-1" id="job-labels-display-be304c5d-0968-49c1-a1e6-eefde5dd6eab" data-labels="">

</div>
</div> </th> </tr><tr id="job-20009fb7-e95b-431b-9857-7e50071a2827" class="job-table-row">
<td><input id="select-20009fb7-e95b-431b-9857-7e50071a2827" class="select-job" type="checkbox" data-id="20009fb7-e95b-431b-9857-7e50071a2827" data-status="successful" autocomplete="off"></td>
<th scope="row"><a href="workflow-ui/20009fb7-e95b-431b-9857-7e50071a2827?fromDateTime=&amp;toDateTime=&amp;dateKind=createdAt&amp;tzOffsetMinutes=&amp;jobsLink=http%3A%2F%2Flocalhost%3A3000%2Fworkflow-ui%3Fpage%3D1%26limit%3D10">20009fb7-e95b-431b-9857-7e50071a2827</a></th>
<td>harmony/service-example</td>
<td><span class="badge rounded-pill bg-success">successful</span></td>
<td id="message-td" title="The job has completed successfully">The job has completed successfully</td>
<td>1</td>
<td>100%</td>
<td class="date-td" data-time="1734364899440">12/16/2024, 11:01:39 AM</td>
<td class="date-td" data-time="1734364913509">12/16/2024, 11:01:53 AM</td>
</tr>
<tr><th id="copy-20009fb7-e95b-431b-9857-7e50071a2827" class="job-url-th" colspan="12">
<div class="d-flex flex-row justify-content-between">
<div>
<i class="bi bi-copy text-primary copy-request" data-text="http://localhost:3000/C1233800302-EEDTEST/ogc-api-coverages/1.0.0/collections/all/coverage/rangeset?granuleId=G1233800343-EEDTEST&amp;format=image%2Ftiff" data-truncated="false"></i>
<span title="http://localhost:3000/C1233800302-EEDTEST/ogc-api-coverages/1.0.0/collections/all/coverage/rangeset?granuleId=G1233800343-EEDTEST&amp;format=image/tiff" class="text-muted job-url-text">/C1233800302-EEDTEST/ogc-api-coverages/.../all/...?granuleId=G1233800343-EEDTEST&amp;format=image/tiff</span>
</div>
<div class="ml-1" id="job-labels-display-20009fb7-e95b-431b-9857-7e50071a2827" data-labels="">

</div>
</div> </th> </tr><tr id="job-3ad89e91-5c02-4805-b352-083797504319" class="job-table-row">
<td><input id="select-3ad89e91-5c02-4805-b352-083797504319" class="select-job" type="checkbox" data-id="3ad89e91-5c02-4805-b352-083797504319" data-status="successful" autocomplete="off" checked></td>
<th scope="row"><a href="workflow-ui/3ad89e91-5c02-4805-b352-083797504319?fromDateTime=&amp;toDateTime=&amp;dateKind=createdAt&amp;tzOffsetMinutes=&amp;jobsLink=http%3A%2F%2Flocalhost%3A3000%2Fworkflow-ui%3Fpage%3D1%26limit%3D10">3ad89e91-5c02-4805-b352-083797504319</a></th>
<td>harmony/service-example</td>
<td><span class="badge rounded-pill bg-success">successful</span></td>
<td id="message-td" title="The job has completed successfully">The job has completed successfully</td>
<td>1</td>
<td>100%</td>
<td class="date-td" data-time="1733252214362">12/3/2024, 1:56:54 PM</td>
<td class="date-td" data-time="1733252229597">12/3/2024, 1:57:09 PM</td>
</tr>
<tr><th id="copy-3ad89e91-5c02-4805-b352-083797504319" class="job-url-th" colspan="12">
<div class="d-flex flex-row justify-content-between">
<div>
<i class="bi bi-copy text-primary copy-request" data-text="http://localhost:3000/C1233800302-EEDTEST/ogc-api-coverages/1.0.0/collections/all/coverage/rangeset?granuleId=G1233800343-EEDTEST&amp;format=image%2Ftiff" data-truncated="false"></i>
<span title="http://localhost:3000/C1233800302-EEDTEST/ogc-api-coverages/1.0.0/collections/all/coverage/rangeset?granuleId=G1233800343-EEDTEST&amp;format=image/tiff" class="text-muted job-url-text">/C1233800302-EEDTEST/ogc-api-coverages/.../all/...?granuleId=G1233800343-EEDTEST&amp;format=image/tiff</span>
</div>
<div class="ml-1" id="job-labels-display-3ad89e91-5c02-4805-b352-083797504319" data-labels="">

</div>
</div> </th> </tr></tbody>
</table> <nav id="page-nav" aria-label="Page navigation" class="bg-white d-flex flex-column align-items-center py-2 sticky-paging">
<ul class="pagination px-0 mx-auto mb-1">
<li class="page-item disabled">
<a class="page-link" href="" title="first">first</a>
</li>
<li class="page-item disabled">
<a class="page-link" href="" title="previous">previous</a>
</li>
<li class="page-item disabled">
<a class="page-link" href="" title="next">next</a>
</li>
<li class="page-item disabled">
<a class="page-link" href="" title="last">last</a>
</li>
</ul>
<small class="text-muted">
1-4 of 4 (page 1 of 1)
</small>
</nav>
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path';
import Labels from '../../public/js/workflow-ui/labels';

beforeEach(async () => {
const dom = await JSDOM.fromFile(path.resolve(__dirname, 'labels.html'), { url: 'http://localhost' });
const dom = await JSDOM.fromFile(path.resolve(__dirname, 'jobs.html'), { url: 'http://localhost' });
global.window = dom.window as unknown as Window & typeof globalThis;
global.document = dom.window.document;
});
Expand Down

0 comments on commit e9b3d3e

Please sign in to comment.