ToolJet/frontend/src/TooljetDatabase/Menu/CellEditMenu/index.jsx

251 lines
8.4 KiB
React
Raw Normal View History

Feature: TJDB UX Revamp (#8538) * Added Edit column functionality in ToolJet Database Table * feat: null constraint support for create_table add_column edit_column * fix: default data-type validation has been added * completed column header revamp * feat: added not null toggle in create new table drawer * feat: on toggle not null constraint value will be persisted * fix: loads label for not null toggle dynamically * feat: add new column to tjdb null constraint support * new datatype dropdown design implemented * added new icon for delete column * added delete icon for column * added delete icon for column * fix: when table name is empty create button will be disabled * fix: datatype dropdown height fix * fix: datatype drop down issue fix * fix: datatype dropdown alignment fix * fix: delete icon changed to new theme * fix: delete icon changed to new one * fix: create new column column name and datatype mandatory validation added * fixed styling issues * Added 2 space indentation for css * inline css moved to css files as well as added 2 space indentation * fix: createTable addColumn editColumn api payload structure change to incorporate constraint changes * fix: error handling added for editColumn api * added 2 space indentation * fix: create table API payload structure changes * added 2 space indentation and applied styles for dark mode as well * disabled the existing column's dataType * fix: create new column payload updated * renamed columnIndex to columnSelection and fixed the plus column creator button position issue * renamed columnIndex to columnSelection and added text visiblity for dropdown in dark and light mode * moved the react-select's new styles to constants.js file as function * react select's css moved to constants.js file * fix: review comments has been fixed * added edit column warning UI * completed edit column new flow * remove Please wait for ToolJet to update..this line from edit column warning message * increased height for add column + button * fix: create table will not accept empty values for mandatory fields like tablename column_name datatype * fix: custom error message for tjdb add row operation * stylefix: table footer page info section realignment changes * fix: moved addNewColumn btn to dropdown on clicking table in sidebar * feat: bulk update and add row option is moved to drop down * add ability to collapse sidebar * add tooltip * fiexed the tooltip issue in collapsible sidebar * fix background on blank slate * fix: layout changes for tjdb table header section * stylefix: tjdb table menu bar style fixes * stylefix: header btn gap has been reduced * fix: edit row data populated into the form * adjusted height * added small alignment changes * pagination-rewamp * adjusted footer style when we collapse the sidebar * fixed the pagination issue when we add new row * feat : sticky column header * feat: expandable row with menu bar flaky issue * fix: on row hover expand icon will now be visible * stylefix: added bg color for row hover and cell hover * stylefix: adjusted expand icon sise * feature : cell navigation * fix: flaky issue on tjdb menu bar while expanding row has been fixed * added naviagation function for table cells * fix: edit row drawer variable name fixes * added cell edit option in table cell * feat: tjdb cell edit dropdown menu completed * fix merge * updates node version * fix: sticky column to left * feature : cell navigation * add support for null values on tjdb bulk upload * stylefix: table background for dark mode fixed * feature : cell edit implementation * feat: progress bar for cell edit * feature : cell edit implementation on boolean datatye * bug fixes * toggle implementation * fix: removed duplicate not null constraint toggle in edit column form * fix: when last filter is deleter in tjdb dashboard filter drop down will be closed * feat : cell edit implementation completed * removed console logs * fix: edit column onclick not null toggle crash issue fixed * solved bugs * added border 2px for selected cells * added cellvalue in cell input if it have not null constraint * stylefix: css value for cell hover has been updated * fix: table header sticky * stylefix: row hover background color for dark mode * fix: autocomplete is off for cell edit input field * fix: null tag was shown when we focus on the input field as well * fix: in cell edit menu either null or default can be choosen * fix: cell edit menu null toggle value sync and edit menu not opening issue * stylefix: row hover bg color was broken * fix: cell navigation flaky issue * stylefix: progress bar attached to the bottom of the cell * fix: tooljetdb collapsible side bar style changes has been fixed * fix: added infor for cell edit menu navigation * fix: cell navigation and cell edit menu boolean view arrow navigation * fix: flow issues in cell navigation has been fixed * fix: backspace key will remove null values and open cell edit mode * fix: updated icon for openai datasource * fix: when we update or delete record pagesize has been modified but it should remain same * feat: typing on selected field inserts value and enable edit menu and removes null value if exist * stylefix: table checkbox styling updated * stylefix: tooljetdb table checkbox indeterminate mode style fixes * stylefix: row selection background color * fix: table first column can be selected but not edited * fix: tooljetDB delete row btn text should be in plural when multiple rows are selected * fix: when column header menu is opened and closed cell click was not working it is fixed now * fix null value on id column on row insert * fix: cell text overlfow will truncate * fix: in tooljetdb while creating new row filters and sorts which were selected will be made default * fix: tooljetdb table cell tooltip design change * fix: on column select and hover entire column was flaky issue fixed * fix: on edit cell and delete row filter-sort-page-pagesize will be retained * fix: text info for multiple records selected was wrong * fix: In tooljetdb tooltip on cell hover wasnt shown for cells pertaining to selected column * fix: tooljetdb on create row operation scroll will be moved to top * stylefix: in dark mode on hovering selected row cell background color was wrong --------- Co-authored-by: Abd-Rahman-1999 <s.rahmanabd1999@gmail.com> Co-authored-by: Ganesh Kumar <ganesh8056234@gmail.com>
2024-02-08 09:35:26 +00:00
import React, { useEffect, useState } from 'react';
import Popover from 'react-bootstrap/Popover';
import OverlayTrigger from 'react-bootstrap/OverlayTrigger';
import { ButtonSolid } from '@/_ui/AppButton/AppButton';
import SolidIcon from '@/_ui/Icon/SolidIcons';
import LeftNav from '../../Icons/LeftNav.svg';
import RightNav from '../../Icons/RightNav.svg';
import cx from 'classnames';
import './styles.scss';
export const CellEditMenu = ({
darkMode = false,
children,
show,
close,
columnDetails,
saveFunction,
setCellValue,
cellValue,
previousCellValue,
setDefaultValue,
defaultValue,
setNullValue,
nullValue,
isBoolean,
}) => {
// below state is used only for boolean cell
const [selectedValue, setSelectedValue] = useState(cellValue);
const handleDefaultChange = (defaultColumnValue, defaultBooleanValue) => {
if (defaultBooleanValue === true) {
setCellValue(defaultColumnValue);
} else {
setCellValue(previousCellValue);
}
setDefaultValue(defaultBooleanValue);
setNullValue(false);
};
const handleNullChange = (nullVal) => {
if (nullVal === true) {
setCellValue(null);
} else {
if (previousCellValue === null) {
setCellValue('');
} else {
setCellValue(previousCellValue);
}
}
setNullValue(nullVal);
setDefaultValue(false);
};
const handleSelectedState = (value) => {
setSelectedValue(value);
setCellValue(value);
};
const closePopover = () => {
setSelectedValue(previousCellValue);
close();
};
const handleKeyDown = (e) => {
if (e.key === 'ArrowRight' && isBoolean) {
e.preventDefault();
if (selectedValue === false) handleSelectedState(true);
if (selectedValue === true) handleSelectedState(null);
}
if (e.key === 'ArrowLeft' && isBoolean) {
e.preventDefault();
if (selectedValue === null) handleSelectedState(true);
if (selectedValue === true) handleSelectedState(false);
}
if (e.key === 'Escape') {
closePopover();
}
if (e.key === 'Enter' && cellValue != previousCellValue && show) {
Feature: TJDB UX Revamp (#8538) * Added Edit column functionality in ToolJet Database Table * feat: null constraint support for create_table add_column edit_column * fix: default data-type validation has been added * completed column header revamp * feat: added not null toggle in create new table drawer * feat: on toggle not null constraint value will be persisted * fix: loads label for not null toggle dynamically * feat: add new column to tjdb null constraint support * new datatype dropdown design implemented * added new icon for delete column * added delete icon for column * added delete icon for column * fix: when table name is empty create button will be disabled * fix: datatype dropdown height fix * fix: datatype drop down issue fix * fix: datatype dropdown alignment fix * fix: delete icon changed to new theme * fix: delete icon changed to new one * fix: create new column column name and datatype mandatory validation added * fixed styling issues * Added 2 space indentation for css * inline css moved to css files as well as added 2 space indentation * fix: createTable addColumn editColumn api payload structure change to incorporate constraint changes * fix: error handling added for editColumn api * added 2 space indentation * fix: create table API payload structure changes * added 2 space indentation and applied styles for dark mode as well * disabled the existing column's dataType * fix: create new column payload updated * renamed columnIndex to columnSelection and fixed the plus column creator button position issue * renamed columnIndex to columnSelection and added text visiblity for dropdown in dark and light mode * moved the react-select's new styles to constants.js file as function * react select's css moved to constants.js file * fix: review comments has been fixed * added edit column warning UI * completed edit column new flow * remove Please wait for ToolJet to update..this line from edit column warning message * increased height for add column + button * fix: create table will not accept empty values for mandatory fields like tablename column_name datatype * fix: custom error message for tjdb add row operation * stylefix: table footer page info section realignment changes * fix: moved addNewColumn btn to dropdown on clicking table in sidebar * feat: bulk update and add row option is moved to drop down * add ability to collapse sidebar * add tooltip * fiexed the tooltip issue in collapsible sidebar * fix background on blank slate * fix: layout changes for tjdb table header section * stylefix: tjdb table menu bar style fixes * stylefix: header btn gap has been reduced * fix: edit row data populated into the form * adjusted height * added small alignment changes * pagination-rewamp * adjusted footer style when we collapse the sidebar * fixed the pagination issue when we add new row * feat : sticky column header * feat: expandable row with menu bar flaky issue * fix: on row hover expand icon will now be visible * stylefix: added bg color for row hover and cell hover * stylefix: adjusted expand icon sise * feature : cell navigation * fix: flaky issue on tjdb menu bar while expanding row has been fixed * added naviagation function for table cells * fix: edit row drawer variable name fixes * added cell edit option in table cell * feat: tjdb cell edit dropdown menu completed * fix merge * updates node version * fix: sticky column to left * feature : cell navigation * add support for null values on tjdb bulk upload * stylefix: table background for dark mode fixed * feature : cell edit implementation * feat: progress bar for cell edit * feature : cell edit implementation on boolean datatye * bug fixes * toggle implementation * fix: removed duplicate not null constraint toggle in edit column form * fix: when last filter is deleter in tjdb dashboard filter drop down will be closed * feat : cell edit implementation completed * removed console logs * fix: edit column onclick not null toggle crash issue fixed * solved bugs * added border 2px for selected cells * added cellvalue in cell input if it have not null constraint * stylefix: css value for cell hover has been updated * fix: table header sticky * stylefix: row hover background color for dark mode * fix: autocomplete is off for cell edit input field * fix: null tag was shown when we focus on the input field as well * fix: in cell edit menu either null or default can be choosen * fix: cell edit menu null toggle value sync and edit menu not opening issue * stylefix: row hover bg color was broken * fix: cell navigation flaky issue * stylefix: progress bar attached to the bottom of the cell * fix: tooljetdb collapsible side bar style changes has been fixed * fix: added infor for cell edit menu navigation * fix: cell navigation and cell edit menu boolean view arrow navigation * fix: flow issues in cell navigation has been fixed * fix: backspace key will remove null values and open cell edit mode * fix: updated icon for openai datasource * fix: when we update or delete record pagesize has been modified but it should remain same * feat: typing on selected field inserts value and enable edit menu and removes null value if exist * stylefix: table checkbox styling updated * stylefix: tooljetdb table checkbox indeterminate mode style fixes * stylefix: row selection background color * fix: table first column can be selected but not edited * fix: tooljetDB delete row btn text should be in plural when multiple rows are selected * fix: when column header menu is opened and closed cell click was not working it is fixed now * fix null value on id column on row insert * fix: cell text overlfow will truncate * fix: in tooljetdb while creating new row filters and sorts which were selected will be made default * fix: tooljetdb table cell tooltip design change * fix: on column select and hover entire column was flaky issue fixed * fix: on edit cell and delete row filter-sort-page-pagesize will be retained * fix: text info for multiple records selected was wrong * fix: In tooljetdb tooltip on cell hover wasnt shown for cells pertaining to selected column * fix: tooljetdb on create row operation scroll will be moved to top * stylefix: in dark mode on hovering selected row cell background color was wrong --------- Co-authored-by: Abd-Rahman-1999 <s.rahmanabd1999@gmail.com> Co-authored-by: Ganesh Kumar <ganesh8056234@gmail.com>
2024-02-08 09:35:26 +00:00
saveFunction(cellValue);
}
if (e.key === 'Backspace') {
if (selectedValue === null) {
if (isBoolean) {
setSelectedValue(true);
setCellValue(true);
} else {
setSelectedValue('');
setCellValue('');
}
setNullValue(false);
setDefaultValue(false);
document.getElementById('edit-input-blur').focus();
}
}
e.stopPropagation();
};
useEffect(() => {
if (show) {
document.addEventListener('keydown', handleKeyDown);
return () => {
document.removeEventListener('keydown', handleKeyDown);
};
}
}, [show, isBoolean, selectedValue, cellValue]);
useEffect(() => {
if (selectedValue !== cellValue) setSelectedValue(cellValue);
}, [cellValue]);
const popover = (
<Popover className={`${darkMode && 'dark-theme'} tjdb-table-cell-edit-popover`}>
<Popover.Body className={`${darkMode && 'dark-theme'}`}>
<div className={`d-flex flex-column ${isBoolean ? 'gap-4' : 'gap-3'}`}>
{/* Boolean View */}
{isBoolean && (
<div className="d-flex align-items-start gap-2">
<span
className={`boolean-state-${
selectedValue === false ? 'selected' : ''
} d-flex align-items-center gap-2 fw-500 tjdb-bool-cell-menu-badge-default`}
tabIndex="0"
onClick={() => handleSelectedState(false)}
>
False
</span>
<span
className={`boolean-state-${
selectedValue === true ? 'selected' : ''
} d-flex align-items-center gap-2 fw-500 tjdb-bool-cell-menu-badge-default`}
tabIndex="1"
onClick={() => handleSelectedState(true)}
>
True
</span>
{columnDetails?.constraints_type.is_not_null === false && (
<span
className={`boolean-state-${
selectedValue === null ? 'selected' : ''
} d-flex align-items-center gap-2 fw-500 tjdb-bool-cell-menu-badge-default`}
tabIndex="2"
onClick={() => handleSelectedState(null)}
>
Null
</span>
)}
</div>
)}
{!isBoolean && (
<div className="d-flex justify-content-between align-items-center">
<div className="d-flex flex-column align-items-start gap-1">
<div className="d-flex align-items-center gap-1">
<div className="fw-500 tjdb-cell-menu-shortcuts-info">
<SolidIcon name="enterbutton" />
</div>
<div className="fw-400 tjdb-cell-menu-shortcuts-text">Save Changes</div>
</div>
<div className="d-flex align-items-center gap-1">
<div className="fw-500 tjdb-cell-menu-shortcuts-info">Esc</div>
<div className="fw-400 tjdb-cell-menu-shortcuts-text">Discard Changes</div>
</div>
</div>
<div className="d-flex flex-column align-items-end gap-1">
{columnDetails?.constraints_type.is_not_null === false && (
<div className="d-flex align-items-center gap-2">
<div className="d-flex flex-column">
<span className="fw-400 fs-12">Set to null</span>
</div>
<div>
<label className={`form-switch`}>
<input
className="form-check-input"
type="checkbox"
checked={nullValue}
onChange={() => handleNullChange(!nullValue)}
/>
</label>
</div>
</div>
)}
{columnDetails?.column_default !== null && (
<div className="d-flex align-items-center gap-2">
<div className="d-flex flex-column">
<span className="fw-400 fs-12">Set to default</span>
</div>
<div>
<label className={`form-switch`}>
<input
className="form-check-input"
type="checkbox"
checked={defaultValue}
onChange={() => handleDefaultChange(columnDetails?.column_default, !defaultValue)}
/>
</label>
</div>
</div>
)}
</div>
</div>
)}
{/* Footer */}
<div
className={cx('d-flex align-items-center gap-2', {
'justify-content-between': isBoolean,
'justify-content-end': !isBoolean,
})}
>
{isBoolean ? (
<div className="cell-editmenu-keyActions">
<div className="leftNav-parent-container">
<LeftNav style={{ verticalAlign: 'baseline' }} width={8} height={8} />
</div>
<div className="rightNav-parent-container">
<RightNav style={{ verticalAlign: 'baseline' }} width={8} height={8} />
</div>
<div className="navigate-title fs-10">Navigate</div>
</div>
) : null}
<div className="d-flex" style={{ gap: '8px' }}>
<ButtonSolid onClick={closePopover} variant="tertiary" size="sm" className="fs-12">
Cancel
</ButtonSolid>
<ButtonSolid
onClick={() => saveFunction(selectedValue)}
disabled={cellValue == previousCellValue ? true : false}
variant="primary"
size="sm"
className="fs-12"
>
Save
</ButtonSolid>
</div>
</div>
</div>
</Popover.Body>
</Popover>
);
return (
<OverlayTrigger show={show} trigger="click" placement="bottom-start" rootclose overlay={popover} defaultShow>
{children}
</OverlayTrigger>
);
};