Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Refactor derived properties #37390

Draft
wants to merge 3 commits into
base: release
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import {
PaginationDirection,
TABLE_COLUMN_ORDER_KEY,
} from "../constants";
import derivedProperties from "./parseDerivedProperties";
import {
deleteLocalTableColumnOrderByWidgetId,
generateLocalNewColumnOrderFromStickyValue,
Expand All @@ -61,7 +60,7 @@ import {
} from "./utilities";
import type { BatchPropertyUpdatePayload } from "actions/controlActions";
import equal from "fast-deep-equal/es6";
import { sanitizeKey } from "widgets/WidgetUtils";
import { parseDerivedProperties, sanitizeKey } from "widgets/WidgetUtils";
import {
PlainTextCell,
URLCell,
Expand All @@ -82,6 +81,7 @@ import * as config from "../config";
import { getAnvilWidgetDOMId } from "layoutSystems/common/utils/LayoutElementPositionsObserver/utils";
import type { CanvasWidgetsReduxState } from "reducers/entityReducers/canvasWidgetsReducer";
import { klonaRegularWithTelemetry } from "utils/helpers";
import derivedPropertyFns from "./derived";

const ReactTableComponent = lazy(async () =>
retryPromise(async () => import("../component")),
Expand Down Expand Up @@ -194,20 +194,22 @@ export class WDSTableWidget extends BaseWidget<TableWidgetProps, WidgetState> {
}

static getDerivedPropertiesMap() {
const parsedDerivedProperties = parseDerivedProperties(derivedPropertyFns);

return {
selectedRow: `{{(()=>{${derivedProperties.getSelectedRow}})()}}`,
triggeredRow: `{{(()=>{${derivedProperties.getTriggeredRow}})()}}`,
selectedRows: `{{(()=>{${derivedProperties.getSelectedRows}})()}}`,
selectedRow: `{{(()=>{${parsedDerivedProperties.getSelectedRow}})()}}`,
triggeredRow: `{{(()=>{${parsedDerivedProperties.getTriggeredRow}})()}}`,
selectedRows: `{{(()=>{${parsedDerivedProperties.getSelectedRows}})()}}`,
triggerRowSelection: "{{!!this.onRowSelected}}",
processedTableData: `{{(()=>{${derivedProperties.getProcessedTableData}})()}}`,
orderedTableColumns: `{{(()=>{${derivedProperties.getOrderedTableColumns}})()}}`,
filteredTableData: `{{(()=>{ ${derivedProperties.getFilteredTableData}})()}}`,
updatedRows: `{{(()=>{ ${derivedProperties.getUpdatedRows}})()}}`,
updatedRowIndices: `{{(()=>{ ${derivedProperties.getUpdatedRowIndices}})()}}`,
updatedRow: `{{(()=>{ ${derivedProperties.getUpdatedRow}})()}}`,
pageOffset: `{{(()=>{${derivedProperties.getPageOffset}})()}}`,
isEditableCellsValid: `{{(()=>{ ${derivedProperties.getEditableCellValidity}})()}}`,
tableHeaders: `{{(()=>{${derivedProperties.getTableHeaders}})()}}`,
processedTableData: `{{(()=>{${parsedDerivedProperties.getProcessedTableData}})()}}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix: Cannot access this.onRowSelected in a static method

The reference to this.onRowSelected inside the static method getDerivedPropertiesMap is invalid since this is undefined in static context.

Apply this diff to fix the issue:

-static getDerivedPropertiesMap() {
+getDerivedPropertiesMap() {
...
  triggerRowSelection: "{{!!this.onRowSelected}}",
...
}

Consider moving triggerRowSelection to an instance method or refactoring the code to avoid using this in a static context.

Committable suggestion skipped: line range outside the PR's diff.

orderedTableColumns: `{{(()=>{${parsedDerivedProperties.getOrderedTableColumns}})()}}`,
filteredTableData: `{{(()=>{ ${parsedDerivedProperties.getFilteredTableData}})()}}`,
updatedRows: `{{(()=>{ ${parsedDerivedProperties.getUpdatedRows}})()}}`,
updatedRowIndices: `{{(()=>{ ${parsedDerivedProperties.getUpdatedRowIndices}})()}}`,
updatedRow: `{{(()=>{ ${parsedDerivedProperties.getUpdatedRow}})()}}`,
pageOffset: `{{(()=>{${parsedDerivedProperties.getPageOffset}})()}}`,
isEditableCellsValid: `{{(()=>{ ${parsedDerivedProperties.getEditableCellValidity}})()}}`,
tableHeaders: `{{(()=>{${parsedDerivedProperties.getTableHeaders}})()}}`,
};
}

Expand Down

This file was deleted.

This file was deleted.

7 changes: 5 additions & 2 deletions app/client/src/widgets/DatePickerWidget2/widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
import type { DatePickerType } from "../constants";
import { TimePrecision } from "../constants";
import { DateFormatOptions } from "./constants";
import derivedProperties from "./parseDerivedProperties";
import derivedPropertyFns from "./derived";
import { parseDerivedProperties } from "widgets/WidgetUtils";
import { isAutoLayout } from "layoutSystems/autolayout/utils/flexWidgetUtils";
import type {
AnvilConfig,
Expand Down Expand Up @@ -632,8 +633,10 @@ class DatePickerWidget extends BaseWidget<DatePickerWidget2Props, WidgetState> {
}

static getDerivedPropertiesMap(): DerivedPropertiesMap {
const parsedDerivedProperties = parseDerivedProperties(derivedPropertyFns);

return {
isValid: `{{(()=>{${derivedProperties.isValidDate}})()}}`,
isValid: `{{(()=>{${parsedDerivedProperties.isValidDate}})()}}`,
selectedDate: `{{ this.value ? moment(this.value).toISOString() : "" }}`,
formattedDate: `{{ this.value ? moment(this.value).format(this.dateFormat) : "" }}`,
};
Expand Down

This file was deleted.

This file was deleted.

13 changes: 8 additions & 5 deletions app/client/src/widgets/ListWidget/widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ import ListPagination, {
ServerSideListPagination,
} from "../component/ListPagination";
import IconSVG from "../icon.svg";
import derivedProperties from "./parseDerivedProperties";
import derivedPropertyFns from "./derived";
import { parseDerivedProperties } from "widgets/WidgetUtils";
import {
PropertyPaneContentConfig,
PropertyPaneStyleConfig,
Expand Down Expand Up @@ -606,11 +607,13 @@ class ListWidget extends BaseWidget<ListWidgetProps<WidgetProps>, WidgetState> {
}

static getDerivedPropertiesMap() {
const parsedDerivedProperties = parseDerivedProperties(derivedPropertyFns);

return {
pageSize: `{{(()=>{${derivedProperties.getPageSize}})()}}`,
selectedItem: `{{(()=>{${derivedProperties.getSelectedItem}})()}}`,
items: `{{(() => {${derivedProperties.getItems}})()}}`,
childAutoComplete: `{{(() => {${derivedProperties.getChildAutoComplete}})()}}`,
pageSize: `{{(()=>{${parsedDerivedProperties.getPageSize}})()}}`,
selectedItem: `{{(()=>{${parsedDerivedProperties.getSelectedItem}})()}}`,
items: `{{(() => {${parsedDerivedProperties.getItems}})()}}`,
childAutoComplete: `{{(() => {${parsedDerivedProperties.getChildAutoComplete}})()}}`,
};
}

Expand Down
40 changes: 0 additions & 40 deletions app/client/src/widgets/ListWidget/widget/parseDerivedProperties.ts

This file was deleted.

Loading
Loading