Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/client/cypress/fixtures/testdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"apiFormDataBodyType": "x-www-form-urlencoded",
"defaultMoustacheData": "{{Input1.text",
"defaultInputWidget": "{{Table1.selectedRow.id",
"sortedColumn": "{{Table1.sortOrder.column",
"deafultDropDownWidget": [
{
"label": "{{Table1.selectedRow.email}}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,32 @@ describe("Binding the Table and input Widget", function() {
.should("contain", tabValue);
});
});

it("validation of column id displayed in input widgets based on sorted column", function() {
cy.SearchEntityandOpen("Input1");
cy.get(".t--property-control-defaulttext .CodeMirror textarea")
.first()
.focus()
.type("{ctrl}{shift}{downarrow}")
.then(($cm) => {
if ($cm.val() !== "") {
cy.get(".t--property-control-defaulttext .CodeMirror textarea")
.first()
.clear({
force: true,
});
}
});
cy.get(widgetsPage.defaultInput).type(testdata.sortedColumn);
cy.get(commonlocators.editPropCrossButton).click({ force: true });
cy.wait("@updateLayout").should(
"have.nested.property",
"response.body.responseMeta.status",
200,
);
cy.get(publish.inputWidget + " " + "input")
.first()
.invoke("attr", "value")
.should("contain", "id");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export enum OperatorTypes {
AND = "AND",
}

export enum SortOrderTypes {
asc = "asc",
desc = "desc",
}

export interface TableStyles {
cellBackground?: string;
textColor?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export enum EventType {
ON_RATE_CHANGED = "ON_RATE_CHANGED",
ON_IFRAME_URL_CHANGED = "ON_IFRAME_URL_CHANGED",
ON_IFRAME_MESSAGE_RECEIVED = "ON_IFRAME_MESSAGE_RECEIVED",
ON_SORT = "ON_SORT",
}

export type ActionType =
Expand Down
1 change: 1 addition & 0 deletions app/client/src/entities/Widget/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ describe("getAllPathsFromPropertyConfig", () => {
onRowSelected: true,
onPageChange: true,
onSearchTextChanged: true,
onSort: true,
onPageSizeChange: true,
"primaryColumns.status.onClick": true,
},
Expand Down
5 changes: 5 additions & 0 deletions app/client/src/utils/autocomplete/EntityDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export const entityDefinitions = {
pageSize: "number",
isVisible: isVisible,
searchText: "string",
sortOrder: {
column: "string",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort order should be a enum, not boolean.
['ASC','DESC']

asc: "bool",
order: "string",
},
}),
VIDEO_WIDGET: {
"!doc":
Expand Down
9 changes: 9 additions & 0 deletions app/client/src/widgets/TableWidget/TablePropertyPaneConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,15 @@ export default [
isBindProperty: true,
isTriggerProperty: true,
},
{
helpText: "Triggers an action when a table column is sorted",
propertyName: "onSort",
label: "onSort",
controlType: "ACTION_SELECTOR",
isJSConvertible: true,
isBindProperty: true,
isTriggerProperty: true,
},
],
},
{
Expand Down
5 changes: 4 additions & 1 deletion app/client/src/widgets/TableWidget/TableWidgetConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
CompactMode,
ReactTableFilter,
TableStyles,
SortOrderTypes,
} from "components/designSystems/appsmith/TableComponent/Constants";
import { WidgetProps } from "widgets/BaseWidget";
import { WithMeta } from "widgets/MetaHOC";
Expand All @@ -19,6 +20,7 @@ export interface TableWidgetProps extends WidgetProps, WithMeta, TableStyles {
pageSize: number;
onRowSelected?: string;
onSearchTextChanged: string;
onSort: string;
selectedRowIndex?: number;
selectedRowIndices: number[];
serverSidePaginationEnabled?: boolean;
Expand All @@ -34,9 +36,10 @@ export interface TableWidgetProps extends WidgetProps, WithMeta, TableStyles {
compactMode?: CompactMode;
primaryColumns: Record<string, ColumnProperties>;
derivedColumns: Record<string, ColumnProperties>;
sortedColumn?: {
sortOrder?: {
column: string;
asc: boolean;
order: SortOrderTypes;
};
}

Expand Down
10 changes: 5 additions & 5 deletions app/client/src/widgets/TableWidget/derived.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ export default {
.filter(Boolean);
idsNotToShow.forEach((id) => delete allColumns[id]);
}
const sortColumn = props.sortedColumn?.column;
const sortOrder = props.sortedColumn?.asc;
const sortColumn = props.sortOrder?.column;
const sortOrder = props.sortOrder?.asc;
if (
props.columnOrder &&
Array.isArray(props.columnOrder) &&
Expand Down Expand Up @@ -234,9 +234,9 @@ export default {
const columns = props.tableColumns;

let sortedTableData;
if (props.sortedColumn) {
const sortedColumn = props.sortedColumn.column;
const sortOrder = props.sortedColumn.asc;
if (props.sortOrder) {
const sortedColumn = props.sortOrder.column;
const sortOrder = props.sortOrder.asc;
const column = columns.find((column) => column.id === sortedColumn);
const columnType =
column && column.columnType ? column.columnType : "text";
Expand Down
18 changes: 9 additions & 9 deletions app/client/src/widgets/TableWidget/derived.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe("Validates Derived Properties", () => {
const { getTableColumns } = derivedProperty;
const input = {
sanitizedTableData: [],
sortedColumn: undefined,
sortOrder: undefined,
columnOrder: ["id", "another"],
};
const expected = [];
Expand All @@ -25,7 +25,7 @@ describe("Validates Derived Properties", () => {
{ id: 123, name: "John Doe" },
{ id: 234, name: "Jane Doe" },
],
sortedColumn: { column: "id", asc: false },
sortOrder: { column: "id", asc: false },
columnOrder: ["name", "id"],
};
const expected = [
Expand Down Expand Up @@ -77,7 +77,7 @@ describe("Validates Derived Properties", () => {
{ id: 123, name: "John Doe" },
{ id: 234, name: "Jane Doe" },
],
sortedColumn: { column: "id", asc: false },
sortOrder: { column: "id", asc: false },
columnOrder: ["name", "id"],
primaryColumns: {
id: {
Expand Down Expand Up @@ -168,7 +168,7 @@ describe("Validates Derived Properties", () => {
{ id: 123, name: "John Doe" },
{ id: 234, name: "Jane Doe" },
],
sortedColumn: { column: "id", asc: false },
sortOrder: { column: "id", asc: false },
columnOrder: ["name", "id"],
primaryColumns: {
id: {
Expand Down Expand Up @@ -276,7 +276,7 @@ describe("Validates Derived Properties", () => {
{ id: 123, name: "John Doe" },
{ id: 234, name: "Jane Doe" },
],
sortedColumn: { column: "id", asc: false },
sortOrder: { column: "id", asc: false },
columnOrder: ["name", "id"],
primaryColumns: {
id: {
Expand Down Expand Up @@ -403,7 +403,7 @@ describe("Validates Derived Properties", () => {
{ id: 123, name: "John Doe" },
{ id: 234, name: "Jane Doe" },
],
sortedColumn: { column: "id", asc: false },
sortOrder: { column: "id", asc: false },
columnOrder: ["name", "id"],
primaryColumns: {
id: {
Expand Down Expand Up @@ -531,7 +531,7 @@ describe("Validates Derived Properties", () => {
const { getFilteredTableData } = derivedProperty;
const input = {
sanitizedTableData: [],
sortedColumn: { column: "id", asc: false },
sortOrder: { column: "id", asc: false },
columnOrder: ["name", "id"],
primaryColumns: {},
columns: [],
Expand All @@ -550,7 +550,7 @@ describe("Validates Derived Properties", () => {
{ id: 123, name: "John Doe" },
{ id: 234, name: "Jane Doe" },
],
sortedColumn: { column: "id", asc: false },
sortOrder: { column: "id", asc: false },
columnOrder: ["name", "id"],
primaryColumns: {
id: {
Expand Down Expand Up @@ -691,7 +691,7 @@ describe("Validates Derived Properties", () => {
operator: "OR",
},
],
sortedColumn: { column: "id", asc: false },
sortOrder: { column: "id", asc: false },
columnOrder: ["name", "id"],
primaryColumns: {
id: {
Expand Down
24 changes: 16 additions & 8 deletions app/client/src/widgets/TableWidget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
ColumnTypes,
CompactModeTypes,
CompactMode,
SortOrderTypes,
} from "components/designSystems/appsmith/TableComponent/Constants";
import tablePropertyPaneConfig from "./TablePropertyPaneConfig";
import { BatchPropertyUpdatePayload } from "actions/controlActions";
Expand Down Expand Up @@ -719,14 +720,21 @@ class TableWidget extends BaseWidget<TableWidgetProps, WidgetState> {

handleColumnSorting = (column: string, asc: boolean) => {
this.resetSelectedRowIndex();
if (column === "") {
this.props.updateWidgetMetaProperty("sortedColumn", undefined);
} else {
this.props.updateWidgetMetaProperty("sortedColumn", {
column: column,
asc: asc,
});
}
const sortOrderProps =
column === ""
? undefined
: {
column: column,
asc: asc,
order: asc ? SortOrderTypes.asc : SortOrderTypes.desc,
};
this.props.updateWidgetMetaProperty("sortOrder", sortOrderProps, {
triggerPropertyName: "onSort",
dynamicString: this.props.onSort,
event: {
type: EventType.ON_SORT,
},
});
};

handleResizeColumn = (columnSizeMap: { [key: string]: number }) => {
Expand Down