2022-07-14 07:02:35 +00:00
|
|
|
import React, { lazy, Suspense } from "react";
|
|
|
|
|
import log from "loglevel";
|
|
|
|
|
import moment, { MomentInput } from "moment";
|
|
|
|
|
import _, {
|
|
|
|
|
isNumber,
|
|
|
|
|
isString,
|
|
|
|
|
isNil,
|
|
|
|
|
xor,
|
|
|
|
|
without,
|
|
|
|
|
isBoolean,
|
|
|
|
|
isArray,
|
|
|
|
|
xorWith,
|
|
|
|
|
isEmpty,
|
|
|
|
|
union,
|
2022-11-18 10:54:35 +00:00
|
|
|
isObject,
|
2022-12-30 10:52:11 +00:00
|
|
|
orderBy,
|
2022-07-14 07:02:35 +00:00
|
|
|
} from "lodash";
|
|
|
|
|
|
|
|
|
|
import BaseWidget, { WidgetState } from "widgets/BaseWidget";
|
2022-09-22 11:15:00 +00:00
|
|
|
import {
|
|
|
|
|
RenderModes,
|
|
|
|
|
WidgetType,
|
|
|
|
|
WIDGET_PADDING,
|
|
|
|
|
} from "constants/WidgetConstants";
|
2022-07-14 07:02:35 +00:00
|
|
|
import { EventType } from "constants/AppsmithActionConstants/ActionConstants";
|
|
|
|
|
import Skeleton from "components/utils/Skeleton";
|
|
|
|
|
import { noop, retryPromise } from "utils/AppsmithUtils";
|
|
|
|
|
import {
|
2022-11-05 09:54:20 +00:00
|
|
|
ReactTableFilter,
|
|
|
|
|
AddNewRowActions,
|
2023-02-09 11:29:06 +00:00
|
|
|
DEFAULT_FILTER,
|
2022-11-05 09:54:20 +00:00
|
|
|
} from "../component/Constants";
|
|
|
|
|
import {
|
|
|
|
|
ActionColumnTypes,
|
2022-07-14 07:02:35 +00:00
|
|
|
ColumnTypes,
|
|
|
|
|
COLUMN_MIN_WIDTH,
|
|
|
|
|
DateInputFormat,
|
2022-09-13 05:41:59 +00:00
|
|
|
defaultEditableCell,
|
2022-07-14 07:02:35 +00:00
|
|
|
DEFAULT_BUTTON_LABEL,
|
|
|
|
|
DEFAULT_COLUMN_WIDTH,
|
|
|
|
|
DEFAULT_MENU_BUTTON_LABEL,
|
|
|
|
|
DEFAULT_MENU_VARIANT,
|
2022-09-13 05:41:59 +00:00
|
|
|
EditableCell,
|
2022-07-14 07:02:35 +00:00
|
|
|
EditableCellActions,
|
|
|
|
|
InlineEditingSaveOptions,
|
|
|
|
|
OnColumnEventArgs,
|
|
|
|
|
ORIGINAL_INDEX_KEY,
|
|
|
|
|
TableWidgetProps,
|
|
|
|
|
TransientDataPayload,
|
|
|
|
|
} from "../constants";
|
|
|
|
|
import derivedProperties from "./parseDerivedProperties";
|
|
|
|
|
import {
|
|
|
|
|
getAllTableColumnKeys,
|
|
|
|
|
getDefaultColumnProperties,
|
|
|
|
|
getDerivedColumns,
|
|
|
|
|
getTableStyles,
|
|
|
|
|
getSelectRowIndex,
|
|
|
|
|
getSelectRowIndices,
|
|
|
|
|
getCellProperties,
|
|
|
|
|
isColumnTypeEditable,
|
2022-09-29 05:26:08 +00:00
|
|
|
getColumnType,
|
2022-12-30 10:52:11 +00:00
|
|
|
getBooleanPropertyValue,
|
2022-07-14 07:02:35 +00:00
|
|
|
} from "./utilities";
|
|
|
|
|
import {
|
|
|
|
|
ColumnProperties,
|
|
|
|
|
ReactTableColumnProps,
|
|
|
|
|
CompactModeTypes,
|
|
|
|
|
SortOrderTypes,
|
|
|
|
|
} from "../component/Constants";
|
2022-08-17 18:23:53 +00:00
|
|
|
import contentConfig from "./propertyConfig/contentConfig";
|
|
|
|
|
import styleConfig from "./propertyConfig/styleConfig";
|
2022-07-14 07:02:35 +00:00
|
|
|
import { BatchPropertyUpdatePayload } from "actions/controlActions";
|
2022-09-30 04:03:53 +00:00
|
|
|
import { IconName, IconNames } from "@blueprintjs/icons";
|
2022-07-14 07:02:35 +00:00
|
|
|
import { Colors } from "constants/Colors";
|
|
|
|
|
import equal from "fast-deep-equal/es6";
|
|
|
|
|
import { sanitizeKey } from "widgets/WidgetUtils";
|
2022-09-30 04:03:53 +00:00
|
|
|
import PlainTextCell from "../component/cellComponents/PlainTextCell";
|
2022-07-14 07:02:35 +00:00
|
|
|
import { ButtonCell } from "../component/cellComponents/ButtonCell";
|
|
|
|
|
import { MenuButtonCell } from "../component/cellComponents/MenuButtonCell";
|
|
|
|
|
import { ImageCell } from "../component/cellComponents/ImageCell";
|
|
|
|
|
import { VideoCell } from "../component/cellComponents/VideoCell";
|
|
|
|
|
import { IconButtonCell } from "../component/cellComponents/IconButtonCell";
|
|
|
|
|
import { EditActionCell } from "../component/cellComponents/EditActionsCell";
|
|
|
|
|
import { klona as clone } from "klona";
|
2022-09-08 11:05:59 +00:00
|
|
|
import { CheckboxCell } from "../component/cellComponents/CheckboxCell";
|
2022-09-16 04:34:11 +00:00
|
|
|
import { SwitchCell } from "../component/cellComponents/SwitchCell";
|
2022-09-30 04:03:53 +00:00
|
|
|
import { SelectCell } from "../component/cellComponents/SelectCell";
|
2022-11-05 09:54:20 +00:00
|
|
|
import { CellWrapper } from "../component/TableStyledWrappers";
|
2022-11-28 04:44:31 +00:00
|
|
|
import { Stylesheet } from "entities/AppTheming";
|
2023-01-16 09:23:56 +00:00
|
|
|
import { DateCell } from "../component/cellComponents/DateCell";
|
2022-12-30 10:52:11 +00:00
|
|
|
import { MenuItem, MenuItemsSource } from "widgets/MenuButtonWidget/constants";
|
2023-01-16 09:23:56 +00:00
|
|
|
import { TimePrecision } from "widgets/DatePickerWidget2/constants";
|
2022-07-14 07:02:35 +00:00
|
|
|
|
|
|
|
|
const ReactTableComponent = lazy(() =>
|
|
|
|
|
retryPromise(() => import("../component")),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
class TableWidgetV2 extends BaseWidget<TableWidgetProps, WidgetState> {
|
2022-09-13 05:41:59 +00:00
|
|
|
inlineEditTimer: number | null = null;
|
2022-07-14 07:02:35 +00:00
|
|
|
|
2022-08-17 18:23:53 +00:00
|
|
|
static getPropertyPaneContentConfig() {
|
|
|
|
|
return contentConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static getPropertyPaneStyleConfig() {
|
|
|
|
|
return styleConfig;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-14 07:02:35 +00:00
|
|
|
static getMetaPropertiesMap(): Record<string, any> {
|
|
|
|
|
return {
|
|
|
|
|
pageNo: 1,
|
|
|
|
|
selectedRowIndex: undefined,
|
|
|
|
|
selectedRowIndices: undefined,
|
|
|
|
|
searchText: undefined,
|
|
|
|
|
triggeredRowIndex: undefined,
|
|
|
|
|
filters: [],
|
|
|
|
|
sortOrder: {
|
|
|
|
|
column: "",
|
|
|
|
|
order: null,
|
|
|
|
|
},
|
|
|
|
|
transientTableData: {},
|
2022-11-25 04:39:59 +00:00
|
|
|
updatedRowIndex: -1,
|
2022-09-13 05:41:59 +00:00
|
|
|
editableCell: defaultEditableCell,
|
|
|
|
|
columnEditableCellValue: {},
|
2022-09-30 04:03:53 +00:00
|
|
|
selectColumnFilterText: {},
|
2022-11-05 09:54:20 +00:00
|
|
|
isAddRowInProgress: false,
|
|
|
|
|
newRowContent: undefined,
|
|
|
|
|
newRow: undefined,
|
2022-07-14 07:02:35 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static getDerivedPropertiesMap() {
|
|
|
|
|
return {
|
|
|
|
|
selectedRow: `{{(()=>{${derivedProperties.getSelectedRow}})()}}`,
|
|
|
|
|
triggeredRow: `{{(()=>{${derivedProperties.getTriggeredRow}})()}}`,
|
|
|
|
|
selectedRows: `{{(()=>{${derivedProperties.getSelectedRows}})()}}`,
|
|
|
|
|
pageSize: `{{(()=>{${derivedProperties.getPageSize}})()}}`,
|
|
|
|
|
triggerRowSelection: "{{!!this.onRowSelected}}",
|
|
|
|
|
processedTableData: `{{(()=>{${derivedProperties.getProcessedTableData}})()}}`,
|
|
|
|
|
orderedTableColumns: `{{(()=>{${derivedProperties.getOrderedTableColumns}})()}}`,
|
|
|
|
|
filteredTableData: `{{(()=>{ ${derivedProperties.getFilteredTableData}})()}}`,
|
|
|
|
|
updatedRows: `{{(()=>{ ${derivedProperties.getUpdatedRows}})()}}`,
|
|
|
|
|
updatedRowIndices: `{{(()=>{ ${derivedProperties.getUpdatedRowIndices}})()}}`,
|
2022-11-25 04:39:59 +00:00
|
|
|
updatedRow: `{{(()=>{ ${derivedProperties.getUpdatedRow}})()}}`,
|
2022-09-01 10:01:02 +00:00
|
|
|
pageOffset: `{{(()=>{${derivedProperties.getPageOffset}})()}}`,
|
2022-11-05 09:54:20 +00:00
|
|
|
isEditableCellsValid: `{{(()=>{ ${derivedProperties.getEditableCellValidity}})()}}`,
|
2022-11-25 06:12:23 +00:00
|
|
|
tableHeaders: `{{(()=>{${derivedProperties.getTableHeaders}})()}}`,
|
2022-07-14 07:02:35 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static getDefaultPropertiesMap(): Record<string, string> {
|
|
|
|
|
return {
|
|
|
|
|
searchText: "defaultSearchText",
|
|
|
|
|
selectedRowIndex: "defaultSelectedRowIndex",
|
|
|
|
|
selectedRowIndices: "defaultSelectedRowIndices",
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-13 05:40:08 +00:00
|
|
|
static getLoadingProperties(): Array<RegExp> | undefined {
|
|
|
|
|
return [/\.tableData$/];
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-28 04:44:31 +00:00
|
|
|
static getStylesheetConfig(): Stylesheet {
|
|
|
|
|
return {
|
|
|
|
|
accentColor: "{{appsmith.theme.colors.primaryColor}}",
|
|
|
|
|
borderRadius: "{{appsmith.theme.borderRadius.appBorderRadius}}",
|
|
|
|
|
boxShadow: "{{appsmith.theme.boxShadow.appBoxShadow}}",
|
|
|
|
|
childStylesheet: {
|
|
|
|
|
button: {
|
|
|
|
|
buttonColor: "{{appsmith.theme.colors.primaryColor}}",
|
|
|
|
|
borderRadius: "{{appsmith.theme.borderRadius.appBorderRadius}}",
|
|
|
|
|
boxShadow: "none",
|
|
|
|
|
},
|
|
|
|
|
menuButton: {
|
|
|
|
|
menuColor: "{{appsmith.theme.colors.primaryColor}}",
|
|
|
|
|
borderRadius: "{{appsmith.theme.borderRadius.appBorderRadius}}",
|
|
|
|
|
boxShadow: "none",
|
|
|
|
|
},
|
|
|
|
|
iconButton: {
|
|
|
|
|
buttonColor: "{{appsmith.theme.colors.primaryColor}}",
|
|
|
|
|
borderRadius: "{{appsmith.theme.borderRadius.appBorderRadius}}",
|
|
|
|
|
boxShadow: "none",
|
|
|
|
|
},
|
|
|
|
|
editActions: {
|
|
|
|
|
saveButtonColor: "{{appsmith.theme.colors.primaryColor}}",
|
|
|
|
|
saveBorderRadius: "{{appsmith.theme.borderRadius.appBorderRadius}}",
|
|
|
|
|
discardButtonColor: "{{appsmith.theme.colors.primaryColor}}",
|
|
|
|
|
discardBorderRadius:
|
|
|
|
|
"{{appsmith.theme.borderRadius.appBorderRadius}}",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-14 07:02:35 +00:00
|
|
|
/*
|
|
|
|
|
* Function to get the table columns with appropriate render functions
|
|
|
|
|
* based on columnType
|
|
|
|
|
*/
|
|
|
|
|
getTableColumns = () => {
|
|
|
|
|
const { columnWidthMap = {}, orderedTableColumns = [] } = this.props;
|
|
|
|
|
let columns: ReactTableColumnProps[] = [];
|
|
|
|
|
const hiddenColumns: ReactTableColumnProps[] = [];
|
|
|
|
|
|
2022-09-22 11:15:00 +00:00
|
|
|
const { componentWidth } = this.getPaddingAdjustedDimensions();
|
2022-07-14 07:02:35 +00:00
|
|
|
let totalColumnWidth = 0;
|
|
|
|
|
|
|
|
|
|
if (isArray(orderedTableColumns)) {
|
|
|
|
|
orderedTableColumns.forEach((column: any) => {
|
|
|
|
|
const isHidden = !column.isVisible;
|
|
|
|
|
const columnData = {
|
|
|
|
|
id: column.id,
|
|
|
|
|
Header: column.label,
|
|
|
|
|
alias: column.alias,
|
|
|
|
|
accessor: (row: any) => row[column.alias],
|
|
|
|
|
width: columnWidthMap[column.id] || DEFAULT_COLUMN_WIDTH,
|
|
|
|
|
minWidth: COLUMN_MIN_WIDTH,
|
|
|
|
|
draggable: true,
|
|
|
|
|
isHidden: false,
|
|
|
|
|
isAscOrder: column.isAscOrder,
|
|
|
|
|
isDerived: column.isDerived,
|
|
|
|
|
metaProperties: {
|
|
|
|
|
isHidden: isHidden,
|
|
|
|
|
type: column.columnType,
|
|
|
|
|
format: column.outputFormat || "",
|
|
|
|
|
inputFormat: column.inputFormat || "",
|
|
|
|
|
},
|
|
|
|
|
columnProperties: column,
|
2022-09-30 04:03:53 +00:00
|
|
|
Cell: this.renderCell,
|
2022-07-14 07:02:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const isAllCellVisible: boolean | boolean[] = column.isCellVisible;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If all cells are not visible or column itself is not visible,
|
|
|
|
|
* set isHidden and push it to hiddenColumns array else columns array
|
|
|
|
|
*/
|
|
|
|
|
if (
|
|
|
|
|
(isBoolean(isAllCellVisible) && !isAllCellVisible) ||
|
|
|
|
|
(isArray(isAllCellVisible) &&
|
|
|
|
|
isAllCellVisible.every((visibility) => visibility === false)) ||
|
|
|
|
|
isHidden
|
|
|
|
|
) {
|
|
|
|
|
columnData.isHidden = true;
|
|
|
|
|
hiddenColumns.push(columnData);
|
|
|
|
|
} else {
|
|
|
|
|
totalColumnWidth += columnData.width;
|
|
|
|
|
columns.push(columnData);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-22 11:15:00 +00:00
|
|
|
const lastColumnIndex = columns.length - 1;
|
2022-07-14 07:02:35 +00:00
|
|
|
if (totalColumnWidth < componentWidth) {
|
2022-09-22 11:15:00 +00:00
|
|
|
/*
|
|
|
|
|
This "if" block is responsible for upsizing the last column width
|
|
|
|
|
if there is space left in the table container towards the right
|
|
|
|
|
*/
|
2022-07-14 07:02:35 +00:00
|
|
|
if (columns[lastColumnIndex]) {
|
|
|
|
|
const lastColumnWidth =
|
|
|
|
|
columns[lastColumnIndex].width || DEFAULT_COLUMN_WIDTH;
|
|
|
|
|
const remainingWidth = componentWidth - totalColumnWidth;
|
2022-09-22 11:15:00 +00:00
|
|
|
// Adding the remaining width i.e. space left towards the right, to the last column width
|
|
|
|
|
columns[lastColumnIndex].width = lastColumnWidth + remainingWidth;
|
|
|
|
|
}
|
|
|
|
|
} else if (totalColumnWidth > componentWidth) {
|
|
|
|
|
/*
|
|
|
|
|
This "else-if" block is responsible for downsizing the last column width
|
|
|
|
|
if the last column spills over resulting in horizontal scroll
|
|
|
|
|
*/
|
|
|
|
|
const extraWidth = totalColumnWidth - componentWidth;
|
|
|
|
|
const lastColWidth =
|
|
|
|
|
columns[lastColumnIndex].width || DEFAULT_COLUMN_WIDTH;
|
|
|
|
|
/*
|
|
|
|
|
Below if condition explanation:
|
|
|
|
|
Condition 1: (lastColWidth > COLUMN_MIN_WIDTH)
|
|
|
|
|
We will downsize the last column only if its greater than COLUMN_MIN_WIDTH
|
|
|
|
|
Condition 2: (extraWidth < lastColWidth)
|
|
|
|
|
This condition checks whether the last column is the only column that is spilling over.
|
|
|
|
|
If more than one columns are spilling over we won't downsize the last column
|
|
|
|
|
*/
|
|
|
|
|
if (lastColWidth > COLUMN_MIN_WIDTH && extraWidth < lastColWidth) {
|
|
|
|
|
const availableWidthForLastColumn = lastColWidth - extraWidth;
|
|
|
|
|
/*
|
|
|
|
|
Below we are making sure last column width doesn't go lower than COLUMN_MIN_WIDTH again
|
|
|
|
|
as availableWidthForLastColumn might go lower than COLUMN_MIN_WIDTH in some cases
|
|
|
|
|
*/
|
2022-07-14 07:02:35 +00:00
|
|
|
columns[lastColumnIndex].width =
|
2022-09-22 11:15:00 +00:00
|
|
|
availableWidthForLastColumn < COLUMN_MIN_WIDTH
|
|
|
|
|
? COLUMN_MIN_WIDTH
|
|
|
|
|
: availableWidthForLastColumn;
|
2022-07-14 07:02:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hiddenColumns.length && this.props.renderMode === RenderModes.CANVAS) {
|
|
|
|
|
columns = columns.concat(hiddenColumns);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return columns.filter((column: ReactTableColumnProps) => !!column.id);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
transformData = (
|
|
|
|
|
tableData: Array<Record<string, unknown>>,
|
|
|
|
|
columns: ReactTableColumnProps[],
|
|
|
|
|
) => {
|
|
|
|
|
if (isArray(tableData)) {
|
|
|
|
|
return tableData.map((row, rowIndex) => {
|
|
|
|
|
const newRow: { [key: string]: any } = {};
|
|
|
|
|
|
|
|
|
|
columns.forEach((column) => {
|
|
|
|
|
const { alias } = column;
|
|
|
|
|
let value = row[alias];
|
|
|
|
|
|
|
|
|
|
if (column.metaProperties) {
|
|
|
|
|
switch (column.metaProperties.type) {
|
|
|
|
|
case ColumnTypes.DATE:
|
|
|
|
|
let isValidDate = true;
|
|
|
|
|
const outputFormat = _.isArray(column.metaProperties.format)
|
|
|
|
|
? column.metaProperties.format[rowIndex]
|
|
|
|
|
: column.metaProperties.format;
|
|
|
|
|
let inputFormat;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const type = _.isArray(column.metaProperties.inputFormat)
|
|
|
|
|
? column.metaProperties.inputFormat[rowIndex]
|
|
|
|
|
: column.metaProperties.inputFormat;
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
type !== DateInputFormat.EPOCH &&
|
|
|
|
|
type !== DateInputFormat.MILLISECONDS
|
|
|
|
|
) {
|
|
|
|
|
inputFormat = type;
|
|
|
|
|
moment(value as MomentInput, inputFormat);
|
|
|
|
|
} else if (!isNumber(value)) {
|
|
|
|
|
isValidDate = false;
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
isValidDate = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isValidDate && value) {
|
|
|
|
|
try {
|
|
|
|
|
if (
|
|
|
|
|
column.metaProperties.inputFormat ===
|
|
|
|
|
DateInputFormat.MILLISECONDS
|
|
|
|
|
) {
|
|
|
|
|
value = Number(value);
|
|
|
|
|
} else if (
|
|
|
|
|
column.metaProperties.inputFormat ===
|
|
|
|
|
DateInputFormat.EPOCH
|
|
|
|
|
) {
|
|
|
|
|
value = 1000 * Number(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newRow[alias] = moment(
|
|
|
|
|
value as MomentInput,
|
|
|
|
|
inputFormat,
|
|
|
|
|
).format(outputFormat);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
log.debug("Unable to parse Date:", { e });
|
|
|
|
|
newRow[alias] = "";
|
|
|
|
|
}
|
|
|
|
|
} else if (value) {
|
|
|
|
|
newRow[alias] = "Invalid Value";
|
|
|
|
|
} else {
|
|
|
|
|
newRow[alias] = "";
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
let data;
|
|
|
|
|
|
2022-09-08 11:05:59 +00:00
|
|
|
if (
|
|
|
|
|
_.isString(value) ||
|
|
|
|
|
_.isNumber(value) ||
|
|
|
|
|
_.isBoolean(value)
|
|
|
|
|
) {
|
2022-07-14 07:02:35 +00:00
|
|
|
data = value;
|
|
|
|
|
} else if (isNil(value)) {
|
|
|
|
|
data = "";
|
|
|
|
|
} else {
|
|
|
|
|
data = JSON.stringify(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newRow[alias] = data;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Inject the edited cell value from the editableCell object
|
|
|
|
|
*/
|
2022-09-15 07:47:15 +00:00
|
|
|
if (this.props.editableCell?.index === rowIndex) {
|
2022-09-13 05:41:59 +00:00
|
|
|
const { column, inputValue } = this.props.editableCell;
|
2022-07-14 07:02:35 +00:00
|
|
|
|
2022-09-13 05:41:59 +00:00
|
|
|
newRow[column] = inputValue;
|
2022-07-14 07:02:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newRow;
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
updateDerivedColumnsIndex = (
|
|
|
|
|
derivedColumns: Record<string, ColumnProperties>,
|
|
|
|
|
tableColumnCount: number,
|
|
|
|
|
) => {
|
|
|
|
|
if (!derivedColumns) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//update index property of all columns in new derived columns
|
|
|
|
|
return Object.values(derivedColumns).map(
|
|
|
|
|
(column: ColumnProperties, index: number) => {
|
|
|
|
|
return {
|
|
|
|
|
...column,
|
|
|
|
|
index: index + tableColumnCount,
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Function to create new primary Columns from the tableData
|
|
|
|
|
* gets called on component mount and on component update
|
|
|
|
|
*/
|
|
|
|
|
createTablePrimaryColumns = ():
|
|
|
|
|
| Record<string, ColumnProperties>
|
|
|
|
|
| undefined => {
|
|
|
|
|
const { tableData = [], primaryColumns = {} } = this.props;
|
|
|
|
|
|
|
|
|
|
if (!_.isArray(tableData) || tableData.length === 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const existingColumnIds = Object.keys(primaryColumns);
|
|
|
|
|
const newTableColumns: Record<string, ColumnProperties> = {};
|
|
|
|
|
const tableStyles = getTableStyles(this.props);
|
|
|
|
|
const columnKeys: string[] = getAllTableColumnKeys(tableData);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Generate default column properties for all columns
|
|
|
|
|
* But do not replace existing columns with the same id
|
|
|
|
|
*/
|
|
|
|
|
columnKeys.forEach((columnKey, index) => {
|
|
|
|
|
const existingColumn = this.getColumnByOriginalId(columnKey);
|
|
|
|
|
|
|
|
|
|
if (!!existingColumn) {
|
|
|
|
|
// Use the existing column properties
|
|
|
|
|
newTableColumns[existingColumn.id] = existingColumn;
|
|
|
|
|
} else {
|
|
|
|
|
const hashedColumnKey = sanitizeKey(columnKey, {
|
|
|
|
|
existingKeys: union(existingColumnIds, Object.keys(newTableColumns)),
|
|
|
|
|
});
|
|
|
|
|
// Create column properties for the new column
|
2022-09-29 05:26:08 +00:00
|
|
|
const columnType = getColumnType(tableData, columnKey);
|
2022-07-14 07:02:35 +00:00
|
|
|
const columnProperties = getDefaultColumnProperties(
|
|
|
|
|
columnKey,
|
|
|
|
|
hashedColumnKey,
|
|
|
|
|
index,
|
|
|
|
|
this.props.widgetName,
|
2022-09-29 05:26:08 +00:00
|
|
|
false,
|
|
|
|
|
columnType,
|
2022-07-14 07:02:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
newTableColumns[columnProperties.id] = {
|
|
|
|
|
...columnProperties,
|
|
|
|
|
...tableStyles,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const derivedColumns: Record<string, ColumnProperties> = getDerivedColumns(
|
|
|
|
|
primaryColumns,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const updatedDerivedColumns = this.updateDerivedColumnsIndex(
|
|
|
|
|
derivedColumns,
|
|
|
|
|
Object.keys(newTableColumns).length,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
//add derived columns to new Table columns
|
|
|
|
|
updatedDerivedColumns.forEach((derivedColumn: ColumnProperties) => {
|
|
|
|
|
newTableColumns[derivedColumn.id] = derivedColumn;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const newColumnIds = Object.keys(newTableColumns);
|
|
|
|
|
|
|
|
|
|
// check if the columns ids differ
|
|
|
|
|
if (_.xor(existingColumnIds, newColumnIds).length > 0) {
|
|
|
|
|
return newTableColumns;
|
|
|
|
|
} else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Function to update primaryColumns when the tablData schema changes
|
|
|
|
|
*/
|
|
|
|
|
updateColumnProperties = (
|
|
|
|
|
tableColumns?: Record<string, ColumnProperties>,
|
|
|
|
|
) => {
|
|
|
|
|
const { columnOrder = [], primaryColumns = {} } = this.props;
|
|
|
|
|
const derivedColumns = getDerivedColumns(primaryColumns);
|
|
|
|
|
|
|
|
|
|
if (tableColumns) {
|
|
|
|
|
const existingColumnIds = Object.keys(primaryColumns);
|
|
|
|
|
const existingDerivedColumnIds = Object.keys(derivedColumns);
|
|
|
|
|
|
|
|
|
|
const newColumnIds = Object.keys(tableColumns);
|
|
|
|
|
|
|
|
|
|
//Check if there is any difference in the existing and new columns ids
|
|
|
|
|
if (_.xor(existingColumnIds, newColumnIds).length > 0) {
|
|
|
|
|
const newColumnIdsToAdd = _.without(newColumnIds, ...existingColumnIds);
|
|
|
|
|
|
|
|
|
|
const propertiesToAdd: Record<string, unknown> = {};
|
|
|
|
|
|
|
|
|
|
newColumnIdsToAdd.forEach((columnId: string) => {
|
|
|
|
|
// id could be an empty string
|
|
|
|
|
if (!!columnId) {
|
|
|
|
|
Object.entries(tableColumns[columnId]).forEach(([key, value]) => {
|
|
|
|
|
propertiesToAdd[`primaryColumns.${columnId}.${key}`] = value;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If new columnOrders have different values from the original columnOrders
|
|
|
|
|
* Only update when there are new Columns(Derived or Primary)
|
|
|
|
|
*/
|
|
|
|
|
if (
|
|
|
|
|
!!newColumnIds.length &&
|
|
|
|
|
!!_.xor(newColumnIds, columnOrder).length &&
|
2022-09-02 09:16:30 +00:00
|
|
|
!equal(_.sortBy(newColumnIds), _.sortBy(existingDerivedColumnIds))
|
2022-07-14 07:02:35 +00:00
|
|
|
) {
|
2022-09-01 06:10:19 +00:00
|
|
|
// Maintain original columnOrder and keep new columns at the end
|
|
|
|
|
let newColumnOrder = _.intersection(columnOrder, newColumnIds);
|
|
|
|
|
newColumnOrder = _.union(newColumnOrder, newColumnIds);
|
|
|
|
|
propertiesToAdd["columnOrder"] = newColumnOrder;
|
2022-07-14 07:02:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const propertiesToUpdate: BatchPropertyUpdatePayload = {
|
|
|
|
|
modify: propertiesToAdd,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const pathsToDelete: string[] = [];
|
|
|
|
|
const columnsIdsToDelete = without(existingColumnIds, ...newColumnIds);
|
|
|
|
|
|
|
|
|
|
if (!!columnsIdsToDelete.length) {
|
|
|
|
|
columnsIdsToDelete.forEach((id: string) => {
|
|
|
|
|
if (!primaryColumns[id].isDerived) {
|
|
|
|
|
pathsToDelete.push(`primaryColumns.${id}`);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
propertiesToUpdate.remove = pathsToDelete;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
super.batchUpdateWidgetProperty(propertiesToUpdate, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
const { tableData } = this.props;
|
|
|
|
|
|
|
|
|
|
if (_.isArray(tableData) && !!tableData.length) {
|
|
|
|
|
const newPrimaryColumns = this.createTablePrimaryColumns();
|
|
|
|
|
|
|
|
|
|
// When the Table data schema changes
|
|
|
|
|
if (newPrimaryColumns && !!Object.keys(newPrimaryColumns).length) {
|
|
|
|
|
this.updateColumnProperties(newPrimaryColumns);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps: TableWidgetProps) {
|
|
|
|
|
const {
|
|
|
|
|
defaultSelectedRowIndex,
|
|
|
|
|
defaultSelectedRowIndices,
|
|
|
|
|
pageNo,
|
|
|
|
|
pageSize,
|
|
|
|
|
primaryColumns = {},
|
|
|
|
|
serverSidePaginationEnabled,
|
|
|
|
|
totalRecordsCount,
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
// Bail out if tableData is a string. This signifies an error in evaluations
|
|
|
|
|
if (isString(this.props.tableData)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if tableData is modifed
|
|
|
|
|
const isTableDataModified = !equal(
|
|
|
|
|
this.props.tableData,
|
|
|
|
|
prevProps.tableData,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// If the user has changed the tableData OR
|
|
|
|
|
// The binding has returned a new value
|
|
|
|
|
if (isTableDataModified) {
|
|
|
|
|
this.updateMetaRowData(
|
|
|
|
|
prevProps.filteredTableData,
|
|
|
|
|
this.props.filteredTableData,
|
|
|
|
|
);
|
|
|
|
|
|
2022-12-01 05:24:48 +00:00
|
|
|
this.props.updateWidgetMetaProperty("triggeredRowIndex", -1);
|
2022-07-14 07:02:35 +00:00
|
|
|
|
|
|
|
|
const newColumnIds: string[] = getAllTableColumnKeys(
|
|
|
|
|
this.props.tableData,
|
|
|
|
|
);
|
|
|
|
|
const primaryColumnIds = Object.keys(primaryColumns).filter(
|
|
|
|
|
(id: string) => !primaryColumns[id].isDerived,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (xor(newColumnIds, primaryColumnIds).length > 0) {
|
|
|
|
|
const newTableColumns = this.createTablePrimaryColumns();
|
|
|
|
|
|
|
|
|
|
if (newTableColumns) {
|
|
|
|
|
this.updateColumnProperties(newTableColumns);
|
|
|
|
|
}
|
2022-12-01 05:24:48 +00:00
|
|
|
|
2023-02-09 11:29:06 +00:00
|
|
|
this.props.updateWidgetMetaProperty("filters", [DEFAULT_FILTER]);
|
2022-07-14 07:02:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Clear transient table data and editablecell when tableData changes
|
|
|
|
|
*/
|
|
|
|
|
if (isTableDataModified) {
|
|
|
|
|
this.props.updateWidgetMetaProperty("transientTableData", {});
|
2022-11-25 04:39:59 +00:00
|
|
|
// reset updatedRowIndex whenever transientTableData is flushed.
|
|
|
|
|
this.props.updateWidgetMetaProperty("updatedRowIndex", -1);
|
|
|
|
|
|
2022-09-13 05:41:59 +00:00
|
|
|
this.clearEditableCell(true);
|
2022-09-30 04:03:53 +00:00
|
|
|
this.props.updateWidgetMetaProperty("selectColumnFilterText", {});
|
2022-07-14 07:02:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!pageNo) {
|
|
|
|
|
this.props.updateWidgetMetaProperty("pageNo", 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//check if pageNo does not excede the max Page no, due to change of totalRecordsCount
|
|
|
|
|
if (serverSidePaginationEnabled && totalRecordsCount) {
|
|
|
|
|
const maxAllowedPageNumber = Math.ceil(totalRecordsCount / pageSize);
|
|
|
|
|
|
|
|
|
|
if (pageNo > maxAllowedPageNumber) {
|
|
|
|
|
this.props.updateWidgetMetaProperty("pageNo", maxAllowedPageNumber);
|
|
|
|
|
}
|
|
|
|
|
} else if (
|
|
|
|
|
serverSidePaginationEnabled !== prevProps.serverSidePaginationEnabled
|
|
|
|
|
) {
|
|
|
|
|
//reset pageNo when serverSidePaginationEnabled is toggled
|
|
|
|
|
this.props.updateWidgetMetaProperty("pageNo", 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* When defaultSelectedRowIndex or defaultSelectedRowIndices
|
|
|
|
|
* is changed from property pane
|
|
|
|
|
*/
|
|
|
|
|
if (
|
2022-09-02 09:16:30 +00:00
|
|
|
!equal(defaultSelectedRowIndex, prevProps.defaultSelectedRowIndex) ||
|
|
|
|
|
!equal(defaultSelectedRowIndices, prevProps.defaultSelectedRowIndices)
|
2022-07-14 07:02:35 +00:00
|
|
|
) {
|
|
|
|
|
this.updateSelectedRowIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.resetPageNo(prevProps);
|
|
|
|
|
|
|
|
|
|
this.resetRowSelectionProperties(prevProps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resetPageNo = (prevProps: TableWidgetProps) => {
|
|
|
|
|
const { onPageSizeChange, pageSize } = this.props;
|
|
|
|
|
|
|
|
|
|
if (pageSize !== prevProps.pageSize) {
|
|
|
|
|
if (onPageSizeChange) {
|
|
|
|
|
this.props.updateWidgetMetaProperty("pageNo", 1, {
|
|
|
|
|
triggerPropertyName: "onPageSizeChange",
|
|
|
|
|
dynamicString: onPageSizeChange,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_PAGE_SIZE_CHANGE,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
this.props.updateWidgetMetaProperty("pageNo", 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
resetRowSelectionProperties = (prevProps: TableWidgetProps) => {
|
|
|
|
|
const {
|
|
|
|
|
defaultSelectedRowIndex,
|
|
|
|
|
defaultSelectedRowIndices,
|
|
|
|
|
multiRowSelection,
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
// reset selectedRowIndices and selectedRowIndex to defaults
|
|
|
|
|
if (multiRowSelection !== prevProps.multiRowSelection) {
|
|
|
|
|
if (multiRowSelection) {
|
|
|
|
|
if (
|
|
|
|
|
defaultSelectedRowIndices &&
|
|
|
|
|
_.isArray(defaultSelectedRowIndices) &&
|
|
|
|
|
defaultSelectedRowIndices.every((i) => _.isFinite(i))
|
|
|
|
|
) {
|
|
|
|
|
this.props.updateWidgetMetaProperty(
|
|
|
|
|
"selectedRowIndices",
|
|
|
|
|
defaultSelectedRowIndices,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.props.updateWidgetMetaProperty("selectedRowIndex", -1);
|
|
|
|
|
} else {
|
|
|
|
|
if (!isNil(defaultSelectedRowIndex) && defaultSelectedRowIndex > -1) {
|
|
|
|
|
this.props.updateWidgetMetaProperty(
|
|
|
|
|
"selectedRowIndex",
|
|
|
|
|
defaultSelectedRowIndex,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.props.updateWidgetMetaProperty("selectedRowIndices", []);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Function to update selectedRowIndices & selectedRowIndex from
|
|
|
|
|
* defaultSelectedRowIndices & defaultSelectedRowIndex respectively
|
|
|
|
|
*/
|
|
|
|
|
updateSelectedRowIndex = () => {
|
|
|
|
|
const {
|
|
|
|
|
defaultSelectedRowIndex,
|
|
|
|
|
defaultSelectedRowIndices,
|
|
|
|
|
multiRowSelection,
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
if (multiRowSelection) {
|
|
|
|
|
this.props.updateWidgetMetaProperty(
|
|
|
|
|
"selectedRowIndices",
|
|
|
|
|
defaultSelectedRowIndices,
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
this.props.updateWidgetMetaProperty(
|
|
|
|
|
"selectedRowIndex",
|
|
|
|
|
defaultSelectedRowIndex,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Function to update selectedRow details when order of tableData changes
|
|
|
|
|
*/
|
|
|
|
|
updateMetaRowData = (
|
|
|
|
|
oldTableData: Array<Record<string, unknown>>,
|
|
|
|
|
newTableData: Array<Record<string, unknown>>,
|
|
|
|
|
) => {
|
|
|
|
|
const {
|
|
|
|
|
defaultSelectedRowIndex,
|
|
|
|
|
defaultSelectedRowIndices,
|
|
|
|
|
multiRowSelection,
|
|
|
|
|
primaryColumnId,
|
|
|
|
|
selectedRowIndex,
|
|
|
|
|
selectedRowIndices,
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
if (multiRowSelection) {
|
|
|
|
|
const indices = getSelectRowIndices(
|
|
|
|
|
oldTableData,
|
|
|
|
|
newTableData,
|
|
|
|
|
defaultSelectedRowIndices,
|
|
|
|
|
selectedRowIndices,
|
|
|
|
|
primaryColumnId,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
this.props.updateWidgetMetaProperty("selectedRowIndices", indices);
|
|
|
|
|
} else {
|
|
|
|
|
const index = getSelectRowIndex(
|
|
|
|
|
oldTableData,
|
|
|
|
|
newTableData,
|
|
|
|
|
defaultSelectedRowIndex,
|
|
|
|
|
selectedRowIndex,
|
|
|
|
|
primaryColumnId,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
this.props.updateWidgetMetaProperty("selectedRowIndex", index);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getSelectedRowIndices = () => {
|
|
|
|
|
const { multiRowSelection, selectedRowIndices } = this.props;
|
|
|
|
|
|
|
|
|
|
let indices: number[] | undefined;
|
|
|
|
|
|
|
|
|
|
if (multiRowSelection) {
|
|
|
|
|
if (_.isArray(selectedRowIndices)) {
|
|
|
|
|
indices = selectedRowIndices;
|
|
|
|
|
} else if (_.isNumber(selectedRowIndices)) {
|
|
|
|
|
indices = [selectedRowIndices];
|
|
|
|
|
} else {
|
|
|
|
|
indices = [];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
indices = undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return indices;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
updateFilters = (filters: ReactTableFilter[]) => {
|
|
|
|
|
this.resetSelectedRowIndex();
|
|
|
|
|
this.props.updateWidgetMetaProperty("filters", filters);
|
|
|
|
|
|
|
|
|
|
// Reset Page only when a filter is added
|
2023-02-09 11:29:06 +00:00
|
|
|
if (!isEmpty(xorWith(filters, [DEFAULT_FILTER], equal))) {
|
2022-07-14 07:02:35 +00:00
|
|
|
this.props.updateWidgetMetaProperty("pageNo", 1);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
toggleDrag = (disable: boolean) => {
|
|
|
|
|
this.disableDrag(disable);
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-22 11:15:00 +00:00
|
|
|
getPaddingAdjustedDimensions = () => {
|
|
|
|
|
// eslint-disable-next-line prefer-const
|
|
|
|
|
let { componentHeight, componentWidth } = this.getComponentDimensions();
|
|
|
|
|
// (2 * WIDGET_PADDING) gives the total horizontal padding (i.e. paddingLeft + paddingRight)
|
|
|
|
|
componentWidth = componentWidth - 2 * WIDGET_PADDING;
|
|
|
|
|
return { componentHeight, componentWidth };
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-14 07:02:35 +00:00
|
|
|
getPageView() {
|
|
|
|
|
const {
|
|
|
|
|
totalRecordsCount,
|
|
|
|
|
delimiter,
|
|
|
|
|
pageSize,
|
|
|
|
|
filteredTableData = [],
|
|
|
|
|
isVisibleDownload,
|
|
|
|
|
isVisibleFilters,
|
|
|
|
|
isVisiblePagination,
|
|
|
|
|
isVisibleSearch,
|
|
|
|
|
} = this.props;
|
|
|
|
|
const tableColumns = this.getTableColumns() || [];
|
|
|
|
|
const transformedData = this.transformData(filteredTableData, tableColumns);
|
|
|
|
|
const isVisibleHeaderOptions =
|
|
|
|
|
isVisibleDownload ||
|
|
|
|
|
isVisibleFilters ||
|
|
|
|
|
isVisiblePagination ||
|
|
|
|
|
isVisibleSearch;
|
|
|
|
|
|
2022-09-22 11:15:00 +00:00
|
|
|
const {
|
|
|
|
|
componentHeight,
|
|
|
|
|
componentWidth,
|
|
|
|
|
} = this.getPaddingAdjustedDimensions();
|
2022-07-14 07:02:35 +00:00
|
|
|
|
2022-11-05 09:54:20 +00:00
|
|
|
if (this.props.isAddRowInProgress) {
|
|
|
|
|
transformedData.unshift(this.props.newRowContent);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-14 07:02:35 +00:00
|
|
|
return (
|
|
|
|
|
<Suspense fallback={<Skeleton />}>
|
|
|
|
|
<ReactTableComponent
|
|
|
|
|
accentColor={this.props.accentColor}
|
2022-11-05 09:54:20 +00:00
|
|
|
allowAddNewRow={this.props.allowAddNewRow}
|
|
|
|
|
allowRowSelection={!this.props.isAddRowInProgress}
|
|
|
|
|
allowSorting={!this.props.isAddRowInProgress}
|
2022-07-14 07:02:35 +00:00
|
|
|
applyFilter={this.updateFilters}
|
2022-10-14 04:53:31 +00:00
|
|
|
borderColor={this.props.borderColor}
|
2022-07-14 07:02:35 +00:00
|
|
|
borderRadius={this.props.borderRadius}
|
2022-10-14 04:53:31 +00:00
|
|
|
borderWidth={this.props.borderWidth}
|
2022-07-14 07:02:35 +00:00
|
|
|
boxShadow={this.props.boxShadow}
|
|
|
|
|
columnWidthMap={this.props.columnWidthMap}
|
|
|
|
|
columns={tableColumns}
|
|
|
|
|
compactMode={this.props.compactMode || CompactModeTypes.DEFAULT}
|
|
|
|
|
delimiter={delimiter}
|
|
|
|
|
disableDrag={this.toggleDrag}
|
2022-11-05 09:54:20 +00:00
|
|
|
disabledAddNewRowSave={this.hasInvalidColumnCell()}
|
2022-07-14 07:02:35 +00:00
|
|
|
editMode={this.props.renderMode === RenderModes.CANVAS}
|
|
|
|
|
editableCell={this.props.editableCell}
|
|
|
|
|
filters={this.props.filters}
|
|
|
|
|
handleReorderColumn={this.handleReorderColumn}
|
|
|
|
|
handleResizeColumn={this.handleResizeColumn}
|
|
|
|
|
height={componentHeight}
|
2022-11-05 09:54:20 +00:00
|
|
|
isAddRowInProgress={this.props.isAddRowInProgress}
|
|
|
|
|
isEditableCellsValid={this.props.isEditableCellsValid}
|
2022-07-14 07:02:35 +00:00
|
|
|
isLoading={this.props.isLoading}
|
|
|
|
|
isSortable={this.props.isSortable ?? true}
|
|
|
|
|
isVisibleDownload={isVisibleDownload}
|
|
|
|
|
isVisibleFilters={isVisibleFilters}
|
|
|
|
|
isVisiblePagination={isVisiblePagination}
|
|
|
|
|
isVisibleSearch={isVisibleSearch}
|
2022-11-05 09:54:20 +00:00
|
|
|
multiRowSelection={
|
|
|
|
|
this.props.multiRowSelection && !this.props.isAddRowInProgress
|
|
|
|
|
}
|
2022-07-14 07:02:35 +00:00
|
|
|
nextPageClick={this.handleNextPageClick}
|
2022-11-05 09:54:20 +00:00
|
|
|
onAddNewRow={this.handleAddNewRowClick}
|
|
|
|
|
onAddNewRowAction={this.handleAddNewRowAction}
|
2022-07-14 07:02:35 +00:00
|
|
|
onBulkEditDiscard={this.onBulkEditDiscard}
|
|
|
|
|
onBulkEditSave={this.onBulkEditSave}
|
|
|
|
|
onRowClick={this.handleRowClick}
|
|
|
|
|
pageNo={this.props.pageNo}
|
|
|
|
|
pageSize={
|
|
|
|
|
isVisibleHeaderOptions ? Math.max(1, pageSize) : pageSize + 1
|
|
|
|
|
}
|
|
|
|
|
prevPageClick={this.handlePrevPageClick}
|
2022-10-06 09:32:09 +00:00
|
|
|
primaryColumnId={this.props.primaryColumnId}
|
2022-07-14 07:02:35 +00:00
|
|
|
searchKey={this.props.searchText}
|
|
|
|
|
searchTableData={this.handleSearchTable}
|
|
|
|
|
selectAllRow={this.handleAllRowSelect}
|
|
|
|
|
selectedRowIndex={
|
|
|
|
|
this.props.selectedRowIndex === undefined
|
|
|
|
|
? -1
|
|
|
|
|
: this.props.selectedRowIndex
|
|
|
|
|
}
|
|
|
|
|
selectedRowIndices={this.getSelectedRowIndices()}
|
|
|
|
|
serverSidePaginationEnabled={!!this.props.serverSidePaginationEnabled}
|
|
|
|
|
sortTableColumn={this.handleColumnSorting}
|
|
|
|
|
tableData={transformedData}
|
|
|
|
|
totalRecordsCount={totalRecordsCount}
|
|
|
|
|
triggerRowSelection={this.props.triggerRowSelection}
|
|
|
|
|
unSelectAllRow={this.unSelectAllRow}
|
|
|
|
|
updatePageNo={this.updatePageNumber}
|
2022-10-14 04:53:31 +00:00
|
|
|
variant={this.props.variant}
|
2022-07-14 07:02:35 +00:00
|
|
|
widgetId={this.props.widgetId}
|
|
|
|
|
widgetName={this.props.widgetName}
|
|
|
|
|
width={componentWidth}
|
|
|
|
|
/>
|
|
|
|
|
</Suspense>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleReorderColumn = (columnOrder: string[]) => {
|
|
|
|
|
columnOrder = columnOrder.map((alias) => this.getColumnIdByAlias(alias));
|
|
|
|
|
|
|
|
|
|
if (this.props.renderMode === RenderModes.CANVAS) {
|
|
|
|
|
super.updateWidgetProperty("columnOrder", columnOrder);
|
|
|
|
|
} else {
|
|
|
|
|
this.props.updateWidgetMetaProperty("columnOrder", columnOrder);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
handleColumnSorting = (columnAccessor: string, isAsc: boolean) => {
|
|
|
|
|
const columnId = this.getColumnIdByAlias(columnAccessor);
|
|
|
|
|
this.resetSelectedRowIndex(false);
|
|
|
|
|
|
|
|
|
|
let sortOrderProps;
|
|
|
|
|
|
|
|
|
|
if (columnId) {
|
|
|
|
|
sortOrderProps = {
|
|
|
|
|
column: columnId,
|
|
|
|
|
order: isAsc ? SortOrderTypes.asc : SortOrderTypes.desc,
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
sortOrderProps = {
|
|
|
|
|
column: "",
|
|
|
|
|
order: null,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.props.updateWidgetMetaProperty("sortOrder", sortOrderProps, {
|
|
|
|
|
triggerPropertyName: "onSort",
|
|
|
|
|
dynamicString: this.props.onSort,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_SORT,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
handleResizeColumn = (columnWidthMap: { [key: string]: number }) => {
|
|
|
|
|
if (this.props.renderMode === RenderModes.CANVAS) {
|
|
|
|
|
super.updateWidgetProperty("columnWidthMap", columnWidthMap);
|
|
|
|
|
} else {
|
|
|
|
|
this.props.updateWidgetMetaProperty("columnWidthMap", columnWidthMap);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
handleSearchTable = (searchKey: any) => {
|
|
|
|
|
const { multiRowSelection, onSearchTextChanged } = this.props;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Clear rowSelection to avoid selecting filtered rows
|
|
|
|
|
* based on stale selection indices
|
|
|
|
|
*/
|
|
|
|
|
if (multiRowSelection) {
|
|
|
|
|
this.props.updateWidgetMetaProperty("selectedRowIndices", []);
|
|
|
|
|
} else {
|
|
|
|
|
this.props.updateWidgetMetaProperty("selectedRowIndex", -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.props.updateWidgetMetaProperty("pageNo", 1);
|
|
|
|
|
this.props.updateWidgetMetaProperty("searchText", searchKey, {
|
|
|
|
|
triggerPropertyName: "onSearchTextChanged",
|
|
|
|
|
dynamicString: onSearchTextChanged,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_SEARCH,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Function to handle customColumn button type click interactions
|
|
|
|
|
*/
|
|
|
|
|
onColumnEvent = ({
|
|
|
|
|
rowIndex,
|
|
|
|
|
action,
|
|
|
|
|
onComplete = noop,
|
|
|
|
|
triggerPropertyName,
|
|
|
|
|
eventType,
|
|
|
|
|
row,
|
2022-09-30 04:03:53 +00:00
|
|
|
additionalData = {},
|
2022-07-14 07:02:35 +00:00
|
|
|
}: OnColumnEventArgs) => {
|
|
|
|
|
const { filteredTableData = [] } = this.props;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
row = row || filteredTableData[rowIndex];
|
|
|
|
|
|
|
|
|
|
if (action) {
|
|
|
|
|
this.props.updateWidgetMetaProperty(
|
|
|
|
|
"triggeredRowIndex",
|
|
|
|
|
row?.[ORIGINAL_INDEX_KEY],
|
|
|
|
|
{
|
|
|
|
|
triggerPropertyName: triggerPropertyName,
|
|
|
|
|
dynamicString: action,
|
|
|
|
|
event: {
|
|
|
|
|
type: eventType,
|
|
|
|
|
callback: onComplete,
|
|
|
|
|
},
|
2022-09-30 04:03:53 +00:00
|
|
|
globalContext: { currentRow: row, ...additionalData },
|
2022-07-14 07:02:35 +00:00
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
onComplete();
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
log.debug("Error parsing row action", error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onDropdownOptionSelect = (action: string) => {
|
|
|
|
|
super.executeAction({
|
|
|
|
|
dynamicString: action,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_OPTION_CHANGE,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
handleAllRowSelect = (pageData: Record<string, unknown>[]) => {
|
|
|
|
|
if (this.props.multiRowSelection) {
|
|
|
|
|
const selectedRowIndices = pageData.map(
|
|
|
|
|
(row: Record<string, unknown>) => row.index,
|
|
|
|
|
);
|
|
|
|
|
this.props.updateWidgetMetaProperty(
|
|
|
|
|
"selectedRowIndices",
|
|
|
|
|
selectedRowIndices,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
handleRowClick = (row: Record<string, unknown>, selectedIndex: number) => {
|
|
|
|
|
const {
|
|
|
|
|
multiRowSelection,
|
|
|
|
|
selectedRowIndex,
|
|
|
|
|
selectedRowIndices,
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
if (multiRowSelection) {
|
|
|
|
|
let indices: Array<number>;
|
|
|
|
|
|
|
|
|
|
if (_.isArray(selectedRowIndices)) {
|
|
|
|
|
indices = [...selectedRowIndices];
|
|
|
|
|
} else {
|
|
|
|
|
indices = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Deselect if the index is already present
|
|
|
|
|
*/
|
|
|
|
|
if (indices.includes(selectedIndex)) {
|
|
|
|
|
indices.splice(indices.indexOf(selectedIndex), 1);
|
|
|
|
|
this.props.updateWidgetMetaProperty("selectedRowIndices", indices);
|
|
|
|
|
} else {
|
|
|
|
|
/*
|
|
|
|
|
* select if the index is not present already
|
|
|
|
|
*/
|
|
|
|
|
indices.push(selectedIndex);
|
|
|
|
|
|
|
|
|
|
this.props.updateWidgetMetaProperty("selectedRowIndices", indices, {
|
|
|
|
|
triggerPropertyName: "onRowSelected",
|
|
|
|
|
dynamicString: this.props.onRowSelected,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_ROW_SELECTED,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
let index;
|
|
|
|
|
|
|
|
|
|
if (isNumber(selectedRowIndex)) {
|
|
|
|
|
index = selectedRowIndex;
|
|
|
|
|
} else {
|
|
|
|
|
index = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (index !== selectedIndex) {
|
|
|
|
|
this.props.updateWidgetMetaProperty("selectedRowIndex", selectedIndex, {
|
|
|
|
|
triggerPropertyName: "onRowSelected",
|
|
|
|
|
dynamicString: this.props.onRowSelected,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_ROW_SELECTED,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
this.props.updateWidgetMetaProperty("selectedRowIndex", -1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
updatePageNumber = (pageNo: number, event?: EventType) => {
|
|
|
|
|
if (event) {
|
|
|
|
|
this.props.updateWidgetMetaProperty("pageNo", pageNo, {
|
|
|
|
|
triggerPropertyName: "onPageChange",
|
|
|
|
|
dynamicString: this.props.onPageChange,
|
|
|
|
|
event: {
|
|
|
|
|
type: event,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
this.props.updateWidgetMetaProperty("pageNo", pageNo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.props.onPageChange) {
|
|
|
|
|
this.resetSelectedRowIndex();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
handleNextPageClick = () => {
|
|
|
|
|
const pageNo = (this.props.pageNo || 1) + 1;
|
|
|
|
|
|
|
|
|
|
this.props.updateWidgetMetaProperty("pageNo", pageNo, {
|
|
|
|
|
triggerPropertyName: "onPageChange",
|
|
|
|
|
dynamicString: this.props.onPageChange,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_NEXT_PAGE,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (this.props.onPageChange) {
|
|
|
|
|
this.resetSelectedRowIndex();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
resetSelectedRowIndex = (skipDefault?: boolean) => {
|
|
|
|
|
const {
|
|
|
|
|
defaultSelectedRowIndex,
|
|
|
|
|
defaultSelectedRowIndices,
|
|
|
|
|
multiRowSelection,
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
if (multiRowSelection) {
|
|
|
|
|
this.props.updateWidgetMetaProperty(
|
|
|
|
|
"selectedRowIndices",
|
|
|
|
|
skipDefault ? [] : defaultSelectedRowIndices,
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
this.props.updateWidgetMetaProperty(
|
|
|
|
|
"selectedRowIndex",
|
|
|
|
|
skipDefault ? -1 : defaultSelectedRowIndex,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
unSelectAllRow = () => {
|
|
|
|
|
this.props.updateWidgetMetaProperty("selectedRowIndices", []);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
handlePrevPageClick = () => {
|
|
|
|
|
const pageNo = (this.props.pageNo || 1) - 1;
|
|
|
|
|
|
|
|
|
|
if (pageNo >= 1) {
|
|
|
|
|
this.props.updateWidgetMetaProperty("pageNo", pageNo, {
|
|
|
|
|
triggerPropertyName: "onPageChange",
|
|
|
|
|
dynamicString: this.props.onPageChange,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_PREV_PAGE,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (this.props.onPageChange) {
|
|
|
|
|
this.resetSelectedRowIndex();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static getWidgetType(): WidgetType {
|
|
|
|
|
return "TABLE_WIDGET_V2";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getColumnIdByAlias(alias: string) {
|
|
|
|
|
const { primaryColumns } = this.props;
|
|
|
|
|
|
|
|
|
|
if (primaryColumns) {
|
|
|
|
|
const column = Object.values(primaryColumns).find(
|
|
|
|
|
(column) => column.alias === alias,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (column) {
|
|
|
|
|
return column.id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return alias;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getColumnByOriginalId(originalId: string) {
|
|
|
|
|
return Object.values(this.props.primaryColumns).find((column) => {
|
|
|
|
|
return column.originalId === originalId;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateTransientTableData = (data: TransientDataPayload) => {
|
2022-11-05 09:54:20 +00:00
|
|
|
const { __originalIndex__, ...transientData } = data;
|
2022-07-14 07:02:35 +00:00
|
|
|
|
|
|
|
|
this.props.updateWidgetMetaProperty("transientTableData", {
|
|
|
|
|
...this.props.transientTableData,
|
2022-11-05 09:54:20 +00:00
|
|
|
[__originalIndex__]: {
|
|
|
|
|
...this.props.transientTableData[__originalIndex__],
|
2022-07-14 07:02:35 +00:00
|
|
|
...transientData,
|
|
|
|
|
},
|
|
|
|
|
});
|
2022-11-25 04:39:59 +00:00
|
|
|
|
|
|
|
|
this.props.updateWidgetMetaProperty("updatedRowIndex", __originalIndex__);
|
2022-07-14 07:02:35 +00:00
|
|
|
};
|
|
|
|
|
|
2022-11-05 09:54:20 +00:00
|
|
|
removeRowFromTransientTableData = (index: number) => {
|
2022-07-14 07:02:35 +00:00
|
|
|
const newTransientTableData = clone(this.props.transientTableData);
|
|
|
|
|
|
|
|
|
|
if (newTransientTableData) {
|
2022-11-05 09:54:20 +00:00
|
|
|
delete newTransientTableData[index];
|
2022-07-14 07:02:35 +00:00
|
|
|
|
|
|
|
|
this.props.updateWidgetMetaProperty(
|
|
|
|
|
"transientTableData",
|
|
|
|
|
newTransientTableData,
|
|
|
|
|
);
|
|
|
|
|
}
|
2022-11-25 04:39:59 +00:00
|
|
|
this.props.updateWidgetMetaProperty("updatedRowIndex", -1);
|
2022-07-14 07:02:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getRowOriginalIndex = (index: number) => {
|
|
|
|
|
const { filteredTableData } = this.props;
|
|
|
|
|
|
|
|
|
|
if (filteredTableData) {
|
|
|
|
|
const row = filteredTableData[index];
|
|
|
|
|
|
|
|
|
|
if (row) {
|
|
|
|
|
return row[ORIGINAL_INDEX_KEY];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onBulkEditSave = () => {
|
|
|
|
|
this.props.updateWidgetMetaProperty(
|
|
|
|
|
"transientTableData",
|
|
|
|
|
this.props.transientTableData,
|
|
|
|
|
{
|
|
|
|
|
triggerPropertyName: "onBulkSave",
|
|
|
|
|
dynamicString: this.props.onBulkSave,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_BULK_SAVE,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onBulkEditDiscard = () => {
|
|
|
|
|
this.props.updateWidgetMetaProperty(
|
|
|
|
|
"transientTableData",
|
|
|
|
|
{},
|
|
|
|
|
{
|
|
|
|
|
triggerPropertyName: "onBulkDiscard",
|
|
|
|
|
dynamicString: this.props.onBulkDiscard,
|
|
|
|
|
event: {
|
|
|
|
|
type: EventType.ON_BULK_DISCARD,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-30 04:03:53 +00:00
|
|
|
renderCell = (props: any) => {
|
|
|
|
|
const column =
|
|
|
|
|
this.getColumnByOriginalId(
|
|
|
|
|
props.cell.column.columnProperties.originalId,
|
|
|
|
|
) || props.cell.column.columnProperties;
|
2022-11-05 09:54:20 +00:00
|
|
|
const rowIndex = props.cell.row.index;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We don't need to render cells that don't display data (button, iconButton, etc)
|
|
|
|
|
*/
|
|
|
|
|
if (
|
|
|
|
|
this.props.isAddRowInProgress &&
|
|
|
|
|
rowIndex === 0 &&
|
|
|
|
|
ActionColumnTypes.includes(column.columnType)
|
|
|
|
|
) {
|
|
|
|
|
return <CellWrapper />;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-14 07:02:35 +00:00
|
|
|
const isHidden = !column.isVisible;
|
|
|
|
|
const {
|
|
|
|
|
filteredTableData = [],
|
|
|
|
|
multiRowSelection,
|
|
|
|
|
selectedRowIndex,
|
|
|
|
|
selectedRowIndices,
|
|
|
|
|
compactMode = CompactModeTypes.DEFAULT,
|
|
|
|
|
} = this.props;
|
2022-11-05 09:54:20 +00:00
|
|
|
let row;
|
|
|
|
|
let originalIndex: number;
|
2022-07-14 07:02:35 +00:00
|
|
|
|
2022-11-05 09:54:20 +00:00
|
|
|
/*
|
|
|
|
|
* In add new row flow, a temporary row is injected at the top of the tableData, which doesn't
|
|
|
|
|
* have original row index value. so we are using -1 as the value
|
|
|
|
|
*/
|
|
|
|
|
if (this.props.isAddRowInProgress) {
|
|
|
|
|
row = filteredTableData[rowIndex - 1];
|
|
|
|
|
originalIndex = rowIndex === 0 ? -1 : row[ORIGINAL_INDEX_KEY] ?? rowIndex;
|
|
|
|
|
} else {
|
|
|
|
|
row = filteredTableData[rowIndex];
|
|
|
|
|
originalIndex = row[ORIGINAL_INDEX_KEY] ?? rowIndex;
|
|
|
|
|
}
|
2022-07-14 07:02:35 +00:00
|
|
|
|
2022-11-05 09:54:20 +00:00
|
|
|
/*
|
|
|
|
|
* cellProperties order or size does not change when filter/sorting/grouping is applied
|
|
|
|
|
* on the data thus original index is needed to identify the column's cell property.
|
|
|
|
|
*/
|
2022-07-14 07:02:35 +00:00
|
|
|
const cellProperties = getCellProperties(column, originalIndex);
|
|
|
|
|
let isSelected = false;
|
|
|
|
|
|
|
|
|
|
if (this.props.transientTableData) {
|
2022-09-30 04:03:53 +00:00
|
|
|
cellProperties.hasUnsavedChanges =
|
2022-07-14 07:02:35 +00:00
|
|
|
this.props.transientTableData.hasOwnProperty(originalIndex) &&
|
|
|
|
|
this.props.transientTableData[originalIndex].hasOwnProperty(
|
|
|
|
|
props.cell.column.columnProperties.alias,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (multiRowSelection) {
|
|
|
|
|
isSelected =
|
|
|
|
|
_.isArray(selectedRowIndices) && selectedRowIndices.includes(rowIndex);
|
|
|
|
|
} else {
|
|
|
|
|
isSelected = selectedRowIndex === rowIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isColumnEditable =
|
|
|
|
|
column.isEditable && isColumnTypeEditable(column.columnType);
|
2022-09-16 04:34:11 +00:00
|
|
|
const alias = props.cell.column.columnProperties.alias;
|
2022-11-05 09:54:20 +00:00
|
|
|
|
|
|
|
|
const isNewRow = this.props.isAddRowInProgress && rowIndex === 0;
|
|
|
|
|
|
|
|
|
|
const isCellEditable = isColumnEditable && cellProperties.isCellEditable;
|
|
|
|
|
|
2022-09-08 11:05:59 +00:00
|
|
|
const isCellEditMode =
|
2022-11-05 09:54:20 +00:00
|
|
|
(props.cell.column.alias === this.props.editableCell?.column &&
|
|
|
|
|
rowIndex === this.props.editableCell?.index) ||
|
|
|
|
|
(isNewRow && isColumnEditable);
|
|
|
|
|
|
|
|
|
|
const shouldDisableEdit =
|
|
|
|
|
(this.props.inlineEditingSaveOption ===
|
|
|
|
|
InlineEditingSaveOptions.ROW_LEVEL &&
|
|
|
|
|
this.props.updatedRowIndices.length &&
|
|
|
|
|
this.props.updatedRowIndices.indexOf(originalIndex) === -1) ||
|
|
|
|
|
(this.hasInvalidColumnCell() && !isNewRow);
|
|
|
|
|
|
|
|
|
|
const disabledEditMessage = `Save or discard the ${
|
|
|
|
|
this.props.isAddRowInProgress ? "newly added" : "unsaved"
|
|
|
|
|
} row to start editing here`;
|
|
|
|
|
|
|
|
|
|
if (this.props.isAddRowInProgress) {
|
|
|
|
|
cellProperties.isCellDisabled = rowIndex !== 0;
|
|
|
|
|
|
|
|
|
|
if (rowIndex === 0) {
|
|
|
|
|
cellProperties.cellBackground = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-14 07:02:35 +00:00
|
|
|
|
|
|
|
|
switch (column.columnType) {
|
|
|
|
|
case ColumnTypes.BUTTON:
|
|
|
|
|
return (
|
|
|
|
|
<ButtonCell
|
|
|
|
|
allowCellWrapping={cellProperties.allowCellWrapping}
|
|
|
|
|
cellBackground={cellProperties.cellBackground}
|
|
|
|
|
columnActions={[
|
|
|
|
|
{
|
|
|
|
|
backgroundColor:
|
|
|
|
|
cellProperties.buttonColor || this.props.accentColor,
|
|
|
|
|
eventType: EventType.ON_CLICK,
|
|
|
|
|
id: column.id,
|
|
|
|
|
isVisible: true,
|
|
|
|
|
label: cellProperties.buttonLabel || DEFAULT_BUTTON_LABEL,
|
|
|
|
|
dynamicTrigger: column.onClick || "",
|
|
|
|
|
variant: cellProperties.buttonVariant,
|
|
|
|
|
borderRadius:
|
|
|
|
|
cellProperties.borderRadius || this.props.borderRadius,
|
|
|
|
|
boxShadow: cellProperties.boxShadow,
|
|
|
|
|
},
|
|
|
|
|
]}
|
|
|
|
|
compactMode={compactMode}
|
|
|
|
|
fontStyle={cellProperties.fontStyle}
|
|
|
|
|
horizontalAlignment={cellProperties.horizontalAlignment}
|
2022-11-05 09:54:20 +00:00
|
|
|
isCellDisabled={cellProperties.isCellDisabled}
|
2022-07-14 07:02:35 +00:00
|
|
|
isCellVisible={cellProperties.isCellVisible ?? true}
|
|
|
|
|
isDisabled={!!cellProperties.isDisabled}
|
|
|
|
|
isHidden={isHidden}
|
|
|
|
|
isSelected={isSelected}
|
|
|
|
|
onCommandClick={(action: string, onComplete: () => void) =>
|
|
|
|
|
this.onColumnEvent({
|
|
|
|
|
rowIndex,
|
|
|
|
|
action,
|
|
|
|
|
onComplete,
|
|
|
|
|
triggerPropertyName: "onClick",
|
|
|
|
|
eventType: EventType.ON_CLICK,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
textColor={cellProperties.textColor}
|
|
|
|
|
textSize={cellProperties.textSize}
|
|
|
|
|
verticalAlignment={cellProperties.verticalAlignment}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
case ColumnTypes.EDIT_ACTIONS:
|
|
|
|
|
return (
|
|
|
|
|
<EditActionCell
|
|
|
|
|
allowCellWrapping={cellProperties.allowCellWrapping}
|
|
|
|
|
cellBackground={cellProperties.cellBackground}
|
|
|
|
|
columnActions={[
|
|
|
|
|
{
|
|
|
|
|
id: EditableCellActions.SAVE,
|
|
|
|
|
label: cellProperties.saveActionLabel,
|
|
|
|
|
dynamicTrigger: column.onSave || "",
|
|
|
|
|
eventType: EventType.ON_ROW_SAVE,
|
|
|
|
|
iconName: cellProperties.saveActionIconName,
|
|
|
|
|
variant: cellProperties.saveButtonVariant,
|
|
|
|
|
backgroundColor:
|
|
|
|
|
cellProperties.saveButtonColor || this.props.accentColor,
|
|
|
|
|
iconAlign: cellProperties.saveIconAlign,
|
|
|
|
|
borderRadius:
|
|
|
|
|
cellProperties.saveBorderRadius || this.props.borderRadius,
|
|
|
|
|
isVisible: cellProperties.isSaveVisible,
|
2022-09-13 05:41:59 +00:00
|
|
|
isDisabled:
|
2022-11-05 09:54:20 +00:00
|
|
|
cellProperties.isSaveDisabled || this.hasInvalidColumnCell(),
|
2022-07-14 07:02:35 +00:00
|
|
|
boxShadow: cellProperties.boxShadow,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: EditableCellActions.DISCARD,
|
|
|
|
|
label: cellProperties.discardActionLabel,
|
|
|
|
|
dynamicTrigger: column.onDiscard || "",
|
|
|
|
|
eventType: EventType.ON_ROW_DISCARD,
|
|
|
|
|
iconName: cellProperties.discardActionIconName,
|
|
|
|
|
variant: cellProperties.discardButtonVariant,
|
|
|
|
|
backgroundColor:
|
|
|
|
|
cellProperties.discardButtonColor || this.props.accentColor,
|
|
|
|
|
iconAlign: cellProperties.discardIconAlign,
|
|
|
|
|
borderRadius:
|
|
|
|
|
cellProperties.discardBorderRadius || this.props.borderRadius,
|
|
|
|
|
isVisible: cellProperties.isDiscardVisible,
|
2022-09-13 05:41:59 +00:00
|
|
|
isDisabled:
|
|
|
|
|
cellProperties.isDiscardDisabled ||
|
2022-11-05 09:54:20 +00:00
|
|
|
this.hasInvalidColumnCell(),
|
2022-07-14 07:02:35 +00:00
|
|
|
boxShadow: cellProperties.boxShadow,
|
|
|
|
|
},
|
|
|
|
|
]}
|
|
|
|
|
compactMode={compactMode}
|
|
|
|
|
fontStyle={cellProperties.fontStyle}
|
|
|
|
|
horizontalAlignment={cellProperties.horizontalAlignment}
|
2022-11-05 09:54:20 +00:00
|
|
|
isCellDisabled={cellProperties.isCellDisabled}
|
|
|
|
|
isCellVisible={cellProperties.isCellVisible}
|
2022-07-14 07:02:35 +00:00
|
|
|
isHidden={isHidden}
|
|
|
|
|
isSelected={isSelected}
|
|
|
|
|
onCommandClick={(
|
|
|
|
|
action: string,
|
|
|
|
|
onComplete: () => void,
|
|
|
|
|
eventType: EventType,
|
|
|
|
|
) =>
|
|
|
|
|
this.onColumnEvent({
|
|
|
|
|
rowIndex,
|
|
|
|
|
action,
|
|
|
|
|
onComplete,
|
|
|
|
|
triggerPropertyName: "onClick",
|
|
|
|
|
eventType: eventType,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
onDiscard={() =>
|
|
|
|
|
this.removeRowFromTransientTableData(originalIndex)
|
|
|
|
|
}
|
|
|
|
|
textColor={cellProperties.textColor}
|
|
|
|
|
textSize={cellProperties.textSize}
|
|
|
|
|
verticalAlignment={cellProperties.verticalAlignment}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
2022-09-30 04:03:53 +00:00
|
|
|
case ColumnTypes.SELECT:
|
|
|
|
|
return (
|
|
|
|
|
<SelectCell
|
|
|
|
|
accentColor={this.props.accentColor}
|
|
|
|
|
alias={props.cell.column.columnProperties.alias}
|
|
|
|
|
allowCellWrapping={cellProperties.allowCellWrapping}
|
2022-11-05 09:54:20 +00:00
|
|
|
autoOpen={!this.props.isAddRowInProgress}
|
2022-09-30 04:03:53 +00:00
|
|
|
borderRadius={cellProperties.borderRadius}
|
|
|
|
|
cellBackground={cellProperties.cellBackground}
|
|
|
|
|
columnType={column.columnType}
|
|
|
|
|
compactMode={compactMode}
|
|
|
|
|
disabledEditIcon={
|
2022-11-05 09:54:20 +00:00
|
|
|
shouldDisableEdit || this.props.isAddRowInProgress
|
2022-09-30 04:03:53 +00:00
|
|
|
}
|
2022-11-05 09:54:20 +00:00
|
|
|
disabledEditIconMessage={disabledEditMessage}
|
2022-09-30 04:03:53 +00:00
|
|
|
filterText={
|
|
|
|
|
this.props.selectColumnFilterText?.[
|
|
|
|
|
this.props.editableCell?.column || column.alias
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
fontStyle={cellProperties.fontStyle}
|
|
|
|
|
hasUnsavedChanges={cellProperties.hasUnsavedChanges}
|
|
|
|
|
horizontalAlignment={cellProperties.horizontalAlignment}
|
2022-11-05 09:54:20 +00:00
|
|
|
isCellDisabled={cellProperties.isCellDisabled}
|
2022-09-30 04:03:53 +00:00
|
|
|
isCellEditMode={isCellEditMode}
|
2022-11-05 09:54:20 +00:00
|
|
|
isCellEditable={isCellEditable}
|
2022-09-30 04:03:53 +00:00
|
|
|
isCellVisible={cellProperties.isCellVisible ?? true}
|
|
|
|
|
isEditable={isColumnEditable}
|
|
|
|
|
isFilterable={cellProperties.isFilterable}
|
|
|
|
|
isHidden={isHidden}
|
2022-11-05 09:54:20 +00:00
|
|
|
isNewRow={isNewRow}
|
2022-09-30 04:03:53 +00:00
|
|
|
key={props.key}
|
|
|
|
|
onFilterChange={this.onSelectFilterChange}
|
|
|
|
|
onFilterChangeActionString={column.onFilterUpdate}
|
|
|
|
|
onItemSelect={this.onOptionSelect}
|
|
|
|
|
onOptionSelectActionString={column.onOptionChange}
|
2022-12-16 04:35:51 +00:00
|
|
|
options={cellProperties.selectOptions}
|
2022-09-30 04:03:53 +00:00
|
|
|
placeholderText={cellProperties.placeholderText}
|
|
|
|
|
resetFilterTextOnClose={cellProperties.resetFilterTextOnClose}
|
|
|
|
|
rowIndex={rowIndex}
|
|
|
|
|
serverSideFiltering={cellProperties.serverSideFiltering}
|
|
|
|
|
tableWidth={this.getComponentDimensions().componentWidth}
|
|
|
|
|
textColor={cellProperties.textColor}
|
|
|
|
|
textSize={cellProperties.textSize}
|
|
|
|
|
toggleCellEditMode={this.toggleCellEditMode}
|
|
|
|
|
value={props.cell.value}
|
|
|
|
|
verticalAlignment={cellProperties.verticalAlignment}
|
|
|
|
|
width={
|
|
|
|
|
this.props.columnWidthMap?.[column.id] || DEFAULT_COLUMN_WIDTH
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2022-07-14 07:02:35 +00:00
|
|
|
|
|
|
|
|
case ColumnTypes.IMAGE:
|
|
|
|
|
const onClick = column.onClick
|
|
|
|
|
? () =>
|
|
|
|
|
this.onColumnEvent({
|
|
|
|
|
rowIndex,
|
|
|
|
|
action: column.onClick,
|
|
|
|
|
triggerPropertyName: "onClick",
|
|
|
|
|
eventType: EventType.ON_CLICK,
|
|
|
|
|
})
|
|
|
|
|
: noop;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ImageCell
|
|
|
|
|
allowCellWrapping={cellProperties.allowCellWrapping}
|
|
|
|
|
cellBackground={cellProperties.cellBackground}
|
|
|
|
|
compactMode={compactMode}
|
|
|
|
|
fontStyle={cellProperties.fontStyle}
|
|
|
|
|
horizontalAlignment={cellProperties.horizontalAlignment}
|
2022-10-14 12:21:54 +00:00
|
|
|
imageSize={cellProperties.imageSize}
|
2022-11-05 09:54:20 +00:00
|
|
|
isCellDisabled={cellProperties.isCellDisabled}
|
2022-07-14 07:02:35 +00:00
|
|
|
isCellVisible={cellProperties.isCellVisible ?? true}
|
|
|
|
|
isHidden={isHidden}
|
|
|
|
|
isSelected={isSelected}
|
|
|
|
|
onClick={onClick}
|
|
|
|
|
textColor={cellProperties.textColor}
|
|
|
|
|
textSize={cellProperties.textSize}
|
|
|
|
|
value={props.cell.value}
|
|
|
|
|
verticalAlignment={cellProperties.verticalAlignment}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
case ColumnTypes.MENU_BUTTON:
|
2022-12-30 10:52:11 +00:00
|
|
|
const getVisibleItems = (rowIndex: number) => {
|
|
|
|
|
const {
|
|
|
|
|
configureMenuItems,
|
|
|
|
|
menuItems,
|
|
|
|
|
menuItemsSource,
|
|
|
|
|
sourceData,
|
|
|
|
|
} = cellProperties;
|
|
|
|
|
|
|
|
|
|
if (menuItemsSource === MenuItemsSource.STATIC && menuItems) {
|
|
|
|
|
const visibleItems = Object.values(menuItems)?.filter((item) =>
|
|
|
|
|
getBooleanPropertyValue(item.isVisible, rowIndex),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return visibleItems?.length
|
|
|
|
|
? orderBy(visibleItems, ["index"], ["asc"])
|
|
|
|
|
: [];
|
|
|
|
|
} else if (
|
|
|
|
|
menuItemsSource === MenuItemsSource.DYNAMIC &&
|
|
|
|
|
isArray(sourceData) &&
|
|
|
|
|
sourceData?.length &&
|
|
|
|
|
configureMenuItems?.config
|
|
|
|
|
) {
|
|
|
|
|
const { config } = configureMenuItems;
|
|
|
|
|
|
|
|
|
|
const getValue = (
|
|
|
|
|
propertyName: keyof MenuItem,
|
|
|
|
|
index: number,
|
|
|
|
|
rowIndex: number,
|
|
|
|
|
) => {
|
|
|
|
|
const value = config[propertyName];
|
|
|
|
|
|
|
|
|
|
if (isArray(value) && isArray(value[rowIndex])) {
|
|
|
|
|
return value[rowIndex][index];
|
|
|
|
|
} else if (isArray(value)) {
|
|
|
|
|
return value[index];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value ?? null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const visibleItems = sourceData
|
|
|
|
|
.map((item, index) => ({
|
|
|
|
|
...item,
|
|
|
|
|
id: index.toString(),
|
|
|
|
|
isVisible: getValue("isVisible", index, rowIndex),
|
|
|
|
|
isDisabled: getValue("isDisabled", index, rowIndex),
|
|
|
|
|
index: index,
|
|
|
|
|
widgetId: "",
|
|
|
|
|
label: getValue("label", index, rowIndex),
|
|
|
|
|
onClick: config?.onClick,
|
|
|
|
|
textColor: getValue("textColor", index, rowIndex),
|
|
|
|
|
backgroundColor: getValue("backgroundColor", index, rowIndex),
|
|
|
|
|
iconAlign: getValue("iconAlign", index, rowIndex),
|
|
|
|
|
iconColor: getValue("iconColor", index, rowIndex),
|
|
|
|
|
iconName: getValue("iconName", index, rowIndex),
|
|
|
|
|
}))
|
|
|
|
|
.filter((item) => item.isVisible === true);
|
|
|
|
|
|
|
|
|
|
return visibleItems;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [];
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-14 07:02:35 +00:00
|
|
|
return (
|
|
|
|
|
<MenuButtonCell
|
|
|
|
|
allowCellWrapping={cellProperties.allowCellWrapping}
|
|
|
|
|
borderRadius={
|
|
|
|
|
cellProperties.borderRadius || this.props.borderRadius
|
|
|
|
|
}
|
|
|
|
|
boxShadow={cellProperties.boxShadow}
|
|
|
|
|
cellBackground={cellProperties.cellBackground}
|
|
|
|
|
compactMode={compactMode}
|
2022-12-30 10:52:11 +00:00
|
|
|
configureMenuItems={cellProperties.configureMenuItems}
|
2022-07-14 07:02:35 +00:00
|
|
|
fontStyle={cellProperties.fontStyle}
|
2022-12-30 10:52:11 +00:00
|
|
|
getVisibleItems={getVisibleItems}
|
2022-07-14 07:02:35 +00:00
|
|
|
horizontalAlignment={cellProperties.horizontalAlignment}
|
|
|
|
|
iconAlign={cellProperties.iconAlign}
|
|
|
|
|
iconName={cellProperties.menuButtoniconName || undefined}
|
2022-11-05 09:54:20 +00:00
|
|
|
isCellDisabled={cellProperties.isCellDisabled}
|
2022-07-14 07:02:35 +00:00
|
|
|
isCellVisible={cellProperties.isCellVisible ?? true}
|
|
|
|
|
isCompact={!!cellProperties.isCompact}
|
|
|
|
|
isDisabled={!!cellProperties.isDisabled}
|
|
|
|
|
isHidden={isHidden}
|
|
|
|
|
isSelected={isSelected}
|
|
|
|
|
label={cellProperties.menuButtonLabel ?? DEFAULT_MENU_BUTTON_LABEL}
|
|
|
|
|
menuColor={
|
|
|
|
|
cellProperties.menuColor || this.props.accentColor || Colors.GREEN
|
|
|
|
|
}
|
|
|
|
|
menuItems={cellProperties.menuItems}
|
2022-12-30 10:52:11 +00:00
|
|
|
menuItemsSource={cellProperties.menuItemsSource}
|
2022-07-14 07:02:35 +00:00
|
|
|
menuVariant={cellProperties.menuVariant ?? DEFAULT_MENU_VARIANT}
|
2022-12-30 10:52:11 +00:00
|
|
|
onCommandClick={(
|
|
|
|
|
action: string,
|
|
|
|
|
index?: number,
|
|
|
|
|
onComplete?: () => void,
|
|
|
|
|
) => {
|
|
|
|
|
const additionalData: Record<
|
|
|
|
|
string,
|
|
|
|
|
string | number | Record<string, unknown>
|
|
|
|
|
> = {};
|
|
|
|
|
|
|
|
|
|
if (cellProperties?.sourceData && _.isNumber(index)) {
|
|
|
|
|
additionalData.currentItem = cellProperties.sourceData[index];
|
|
|
|
|
additionalData.currentIndex = index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this.onColumnEvent({
|
2022-07-14 07:02:35 +00:00
|
|
|
rowIndex,
|
|
|
|
|
action,
|
|
|
|
|
onComplete,
|
|
|
|
|
triggerPropertyName: "onClick",
|
|
|
|
|
eventType: EventType.ON_CLICK,
|
2022-12-30 10:52:11 +00:00
|
|
|
additionalData,
|
|
|
|
|
});
|
|
|
|
|
}}
|
2022-08-01 05:01:34 +00:00
|
|
|
rowIndex={originalIndex}
|
2022-12-30 10:52:11 +00:00
|
|
|
sourceData={cellProperties.sourceData}
|
2022-07-14 07:02:35 +00:00
|
|
|
textColor={cellProperties.textColor}
|
|
|
|
|
textSize={cellProperties.textSize}
|
|
|
|
|
verticalAlignment={cellProperties.verticalAlignment}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
case ColumnTypes.ICON_BUTTON:
|
|
|
|
|
return (
|
|
|
|
|
<IconButtonCell
|
|
|
|
|
allowCellWrapping={cellProperties.allowCellWrapping}
|
|
|
|
|
borderRadius={
|
|
|
|
|
cellProperties.borderRadius || this.props.borderRadius
|
|
|
|
|
}
|
|
|
|
|
boxShadow={cellProperties.boxShadow || "NONE"}
|
|
|
|
|
buttonColor={
|
|
|
|
|
cellProperties.buttonColor ||
|
|
|
|
|
this.props.accentColor ||
|
|
|
|
|
Colors.GREEN
|
|
|
|
|
}
|
|
|
|
|
buttonVariant={cellProperties.buttonVariant || "PRIMARY"}
|
|
|
|
|
cellBackground={cellProperties.cellBackground}
|
|
|
|
|
columnActions={[
|
|
|
|
|
{
|
|
|
|
|
id: column.id,
|
|
|
|
|
dynamicTrigger: column.onClick || "",
|
|
|
|
|
},
|
|
|
|
|
]}
|
|
|
|
|
compactMode={compactMode}
|
|
|
|
|
disabled={!!cellProperties.isDisabled}
|
|
|
|
|
fontStyle={cellProperties.fontStyle}
|
|
|
|
|
horizontalAlignment={cellProperties.horizontalAlignment}
|
|
|
|
|
iconName={(cellProperties.iconName || IconNames.ADD) as IconName}
|
2022-11-05 09:54:20 +00:00
|
|
|
isCellDisabled={cellProperties.isCellDisabled}
|
2022-07-14 07:02:35 +00:00
|
|
|
isCellVisible={cellProperties.isCellVisible ?? true}
|
|
|
|
|
isHidden={isHidden}
|
|
|
|
|
isSelected={isSelected}
|
|
|
|
|
onCommandClick={(action: string, onComplete: () => void) =>
|
|
|
|
|
this.onColumnEvent({
|
|
|
|
|
rowIndex,
|
|
|
|
|
action,
|
|
|
|
|
onComplete,
|
|
|
|
|
triggerPropertyName: "onClick",
|
|
|
|
|
eventType: EventType.ON_CLICK,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
textColor={cellProperties.textColor}
|
|
|
|
|
textSize={cellProperties.textSize}
|
|
|
|
|
verticalAlignment={cellProperties.verticalAlignment}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
case ColumnTypes.VIDEO:
|
|
|
|
|
return (
|
|
|
|
|
<VideoCell
|
|
|
|
|
allowCellWrapping={cellProperties.allowCellWrapping}
|
|
|
|
|
cellBackground={cellProperties.cellBackground}
|
|
|
|
|
compactMode={compactMode}
|
|
|
|
|
fontStyle={cellProperties.fontStyle}
|
|
|
|
|
horizontalAlignment={cellProperties.horizontalAlignment}
|
2022-11-05 09:54:20 +00:00
|
|
|
isCellDisabled={cellProperties.isCellDisabled}
|
2022-07-14 07:02:35 +00:00
|
|
|
isCellVisible={cellProperties.isCellVisible ?? true}
|
|
|
|
|
isHidden={isHidden}
|
|
|
|
|
textColor={cellProperties.textColor}
|
|
|
|
|
textSize={cellProperties.textSize}
|
|
|
|
|
value={props.cell.value}
|
|
|
|
|
verticalAlignment={cellProperties.verticalAlignment}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
2022-09-08 11:05:59 +00:00
|
|
|
case ColumnTypes.CHECKBOX:
|
|
|
|
|
return (
|
|
|
|
|
<CheckboxCell
|
|
|
|
|
accentColor={this.props.accentColor}
|
|
|
|
|
borderRadius={
|
|
|
|
|
cellProperties.borderRadius || this.props.borderRadius
|
|
|
|
|
}
|
|
|
|
|
cellBackground={cellProperties.cellBackground}
|
|
|
|
|
compactMode={compactMode}
|
|
|
|
|
disabledCheckbox={
|
2022-11-05 09:54:20 +00:00
|
|
|
shouldDisableEdit || (this.props.isAddRowInProgress && !isNewRow)
|
2022-09-08 11:05:59 +00:00
|
|
|
}
|
2022-11-05 09:54:20 +00:00
|
|
|
disabledCheckboxMessage={disabledEditMessage}
|
2022-09-30 04:03:53 +00:00
|
|
|
hasUnSavedChanges={cellProperties.hasUnsavedChanges}
|
2022-09-08 11:05:59 +00:00
|
|
|
horizontalAlignment={cellProperties.horizontalAlignment}
|
2022-11-05 09:54:20 +00:00
|
|
|
isCellDisabled={cellProperties.isCellDisabled}
|
|
|
|
|
isCellEditable={isCellEditable}
|
2022-09-08 11:05:59 +00:00
|
|
|
isCellVisible={cellProperties.isCellVisible ?? true}
|
|
|
|
|
isHidden={isHidden}
|
2022-11-05 09:54:20 +00:00
|
|
|
onChange={() =>
|
|
|
|
|
this.onCheckChange(
|
|
|
|
|
column,
|
|
|
|
|
props.cell.row.values,
|
|
|
|
|
!props.cell.value,
|
|
|
|
|
alias,
|
|
|
|
|
originalIndex,
|
2022-09-16 04:34:11 +00:00
|
|
|
rowIndex,
|
2022-11-05 09:54:20 +00:00
|
|
|
)
|
|
|
|
|
}
|
2022-09-16 04:34:11 +00:00
|
|
|
value={props.cell.value}
|
|
|
|
|
verticalAlignment={cellProperties.verticalAlignment}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
case ColumnTypes.SWITCH:
|
|
|
|
|
return (
|
|
|
|
|
<SwitchCell
|
|
|
|
|
accentColor={this.props.accentColor}
|
|
|
|
|
cellBackground={cellProperties.cellBackground}
|
|
|
|
|
compactMode={compactMode}
|
|
|
|
|
disabledSwitch={
|
2022-11-05 09:54:20 +00:00
|
|
|
shouldDisableEdit || (this.props.isAddRowInProgress && !isNewRow)
|
2022-09-16 04:34:11 +00:00
|
|
|
}
|
2022-11-05 09:54:20 +00:00
|
|
|
disabledSwitchMessage={disabledEditMessage}
|
2022-09-30 04:03:53 +00:00
|
|
|
hasUnSavedChanges={cellProperties.hasUnsavedChanges}
|
2022-09-16 04:34:11 +00:00
|
|
|
horizontalAlignment={cellProperties.horizontalAlignment}
|
2022-11-05 09:54:20 +00:00
|
|
|
isCellDisabled={cellProperties.isCellDisabled}
|
|
|
|
|
isCellEditable={isCellEditable}
|
2022-09-16 04:34:11 +00:00
|
|
|
isCellVisible={cellProperties.isCellVisible ?? true}
|
|
|
|
|
isHidden={isHidden}
|
2022-11-05 09:54:20 +00:00
|
|
|
onChange={() =>
|
|
|
|
|
this.onCheckChange(
|
|
|
|
|
column,
|
|
|
|
|
props.cell.row.values,
|
|
|
|
|
!props.cell.value,
|
|
|
|
|
alias,
|
|
|
|
|
originalIndex,
|
2022-09-08 11:05:59 +00:00
|
|
|
rowIndex,
|
2022-11-05 09:54:20 +00:00
|
|
|
)
|
|
|
|
|
}
|
2022-09-08 11:05:59 +00:00
|
|
|
value={props.cell.value}
|
|
|
|
|
verticalAlignment={cellProperties.verticalAlignment}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
2023-01-16 09:23:56 +00:00
|
|
|
case ColumnTypes.DATE:
|
|
|
|
|
return (
|
|
|
|
|
<DateCell
|
|
|
|
|
accentColor={this.props.accentColor}
|
|
|
|
|
alias={props.cell.column.columnProperties.alias}
|
|
|
|
|
borderRadius={this.props.borderRadius}
|
|
|
|
|
cellBackground={cellProperties.cellBackground}
|
|
|
|
|
closeOnSelection
|
|
|
|
|
columnType={column.columnType}
|
|
|
|
|
compactMode={compactMode}
|
|
|
|
|
disabledEditIcon={
|
|
|
|
|
shouldDisableEdit || this.props.isAddRowInProgress
|
|
|
|
|
}
|
|
|
|
|
disabledEditIconMessage={disabledEditMessage}
|
|
|
|
|
firstDayOfWeek={props.cell.column.columnProperties.firstDayOfWeek}
|
|
|
|
|
fontStyle={cellProperties.fontStyle}
|
|
|
|
|
hasUnsavedChanges={cellProperties.hasUnsavedChanges}
|
|
|
|
|
horizontalAlignment={cellProperties.horizontalAlignment}
|
|
|
|
|
inputFormat={cellProperties.inputFormat}
|
|
|
|
|
isCellDisabled={cellProperties.isCellDisabled}
|
|
|
|
|
isCellEditMode={isCellEditMode}
|
|
|
|
|
isCellEditable={isCellEditable}
|
|
|
|
|
isCellVisible={cellProperties.isCellVisible ?? true}
|
|
|
|
|
isEditableCellValid={this.isColumnCellValid(alias)}
|
|
|
|
|
isHidden={isHidden}
|
|
|
|
|
isNewRow={isNewRow}
|
|
|
|
|
isRequired={
|
|
|
|
|
props.cell.column.columnProperties.validation
|
|
|
|
|
.isColumnEditableCellRequired
|
|
|
|
|
}
|
|
|
|
|
maxDate={props.cell.column.columnProperties.validation.maxDate}
|
|
|
|
|
minDate={props.cell.column.columnProperties.validation.minDate}
|
|
|
|
|
onCellTextChange={this.onCellTextChange}
|
|
|
|
|
onDateSave={this.onDateSave}
|
|
|
|
|
onDateSelectedString={
|
|
|
|
|
props.cell.column.columnProperties.onDateSelected
|
|
|
|
|
}
|
|
|
|
|
outputFormat={cellProperties.outputFormat}
|
|
|
|
|
rowIndex={rowIndex}
|
|
|
|
|
shortcuts={cellProperties.shortcuts}
|
|
|
|
|
tableWidth={this.getComponentDimensions().componentWidth}
|
|
|
|
|
textColor={cellProperties.textColor}
|
|
|
|
|
textSize={cellProperties.textSize}
|
|
|
|
|
timePrecision={cellProperties.timePrecision || TimePrecision.NONE}
|
|
|
|
|
toggleCellEditMode={this.toggleCellEditMode}
|
|
|
|
|
updateNewRowValues={this.updateNewRowValues}
|
|
|
|
|
validationErrorMessage="This field is required"
|
|
|
|
|
value={props.cell.value}
|
|
|
|
|
verticalAlignment={cellProperties.verticalAlignment}
|
|
|
|
|
widgetId={this.props.widgetId}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
2022-07-14 07:02:35 +00:00
|
|
|
default:
|
2022-09-13 05:41:59 +00:00
|
|
|
let validationErrorMessage;
|
|
|
|
|
|
|
|
|
|
if (isCellEditMode) {
|
|
|
|
|
validationErrorMessage =
|
|
|
|
|
column.validation.isColumnEditableCellRequired &&
|
2022-11-05 09:54:20 +00:00
|
|
|
(isNil(props.cell.value) || props.cell.value === "")
|
2022-09-13 05:41:59 +00:00
|
|
|
? "This field is required"
|
|
|
|
|
: column.validation?.errorMessage;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-14 07:02:35 +00:00
|
|
|
return (
|
2022-09-30 04:03:53 +00:00
|
|
|
<PlainTextCell
|
2022-07-14 07:02:35 +00:00
|
|
|
accentColor={this.props.accentColor}
|
|
|
|
|
alias={props.cell.column.columnProperties.alias}
|
|
|
|
|
allowCellWrapping={cellProperties.allowCellWrapping}
|
|
|
|
|
cellBackground={cellProperties.cellBackground}
|
|
|
|
|
columnType={column.columnType}
|
|
|
|
|
compactMode={compactMode}
|
2022-11-05 09:54:20 +00:00
|
|
|
disabledEditIcon={
|
|
|
|
|
shouldDisableEdit || this.props.isAddRowInProgress
|
|
|
|
|
}
|
|
|
|
|
disabledEditIconMessage={disabledEditMessage}
|
2022-07-14 07:02:35 +00:00
|
|
|
displayText={cellProperties.displayText}
|
|
|
|
|
fontStyle={cellProperties.fontStyle}
|
2022-09-30 04:03:53 +00:00
|
|
|
hasUnsavedChanges={cellProperties.hasUnsavedChanges}
|
2022-07-14 07:02:35 +00:00
|
|
|
horizontalAlignment={cellProperties.horizontalAlignment}
|
2022-11-05 09:54:20 +00:00
|
|
|
isCellDisabled={cellProperties.isCellDisabled}
|
2022-07-14 07:02:35 +00:00
|
|
|
isCellEditMode={isCellEditMode}
|
2022-11-05 09:54:20 +00:00
|
|
|
isCellEditable={isCellEditable}
|
2022-07-14 07:02:35 +00:00
|
|
|
isCellVisible={cellProperties.isCellVisible ?? true}
|
2022-11-05 09:54:20 +00:00
|
|
|
isEditableCellValid={this.isColumnCellValid(alias)}
|
2022-07-14 07:02:35 +00:00
|
|
|
isHidden={isHidden}
|
2022-11-05 09:54:20 +00:00
|
|
|
isNewRow={isNewRow}
|
|
|
|
|
onCellTextChange={this.onCellTextChange}
|
2022-07-14 07:02:35 +00:00
|
|
|
onSubmitString={props.cell.column.columnProperties.onSubmit}
|
|
|
|
|
rowIndex={rowIndex}
|
2022-09-30 04:03:53 +00:00
|
|
|
tableWidth={this.getComponentDimensions().componentWidth}
|
2022-07-14 07:02:35 +00:00
|
|
|
textColor={cellProperties.textColor}
|
|
|
|
|
textSize={cellProperties.textSize}
|
|
|
|
|
toggleCellEditMode={this.toggleCellEditMode}
|
2022-09-13 05:41:59 +00:00
|
|
|
validationErrorMessage={validationErrorMessage}
|
2022-07-14 07:02:35 +00:00
|
|
|
value={props.cell.value}
|
|
|
|
|
verticalAlignment={cellProperties.verticalAlignment}
|
2022-09-13 05:41:59 +00:00
|
|
|
widgetId={this.props.widgetId}
|
2022-07-14 07:02:35 +00:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-11-05 09:54:20 +00:00
|
|
|
onCellTextChange = (
|
2022-09-13 05:41:59 +00:00
|
|
|
value: EditableCell["value"],
|
|
|
|
|
inputValue: string,
|
2022-11-05 09:54:20 +00:00
|
|
|
alias: string,
|
2022-09-13 05:41:59 +00:00
|
|
|
) => {
|
2022-11-05 09:54:20 +00:00
|
|
|
if (this.props.isAddRowInProgress) {
|
|
|
|
|
this.updateNewRowValues(alias, inputValue, value);
|
|
|
|
|
} else {
|
|
|
|
|
this.props.updateWidgetMetaProperty("editableCell", {
|
|
|
|
|
...this.props.editableCell,
|
|
|
|
|
value: value,
|
|
|
|
|
inputValue,
|
2022-09-30 04:03:53 +00:00
|
|
|
});
|
2022-11-05 09:54:20 +00:00
|
|
|
|
|
|
|
|
if (this.props.editableCell?.column) {
|
|
|
|
|
this.props.updateWidgetMetaProperty("columnEditableCellValue", {
|
|
|
|
|
...this.props.columnEditableCellValue,
|
|
|
|
|
[this.props.editableCell?.column]: value,
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-09-30 04:03:53 +00:00
|
|
|
}
|
2022-07-14 07:02:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
toggleCellEditMode = (
|
|
|
|
|
enable: boolean,
|
|
|
|
|
rowIndex: number,
|
|
|
|
|
alias: string,
|
|
|
|
|
value: string | number,
|
2022-09-30 04:03:53 +00:00
|
|
|
onSubmit?: string,
|
|
|
|
|
action?: EditableCellActions,
|
2022-07-14 07:02:35 +00:00
|
|
|
) => {
|
2022-11-05 09:54:20 +00:00
|
|
|
if (this.props.isAddRowInProgress) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-14 07:02:35 +00:00
|
|
|
if (enable) {
|
2022-09-13 05:41:59 +00:00
|
|
|
if (this.inlineEditTimer) {
|
|
|
|
|
clearTimeout(this.inlineEditTimer);
|
2022-07-14 07:02:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.props.updateWidgetMetaProperty("editableCell", {
|
|
|
|
|
column: alias,
|
|
|
|
|
index: rowIndex,
|
|
|
|
|
value: value,
|
|
|
|
|
// To revert back to previous on discard
|
|
|
|
|
initialValue: value,
|
2022-09-13 05:41:59 +00:00
|
|
|
inputValue: value,
|
|
|
|
|
});
|
|
|
|
|
this.props.updateWidgetMetaProperty("columnEditableCellValue", {
|
|
|
|
|
...this.props.columnEditableCellValue,
|
|
|
|
|
[alias]: value,
|
2022-07-14 07:02:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We need to clear the selectedRowIndex and selectedRowIndices
|
|
|
|
|
* if the rows are sorted, to avoid selectedRow jumping to
|
|
|
|
|
* different page.
|
|
|
|
|
*/
|
|
|
|
|
if (this.props.sortOrder.column) {
|
|
|
|
|
if (this.props.multiRowSelection) {
|
|
|
|
|
this.props.updateWidgetMetaProperty("selectedRowIndices", []);
|
|
|
|
|
} else {
|
|
|
|
|
this.props.updateWidgetMetaProperty("selectedRowIndex", -1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (
|
2022-11-05 09:54:20 +00:00
|
|
|
this.isColumnCellValid(alias) &&
|
2022-07-14 07:02:35 +00:00
|
|
|
action === EditableCellActions.SAVE &&
|
2022-09-15 07:47:15 +00:00
|
|
|
value !== this.props.editableCell?.initialValue
|
2022-07-14 07:02:35 +00:00
|
|
|
) {
|
|
|
|
|
this.updateTransientTableData({
|
2022-11-05 09:54:20 +00:00
|
|
|
[ORIGINAL_INDEX_KEY]: this.getRowOriginalIndex(rowIndex),
|
2022-09-15 07:47:15 +00:00
|
|
|
[alias]: this.props.editableCell?.value,
|
2022-07-14 07:02:35 +00:00
|
|
|
});
|
|
|
|
|
|
2022-09-30 04:03:53 +00:00
|
|
|
if (onSubmit && this.props.editableCell?.column) {
|
2022-07-14 07:02:35 +00:00
|
|
|
this.onColumnEvent({
|
|
|
|
|
rowIndex: rowIndex,
|
|
|
|
|
action: onSubmit,
|
|
|
|
|
triggerPropertyName: "onSubmit",
|
|
|
|
|
eventType: EventType.ON_SUBMIT,
|
|
|
|
|
row: {
|
|
|
|
|
...this.props.filteredTableData[rowIndex],
|
2022-09-30 04:03:53 +00:00
|
|
|
[this.props.editableCell.column]: this.props.editableCell.value,
|
2022-07-14 07:02:35 +00:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-09-13 05:41:59 +00:00
|
|
|
|
|
|
|
|
this.clearEditableCell();
|
|
|
|
|
} else if (
|
|
|
|
|
action === EditableCellActions.DISCARD ||
|
2022-09-15 07:47:15 +00:00
|
|
|
value === this.props.editableCell?.initialValue
|
2022-09-13 05:41:59 +00:00
|
|
|
) {
|
|
|
|
|
this.clearEditableCell();
|
2022-07-14 07:02:35 +00:00
|
|
|
}
|
2022-09-13 05:41:59 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-16 09:23:56 +00:00
|
|
|
onDateSave = (
|
|
|
|
|
rowIndex: number,
|
|
|
|
|
alias: string,
|
|
|
|
|
value: string,
|
|
|
|
|
onSubmit?: string,
|
|
|
|
|
) => {
|
|
|
|
|
if (this.isColumnCellValid(alias)) {
|
|
|
|
|
this.updateTransientTableData({
|
|
|
|
|
[ORIGINAL_INDEX_KEY]: this.getRowOriginalIndex(rowIndex),
|
|
|
|
|
[alias]: value,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (onSubmit && this.props.editableCell?.column) {
|
|
|
|
|
this.onColumnEvent({
|
|
|
|
|
rowIndex: rowIndex,
|
|
|
|
|
action: onSubmit,
|
|
|
|
|
triggerPropertyName: "onSubmit",
|
|
|
|
|
eventType: EventType.ON_SUBMIT,
|
|
|
|
|
row: {
|
|
|
|
|
...this.props.filteredTableData[rowIndex],
|
|
|
|
|
[this.props.editableCell.column]: value,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.clearEditableCell();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-13 05:41:59 +00:00
|
|
|
clearEditableCell = (skipTimeout?: boolean) => {
|
|
|
|
|
const clear = () => {
|
|
|
|
|
this.props.updateWidgetMetaProperty("editableCell", defaultEditableCell);
|
|
|
|
|
this.props.updateWidgetMetaProperty("columnEditableCellValue", {});
|
|
|
|
|
};
|
2022-07-14 07:02:35 +00:00
|
|
|
|
2022-09-13 05:41:59 +00:00
|
|
|
if (skipTimeout) {
|
|
|
|
|
clear();
|
|
|
|
|
} else {
|
2022-07-14 07:02:35 +00:00
|
|
|
/*
|
|
|
|
|
* We need to let the evaulations compute derived property (filteredTableData)
|
|
|
|
|
* before we clear the editableCell to avoid the text flickering
|
|
|
|
|
*/
|
2023-01-13 11:05:59 +00:00
|
|
|
// @ts-expect-error: setTimeout return type mismatch
|
2022-09-13 05:41:59 +00:00
|
|
|
this.inlineEditTimer = setTimeout(clear, 100);
|
2022-07-14 07:02:35 +00:00
|
|
|
}
|
|
|
|
|
};
|
2022-09-13 05:41:59 +00:00
|
|
|
|
|
|
|
|
isColumnCellEditable = (column: ColumnProperties, rowIndex: number) => {
|
|
|
|
|
return (
|
2022-09-15 07:47:15 +00:00
|
|
|
column.alias === this.props.editableCell?.column &&
|
|
|
|
|
rowIndex === this.props.editableCell?.index
|
2022-09-13 05:41:59 +00:00
|
|
|
);
|
|
|
|
|
};
|
2022-09-30 04:03:53 +00:00
|
|
|
|
|
|
|
|
onOptionSelect = (
|
2022-10-04 10:45:33 +00:00
|
|
|
value: string | number,
|
2022-09-30 04:03:53 +00:00
|
|
|
rowIndex: number,
|
|
|
|
|
column: string,
|
|
|
|
|
action?: string,
|
|
|
|
|
) => {
|
2022-11-05 09:54:20 +00:00
|
|
|
if (this.props.isAddRowInProgress) {
|
|
|
|
|
this.updateNewRowValues(column, value, value);
|
|
|
|
|
} else {
|
|
|
|
|
this.updateTransientTableData({
|
|
|
|
|
[ORIGINAL_INDEX_KEY]: this.getRowOriginalIndex(rowIndex),
|
|
|
|
|
[column]: value,
|
|
|
|
|
});
|
2022-09-30 04:03:53 +00:00
|
|
|
|
2022-11-05 09:54:20 +00:00
|
|
|
this.props.updateWidgetMetaProperty("editableCell", defaultEditableCell);
|
2022-09-30 04:03:53 +00:00
|
|
|
|
2022-11-05 09:54:20 +00:00
|
|
|
if (action && this.props.editableCell?.column) {
|
|
|
|
|
this.onColumnEvent({
|
|
|
|
|
rowIndex,
|
|
|
|
|
action: action,
|
|
|
|
|
triggerPropertyName: "onOptionChange",
|
|
|
|
|
eventType: EventType.ON_OPTION_CHANGE,
|
|
|
|
|
row: {
|
|
|
|
|
...this.props.filteredTableData[rowIndex],
|
|
|
|
|
[this.props.editableCell.column]: value,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-09-30 04:03:53 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onSelectFilterChange = (
|
|
|
|
|
text: string,
|
|
|
|
|
rowIndex: number,
|
|
|
|
|
serverSideFiltering: boolean,
|
|
|
|
|
alias: string,
|
|
|
|
|
action?: string,
|
|
|
|
|
) => {
|
|
|
|
|
this.props.updateWidgetMetaProperty("selectColumnFilterText", {
|
|
|
|
|
...this.props.selectColumnFilterText,
|
|
|
|
|
[alias]: text,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (action && serverSideFiltering) {
|
|
|
|
|
this.onColumnEvent({
|
|
|
|
|
rowIndex,
|
|
|
|
|
action: action,
|
|
|
|
|
triggerPropertyName: "onFilterUpdate",
|
|
|
|
|
eventType: EventType.ON_FILTER_UPDATE,
|
|
|
|
|
row: {
|
|
|
|
|
...this.props.filteredTableData[rowIndex],
|
|
|
|
|
},
|
|
|
|
|
additionalData: {
|
|
|
|
|
filterText: text,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
2022-11-05 09:54:20 +00:00
|
|
|
|
|
|
|
|
onCheckChange = (
|
|
|
|
|
column: any,
|
|
|
|
|
row: Record<string, unknown>,
|
|
|
|
|
value: boolean,
|
|
|
|
|
alias: string,
|
|
|
|
|
originalIndex: number,
|
|
|
|
|
rowIndex: number,
|
|
|
|
|
) => {
|
|
|
|
|
if (this.props.isAddRowInProgress) {
|
|
|
|
|
this.updateNewRowValues(alias, value, value);
|
|
|
|
|
} else {
|
|
|
|
|
this.updateTransientTableData({
|
|
|
|
|
[ORIGINAL_INDEX_KEY]: originalIndex,
|
|
|
|
|
[alias]: value,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.onColumnEvent({
|
|
|
|
|
rowIndex,
|
|
|
|
|
action: column.onCheckChange,
|
|
|
|
|
triggerPropertyName: "onCheckChange",
|
|
|
|
|
eventType: EventType.ON_CHECK_CHANGE,
|
|
|
|
|
row: {
|
|
|
|
|
...row,
|
|
|
|
|
[alias]: value,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
handleAddNewRowClick = () => {
|
|
|
|
|
const defaultNewRow = this.props.defaultNewRow || {};
|
|
|
|
|
this.props.updateWidgetMetaProperty("isAddRowInProgress", true);
|
|
|
|
|
this.props.updateWidgetMetaProperty("newRowContent", defaultNewRow);
|
|
|
|
|
this.props.updateWidgetMetaProperty("newRow", defaultNewRow);
|
|
|
|
|
|
|
|
|
|
// New row gets added at the top of page 1 when client side pagination enabled
|
|
|
|
|
if (!this.props.serverSidePaginationEnabled) {
|
|
|
|
|
this.props.updateWidgetMetaProperty("pageNo", 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Since we're adding a newRowContent thats not part of tableData, the index changes
|
|
|
|
|
// so we're resetting the row selection
|
|
|
|
|
this.props.updateWidgetMetaProperty("selectedRowIndex", -1);
|
|
|
|
|
this.props.updateWidgetMetaProperty("selectedRowIndices", []);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
handleAddNewRowAction = (
|
|
|
|
|
type: AddNewRowActions,
|
|
|
|
|
onActionComplete: () => void,
|
|
|
|
|
) => {
|
|
|
|
|
let triggerPropertyName, action, eventType;
|
|
|
|
|
|
|
|
|
|
const onComplete = () => {
|
|
|
|
|
this.props.updateWidgetMetaProperty("isAddRowInProgress", false);
|
|
|
|
|
this.props.updateWidgetMetaProperty("newRowContent", undefined);
|
|
|
|
|
this.props.updateWidgetMetaProperty("newRow", undefined);
|
|
|
|
|
onActionComplete();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (type === AddNewRowActions.SAVE) {
|
|
|
|
|
triggerPropertyName = "onAddNewRowSave";
|
|
|
|
|
action = this.props.onAddNewRowSave;
|
|
|
|
|
eventType = EventType.ON_ADD_NEW_ROW_SAVE;
|
|
|
|
|
} else {
|
|
|
|
|
triggerPropertyName = "onAddNewRowDiscard";
|
|
|
|
|
action = this.props.onAddNewRowDiscard;
|
|
|
|
|
eventType = EventType.ON_ADD_NEW_ROW_DISCARD;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (action) {
|
|
|
|
|
super.executeAction({
|
|
|
|
|
triggerPropertyName: triggerPropertyName,
|
|
|
|
|
dynamicString: action,
|
|
|
|
|
event: {
|
|
|
|
|
type: eventType,
|
|
|
|
|
callback: onComplete,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
onComplete();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
isColumnCellValid = (columnsAlias: string) => {
|
|
|
|
|
if (this.props.isEditableCellsValid?.hasOwnProperty(columnsAlias)) {
|
|
|
|
|
return this.props.isEditableCellsValid[columnsAlias];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
hasInvalidColumnCell = () => {
|
2022-11-18 10:54:35 +00:00
|
|
|
if (isObject(this.props.isEditableCellsValid)) {
|
|
|
|
|
return Object.values(this.props.isEditableCellsValid).some((d) => !d);
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-11-05 09:54:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
updateNewRowValues = (
|
|
|
|
|
alias: string,
|
|
|
|
|
value: unknown,
|
|
|
|
|
parsedValue: unknown,
|
|
|
|
|
) => {
|
|
|
|
|
/*
|
|
|
|
|
* newRowContent holds whatever the user types while newRow holds the parsed value
|
|
|
|
|
* newRowContent is being used to populate the cell while newRow is being used
|
|
|
|
|
* for validations.
|
|
|
|
|
*/
|
|
|
|
|
this.props.updateWidgetMetaProperty("newRowContent", {
|
|
|
|
|
...this.props.newRowContent,
|
|
|
|
|
[alias]: value,
|
|
|
|
|
});
|
|
|
|
|
this.props.updateWidgetMetaProperty("newRow", {
|
|
|
|
|
...this.props.newRow,
|
|
|
|
|
[alias]: parsedValue,
|
|
|
|
|
});
|
|
|
|
|
};
|
2022-07-14 07:02:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default TableWidgetV2;
|