PromucFlow_constructor/app/client/src/widgets/TableWidget.tsx

729 lines
23 KiB
TypeScript
Raw Normal View History

2020-10-06 09:01:51 +00:00
import React, { lazy, Suspense } from "react";
import BaseWidget, { WidgetProps, WidgetState } from "./BaseWidget";
2020-10-06 09:01:51 +00:00
import { RenderModes, WidgetType } from "constants/WidgetConstants";
2020-02-18 10:41:52 +00:00
import { EventType } from "constants/ActionConstants";
import {
compare,
2020-10-06 09:01:51 +00:00
ConditionFunctions,
getAllTableColumnKeys,
renderActions,
2020-10-06 09:01:51 +00:00
renderCell,
reorderColumns,
sortTableFunction,
} from "components/designSystems/appsmith/TableUtilities";
2019-11-25 05:07:27 +00:00
import { VALIDATION_TYPES } from "constants/WidgetValidation";
2020-03-16 07:59:07 +00:00
import {
BASE_WIDGET_VALIDATION,
2020-10-06 09:01:51 +00:00
WidgetPropertyValidationType,
2020-03-16 07:59:07 +00:00
} from "utils/ValidationFactory";
2020-01-23 07:53:36 +00:00
import { ColumnAction } from "components/propertyControls/ColumnActionSelectorControl";
2020-02-18 10:41:52 +00:00
import { TriggerPropertiesMap } from "utils/WidgetFactory";
2020-04-16 08:32:58 +00:00
import Skeleton from "components/utils/Skeleton";
import moment from "moment";
2020-10-06 09:01:51 +00:00
import { isNumber, isString, isUndefined } from "lodash";
import * as Sentry from "@sentry/react";
import { retryPromise } from "utils/AppsmithUtils";
2020-10-06 09:01:51 +00:00
import withMeta, { WithMeta } from "./MetaHOC";
const ReactTableComponent = lazy(() =>
retryPromise(() =>
import("components/designSystems/appsmith/ReactTableComponent"),
),
);
2019-10-31 10:10:57 +00:00
export type TableSizes = {
COLUMN_HEADER_HEIGHT: number;
TABLE_HEADER_HEIGHT: number;
ROW_HEIGHT: number;
ROW_FONT_SIZE: number;
};
export enum CompactModeTypes {
SHORT = "SHORT",
DEFAULT = "DEFAULT",
TALL = "TALL",
}
export const TABLE_SIZES: { [key: string]: TableSizes } = {
[CompactModeTypes.DEFAULT]: {
COLUMN_HEADER_HEIGHT: 38,
TABLE_HEADER_HEIGHT: 42,
ROW_HEIGHT: 40,
ROW_FONT_SIZE: 14,
},
[CompactModeTypes.SHORT]: {
COLUMN_HEADER_HEIGHT: 38,
TABLE_HEADER_HEIGHT: 42,
ROW_HEIGHT: 20,
ROW_FONT_SIZE: 12,
},
[CompactModeTypes.TALL]: {
COLUMN_HEADER_HEIGHT: 38,
TABLE_HEADER_HEIGHT: 42,
ROW_HEIGHT: 60,
ROW_FONT_SIZE: 18,
},
};
export enum ColumnTypes {
CURRENCY = "currency",
TIME = "time",
DATE = "date",
VIDEO = "video",
IMAGE = "image",
TEXT = "text",
NUMBER = "number",
}
export enum OperatorTypes {
OR = "OR",
AND = "AND",
}
class TableWidget extends BaseWidget<TableWidgetProps, WidgetState> {
2019-11-19 12:44:58 +00:00
static getPropertyValidationMap(): WidgetPropertyValidationType {
return {
2020-03-16 07:59:07 +00:00
...BASE_WIDGET_VALIDATION,
2019-11-19 12:44:58 +00:00
tableData: VALIDATION_TYPES.TABLE_DATA,
2019-11-22 13:12:39 +00:00
nextPageKey: VALIDATION_TYPES.TEXT,
prevPageKey: VALIDATION_TYPES.TEXT,
label: VALIDATION_TYPES.TEXT,
Fix-Search component in Table widget updated with support for clearing search data (#96) * Added Button component in Table widget for actions * Action button state loading added for Table widget * Action button font-weight made as normal * Created header for common functionalities in Table Widget * Client side searching added in Table Widget. Action created for server side searching also. * Columns visibility feature initial commit * Column visibility list added in Table Widget * Changed pagination designs in accordance with new layout. This enable user to jump page as well. * Using colors values from constants * Table widget pagination, numeric input page number clamped between 1 and total pages * Adding tool tip to truncated values in table widget. Added AutoToolTipComponent that adds tooltip when text is truncated. * Table data download changes. Added downlaod icon and button to table widget. * Table data download changes * Table button loading state fixed. Table code refactored, rendering from props instead of state in ReactTableComponent * Table widget action button alignment fixed * Handled actions column changes * added proper keys to useMemo for react table widget * Download table data as CSV implemented * table data download, unused code removed * Code refactors and added dependency map with meta props and table data for computing columns * Table UI breakages on scroll and empty cells fixed * Handled empty rows in table widget * Fixed last row cut issue * Code review changes * Code review changes * Added table widget component heights as enum * code review changes * Search component in Table widget updated with support for clearing data, renamed properties * Opening image in new tab on clicking in table widget * Fixed table craching due to empty data filtering * Empty extra space on loading removed in table widget * Removed stopping of event propagation on table widget action button click * Fixing for test cases * Table header UI overflow fixed * Clearing selected row on searching data in table widget * fix for cypress test * Table crash issue fix * searchKeyword renamed to searchText. searchText added to entity definitions Co-authored-by: Arpit Mohan <me@arpitmohan.com>
2020-07-24 13:58:28 +00:00
searchText: VALIDATION_TYPES.TEXT,
defaultSearchText: VALIDATION_TYPES.TEXT,
2020-01-17 09:28:26 +00:00
};
}
2019-11-19 12:44:58 +00:00
2020-04-17 16:15:09 +00:00
static getMetaPropertiesMap(): Record<string, any> {
return {
pageNo: 1,
pageSize: undefined,
selectedRowIndex: -1,
selectedRowIndices: [],
searchText: undefined,
selectedRow: {},
selectedRows: [],
// The following meta property is used for rendering the table.
filteredTableData: undefined,
2020-04-17 16:15:09 +00:00
};
}
static getDefaultPropertiesMap(): Record<string, string> {
return {
searchText: "defaultSearchText",
};
}
2020-02-18 10:41:52 +00:00
static getTriggerPropertyMap(): TriggerPropertiesMap {
return {
onRowSelected: true,
onPageChange: true,
Fix-Open image in new tab on clicking it in table widget. (#119) * Added Button component in Table widget for actions * Action button state loading added for Table widget * Action button font-weight made as normal * Created header for common functionalities in Table Widget * Client side searching added in Table Widget. Action created for server side searching also. * Columns visibility feature initial commit * Column visibility list added in Table Widget * Changed pagination designs in accordance with new layout. This enable user to jump page as well. * Using colors values from constants * Table widget pagination, numeric input page number clamped between 1 and total pages * Adding tool tip to truncated values in table widget. Added AutoToolTipComponent that adds tooltip when text is truncated. * Table data download changes. Added downlaod icon and button to table widget. * Table data download changes * Table button loading state fixed. Table code refactored, rendering from props instead of state in ReactTableComponent * Table widget action button alignment fixed * Handled actions column changes * added proper keys to useMemo for react table widget * Download table data as CSV implemented * table data download, unused code removed * Code refactors and added dependency map with meta props and table data for computing columns * Table UI breakages on scroll and empty cells fixed * Handled empty rows in table widget * Fixed last row cut issue * Code review changes * Code review changes * Added table widget component heights as enum * code review changes * Search component in Table widget updated with support for clearing data, renamed properties * Opening image in new tab on clicking in table widget * Fixed table craching due to empty data filtering * Empty extra space on loading removed in table widget * Removed stopping of event propagation on table widget action button click * Table header UI overflow fixed * Clearing selected row on searching data in table widget * fix for cypress test Co-authored-by: Arpit Mohan <me@arpitmohan.com>
2020-07-24 10:32:31 +00:00
onSearchTextChanged: true,
columnActions: true,
2020-02-18 10:41:52 +00:00
};
}
getTableColumns = (tableData: object[]) => {
let columns: ReactTableColumnProps[] = [];
const hiddenColumns: ReactTableColumnProps[] = [];
const {
columnNameMap,
columnSizeMap,
columnTypeMap,
columnActions,
} = this.props;
if (tableData.length) {
const columnKeys: string[] = getAllTableColumnKeys(tableData);
const sortedColumn = this.props.sortedColumn;
for (let index = 0; index < columnKeys.length; index++) {
const i = columnKeys[index];
const columnName: string =
columnNameMap && columnNameMap[i] ? columnNameMap[i] : i;
const columnType: {
type: string;
format?: string;
inputFormat?: string;
} =
columnTypeMap && columnTypeMap[i]
? columnTypeMap[i]
: { type: ColumnTypes.TEXT };
const columnSize: number =
columnSizeMap && columnSizeMap[i] ? columnSizeMap[i] : 150;
const isHidden =
!!this.props.hiddenColumns && this.props.hiddenColumns.includes(i);
const columnData = {
Header: columnName,
accessor: i,
width: columnSize,
minWidth: 60,
draggable: true,
isHidden: false,
isAscOrder:
sortedColumn && sortedColumn.column === i
? sortedColumn.asc
: undefined,
metaProperties: {
isHidden: isHidden,
type: columnType.type,
format: columnType.format,
inputFormat: columnType.inputFormat,
},
Cell: (props: any) => {
return renderCell(props.cell.value, columnType.type, isHidden);
},
};
if (isHidden) {
columnData.isHidden = true;
hiddenColumns.push(columnData);
} else {
columns.push(columnData);
}
}
columns = reorderColumns(columns, this.props.columnOrder || []);
if (columnActions?.length) {
columns.push({
Header:
columnNameMap && columnNameMap["actions"]
? columnNameMap["actions"]
: "Actions",
accessor: "actions",
width: 150,
minWidth: 60,
draggable: true,
Cell: (props: any) => {
return renderActions({
isSelected: props.row.isSelected,
columnActions: columnActions,
onCommandClick: this.onCommandClick,
});
},
});
}
if (
hiddenColumns.length &&
this.props.renderMode === RenderModes.CANVAS
) {
columns = columns.concat(hiddenColumns);
}
}
return columns;
};
transformData = (tableData: object[], columns: ReactTableColumnProps[]) => {
const updatedTableData = [];
for (let row = 0; row < tableData.length; row++) {
const data: { [key: string]: any } = tableData[row];
const tableRow: { [key: string]: any } = {};
for (let colIndex = 0; colIndex < columns.length; colIndex++) {
const column = columns[colIndex];
const { accessor } = column;
let value = data[accessor];
if (column.metaProperties) {
const type = column.metaProperties.type;
const format = column.metaProperties.format;
switch (type) {
case ColumnTypes.CURRENCY:
if (!isNaN(value)) {
tableRow[accessor] = `${format}${value ? value : ""}`;
} else {
tableRow[accessor] = "Invalid Value";
}
break;
case ColumnTypes.DATE:
let isValidDate = true;
let outputFormat = column.metaProperties.format;
let inputFormat;
try {
const type = column.metaProperties.inputFormat;
if (type !== "EPOCH" && type !== "Milliseconds") {
inputFormat = type;
moment(value, inputFormat);
} else if (!isNumber(value)) {
isValidDate = false;
}
} catch (e) {
isValidDate = false;
}
if (isValidDate) {
if (outputFormat === "SAME_AS_INPUT") {
outputFormat = inputFormat;
}
if (column.metaProperties.inputFormat === "Milliseconds") {
value = 1000 * Number(value);
}
tableRow[accessor] = moment(value, inputFormat).format(
outputFormat,
);
} else if (value) {
tableRow[accessor] = "Invalid Value";
} else {
tableRow[accessor] = "";
}
break;
case ColumnTypes.TIME:
let isValidTime = true;
if (isNaN(value)) {
const time = Date.parse(value);
if (isNaN(time)) {
isValidTime = false;
}
}
if (isValidTime) {
tableRow[accessor] = moment(value).format("HH:mm");
} else if (value) {
tableRow[accessor] = "Invalid Value";
} else {
tableRow[accessor] = "";
}
break;
default:
const data =
isString(value) || isNumber(value)
? value
: isUndefined(value)
? ""
: JSON.stringify(value);
tableRow[accessor] = data;
break;
}
}
}
updatedTableData.push(tableRow);
}
return updatedTableData;
};
filterTableData = () => {
const { searchText, sortedColumn, filters, tableData } = this.props;
const columns = this.getTableColumns(tableData);
if (!tableData || !tableData.length) {
return [];
}
2020-10-06 09:01:51 +00:00
let sortedTableData: any[];
const searchKey = searchText ? searchText.toUpperCase() : "";
if (sortedColumn) {
const sortColumn = sortedColumn.column;
const sortOrder = sortedColumn.asc;
sortedTableData = sortTableFunction(
tableData,
columns,
sortColumn,
sortOrder,
);
} else {
sortedTableData = [...tableData];
}
2020-10-06 09:01:51 +00:00
return sortedTableData.filter((item: { [key: string]: any }) => {
const searchFound = searchKey
? Object.values(item)
.join(", ")
.toUpperCase()
.includes(searchKey)
: true;
if (!searchFound) return false;
if (!filters || filters.length === 0) return true;
const filterOperator: Operator =
filters.length >= 2 ? filters[1].operator : OperatorTypes.OR;
let filter = filterOperator === OperatorTypes.AND;
for (let i = 0; i < filters.length; i++) {
const filterValue = compare(
item[filters[i].column],
filters[i].value,
filters[i].condition,
);
if (filterOperator === OperatorTypes.AND) {
filter = filter && filterValue;
} else {
filter = filter || filterValue;
}
2020-10-06 09:01:51 +00:00
}
return filter;
});
};
getSelectedRow = (filteredTableData: object[], selectedRowIndex?: number) => {
if (selectedRowIndex === undefined || selectedRowIndex === -1) {
const columnKeys: string[] = getAllTableColumnKeys(this.props.tableData);
const selectedRow: { [key: string]: any } = {};
for (let i = 0; i < columnKeys.length; i++) {
selectedRow[columnKeys[i]] = undefined;
}
return selectedRow;
}
return filteredTableData[selectedRowIndex];
};
componentDidMount() {
const filteredTableData = this.filterTableData();
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty("filteredTableData", filteredTableData);
const { selectedRowIndex } = this.props;
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty(
"selectedRow",
this.getSelectedRow(filteredTableData, selectedRowIndex),
);
}
componentDidUpdate(prevProps: TableWidgetProps) {
const tableDataUpdated =
JSON.stringify(this.props.tableData) !==
JSON.stringify(prevProps.tableData);
if (
tableDataUpdated ||
JSON.stringify(this.props.filters) !==
JSON.stringify(prevProps.filters) ||
this.props.searchText !== prevProps.searchText ||
JSON.stringify(this.props.sortedColumn) !==
JSON.stringify(prevProps.sortedColumn) ||
!this.props.filteredTableData
) {
const filteredTableData = this.filterTableData();
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty(
"filteredTableData",
filteredTableData,
);
if (!this.props.multiRowSelection) {
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty(
"selectedRow",
this.getSelectedRow(filteredTableData),
);
} else {
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty(
"selectedRows",
filteredTableData.filter((item: object, i: number) => {
return this.props.selectedRowIndices.includes(i);
}),
);
}
}
if (tableDataUpdated) {
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty("selectedRowIndices", []);
this.props.updateWidgetMetaProperty("selectedRows", []);
this.props.updateWidgetMetaProperty("selectedRowIndex", -1);
}
if (this.props.multiRowSelection !== prevProps.multiRowSelection) {
if (this.props.multiRowSelection) {
const selectedRowIndices = this.props.selectedRowIndex
? [this.props.selectedRowIndex]
: [];
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty(
"selectedRowIndices",
selectedRowIndices,
);
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty("selectedRowIndex", -1);
const filteredTableData = this.filterTableData();
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty(
"selectedRows",
filteredTableData.filter((item: object, i: number) => {
return selectedRowIndices.includes(i);
}),
);
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty(
"selectedRow",
this.getSelectedRow(filteredTableData),
);
} else {
const filteredTableData = this.filterTableData();
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty("selectedRowIndices", []);
this.props.updateWidgetMetaProperty("selectedRows", []);
this.props.updateWidgetMetaProperty(
"selectedRow",
this.getSelectedRow(filteredTableData),
);
}
}
}
getSelectedRowIndexes = (selectedRowIndexes: string) => {
return selectedRowIndexes
? selectedRowIndexes.split(",").map(i => Number(i))
: [];
};
2019-09-12 08:11:25 +00:00
getPageView() {
const {
tableData,
hiddenColumns,
filteredTableData,
selectedRowIndices,
} = this.props;
const tableColumns = this.getTableColumns(tableData);
const transformedData = this.transformData(
filteredTableData || [],
tableColumns,
);
2020-02-07 11:34:57 +00:00
const serverSidePaginationEnabled = (this.props
.serverSidePaginationEnabled &&
this.props.serverSidePaginationEnabled) as boolean;
2020-02-07 02:32:52 +00:00
let pageNo = this.props.pageNo;
if (pageNo === undefined) {
pageNo = 1;
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty("pageNo", pageNo);
2020-02-07 02:32:52 +00:00
}
const { componentWidth, componentHeight } = this.getComponentDimensions();
const tableSizes =
TABLE_SIZES[this.props.compactMode || CompactModeTypes.DEFAULT];
let pageSize = Math.floor(
(componentHeight -
tableSizes.TABLE_HEADER_HEIGHT -
tableSizes.COLUMN_HEADER_HEIGHT) /
tableSizes.ROW_HEIGHT,
);
if (
componentHeight -
(tableSizes.TABLE_HEADER_HEIGHT +
tableSizes.COLUMN_HEADER_HEIGHT +
tableSizes.ROW_HEIGHT * pageSize) >
0
)
pageSize += 1;
2020-04-29 05:13:02 +00:00
if (pageSize !== this.props.pageSize) {
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty("pageSize", pageSize);
2020-04-29 05:13:02 +00:00
}
2020-06-03 10:50:10 +00:00
return (
<Suspense fallback={<Skeleton />}>
<ReactTableComponent
height={componentHeight}
width={componentWidth}
tableData={transformedData}
columns={tableColumns}
isLoading={this.props.isLoading}
widgetId={this.props.widgetId}
widgetName={this.props.widgetName}
Fix-Search component in Table widget updated with support for clearing search data (#96) * Added Button component in Table widget for actions * Action button state loading added for Table widget * Action button font-weight made as normal * Created header for common functionalities in Table Widget * Client side searching added in Table Widget. Action created for server side searching also. * Columns visibility feature initial commit * Column visibility list added in Table Widget * Changed pagination designs in accordance with new layout. This enable user to jump page as well. * Using colors values from constants * Table widget pagination, numeric input page number clamped between 1 and total pages * Adding tool tip to truncated values in table widget. Added AutoToolTipComponent that adds tooltip when text is truncated. * Table data download changes. Added downlaod icon and button to table widget. * Table data download changes * Table button loading state fixed. Table code refactored, rendering from props instead of state in ReactTableComponent * Table widget action button alignment fixed * Handled actions column changes * added proper keys to useMemo for react table widget * Download table data as CSV implemented * table data download, unused code removed * Code refactors and added dependency map with meta props and table data for computing columns * Table UI breakages on scroll and empty cells fixed * Handled empty rows in table widget * Fixed last row cut issue * Code review changes * Code review changes * Added table widget component heights as enum * code review changes * Search component in Table widget updated with support for clearing data, renamed properties * Opening image in new tab on clicking in table widget * Fixed table craching due to empty data filtering * Empty extra space on loading removed in table widget * Removed stopping of event propagation on table widget action button click * Fixing for test cases * Table header UI overflow fixed * Clearing selected row on searching data in table widget * fix for cypress test * Table crash issue fix * searchKeyword renamed to searchText. searchText added to entity definitions Co-authored-by: Arpit Mohan <me@arpitmohan.com>
2020-07-24 13:58:28 +00:00
searchKey={this.props.searchText}
editMode={this.props.renderMode === RenderModes.CANVAS}
hiddenColumns={hiddenColumns}
columnActions={this.props.columnActions}
columnNameMap={this.props.columnNameMap}
columnTypeMap={this.props.columnTypeMap}
columnOrder={this.props.columnOrder}
pageSize={pageSize}
onCommandClick={this.onCommandClick}
selectedRowIndex={
this.props.selectedRowIndex === undefined
? -1
: this.props.selectedRowIndex
}
multiRowSelection={this.props.multiRowSelection}
selectedRowIndices={selectedRowIndices}
serverSidePaginationEnabled={serverSidePaginationEnabled}
onRowClick={this.handleRowClick}
pageNo={pageNo}
nextPageClick={this.handleNextPageClick}
prevPageClick={this.handlePrevPageClick}
updatePageNo={(pageNo: number) => {
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty("pageNo", pageNo);
}}
updateHiddenColumns={(hiddenColumns?: string[]) => {
super.updateWidgetProperty("hiddenColumns", hiddenColumns);
}}
updateColumnType={(columnTypeMap: {
[key: string]: { type: string; format: string };
}) => {
super.updateWidgetProperty("columnTypeMap", columnTypeMap);
}}
updateColumnName={(columnNameMap: { [key: string]: string }) => {
super.updateWidgetProperty("columnNameMap", columnNameMap);
}}
handleResizeColumn={(columnSizeMap: { [key: string]: number }) => {
super.updateWidgetProperty("columnSizeMap", columnSizeMap);
}}
handleReorderColumn={(columnOrder: string[]) => {
super.updateWidgetProperty("columnOrder", columnOrder);
}}
columnSizeMap={this.props.columnSizeMap}
disableDrag={(disable: boolean) => {
this.disableDrag(disable);
}}
searchTableData={this.handleSearchTable}
filters={this.props.filters}
applyFilter={(filters: ReactTableFilter[]) => {
this.resetSelectedRowIndex();
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty("filters", filters);
}}
compactMode={this.props.compactMode || CompactModeTypes.DEFAULT}
updateCompactMode={(compactMode: CompactMode) => {
if (this.props.renderMode === RenderModes.CANVAS) {
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty("compactMode", compactMode);
} else {
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty("compactMode", compactMode);
}
}}
sortTableColumn={this.handleColumnSorting}
/>
2020-06-03 10:50:10 +00:00
</Suspense>
);
2019-09-12 08:11:25 +00:00
}
handleColumnSorting = (column: string, asc: boolean) => {
this.resetSelectedRowIndex();
if (column === "") {
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty("sortedColumn", undefined);
} else {
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty("sortedColumn", {
column: column,
asc: asc,
});
}
};
handleSearchTable = (searchKey: any) => {
const { onSearchTextChanged } = this.props;
Fix-Open image in new tab on clicking it in table widget. (#119) * Added Button component in Table widget for actions * Action button state loading added for Table widget * Action button font-weight made as normal * Created header for common functionalities in Table Widget * Client side searching added in Table Widget. Action created for server side searching also. * Columns visibility feature initial commit * Column visibility list added in Table Widget * Changed pagination designs in accordance with new layout. This enable user to jump page as well. * Using colors values from constants * Table widget pagination, numeric input page number clamped between 1 and total pages * Adding tool tip to truncated values in table widget. Added AutoToolTipComponent that adds tooltip when text is truncated. * Table data download changes. Added downlaod icon and button to table widget. * Table data download changes * Table button loading state fixed. Table code refactored, rendering from props instead of state in ReactTableComponent * Table widget action button alignment fixed * Handled actions column changes * added proper keys to useMemo for react table widget * Download table data as CSV implemented * table data download, unused code removed * Code refactors and added dependency map with meta props and table data for computing columns * Table UI breakages on scroll and empty cells fixed * Handled empty rows in table widget * Fixed last row cut issue * Code review changes * Code review changes * Added table widget component heights as enum * code review changes * Search component in Table widget updated with support for clearing data, renamed properties * Opening image in new tab on clicking in table widget * Fixed table craching due to empty data filtering * Empty extra space on loading removed in table widget * Removed stopping of event propagation on table widget action button click * Table header UI overflow fixed * Clearing selected row on searching data in table widget * fix for cypress test Co-authored-by: Arpit Mohan <me@arpitmohan.com>
2020-07-24 10:32:31 +00:00
this.resetSelectedRowIndex();
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty("pageNo", 1);
2020-10-06 16:47:16 +00:00
this.props.updateWidgetMetaProperty("searchText", searchKey, {
dynamicString: onSearchTextChanged,
event: {
type: EventType.ON_SEARCH,
},
});
};
2020-03-30 08:16:43 +00:00
updateHiddenColumns = (hiddenColumns?: string[]) => {
2020-06-03 10:50:10 +00:00
super.updateWidgetProperty("hiddenColumns", hiddenColumns);
2020-03-30 08:16:43 +00:00
};
onCommandClick = (action: string, onComplete: () => void) => {
2020-02-18 10:41:52 +00:00
super.executeAction({
dynamicString: action,
event: {
type: EventType.ON_CLICK,
callback: onComplete,
2020-02-18 10:41:52 +00:00
},
});
};
handleRowClick = (rowData: object, index: number) => {
2020-10-06 16:47:16 +00:00
const { selectedRowIndices } = this.props;
if (this.props.multiRowSelection) {
if (selectedRowIndices.includes(index)) {
const rowIndex = selectedRowIndices.indexOf(index);
selectedRowIndices.splice(rowIndex, 1);
} else {
selectedRowIndices.push(index);
}
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty(
"selectedRowIndices",
selectedRowIndices,
);
this.props.updateWidgetMetaProperty(
"selectedRows",
this.props.filteredTableData.filter((item: object, i: number) => {
return selectedRowIndices.includes(i);
}),
);
} else {
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty("selectedRowIndex", index);
this.props.updateWidgetMetaProperty(
"selectedRow",
this.props.filteredTableData[index],
2020-10-06 16:47:16 +00:00
{
dynamicString: this.props.onRowSelected,
event: {
type: EventType.ON_ROW_SELECTED,
},
2020-02-18 10:41:52 +00:00
},
2020-10-06 16:47:16 +00:00
);
2020-02-18 10:41:52 +00:00
}
};
handleNextPageClick = () => {
let pageNo = this.props.pageNo || 1;
pageNo = pageNo + 1;
2020-10-06 16:47:16 +00:00
this.props.updateWidgetMetaProperty("pageNo", pageNo, {
dynamicString: this.props.onPageChange,
event: {
type: EventType.ON_NEXT_PAGE,
},
});
2020-02-18 10:41:52 +00:00
if (this.props.onPageChange) {
2020-02-27 03:05:14 +00:00
this.resetSelectedRowIndex();
2020-02-18 10:41:52 +00:00
}
};
2020-02-27 03:05:14 +00:00
resetSelectedRowIndex = () => {
2020-10-06 09:01:51 +00:00
this.props.updateWidgetMetaProperty("selectedRowIndex", -1);
this.props.updateWidgetMetaProperty("selectedRowIndices", []);
2020-02-27 03:05:14 +00:00
};
2020-02-18 10:41:52 +00:00
handlePrevPageClick = () => {
let pageNo = this.props.pageNo || 1;
pageNo = pageNo - 1;
if (pageNo >= 1) {
2020-10-06 16:47:16 +00:00
this.props.updateWidgetMetaProperty("pageNo", pageNo, {
dynamicString: this.props.onPageChange,
event: {
type: EventType.ON_PREV_PAGE,
},
});
2020-02-18 10:41:52 +00:00
if (this.props.onPageChange) {
2020-02-27 03:05:14 +00:00
this.resetSelectedRowIndex();
2020-02-18 10:41:52 +00:00
}
}
2020-01-23 07:53:36 +00:00
};
2019-09-12 08:11:25 +00:00
getWidgetType(): WidgetType {
return "TABLE_WIDGET";
}
}
export type CompactMode = keyof typeof CompactModeTypes;
export type Condition = keyof typeof ConditionFunctions | "";
export type Operator = keyof typeof OperatorTypes;
export interface ReactTableFilter {
column: string;
operator: Operator;
condition: Condition;
value: any;
}
export interface TableColumnMetaProps {
isHidden: boolean;
format?: string;
type: string;
inputFormat?: string;
}
export interface ReactTableColumnProps {
Header: string;
accessor: string;
width: number;
minWidth: number;
draggable: boolean;
isHidden?: boolean;
isAscOrder?: boolean;
metaProperties?: TableColumnMetaProps;
Cell: (props: any) => JSX.Element;
}
2020-10-06 09:01:51 +00:00
export interface TableWidgetProps extends WidgetProps, WithMeta {
nextPageKey?: string;
prevPageKey?: string;
label: string;
Fix-Search component in Table widget updated with support for clearing search data (#96) * Added Button component in Table widget for actions * Action button state loading added for Table widget * Action button font-weight made as normal * Created header for common functionalities in Table Widget * Client side searching added in Table Widget. Action created for server side searching also. * Columns visibility feature initial commit * Column visibility list added in Table Widget * Changed pagination designs in accordance with new layout. This enable user to jump page as well. * Using colors values from constants * Table widget pagination, numeric input page number clamped between 1 and total pages * Adding tool tip to truncated values in table widget. Added AutoToolTipComponent that adds tooltip when text is truncated. * Table data download changes. Added downlaod icon and button to table widget. * Table data download changes * Table button loading state fixed. Table code refactored, rendering from props instead of state in ReactTableComponent * Table widget action button alignment fixed * Handled actions column changes * added proper keys to useMemo for react table widget * Download table data as CSV implemented * table data download, unused code removed * Code refactors and added dependency map with meta props and table data for computing columns * Table UI breakages on scroll and empty cells fixed * Handled empty rows in table widget * Fixed last row cut issue * Code review changes * Code review changes * Added table widget component heights as enum * code review changes * Search component in Table widget updated with support for clearing data, renamed properties * Opening image in new tab on clicking in table widget * Fixed table craching due to empty data filtering * Empty extra space on loading removed in table widget * Removed stopping of event propagation on table widget action button click * Fixing for test cases * Table header UI overflow fixed * Clearing selected row on searching data in table widget * fix for cypress test * Table crash issue fix * searchKeyword renamed to searchText. searchText added to entity definitions Co-authored-by: Arpit Mohan <me@arpitmohan.com>
2020-07-24 13:58:28 +00:00
searchText: string;
defaultSearchText: string;
2019-11-22 13:12:39 +00:00
tableData: object[];
2020-02-18 10:41:52 +00:00
onPageChange?: string;
2020-04-29 05:13:02 +00:00
pageSize: number;
2020-02-18 10:41:52 +00:00
onRowSelected?: string;
Fix-Open image in new tab on clicking it in table widget. (#119) * Added Button component in Table widget for actions * Action button state loading added for Table widget * Action button font-weight made as normal * Created header for common functionalities in Table Widget * Client side searching added in Table Widget. Action created for server side searching also. * Columns visibility feature initial commit * Column visibility list added in Table Widget * Changed pagination designs in accordance with new layout. This enable user to jump page as well. * Using colors values from constants * Table widget pagination, numeric input page number clamped between 1 and total pages * Adding tool tip to truncated values in table widget. Added AutoToolTipComponent that adds tooltip when text is truncated. * Table data download changes. Added downlaod icon and button to table widget. * Table data download changes * Table button loading state fixed. Table code refactored, rendering from props instead of state in ReactTableComponent * Table widget action button alignment fixed * Handled actions column changes * added proper keys to useMemo for react table widget * Download table data as CSV implemented * table data download, unused code removed * Code refactors and added dependency map with meta props and table data for computing columns * Table UI breakages on scroll and empty cells fixed * Handled empty rows in table widget * Fixed last row cut issue * Code review changes * Code review changes * Added table widget component heights as enum * code review changes * Search component in Table widget updated with support for clearing data, renamed properties * Opening image in new tab on clicking in table widget * Fixed table craching due to empty data filtering * Empty extra space on loading removed in table widget * Removed stopping of event propagation on table widget action button click * Table header UI overflow fixed * Clearing selected row on searching data in table widget * fix for cypress test Co-authored-by: Arpit Mohan <me@arpitmohan.com>
2020-07-24 10:32:31 +00:00
onSearchTextChanged: string;
2020-01-17 09:28:26 +00:00
selectedRowIndex?: number;
selectedRowIndices: number[];
2020-01-23 07:53:36 +00:00
columnActions?: ColumnAction[];
2020-02-07 11:34:57 +00:00
serverSidePaginationEnabled?: boolean;
multiRowSelection?: boolean;
2020-03-30 08:16:43 +00:00
hiddenColumns?: string[];
2020-06-03 10:50:10 +00:00
columnOrder?: string[];
columnNameMap?: { [key: string]: string };
columnTypeMap?: {
[key: string]: { type: string; format: string; inputFormat?: string };
};
2020-06-03 10:50:10 +00:00
columnSizeMap?: { [key: string]: number };
filters?: ReactTableFilter[];
compactMode?: CompactMode;
sortedColumn?: {
column: string;
asc: boolean;
};
2019-09-12 08:11:25 +00:00
}
export default TableWidget;
2020-10-06 09:01:51 +00:00
export const ProfiledTableWidget = Sentry.withProfiler(withMeta(TableWidget));