PromucFlow_constructor/app/client/src/widgets/TableWidgetV2/constants.ts
balajisoundar a72e3347f5
feat: Table one click binding for MongoDB and Postgres (#23629)
> Pull Request Template
>
> Use this template to quickly create a well written pull request.
Delete all quotes before creating the pull request.
>
## Description
> Add a TL;DR when description is extra long (helps content team)
>
> Please include a summary of the changes and which issue has been
fixed. Please also include relevant motivation
> and context. List any dependencies that are required for this change
>
> Links to Notion, Figma or any other documents that might be relevant
to the PR
>
>
#### PR fixes following issue(s)
Fixes # (issue number)
> if no issue exists, please create an issue and ask the maintainers
about this first
>
>
#### Media
> A video or a GIF is preferred. when using Loom, don’t embed because it
looks like it’s a GIF. instead, just link to the video
>
>
#### Type of change
> Please delete options that are not relevant.
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- Chore (housekeeping or task changes that don't impact user perception)
- This change requires a documentation update
>
>
>
## Testing
>
#### How Has This Been Tested?
> Please describe the tests that you ran to verify your changes. Also
list any relevant details for your test configuration.
> Delete anything that is not relevant
- [x] Manual
- [x] Jest
- [x] Cypress
>
>
#### Test Plan
> One Click Binding -
https://github.com/appsmithorg/TestSmith/issues/2390
>
#### 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
- [x] 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
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Test-plan-implementation#speedbreaker-features-to-consider-for-every-change)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans/_edit#areas-of-interest)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed

---------

Co-authored-by: Vemparala Surya Vamsi <vamsi@appsmith.com>
2023-06-01 22:56:05 +05:30

226 lines
5.5 KiB
TypeScript

import type {
ColumnProperties,
CompactMode,
ReactTableFilter,
TableStyles,
SortOrderTypes,
} from "./component/Constants";
import type { WidgetProps } from "widgets/BaseWidget";
import type { WithMeta } from "widgets/MetaHOC";
import type { EventType } from "constants/AppsmithActionConstants/ActionConstants";
import { IconNames } from "@blueprintjs/icons";
import type { ColumnAction } from "components/propertyControls/ColumnActionSelectorControl";
import type { Alignment } from "@blueprintjs/core";
import type { IconName } from "@blueprintjs/icons";
import type { ButtonVariant } from "components/constants";
export type EditableCell = {
column: string;
index: number;
value: string | number | null;
initialValue: string;
inputValue: string;
};
export enum PaginationDirection {
INITIAL = "INITIAL",
PREVIOUS_PAGE = "PREVIOUS_PAGE",
NEXT_PAGE = "NEXT_PAGE",
}
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 {
pristine: boolean;
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: "",
};
export const DEFAULT_COLUMN_NAME = "Table Column";