-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement/aggregate functions expression editor (#1545)
* aggregate function: use AceEditor to edit sql expression * use ScriptEditor component in analysis props editor Co-authored-by: Stefano Ricci <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
8bdade8
commit 1de1b8a
Showing
15 changed files
with
240 additions
and
125 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
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
46 changes: 46 additions & 0 deletions
46
...izer/Table/Row/Column/CustomAggregateFunctionsEditor/AggregateFunctionExpressionEditor.js
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,46 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import * as NodeDef from '@core/survey/nodeDef' | ||
import { ViewDataNodeDef } from '@common/model/db' | ||
|
||
import { useSurvey } from '@webapp/store/survey' | ||
import { ScriptEditor } from '@webapp/components/ScriptEditor' | ||
|
||
export const AggregateFunctionExpressionEditor = (props) => { | ||
const { expression, entityDef, onChange } = props | ||
|
||
const survey = useSurvey() | ||
|
||
// create entity view column names completer | ||
const viewDataNodeDef = new ViewDataNodeDef(survey, entityDef) | ||
|
||
const columnItems = viewDataNodeDef.columnNodeDefNames.map((columnName) => ({ | ||
caption: columnName, | ||
value: columnName, | ||
meta: `${NodeDef.getName(entityDef)} - Column`, | ||
})) | ||
|
||
const columnNamesCompleter = { | ||
getCompletions: (_editor, _session, _pos, _prefix, callback) => { | ||
callback(null, columnItems) | ||
}, | ||
} | ||
|
||
return ( | ||
<ScriptEditor | ||
name="custom_aggregate_function_editor" | ||
mode="sql" | ||
script={expression} | ||
onChange={onChange} | ||
completer={columnNamesCompleter} | ||
height="150px" | ||
/> | ||
) | ||
} | ||
|
||
AggregateFunctionExpressionEditor.propTypes = { | ||
expression: PropTypes.string.isRequired, | ||
entityDef: PropTypes.object.isRequired, | ||
onChange: PropTypes.func.isRequired, | ||
} |
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 |
---|---|---|
|
@@ -19,10 +19,6 @@ | |
|
||
.form-item { | ||
height: auto; | ||
|
||
textarea { | ||
height: 120px; | ||
} | ||
} | ||
|
||
.button-bar { | ||
|
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,78 @@ | ||
import './ScriptEditor.scss' | ||
|
||
import React, { useEffect, useRef } from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import AceEditor from 'react-ace' | ||
import * as ace from 'ace-builds' | ||
|
||
import 'ace-builds/webpack-resolver' | ||
import 'ace-builds/src-noconflict/mode-r' | ||
import 'ace-builds/src-noconflict/theme-github' | ||
import 'ace-builds/src-noconflict/ext-searchbox' | ||
import 'ace-builds/src-noconflict/ext-language_tools' | ||
|
||
const aceLangTools = ace.require('ace/ext/language_tools') | ||
const { snippetCompleter, textCompleter, keyWordCompleter } = aceLangTools | ||
const defaultCompleters = [snippetCompleter, textCompleter, keyWordCompleter] | ||
|
||
export const ScriptEditor = (props) => { | ||
const { name, mode, script, completer, height, width, onChange } = props | ||
|
||
const editorRef = useRef() | ||
|
||
useEffect(() => { | ||
const { editor } = editorRef.current | ||
|
||
// reset completers | ||
editor.completers = [...defaultCompleters] | ||
|
||
// add custom completer (if any) | ||
if (completer) { | ||
editor.completers.push(completer) | ||
} | ||
}, [completer]) | ||
|
||
return ( | ||
<AceEditor | ||
ref={editorRef} | ||
mode={mode} | ||
theme="github" | ||
onChange={onChange} | ||
name={name} | ||
editorProps={{ $blockScrolling: true }} | ||
fontSize={16} | ||
showPrintMargin | ||
showGutter | ||
highlightActiveLine | ||
setOptions={{ | ||
enableBasicAutocompletion: true, | ||
enableLiveAutocompletion: true, | ||
showLineNumbers: true, | ||
useWorker: true, | ||
tabSize: 2, | ||
}} | ||
defaultValue={script} | ||
height={height} | ||
width={width} | ||
/> | ||
) | ||
} | ||
|
||
ScriptEditor.propTypes = { | ||
name: PropTypes.string.isRequired, | ||
mode: PropTypes.oneOf(['r', 'sql']).isRequired, | ||
completer: PropTypes.shape({ | ||
getCompletions: PropTypes.func.isRequired, | ||
}), | ||
height: PropTypes.string, | ||
width: PropTypes.string, | ||
script: PropTypes.string.isRequired, | ||
onChange: PropTypes.func.isRequired, | ||
} | ||
|
||
ScriptEditor.defaultProps = { | ||
completer: null, | ||
height: '200px', | ||
width: 'inherit', | ||
} |
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 @@ | ||
@import '~@webapp/style/vars'; | ||
|
||
.ace_editor { | ||
border: 1px solid $greyBorder; | ||
} |
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 @@ | ||
export { ScriptEditor } from './ScriptEditor' |
11 changes: 0 additions & 11 deletions
11
webapp/components/survey/NodeDefDetails/AnalysisCodeProps/AnalysisCodeProps.scss
This file was deleted.
Oops, something went wrong.
99 changes: 0 additions & 99 deletions
99
webapp/components/survey/NodeDefDetails/AnalysisCodeProps/index.js
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
webapp/components/survey/NodeDefDetails/AnalysisProps/AnalysisProps.scss
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 @@ | ||
@import '~@webapp/style/vars'; | ||
|
||
.script-form { | ||
align-items: normal; | ||
} |
Oops, something went wrong.