forked from whatsopt/WhatsOpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add variable info search (whatsopt#198)
* Add variable search panel * Implement variable list API * Implement var infos API * Fix find source * Display source and targets discipline * Add discipline path as tooltip to discipline button * Improve variable search UI * Bump version 1.30.1 * Move optional tabs to the left
- Loading branch information
Showing
15 changed files
with
342 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.30.0 | ||
1.30.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
class Api::V1::VariablesController < Api::V1::ApiMdaUpdaterController | ||
|
||
# GET /api/v1/analyses/{mda_id}/variables | ||
def index | ||
@mda = Analysis.find(params[:mda_id]) | ||
authorize @mda, :show? | ||
variables = policy_scope(Variable).of_analysis(@mda).where(io_mode: WhatsOpt::Variable::OUT) | ||
json_response variables, :ok, each_serializer: VariableSearchSerializer | ||
end | ||
|
||
# GET /api/v1/analyses/{mda_id}/variables/{id} | ||
def show | ||
@variable = Variable.find(params[:id]) | ||
@mda = @mda = Analysis.find(params[:mda_id]) | ||
authorize @mda, :show? | ||
varinfo = @mda.find_info(@variable) | ||
json_response varinfo.to_json | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
app/javascript/mda_viewer/components/VariableSearchPanel.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Tooltip } from 'bootstrap'; | ||
import VariableSelector from './VariableSelector'; | ||
|
||
function getDiscButtons(api, discs) { | ||
const buttons = discs.map(([disc, path]) => { | ||
const { name, analysis_id } = disc; | ||
const title = path.map((a) => (a.name)).join('/'); | ||
const label = name === '__DRIVER__' ? 'User' : `${disc.name}`; | ||
return ( | ||
<div key={disc.id} className="btn-group me-2 mt-2 disc-button" role="group" data-bs-toggle="tooltip" title={`${title}`}> | ||
<a href={api.url(`/analyses/${analysis_id}`)} className="btn btn-info" role="button">{label}</a> | ||
</div> | ||
); | ||
}); | ||
return buttons; | ||
} | ||
|
||
class VariableDisplay extends React.PureComponent { | ||
componentDidUpdate() { | ||
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]'); | ||
[...tooltipTriggerList].map((tooltipTriggerEl) => new Tooltip(tooltipTriggerEl, { | ||
trigger: 'hover', | ||
})); | ||
} | ||
|
||
render() { | ||
const { api, varinfo } = this.props; | ||
const disciplineFrom = getDiscButtons(api, varinfo.from); | ||
const disciplineTo = getDiscButtons(api, varinfo.to); | ||
|
||
return ( | ||
<div className="editor-section"> | ||
<div className="editor-section-label">Source</div> | ||
<div className="mb-2"> | ||
{ disciplineFrom } | ||
</div> | ||
|
||
<div className="editor-section-label">Targets</div> | ||
<div className="mb-2"> | ||
{ disciplineTo } | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
VariableDisplay.propTypes = { | ||
api: PropTypes.object.isRequired, | ||
varinfo: PropTypes.object.isRequired, | ||
}; | ||
|
||
class VariableSearchPanel extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
selected: [], | ||
vars: [], | ||
varinfo: { from: [], to: [] }, | ||
}; | ||
this.handleVariableSelected = this.handleVariableSelected.bind(this); | ||
} | ||
|
||
componentDidMount() { | ||
const { mdaId, api } = this.props; | ||
api.getVariables(mdaId, (response) => { | ||
const vars = response.data; | ||
this.setState({ vars }); | ||
}); | ||
} | ||
|
||
handleVariableSelected(selected) { | ||
const [selection] = selected; | ||
const { mdaId, api } = this.props; | ||
|
||
api.getVariableInformation( | ||
mdaId, | ||
selection.id, | ||
(response) => { | ||
const varinfo = { from: [response.data.from], to: response.data.to }; | ||
this.setState({ varinfo, selected }); | ||
}, | ||
(error) => { | ||
console.log(error); | ||
}, | ||
); | ||
} | ||
|
||
render() { | ||
const { selected, vars, varinfo } = this.state; | ||
const { api } = this.props; | ||
|
||
console.log(selected); | ||
let varDisplay = null; | ||
if (selected.length !== 0) { | ||
varDisplay = (<VariableDisplay api={api} varinfo={varinfo} />); | ||
} | ||
|
||
return ( | ||
<div className="container-fluid"> | ||
<div className="row"> | ||
<div className="editor-section col-4"> | ||
<VariableSelector | ||
vars={vars} | ||
message="Search variable..." | ||
selected={selected} | ||
onVariableSelected={this.handleVariableSelected} | ||
disabled={false} | ||
/> | ||
</div> | ||
<div className="editor-section col-12"> | ||
{varDisplay} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
VariableSearchPanel.propTypes = { | ||
api: PropTypes.object.isRequired, | ||
mdaId: PropTypes.number.isRequired, | ||
}; | ||
|
||
export default VariableSearchPanel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { Typeahead } from 'react-bootstrap-typeahead'; | ||
|
||
class VariableSelector extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.handleChange = this.handleChange.bind(this); | ||
} | ||
|
||
handleChange(selected) { | ||
if (selected.length) { | ||
const { onVariableSelected } = this.props; | ||
onVariableSelected(selected); | ||
} | ||
} | ||
|
||
render() { | ||
const { | ||
message, selected, disabled, vars: options, | ||
} = this.props; | ||
return ( | ||
<Typeahead | ||
id="varsearch" | ||
defaultSelected={selected} | ||
clearButton | ||
options={options} | ||
allowNew={false} | ||
multiple={false} | ||
labelKey="name" | ||
minLength={1} | ||
placeholder={message} | ||
onChange={this.handleChange} | ||
disabled={disabled} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
VariableSelector.propTypes = { | ||
vars: PropTypes.array.isRequired, | ||
message: PropTypes.string.isRequired, | ||
selected: PropTypes.array.isRequired, | ||
disabled: PropTypes.bool.isRequired, | ||
onVariableSelected: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default VariableSelector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class VariablePolicy < ApplicationPolicy | ||
class Scope < Scope | ||
def resolve | ||
scope.all | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class VariableSearchSerializer < ActiveModel::Serializer | ||
attributes :name, :id | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.