Skip to content

Commit

Permalink
expression editor binary operator type: layout adjustments (#3680)
Browse files Browse the repository at this point in the history
* Expression editor / binary operator type: show it as a button group

* expression editor placeholder: hide apply if item

---------

Co-authored-by: Stefano Ricci <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 10, 2024
1 parent d344983 commit d4fcccc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 47 deletions.
21 changes: 6 additions & 15 deletions webapp/components/expression/expressionEditorPopup.scss
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,12 @@
width: 160px;
}

.btn-switch-operand {
font-size: 0.75rem;
margin: 0 0.1rem;
height: 32px;
align-self: flex-end;
text-wrap: nowrap;

&.btn-switch-operand-const {
width: 7rem;
}
&.btn-switch-operand-var {
width: 5rem;
}
&.btn-switch-operand-call {
width: 5rem;
.binary-operand-type-btn-group {
height: 2rem;
margin: 0 0.2rem;

button {
white-space: nowrap;
}
}

Expand Down
43 changes: 12 additions & 31 deletions webapp/components/expression/nodes/binaryOperand.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as A from '@core/arena'
import * as Expression from '@core/expressionParser/expression'
import * as NodeDef from '@core/survey/nodeDef'

import { Button } from '@webapp/components/buttons'
import { ButtonGroup } from '@webapp/components/form'

const { types } = Expression

Expand All @@ -23,27 +23,6 @@ const expressionGeneratorByType = {
[types.Literal]: () => Expression.newLiteral(),
}

const BinaryOperandExpressionTypeButton = (props) => {
const { active, expressionType, onClick } = props
const acronym = expressionTypeAcronymByType[expressionType]
return (
<Button
active={active}
className={`btn-switch-operand btn-switch-operand-${acronym}`}
label={`expressionEditor.${acronym}`}
onClick={onClick}
size="small"
variant="outlined"
/>
)
}

BinaryOperandExpressionTypeButton.propTypes = {
active: PropTypes.bool.isRequired,
expressionType: PropTypes.string.isRequired,
onClick: PropTypes.func.isRequired,
}

export const BinaryOperandType = {
left: 'left',
right: 'right',
Expand Down Expand Up @@ -98,7 +77,7 @@ const BinaryOperand = (props) => {
[canOperandExpressionBeOfType]
)

const onOperandTypeClick = (newType) => () => {
const onOperandTypeChange = (newType) => {
const newOperatorExpression = expressionGeneratorByType[newType]()
let nodeUpdated = { ...node, [type]: newOperatorExpression }
if (isLeft && !isBoolean) {
Expand All @@ -113,14 +92,16 @@ const BinaryOperand = (props) => {

return (
<div className={`binary-${type}`}>
{applicableOperandExpressionTypes.map((expressionType) => (
<BinaryOperandExpressionTypeButton
key={expressionType}
active={operandExpressionType === expressionType}
expressionType={expressionType}
onClick={onOperandTypeClick(expressionType)}
/>
))}
<ButtonGroup
className="binary-operand-type-btn-group"
selectedItemKey={operandExpressionType}
onChange={onOperandTypeChange}
items={applicableOperandExpressionTypes.map((expressionType) => {
const acronym = expressionTypeAcronymByType[expressionType]
const label = `expressionEditor.${acronym}`
return { key: expressionType, label }
})}
/>
{React.createElement(renderNode, {
canDelete,
isBoolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const ExpressionProp = (props) => {
/>
</div>

{applyIf && (
{applyIf && !isPlaceholder && (
<div className="expression-item">
<div className="label">{i18n.t('nodeDefEdit.expressionsProp.applyIf')}</div>

Expand Down

0 comments on commit d4fcccc

Please sign in to comment.