Skip to content

Commit

Permalink
Ran prettier in changed files
Browse files Browse the repository at this point in the history
  • Loading branch information
accioly-cassio committed Nov 17, 2024
1 parent c0e676e commit c5b10be
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 183 deletions.
316 changes: 167 additions & 149 deletions components/lib/datatable/BodyCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,57 +128,62 @@ export const Cell = React.memo(
}, 1);
};

const switchCellToViewMode = React.useCallback((event, submit) => {
const callbackParams = getCellCallbackParams(event);
const newRowData = { ...editingRowDataStateRef.current };
const newValue = props.resolveFieldData(newRowData);
const params = { ...callbackParams, newRowData, newValue };
const onCellEditCancel = getColumnProp('onCellEditCancel');
const cellEditValidator = getColumnProp('cellEditValidator');
const onCellEditComplete = getColumnProp('onCellEditComplete');

if (!submit && onCellEditCancel) {
onCellEditCancel(params);
}

let valid = true;
const switchCellToViewMode = React.useCallback(
(event, submit) => {
const callbackParams = getCellCallbackParams(event);
const newRowData = { ...editingRowDataStateRef.current };
const newValue = props.resolveFieldData(newRowData);
const params = { ...callbackParams, newRowData, newValue };
const onCellEditCancel = getColumnProp('onCellEditCancel');
const cellEditValidator = getColumnProp('cellEditValidator');
const onCellEditComplete = getColumnProp('onCellEditComplete');

if (!submit && onCellEditCancel) {
onCellEditCancel(params);
}

if ((!submit || cellEditValidateOnClose()) && cellEditValidator) {
valid = cellEditValidator(params);
}
let valid = true;

if (valid) {
if (submit && onCellEditComplete) {
onCellEditComplete(params);
if ((!submit || cellEditValidateOnClose()) && cellEditValidator) {
valid = cellEditValidator(params);
}

closeCell(event);
} else {
event.preventDefault();
}
if (valid) {
if (submit && onCellEditComplete) {
onCellEditComplete(params);
}

setEditingRowDataState(newRowData);
}, [getCellCallbackParams, props.resolveFieldData, getColumnProp, cellEditValidateOnClose, closeCell]);
closeCell(event);
} else {
event.preventDefault();
}

const editorCallback = React.useCallback((val) => {
let editingRowData = { ...editingRowDataState };
setEditingRowDataState(newRowData);
},
[getCellCallbackParams, props.resolveFieldData, getColumnProp, cellEditValidateOnClose, closeCell]
);

ObjectUtils.mutateFieldData(editingRowData, props.field, val);
setEditingRowDataState(editingRowData);
const editorCallback = React.useCallback(
(val) => {
let editingRowData = { ...editingRowDataState };

// update editing meta for complete methods on row mode
const currentData = props.getEditingRowData();
ObjectUtils.mutateFieldData(editingRowData, props.field, val);
setEditingRowDataState(editingRowData);

if (currentData) {
ObjectUtils.mutateFieldData(currentData, props.field, val);
}
// update editing meta for complete methods on row mode
const currentData = props.getEditingRowData();

editingRowDataStateRef.current = editingRowData;
}, [editingRowDataState, props.field, props.getEditingRowData]);
if (currentData) {
ObjectUtils.mutateFieldData(currentData, props.field, val);
}

editingRowDataStateRef.current = editingRowData;
},
[editingRowDataState, props.field, props.getEditingRowData]
);

const onClick = (event) => {
props.onClick(event, getCellCallbackParams(event), isEditable(), editingState, setEditingState, selfClick,
props.column, bindDocumentClickListener, overlayEventListener)
props.onClick(event, getCellCallbackParams(event), isEditable(), editingState, setEditingState, selfClick, props.column, bindDocumentClickListener, overlayEventListener);
};

const onMouseDown = (event) => {
Expand All @@ -193,90 +198,93 @@ export const Cell = React.memo(
props.onMouseUp && props.onMouseUp(params);
};

const onKeyDown = React.useCallback((event) => {
if (props.editMode !== 'row') {
if (event.code === 'Enter' || event.code === 'NumpadEnter' || event.code === 'Tab') {
switchCellToViewMode(event, true);
}
const onKeyDown = React.useCallback(
(event) => {
if (props.editMode !== 'row') {
if (event.code === 'Enter' || event.code === 'NumpadEnter' || event.code === 'Tab') {
switchCellToViewMode(event, true);
}

if (event.code === 'Escape') {
switchCellToViewMode(event, false);
if (event.code === 'Escape') {
switchCellToViewMode(event, false);
}
}
}

if (props.allowCellSelection) {
const { target, currentTarget: cell } = event;

switch (event.code) {
case 'ArrowLeft':
let prevCell = props.findPrevSelectableCell(cell);
if (props.allowCellSelection) {
const { target, currentTarget: cell } = event;

if (prevCell) {
changeTabIndex(cell, prevCell);
prevCell.focus();
}
switch (event.code) {
case 'ArrowLeft':
let prevCell = props.findPrevSelectableCell(cell);

event.preventDefault();
break;
if (prevCell) {
changeTabIndex(cell, prevCell);
prevCell.focus();
}

case 'ArrowRight':
let nextCell = props.findNextSelectableCell(cell);

if (nextCell) {
changeTabIndex(cell, nextCell);
nextCell.focus();
}

event.preventDefault();
break;

case 'ArrowUp':
let upCell = props.findUpSelectableCell(cell, index);
event.preventDefault();
break;

if (upCell) {
changeTabIndex(cell, upCell);
upCell.focus();
}
case 'ArrowRight':
let nextCell = props.findNextSelectableCell(cell);

event.preventDefault();
break;
if (nextCell) {
changeTabIndex(cell, nextCell);
nextCell.focus();
}

case 'ArrowDown':
let downCell = props.findDownSelectableCell(cell, index);
event.preventDefault();
break;

if (downCell) {
changeTabIndex(cell, downCell);
downCell.focus();
}
case 'ArrowUp':
let upCell = props.findUpSelectableCell(cell, index);

event.preventDefault();
break;
if (upCell) {
changeTabIndex(cell, upCell);
upCell.focus();
}

case 'Enter':
case 'NumpadEnter':
if (event.shiftKey || event.ctrlKey) {
// #5192 allow TextArea to add new lines
} else if (!DomHandler.isClickable(target)) {
onClick(event);
event.preventDefault();
}

break;
break;

case 'Space':
if (!DomHandler.isClickable(target) && !target.readOnly) {
onClick(event);
event.preventDefault();
}
case 'ArrowDown':
let downCell = props.findDownSelectableCell(cell, index);

break;
if (downCell) {
changeTabIndex(cell, downCell);
downCell.focus();
}

default:
//no op
break;
event.preventDefault();
break;

case 'Enter':
case 'NumpadEnter':
if (event.shiftKey || event.ctrlKey) {
// #5192 allow TextArea to add new lines
} else if (!DomHandler.isClickable(target)) {
onClick(event);
event.preventDefault();
}

break;

case 'Space':
if (!DomHandler.isClickable(target) && !target.readOnly) {
onClick(event);
event.preventDefault();
}

break;

default:
//no op
break;
}
}
}
}, [props.editMode, switchCellToViewMode, props.allowCellSelection]);
},
[props.editMode, switchCellToViewMode, props.allowCellSelection]
);

const onBlur = (event) => {
selfClick.current = false;
Expand All @@ -290,43 +298,55 @@ export const Cell = React.memo(
onClick(event);
};

const onRadioChange = React.useCallback((event) => {
props.onRadioChange({
originalEvent: event,
data: props.rowData,
index: props.rowIndex
});
}, [props.onRadioChange, props.rowData, props.rowIndex]);

const onRowToggle = React.useCallback((event) => {
props.onRowToggle({
originalEvent: event,
data: props.rowData
});
event.preventDefault();
event.stopPropagation();
}, [props.onRowToggle, props.rowData]);

const onRowEditInit = React.useCallback((event) => {
props.onRowEditInit({
originalEvent: event,
data: props.rowData,
newData: props.getEditingRowData(),
field: props.field,
index: props.rowIndex
});
}, [props.onRowEditInit, props.rowData, props.getEditingRowData, props.field, props.rowIndex]);

const onRowEditSave = React.useCallback((event) => {
props.onRowEditSave({
originalEvent: event,
data: props.rowData,
newData: props.getEditingRowData(),
field: props.field,
index: props.rowIndex
});
props.focusOnInit(initFocusTimeout, elementRef);
}, [props.onRowEditSave, props.rowData, props.getEditingRowData, props.field, props.rowIndex]);
const onRadioChange = React.useCallback(
(event) => {
props.onRadioChange({
originalEvent: event,
data: props.rowData,
index: props.rowIndex
});
},
[props.onRadioChange, props.rowData, props.rowIndex]
);

const onRowToggle = React.useCallback(
(event) => {
props.onRowToggle({
originalEvent: event,
data: props.rowData
});
event.preventDefault();
event.stopPropagation();
},
[props.onRowToggle, props.rowData]
);

const onRowEditInit = React.useCallback(
(event) => {
props.onRowEditInit({
originalEvent: event,
data: props.rowData,
newData: props.getEditingRowData(),
field: props.field,
index: props.rowIndex
});
},
[props.onRowEditInit, props.rowData, props.getEditingRowData, props.field, props.rowIndex]
);

const onRowEditSave = React.useCallback(
(event) => {
props.onRowEditSave({
originalEvent: event,
data: props.rowData,
newData: props.getEditingRowData(),
field: props.field,
index: props.rowIndex
});
props.focusOnInit(initFocusTimeout, elementRef);
},
[props.onRowEditSave, props.rowData, props.getEditingRowData, props.field, props.rowIndex]
);

const onRowEditCancel = (event) => {
props.onRowEditCancel({ originalEvent: event, data: props.rowData, newData: props.getEditingRowData(), field: props.field, index: props.rowIndex });
Expand Down Expand Up @@ -688,11 +708,10 @@ export const Cell = React.memo(
// RadioCheckCell is used for the Radio and Checkbox selection and has the isRowSelected dependency
export const RadioCheckCell = React.memo(
(props) => {
return <Cell {...props} />
return <Cell {...props} />;
},
(prevProps, nextProps) => {
const keysToCompare = ['isRowSelected', 'field', 'allowCellSelection', 'isCellSelected', 'editMode',
'index', 'tabIndex', 'editing', 'expanded', 'editingMeta', 'rowData', 'column.selectionMode'];
const keysToCompare = ['isRowSelected', 'field', 'allowCellSelection', 'isCellSelected', 'editMode', 'index', 'tabIndex', 'editing', 'expanded', 'editingMeta', 'rowData', 'column.selectionMode'];

return ObjectUtils.selectiveCompare(prevProps, nextProps, keysToCompare);
}
Expand All @@ -702,11 +721,10 @@ RadioCheckCell.displayName = 'RadioCheckCell';

export const BodyCell = React.memo(
(props) => {
return <Cell {...props} />
return <Cell {...props} />;
},
(prevProps, nextProps) => {
const keysToCompare = ['field', 'allowCellSelection', 'isCellSelected', 'editMode', 'index', 'tabIndex',
'editing', 'expanded', 'editingMeta', 'rowData', 'column.selectionMode'];
const keysToCompare = ['field', 'allowCellSelection', 'isCellSelected', 'editMode', 'index', 'tabIndex', 'editing', 'expanded', 'editingMeta', 'rowData', 'column.selectionMode'];

return ObjectUtils.selectiveCompare(prevProps, nextProps, keysToCompare);
}
Expand Down
Loading

0 comments on commit c5b10be

Please sign in to comment.