-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SCT-3097 - fix clustering viewer pop ups, timeouts, tab crash with large clusters #2385
base: develop
Are you sure you want to change the base?
Changes from 38 commits
ff113f2
3b09924
80766a3
fe61c0a
d91670d
98394da
d1a9a56
271ba29
2231a2b
8efb24f
d65549e
7f67f84
1cf849f
ef17db7
f1cffbc
6b8ca67
2001bf9
a995a83
a26f7d2
ad15040
b2e6be2
1c4edc9
cefcd5d
f56e850
2ca0bd6
adc05a2
c42680d
e9abb88
0b1614e
dd75ed7
30b6e9f
a55be38
456ff4a
c749f0f
bf6c0ba
7dc2136
cd7edd8
d0a1843
c14cf4f
f88ecb9
f151891
3e39acd
0201fec
6d3adaa
3e7e66f
4f9f757
f6e2e46
4d34618
eddc302
bb3d0e2
f841f4b
0bf6036
2bc384f
c3cb5e4
52de0e2
41162f6
1d13e8f
39610a3
3f17586
d976bfe
90d49f4
e829eef
4bd485a
6208aa3
f66d4fc
3b99f35
426221a
d3a6aac
c8917e4
2d96cdb
5367b26
6c03a4c
a0a0166
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ kbase-extension/static/ext_packages | |
kbase-extension/static/kbase/js/patched-components | ||
venv | ||
cover | ||
/_temp |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/** | ||
* errorView - A widget which displays common error types, including | ||
* strings, exception objects descended from Error, and plain objects which | ||
* follow the KBase SDK JSON-RPC error form: | ||
* {name, code, message, error} | ||
* name - string - always JSONRPCError | ||
* code - number - JSONRPC compatible error code | ||
* message - string - canonical message | ||
* error - string - captures trace | ||
*/ | ||
define([ | ||
'jquery', | ||
'kb_common/jsonRpc/exceptions', | ||
'widgets/common/RenderIn', | ||
'widgets/common/JSONView', | ||
], ($, jsonRPCExceptions, RenderIn, $JSONView) => { | ||
'use strict'; | ||
|
||
const { $TextIn, $HTMLIn } = RenderIn; | ||
const UNKNOWN_ERROR_TEXT = 'Unknown error'; | ||
|
||
function $renderJSONRPCException(err) { | ||
const $errorTable = $('<table>').addClass('table'); | ||
|
||
const $tbody = $('<tbody>'); | ||
$errorTable.append($tbody); | ||
|
||
const $renderRow = (label, value) => { | ||
return $('<tr>') | ||
.css('background-color', 'transparent') | ||
.append( | ||
$('<th>').css('border', 'none').text(label), | ||
$('<td>').css('border', 'none').text(value) | ||
); | ||
}; | ||
|
||
$tbody.append($renderRow('Type', err.type)); | ||
$tbody.append($renderRow('Code', err.code)); | ||
$tbody.append($renderRow('Module', err.module)); | ||
$tbody.append($renderRow('Function', err.func)); | ||
$tbody.append($renderRow('Message', err.message)); | ||
|
||
return $errorTable; | ||
} | ||
|
||
function $renderError(err) { | ||
if (typeof err === 'string') { | ||
return $TextIn(err); | ||
} | ||
|
||
// This may be a KBase service error, which are somewhat uniform. | ||
// We display some common fields at top, and then dump the | ||
// entire error info as nested tables. | ||
|
||
if (err instanceof jsonRPCExceptions.RpcError) { | ||
return $renderJSONRPCException(err); | ||
} | ||
|
||
// Some other error | ||
if (err instanceof Error) { | ||
return $HTMLIn([ | ||
$TextIn(err.name, 'span'), | ||
$TextIn(': ', 'span'), | ||
$TextIn(err.message, 'span'), | ||
]); | ||
} | ||
|
||
// Some other object | ||
if (typeof err === 'object') { | ||
// Note that order is important. | ||
|
||
if (err === null) { | ||
return $TextIn(UNKNOWN_ERROR_TEXT); | ||
} | ||
|
||
if ('message' in err && typeof err.message === 'string') { | ||
return $TextIn(err.message); | ||
} | ||
|
||
if (err.constructor === {}.constructor) { | ||
return $JSONView(err); | ||
} | ||
|
||
if ('toString' in err && typeof err.toString === 'function') { | ||
return $TextIn(`Unknown error: ${err.toString()}`); | ||
} | ||
} | ||
|
||
// Don't try to do anything fancy if the error value is outside what we are prepared | ||
// to handle. | ||
return $TextIn(UNKNOWN_ERROR_TEXT); | ||
} | ||
|
||
function $renderContactInfo() { | ||
return $('<div>') | ||
.css('margin-top', '20px') | ||
.append($TextIn('You may', 'span')) | ||
.append(' ') | ||
.append( | ||
$('<a>') | ||
.attr('href', 'https://www.kbase.us/support') | ||
.attr('target', '_blank') | ||
.text('contact the KBase team') | ||
) | ||
.append(' ') | ||
.append($TextIn('with the information above.', 'span')); | ||
} | ||
|
||
function $renderTitle() { | ||
return $('<div>').css('font-weight', 'bold').text('Error'); | ||
} | ||
|
||
function $ErrorView(err) { | ||
return $('<div>') | ||
.addClass('alert alert-danger') | ||
.append($renderTitle()) | ||
.append($renderError(err)) | ||
.append($renderContactInfo()); | ||
} | ||
|
||
return $ErrorView; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
define(['jquery', 'widgets/common/RenderIn'], ($, RenderIn) => { | ||
'use strict'; | ||
|
||
const { $TextIn } = RenderIn; | ||
|
||
function $RenderJSONArray(data) { | ||
const $rows = data.map((value, index) => { | ||
return $('<tr>').append( | ||
$('<th>').css('color', 'rgba(150, 150, 150, 1)').text(String(index)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you move all the css declarations be moved out of these JS files and into the appropriate css file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure it is worth the added complexity, but sure. Added css file and created some associated classes. |
||
$('<td>').addClass('fa fa-arrow-right'), | ||
$('<td>').html($JSONView(value)) | ||
); | ||
}); | ||
return $('<table>').addClass('table table-striped').html($('<tbody>').append($rows)); | ||
} | ||
|
||
function $RenderJSONObject(data) { | ||
const $rows = Object.entries(data).map(([key, value]) => { | ||
return $('<tr>').append( | ||
$('<th>').css('color', 'rgba(150, 150, 150, 1)').text(key), | ||
$('<td>').addClass('fa fa-arrow-right'), | ||
$('<td>').html($JSONView(value)) | ||
); | ||
}); | ||
return $('<table>').addClass('table table-striped').html($('<tbody>').append($rows)); | ||
} | ||
|
||
function $RenderNonJSON(data) { | ||
if (typeof data === 'object') { | ||
return $TextIn(`Not representable: ${typeof data} (${data.constructor.name})`); | ||
} else { | ||
return $TextIn(`Not representable: ${typeof data}`); | ||
} | ||
} | ||
|
||
function $JSONView(data) { | ||
switch (typeof data) { | ||
case 'string': | ||
return $TextIn(data); | ||
case 'number': | ||
return $TextIn(String(data)); | ||
case 'boolean': | ||
return $TextIn(String(data)); | ||
case 'object': | ||
if (data === null) { | ||
return $TextIn('NULL'); | ||
} | ||
if (Array.isArray(data)) { | ||
return $RenderJSONArray(data); | ||
} else { | ||
if (data.constructor === {}.constructor) { | ||
return $RenderJSONObject(data); | ||
} else { | ||
return $RenderNonJSON(data); | ||
} | ||
} | ||
default: | ||
return $RenderNonJSON(data); | ||
} | ||
} | ||
|
||
return $JSONView; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
define(['jquery'], ($) => { | ||
'use strict'; | ||
function $LoadingMessage(message) { | ||
const $message = (() => { | ||
if (typeof message === 'string') { | ||
return $('<span>').text(message); | ||
} else { | ||
return message; | ||
} | ||
})(); | ||
return $('<div>') | ||
.addClass('alert alert-info') | ||
.css('display', 'flex') | ||
.css('flex-direction', 'row') | ||
.css('align-items', 'center') | ||
.css('justify-content', 'center') | ||
.css('margin', '10px auto') | ||
.css('max-width', '30em') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move to CSS file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to a stylesheet in this and other cases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this and other css move into scss? |
||
.append($message) | ||
.append(' ') | ||
.append($('<i>').addClass('fa fa-spinner fa-spin fa-2x')); | ||
} | ||
return $LoadingMessage; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
define(['jquery'], ($) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noted in #2378 also, but this seems to be some module duplication / factorization with what's in the Is there a plan to unify those? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally, yes. In this case, I simply wanted some convenience functions for working with jQuery. |
||
'use strict'; | ||
|
||
function $TextIn(text, tag = 'div') { | ||
return $(document.createElement(tag)).text(text); | ||
} | ||
|
||
function $HTMLIn(html, tag = 'div') { | ||
return $(document.createElement(tag)).append(html); | ||
} | ||
|
||
return { $TextIn, $HTMLIn }; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* Base class for viewers visualizaing expression of a set of conditions from various aspects | ||
* | ||
* The descendant classes should override: | ||
* 1. getSubmtrixParams - to set params for get_submatrix_stat method from the KBaseFeatureValues service | ||
* 1. getSubmatrixParams - to set params for get_submatrix_stat method from the KBaseFeatureValues service | ||
* 2. buildWidget - to create a custom visuzualization | ||
* | ||
* | ||
|
@@ -17,13 +17,11 @@ define([ | |
'narrativeConfig', | ||
'kbwidget', | ||
'kbaseAuthenticatedWidget', | ||
'kbaseTabs', | ||
'kb_common/jsonRpc/dynamicServiceClient', | ||
// For effect | ||
'bootstrap', | ||
'jquery-dataTables', | ||
'kbaseFeatureValues-client-api', | ||
], ($, Config, KBWidget, kbaseAuthenticatedWidget, kbaseTabs, DynamicServiceClient) => { | ||
], ($, Config, KBWidget, kbaseAuthenticatedWidget, DynamicServiceClient) => { | ||
'use strict'; | ||
|
||
return KBWidget({ | ||
|
@@ -42,9 +40,6 @@ define([ | |
// Prefix for all div ids | ||
pref: null, | ||
|
||
// KBaseFeatureValue client | ||
featureValueClient: null, | ||
|
||
// Matrix set stat | ||
submatrixStat: null, | ||
|
||
|
@@ -84,7 +79,7 @@ define([ | |
}, | ||
|
||
// To be overriden to specify additional parameters | ||
getSubmtrixParams: function () { | ||
getSubmatrixParams: function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😁 |
||
const self = this; | ||
self.setTestParameters(); | ||
let conditions = []; | ||
|
@@ -104,7 +99,7 @@ define([ | |
self.loading(true); | ||
|
||
const getSubmatrixStatsAndRender = function () { | ||
const smParams = self.getSubmtrixParams(); | ||
const smParams = self.getSubmatrixParams(); | ||
|
||
// some parameter checking | ||
if (!smParams.column_ids || smParams.column_ids.length === 0) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We invented this wheel in the truss branch -- perhaps that file can be pulled over as it's quite similar to this.