PromucFlow_constructor/app/client/src/widgets/TableWidgetV2/component/StaticTable.tsx

104 lines
3.4 KiB
TypeScript
Raw Normal View History

fix: column dragging and column reordering (#20928) ## Description This PR implements the following changes: - Move the drag events from the Parent component's useEffect to the `HeaderCell` component. - Refactored the code. Inside the table component, we refactored the code such that when SSP is disabled the component uses `StaticTable` and when SSP enabled then we use `VirtualTable`. - It also includes the fix for the following issue. Whenever the user has a scroll to the bottom of the page, on clicking of add new button it is expected that the scroll should move to the top but it wasn't happening. > Add a TL;DR when description is extra long (helps content team) Fixes #20858 > if no issue exists, please create an issue and ask the maintainers about this first ## Type of change - Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? - Manual - Test cases: - Column name should appear on update from the property pane - reorder whenever SSP is enabled - On column re-size - When a col is frozen - When a col is unfrozen - When all the headers or one of them is removed - When sorted also should work - Enable multi-row selection - When in preview mode and back and forth(Check the above cases) - When in Deployed mode - Dragging of columns from the column header should work as expected both in Deploy and Published mode. - Cypress ### Test Plan > Add Testsmith test cases links that relate to this PR ### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [ ] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test
2023-03-05 14:19:44 +00:00
import React from "react";
import {
TableBodyPropGetter,
TableBodyProps,
Row as ReactTableRowType,
} from "react-table";
import { ReactElementType } from "react-window";
import SimpleBar from "simplebar-react";
import "simplebar-react/dist/simplebar.min.css";
import {
MULTISELECT_CHECKBOX_WIDTH,
ReactTableColumnProps,
TableSizes,
TABLE_SCROLLBAR_WIDTH,
} from "./Constants";
import TableColumnHeader, {
TableColumnHeaderProps,
} from "./header/TableColumnHeader";
import { TableBody } from "./TableBody";
type StaticTableProps = TableColumnHeaderProps & {
getTableBodyProps(
propGetter?: TableBodyPropGetter<Record<string, unknown>> | undefined,
): TableBodyProps;
pageSize: number;
height: number;
width?: number;
tableSizes: TableSizes;
innerElementType?: ReactElementType;
accentColor: string;
borderRadius: string;
multiRowSelection?: boolean;
prepareRow?(row: ReactTableRowType<Record<string, unknown>>): void;
selectTableRow?: (row: {
original: Record<string, unknown>;
index: number;
}) => void;
selectedRowIndex: number;
selectedRowIndices: number[];
columns: ReactTableColumnProps[];
primaryColumnId?: string;
isAddRowInProgress: boolean;
headerProps?: TableColumnHeaderProps | Record<string, never>;
totalColumnsWidth?: number;
scrollContainerStyles: any;
useVirtual: boolean;
tableBodyRef?: React.MutableRefObject<HTMLDivElement | null>;
};
const StaticTable = (props: StaticTableProps, ref: React.Ref<SimpleBar>) => {
return (
<SimpleBar ref={ref} style={props.scrollContainerStyles}>
<TableColumnHeader
accentColor={props.accentColor}
borderRadius={props.borderRadius}
canFreezeColumn={props.canFreezeColumn}
columns={props.columns}
disableDrag={props.disableDrag}
editMode={props.editMode}
enableDrag={props.enableDrag}
handleAllRowSelectClick={props.handleAllRowSelectClick}
handleColumnFreeze={props.handleColumnFreeze}
handleReorderColumn={props.handleReorderColumn}
headerGroups={props.headerGroups}
headerWidth={
props.multiRowSelection && props.totalColumnsWidth
? MULTISELECT_CHECKBOX_WIDTH + props.totalColumnsWidth
: props.totalColumnsWidth
}
isResizingColumn={props.isResizingColumn}
isSortable={props.isSortable}
multiRowSelection={props.multiRowSelection}
prepareRow={props.prepareRow}
rowSelectionState={props.rowSelectionState}
sortTableColumn={props.sortTableColumn}
subPage={props.subPage}
widgetId={props.widgetId}
width={props.width}
/>
<TableBody
accentColor={props.accentColor}
borderRadius={props.borderRadius}
columns={props.columns}
getTableBodyProps={props.getTableBodyProps}
height={props.height}
isAddRowInProgress={props.isAddRowInProgress}
multiRowSelection={!!props.multiRowSelection}
pageSize={props.pageSize}
prepareRow={props.prepareRow}
primaryColumnId={props.primaryColumnId}
rows={props.subPage}
selectTableRow={props.selectTableRow}
selectedRowIndex={props.selectedRowIndex}
selectedRowIndices={props.selectedRowIndices}
tableSizes={props.tableSizes}
useVirtual={props.useVirtual}
width={props.width - TABLE_SCROLLBAR_WIDTH / 2}
/>
</SimpleBar>
);
};
export default React.forwardRef(StaticTable);