Skip to content
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

Query builder minor improvements #399

Merged
merged 3 commits into from
Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1709,11 +1709,12 @@ function fetchDatasetDetail(datasetname, query, isPublic) {


/* Actions for Query Reducer */
function receiveQueryResult(json){
function receiveQueryResult(json, query){
console.log('receiveQueryResult');
return {
type: RECEIVE_QUERY_RESULT,
result: json,
query: query,
queryLoading: false,
receivedAt: Date.now(),
ope: 'RECEIVE_QUERY_RESULT'
Expand All @@ -1725,6 +1726,7 @@ function fetchDatasetDetail(datasetname, query, isPublic) {
return {
type: REQUEST_QUERY_RESULT,
result: [],
query: undefined,
queryLoading: true,
receivedAt: Date.now(),
ope: 'REQUEST_QUERY_RESULT'
Expand Down Expand Up @@ -1757,7 +1759,7 @@ function fetchDatasetDetail(datasetname, query, isPublic) {
body: JSON.stringify(query)
})
.then(response => response.json())
.then(json => dispatch(receiveQueryResult(json)))
.then(json => dispatch(receiveQueryResult(json, query)))
.catch(error=> console.error(error))
}
}
4 changes: 2 additions & 2 deletions src/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ function userReducer(state = {}, action) {
function queryReducer(state = {}, action){
switch(action.type) {
case REQUEST_QUERY_RESULT:
return Object.assign({}, state, {'query': { 'queryLoading': action.queryLoading, 'queryResult': action.result }})
return Object.assign({}, state, {'query': { 'queryLoading': action.queryLoading, 'queryResult': action.result, 'query': action.query }})
case RECEIVE_QUERY_RESULT:
return Object.assign({}, state, {'query': { 'queryLoading': action.queryLoading, 'queryResult': action.result }})
return Object.assign({}, state, {'query': { 'queryLoading': action.queryLoading, 'queryResult': action.result, 'query': action.query }})
default:
return state
}
Expand Down
67 changes: 44 additions & 23 deletions src/views/Widgets/QueryBuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ModalBody,
ModalFooter
} from 'react-modal-bootstrap';
import { toastr } from 'react-redux-toastr'
import { getAllOrganizations, search, getQueryResult, getDatasetCatalog } from '../../actions'
import { rulesConverter } from '../../utility'
import ReactTable from "react-table"
Expand Down Expand Up @@ -53,6 +54,7 @@ class QueryBuild extends Component {
this.renderSelectFields = this.renderSelectFields.bind(this)
this.renderConditions = this.renderConditions.bind(this)
this.renderONCondition = this.renderONCondition.bind(this)
this.removeDatasetJoin = this.removeDatasetJoin.bind(this)
}

componentDidMount(){
Expand Down Expand Up @@ -148,16 +150,23 @@ class QueryBuild extends Component {
var tmpjoin = { "inner": {}}
if(datasetJoin){
tmpjoin.inner.uri = datasetJoin.operational.logical_uri
tmpjoin.inner.on = { "eq":{ "left": joinOnTo.value, "right": joinOnFrom.value}}

join.push(tmpjoin)
if(joinOnFrom === '' || joinOnTo === '' ){
toastr.error('Impossibile eseguire la query', 'Specificare le condizioni di Join prima di riprovare')
}else if(!query.select){
toastr.error('Impossibile eseguire la query', 'Specificare i campi da selezionare prima di riprovare')
}else{
tmpjoin.inner.on = { "eq":{ "left": joinOnTo.value, "right": joinOnFrom.value}}
join.push(tmpjoin)
query.join = join

console.log(query)
dispatch(getQueryResult(datasetFrom.operational.logical_uri, query))
}
}else{
console.log(query)

query.join = join
dispatch(getQueryResult(datasetFrom.operational.logical_uri, query))
}

console.log(query)

dispatch(getQueryResult(datasetFrom.operational.logical_uri, query))
}

renderTable(){
Expand Down Expand Up @@ -238,8 +247,8 @@ class QueryBuild extends Component {

ruleGroup:"form-group col-md-12", // <div> containing the RuleGroup
combinators:"form-control col-md-1", // <select> control for combinators
addRule:"btn btn-primary mr-1", // <button> to add a Rule
addGroup:"btn btn-primary", // <button> to add a RuleGroup
addRule:"btn btn-primary mr-1 mt-1", // <button> to add a Rule
addGroup:"btn btn-primary ml-1 mt-1", // <button> to add a RuleGroup
removeGroup:"btn btn-primary mx-1", // <button> to remove a RuleGroup

rule:"form-group row col-md-12", // <div> containing the Rule
Expand Down Expand Up @@ -346,6 +355,18 @@ class QueryBuild extends Component {
</div>)
}

removeDatasetJoin(){
this.setState({
modalType:'',
isQuery: false,
datasetJoin: undefined
})

this.setState({
isQuery:true
})
}

render(){
const { loggedUser, isFetching, results, queryLoading, queryResult } = this.props
const { privateWdg, organizations, isQuery, modalOpen } = this.state
Expand Down Expand Up @@ -413,11 +434,8 @@ class QueryBuild extends Component {
</div>
</ModalBody>
<ModalFooter>
<button type="button" className='btn btn-gray-200' onClick={()=>this.setState({modalOpen:false,modalType:'',privateWdg:'',selectedDataset:'',selectedOrg:''})}>
Chiudi
</button>
<button type="button" className="btn btn-primary px-2">
Crea
<button type="button" className="btn btn-primary px-2" onClick={()=>this.setState({modalOpen:false,modalType:'',privateWdg:'',selectedDataset:'',selectedOrg:''})}>
Continua
</button>
</ModalFooter>
</Modal>
Expand Down Expand Up @@ -446,10 +464,10 @@ class QueryBuild extends Component {
{this.state.datasetFrom.dcatapit.title}
</div>
}
<div className="col-1 ml-auto">
<button className="btn btn-link text-primary float-right" title="Aggiungi un dataset da cui selezionare"
<div className="ml-auto">
<button className="btn btn-link text-primary float-right" title={this.state.datasetFrom?"Modifica il dataset da cui selezionare":"Aggiungi un dataset da cui selezionare"}
onClick={()=>this.setState({modalOpen:true,modalType:'FROM',privateWdg:'',selectedDataset:'',selectedOrg:''})}>
<i className="fas fa-plus-circle fa-lg"/>
{this.state.datasetFrom?<i className="far fa-edit fa-lg"/>:<i className="fas fa-plus-circle fa-lg"/>}
</button>
</div>
</div>
Expand All @@ -469,12 +487,15 @@ class QueryBuild extends Component {
{this.state.datasetJoin && <div className="col-12 text-center mt-2">
ON
</div>}
{this.state.datasetJoin && this.renderONCondition()
}
<div className="col-1 ml-auto">
<button className="btn btn-link text-primary float-right" title="Aggiungi un dataset da cui selezionare"
{this.state.datasetJoin && this.renderONCondition()}
<div className="ml-auto">
{this.state.datasetJoin && <button className="btn btn-link text-danger" title="Rimuovi il dataset da cui fare la join"
onClick={this.removeDatasetJoin}>
<i className="fas fa-times-circle fa-lg"/>
</button>}
<button className="btn btn-link text-primary float-right" title={this.state.datasetJoin?"Modifica il dataset da cui fare la join":"Aggiungi un dataset con cui fare la join" }
onClick={()=>this.setState({modalOpen:true,modalType:'JOIN',privateWdg:'',selectedDataset:'',selectedOrg:''})}>
<i className="fas fa-plus-circle fa-lg"/>
{this.state.datasetJoin?<i className="far fa-edit fa-lg"/>:<i className="fas fa-plus-circle fa-lg"/>}
</button>
</div>
</div>
Expand Down