PromucFlow_constructor/app/client/src/widgets/TableWidgetV2/constants.ts
Keyur Paralkar b22ad3a769
feat: added column freeze and unfreeze functionality to table widget (#18757)
**PRD**:
https://www.notion.so/appsmith/Ability-to-freeze-columns-dd118f7ed2e14e008ee305056b79874a?d=300f4968889244da9f737e1bfd8c06dc#2ddaf28e10a0475cb69f1af77b938d0b

This PR adds the following features to the table widget:

- Freeze the columns to the left or right of the table.(Both canvas and
page view mode).
- Unfreeze the frozen columns. (Both canvas and page view mode).
- Columns that are left frozen, will get unfrozen at a position after
the last left frozen column. (Both canvas and page view mode).
- Columns that are right frozen, will get unfrozen at a position before
the first right frozen column. (Both canvas and page view mode).
- Column order can be persisted in the Page view mode.
- Users can also unfreeze the columns that are frozen by the developers.
- Columns that are frozen cannot be reordered(Both canvas and page view
mode)
- **Property pane changes (Columns property)**:
- If the column is frozen to the left then that column should appear at
top of the list.
- If the column is frozen to the right then that column should appear at
the bottom of the list.
- The columns that are frozen cannot be moved or re-ordered in the list.
They remain fixed in their position.
- In-Page mode, If there is a change in frozen or unfrozen columns in
multiple tables then the order of columns and frozen and unfrozen
columns should get persisted on refresh i.e. changes should get
persisted across refreshes.
2023-02-15 17:12:46 +05:30

217 lines
5.2 KiB
TypeScript

import {
ColumnProperties,
CompactMode,
ReactTableFilter,
TableStyles,
SortOrderTypes,
} from "./component/Constants";
import { WidgetProps } from "widgets/BaseWidget";
import { WithMeta } from "widgets/MetaHOC";
import { EventType } from "constants/AppsmithActionConstants/ActionConstants";
import { IconNames } from "@blueprintjs/icons";
import { ColumnAction } from "components/propertyControls/ColumnActionSelectorControl";
import { Alignment } from "@blueprintjs/core";
import { IconName } from "@blueprintjs/icons";
import { ButtonVariant } from "components/constants";
export type EditableCell = {
column: string;
index: number;
value: string | number | null;
initialValue: string;
inputValue: string;
};
export enum EditableCellActions {
SAVE = "SAVE",
DISCARD = "DISCARD",
}
export enum InlineEditingSaveOptions {
ROW_LEVEL = "ROW_LEVEL",
TABLE_LEVEL = "TABLE_LEVEL",
CUSTOM = "CUSTOM",
}
interface AddNewRowProps {
isAddRowInProgress: boolean;
allowAddNewRow: boolean;
onAddNewRowSave: string;
onAddNewRowDiscard: string;
defaultNewRow: Record<string, unknown>;
}
export interface TableWidgetProps
extends WidgetProps,
WithMeta,
TableStyles,
AddNewRowProps {
nextPageKey?: string;
prevPageKey?: string;
label: string;
searchText: string;
defaultSearchText: string;
defaultSelectedRowIndex?: number | string;
defaultSelectedRowIndices?: number[] | string;
tableData: Array<Record<string, unknown>>;
onPageChange?: string;
pageSize: number;
onRowSelected?: string;
onSearchTextChanged: string;
onSort: string;
selectedRowIndex?: number;
selectedRowIndices: number[];
serverSidePaginationEnabled?: boolean;
multiRowSelection?: boolean;
enableClientSideSearch?: boolean;
hiddenColumns?: string[];
columnOrder?: string[];
frozenColumnIndices: Record<string, number>;
canFreezeColumn?: boolean;
columnNameMap?: { [key: string]: string };
columnTypeMap?: {
[key: string]: { type: string; format: string; inputFormat?: string };
};
columnWidthMap?: { [key: string]: number };
filters?: ReactTableFilter[];
compactMode?: CompactMode;
isSortable?: boolean;
primaryColumnId?: string;
primaryColumns: Record<string, ColumnProperties>;
derivedColumns: Record<string, ColumnProperties>;
sortOrder: {
column: string;
order: SortOrderTypes | null;
};
totalRecordsCount?: number;
transientTableData: {
[key: string]: Record<string, string>;
};
editableCell?: EditableCell;
primaryColor: string;
borderRadius: string;
boxShadow?: string;
inlineEditingSaveOption?: InlineEditingSaveOptions;
showInlineEditingOptionDropdown?: boolean;
variant?: TableVariant;
isEditableCellsValid: Record<string, boolean>;
selectColumnFilterText?: Record<string, string>;
isAddRowInProgress: boolean;
newRow: Record<string, unknown>;
firstEditableColumnIdByOrder: string;
}
export enum TableVariantTypes {
DEFAULT = "DEFAULT",
VARIANT2 = "VARIANT2",
VARIANT3 = "VARIANT3",
}
export type TableVariant = keyof typeof TableVariantTypes;
export const ORIGINAL_INDEX_KEY = "__originalIndex__";
export const PRIMARY_COLUMN_KEY_VALUE = "__primaryKey__";
export const DEFAULT_COLUMN_WIDTH = 150;
export const COLUMN_MIN_WIDTH = 60;
export const TABLE_COLUMN_ORDER_KEY = "tableWidgetColumnOrder";
export enum ColumnTypes {
TEXT = "text",
URL = "url",
NUMBER = "number",
IMAGE = "image",
VIDEO = "video",
DATE = "date",
BUTTON = "button",
ICON_BUTTON = "iconButton",
MENU_BUTTON = "menuButton",
SELECT = "select",
EDIT_ACTIONS = "editActions",
CHECKBOX = "checkbox",
SWITCH = "switch",
}
export enum ReadOnlyColumnTypes {
TEXT = "text",
URL = "url",
NUMBER = "number",
IMAGE = "image",
VIDEO = "video",
DATE = "date",
CHECKBOX = "checkbox",
SWITCH = "switch",
SELECT = "select",
}
export const ActionColumnTypes = [
ColumnTypes.BUTTON,
ColumnTypes.ICON_BUTTON,
ColumnTypes.MENU_BUTTON,
ColumnTypes.EDIT_ACTIONS,
];
export const FilterableColumnTypes = [
ColumnTypes.TEXT,
ColumnTypes.URL,
ColumnTypes.NUMBER,
ColumnTypes.DATE,
ColumnTypes.SELECT,
ColumnTypes.CHECKBOX,
ColumnTypes.SWITCH,
];
export const DEFAULT_BUTTON_COLOR = "rgb(3, 179, 101)";
export const DEFAULT_BUTTON_LABEL = "Action";
export const DEFAULT_MENU_VARIANT = "PRIMARY";
export const DEFAULT_MENU_BUTTON_LABEL = "Open menu";
export type TransientDataPayload = {
[key: string]: string | number | boolean;
__originalIndex__: number;
};
export type OnColumnEventArgs = {
rowIndex: number;
action: string;
onComplete?: () => void;
triggerPropertyName: string;
eventType: EventType;
row?: Record<string, unknown>;
additionalData?: Record<string, unknown>;
};
export const ICON_NAMES = Object.keys(IconNames).map(
(name: string) => IconNames[name as keyof typeof IconNames],
);
export type ButtonColumnActions = ColumnAction & {
eventType: EventType;
iconName?: IconName;
variant: ButtonVariant;
backgroundColor?: string;
iconAlign?: Alignment;
borderRadius?: string;
isVisible?: boolean;
isDisabled?: boolean;
boxShadow?: string;
};
export enum DateInputFormat {
EPOCH = "Epoch",
MILLISECONDS = "Milliseconds",
}
export const defaultEditableCell = {
column: "",
index: -1,
inputValue: "",
value: "",
initialValue: "",
};