From c88d98eb0a252d890d70ab2b9356a960970d1480 Mon Sep 17 00:00:00 2001 From: navaneeth Date: Tue, 6 Apr 2021 21:18:35 +0530 Subject: [PATCH] Major bug fixes for table actions --- frontend/src/Editor/Components/Table.jsx | 22 +- .../src/Editor/Inspector/Components/Table.jsx | 270 ++++++++++-------- .../src/Editor/Inspector/EventSelector.jsx | 4 +- frontend/src/Editor/Inspector/Inspector.jsx | 2 +- 4 files changed, 167 insertions(+), 131 deletions(-) diff --git a/frontend/src/Editor/Components/Table.jsx b/frontend/src/Editor/Components/Table.jsx index 1fa4463d1f..bc6bd69861 100644 --- a/frontend/src/Editor/Components/Table.jsx +++ b/frontend/src/Editor/Components/Table.jsx @@ -42,16 +42,18 @@ export const Table = function Table({ id, component, onComponentClick, currentSt { e.stopPropagation(); onEvent('onRowClicked', { component, row }); }}> {columns.map((column) => {row[column.name]})} - - {actions.value.map((action) => ( - - ))} - + {actions.value.length > 0 && + + {actions.value.map((action) => ( + + ))} + + } ))} diff --git a/frontend/src/Editor/Inspector/Components/Table.jsx b/frontend/src/Editor/Inspector/Components/Table.jsx index e82b412411..453fc5d7b7 100644 --- a/frontend/src/Editor/Inspector/Components/Table.jsx +++ b/frontend/src/Editor/Inspector/Components/Table.jsx @@ -1,4 +1,7 @@ -import React, {useRef, useState} from 'react'; + +import React from 'react'; +import CodeMirror from '@uiw/react-codemirror'; +import 'codemirror/theme/duotone-light.css'; import { renderElement, renderEvent } from '../Utils'; import { computeActionName } from '@/_helpers/utils'; import SortableList, { SortableItem } from "react-easy-sort"; @@ -7,19 +10,34 @@ import OverlayTrigger from 'react-bootstrap/OverlayTrigger'; import Popover from 'react-bootstrap/Popover'; import { EventSelector } from '../EventSelector'; -export const Table = ({ dataQueries, component, paramUpdated, componentMeta, eventUpdated, eventOptionUpdated }) => { +class Table extends React.Component { + constructor(props) { + super(props); - const columns = component.component.definition.properties.columns; - const actions = component.component.definition.properties.actions || { value: [] }; + const { dataQueries, component, paramUpdated, componentMeta, eventUpdated, eventOptionUpdated } = props; - function onActionButtonPropertyChanged(index, property, value) { - let newValues = actions.value; - newValues[index][property] = value; - - paramUpdated ({name: 'actions'}, 'value', newValues, 'properties'); + this.state = { + dataQueries, component, paramUpdated, componentMeta, eventUpdated, eventOptionUpdated + }; } - function actionButtonEventUpdated(event, value, extraData) { + componentDidMount() { + const { dataQueries, component, paramUpdated, componentMeta, eventUpdated, eventOptionUpdated } = this.props; + + this.state = { + dataQueries, component, paramUpdated, componentMeta, eventUpdated, eventOptionUpdated + }; + } + + onActionButtonPropertyChanged = (index, property, value) => { + + const actions = this.state.component.component.definition.properties.actions; + actions.value[index][property] = value; + this.props.paramUpdated ({name: 'actions'}, 'value', actions.value, 'properties'); + } + + actionButtonEventUpdated = (event, value, extraData) => { + const actions = this.state.component.component.definition.properties.actions; const actionButton = extraData.actionButton; const index = extraData.index; @@ -28,13 +46,13 @@ export const Table = ({ dataQueries, component, paramUpdated, componentMeta, eve actionId: value } - paramUpdated ({name: 'actions'}, 'value', newValues, 'properties'); + this.props.paramUpdated ({name: 'actions'}, 'value', newValues, 'properties'); } - function actionButtonEventOptionUpdated(event, option, value, extraData) { + actionButtonEventOptionUpdated = (event, option, value, extraData) => { + const actions = this.state.component.component.definition.properties.actions; const index = extraData.index; - let newValues = actions.value; const options = newValues[index][event.name].options; @@ -43,10 +61,10 @@ export const Table = ({ dataQueries, component, paramUpdated, componentMeta, eve [option]: value } - paramUpdated ({name: 'actions'}, 'value', newValues, 'properties'); + this.props.paramUpdated ({name: 'actions'}, 'value', newValues, 'properties'); } - function actionPopOver(action, index) { + actionPopOver = (action, index) => { return ( {action.name} @@ -56,165 +74,183 @@ export const Table = ({ dataQueries, component, paramUpdated, componentMeta, eve { e.stopPropagation(); onActionButtonPropertyChanged(index, 'buttonText', e.target.value)}} + onChange={(e) => { e.stopPropagation(); this.onActionButtonPropertyChanged(index, 'buttonText', e.target.value); }} value={action.buttonText} /> + ); } - const ActionButton = ({ action , index}) => ( - + placement="left" + overlay={this.actionPopOver(action, index)}>
- {action.name} + {action.buttonText}
- ); + }; - function onSortEnd(oldIndex, newIndex) { + onSortEnd(oldIndex, newIndex) { const newColumns = arrayMove(columns.value, oldIndex, newIndex); paramUpdated ({name: 'columns'}, 'value', newColumns, 'properties'); } - function addNewColumn() { + addNewColumn = () => { + const columns = this.state.component.component.definition.properties.columns; const newValue = columns.value; newValue.push({ name: 'new_column'}); - paramUpdated({name: 'columns'}, 'value', newValue, 'properties'); + this.props.paramUpdated({name: 'columns'}, 'value', newValue, 'properties'); } - function addNewAction() { + addNewAction = () => { + const actions = this.state.component.component.definition.properties.actions; const newValue = actions.value; newValue.push({ name: computeActionName(actions), buttonText: 'Button'}); - paramUpdated({name: 'actions'}, 'value', newValue, 'properties'); + this.props.paramUpdated({name: 'actions'}, 'value', newValue, 'properties'); } - function onColumnItemChange(index, e) { + removeAction = (index) => { + const newValue = actions.value; + newValue.splice(index, 1); + paramUpdated ({name: 'actions'}, 'value', newValue, 'properties'); + } + + onColumnItemChange = (index, e) => { e.preventDefault(); + const columns = this.state.component.component.definition.properties.columns; const value = e.target.value; const column = columns.value[index]; column.name = value; const newColumns = columns.value; newColumns[index] = column; - paramUpdated ({name: 'columns'}, 'value', newColumns, 'properties'); + this.props.paramUpdated ({name: 'columns'}, 'value', newColumns, 'properties'); } - function removeColumn(index) { + removeColumn = (index) => { + const columns = this.state.component.component.definition.properties.columns; const newValue = columns.value; newValue.splice(index, 1); - paramUpdated ({name: 'columns'}, 'value', newValue, 'properties'); + this.props.paramUpdated ({name: 'columns'}, 'value', newValue, 'properties'); } - return ( -
- {renderElement(component, componentMeta, paramUpdated, dataQueries, 'title', 'properties')} - {renderElement(component, componentMeta, paramUpdated, dataQueries, 'data', 'properties')} -
-
-
- + render() { + const { dataQueries, component, paramUpdated, componentMeta, eventUpdated, eventOptionUpdated } = this.state; + + const columns = component.component.definition.properties.columns; + const actions = component.component.definition.properties.actions || { value: [] }; + + return ( +
+ {renderElement(component, componentMeta, paramUpdated, dataQueries, 'title', 'properties')} + {renderElement(component, componentMeta, paramUpdated, dataQueries, 'data', 'properties')} + +
+
+
+ +
+
+ +
-
- -
-
-
- - {columns.value.map((item, index) => ( - -
-
-
- - - -
-
-
- onColumnItemChange(index, e)} - class="form-control-plaintext form-control-plaintext-sm" - value={item.name} - /> +
+ + {columns.value.map((item, index) => ( + +
+
+
+ + +
-
-
-
removeColumn(index)}> - x +
+
+ this.onColumnItemChange(index, e)} + class="form-control-plaintext form-control-plaintext-sm" + value={item.name} + /> +
+
+
+
this.removeColumn(index)}> + x +
+ + ))} + + +
+ +
+

Actions

+
+
+
+
- - ))} - - +
+ +
+
+
+ {actions.value.map((action, index) => + this.actionButton(action, index) + )} +
+
+
+ + {renderEvent(component, eventUpdated, dataQueries, eventOptionUpdated, 'onRowClicked')} + +
-
-

Actions

-
-
-
- -
-
- -
-
-
- {actions.value.map((action, index) => - - )} -
-
-
- - {renderEvent(component, eventUpdated, dataQueries, eventOptionUpdated, 'onRowClicked')} - -
-
- - {renderElement(component, componentMeta, paramUpdated, dataQueries, 'visible', 'properties')} - {renderElement(component, componentMeta, paramUpdated, dataQueries, 'backgroundColor', 'styles')} - {renderElement(component, componentMeta, paramUpdated, dataQueries, 'textColor', 'styles')} -
- ) + {renderElement(component, componentMeta, paramUpdated, dataQueries, 'visible', 'properties')} + {renderElement(component, componentMeta, paramUpdated, dataQueries, 'backgroundColor', 'styles')} + {renderElement(component, componentMeta, paramUpdated, dataQueries, 'textColor', 'styles')} +
+ ) + } } + +export { Table }; diff --git a/frontend/src/Editor/Inspector/EventSelector.jsx b/frontend/src/Editor/Inspector/EventSelector.jsx index 0a837791a1..6f7f4aeb98 100644 --- a/frontend/src/Editor/Inspector/EventSelector.jsx +++ b/frontend/src/Editor/Inspector/EventSelector.jsx @@ -5,8 +5,6 @@ export const EventSelector = ({ param, definition, eventUpdated, eventOptionUpda console.log('dq', dataQueries); - debugger - function onChange(e) { const query = dataQueries.find(query => query.id === e.target.value) eventOptionUpdated(param, 'queryId', query.id, extraData); @@ -26,7 +24,7 @@ export const EventSelector = ({ param, definition, eventUpdated, eventOptionUpda return (
- { e.stopPropagation(); e.preventDefault() } } onChange={(e) => { e.stopPropagation(); eventUpdated(param, e.target.value, extraData)}} value={definition.actionId} class="form-select" > {ActionTypes.map((action) => ())} diff --git a/frontend/src/Editor/Inspector/Inspector.jsx b/frontend/src/Editor/Inspector/Inspector.jsx index fbad1f0d15..42c908e60a 100644 --- a/frontend/src/Editor/Inspector/Inspector.jsx +++ b/frontend/src/Editor/Inspector/Inspector.jsx @@ -80,7 +80,7 @@ export const Inspector = ({ selectedComponent, componentDefinitionChanged, dataQ {component.component.name} toast.success('Reference copied to clipboard', { hideProgressBar: true, position: "bottom-center", })}> - +