PromucFlow_constructor/app/client/src/widgets/TableWidgetV2/widget/propertyUtils.ts

1377 lines
35 KiB
TypeScript
Raw Normal View History

import { Alignment } from "@blueprintjs/core";
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com> ## Description This PR upgrades Prettier to v2 + enforces TypeScript’s [`import type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export) syntax where applicable. It’s submitted as a separate PR so we can merge it easily. As a part of this PR, we reformat the codebase heavily: - add `import type` everywhere where it’s required, and - re-format the code to account for Prettier 2’s breaking changes: https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes This PR is submitted against `release` to make sure all new code by team members will adhere to new formatting standards, and we’ll have fewer conflicts when merging `bundle-optimizations` into `release`. (I’ll merge `release` back into `bundle-optimizations` once this PR is merged.) ### Why is this needed? This PR is needed because, for the Lodash optimization from https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3, we need to use `import type`. Otherwise, `babel-plugin-lodash` complains that `LoDashStatic` is not a lodash function. However, just using `import type` in the current codebase will give you this: <img width="962" alt="Screenshot 2023-03-08 at 17 45 59" src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png"> That’s because Prettier 1 can’t parse `import type` at all. To parse it, we need to upgrade to Prettier 2. ### Why enforce `import type`? Apart from just enabling `import type` support, this PR enforces specifying `import type` everywhere it’s needed. (Developers will get immediate TypeScript and ESLint errors when they forget to do so.) I’m doing this because I believe `import type` improves DX and makes refactorings easier. Let’s say you had a few imports like below. Can you tell which of these imports will increase the bundle size? (Tip: it’s not all of them!) ```ts // app/client/src/workers/Linting/utils.ts import { Position } from "codemirror"; import { LintError as JSHintError, LintOptions } from "jshint"; import { get, isEmpty, isNumber, keys, last, set } from "lodash"; ``` It’s pretty hard, right? What about now? ```ts // app/client/src/workers/Linting/utils.ts import type { Position } from "codemirror"; import type { LintError as JSHintError, LintOptions } from "jshint"; import { get, isEmpty, isNumber, keys, last, set } from "lodash"; ``` Now, it’s clear that only `lodash` will be bundled. This helps developers to see which imports are problematic, but it _also_ helps with refactorings. Now, if you want to see where `codemirror` is bundled, you can just grep for `import \{.*\} from "codemirror"` – and you won’t get any type-only imports. This also helps (some) bundlers. Upon transpiling, TypeScript erases type-only imports completely. In some environment (not ours), this makes the bundle smaller, as the bundler doesn’t need to bundle type-only imports anymore. ## Type of change - Chore (housekeeping or task changes that don't impact user perception) ## How Has This Been Tested? This was tested to not break the build. ### 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 - [ ] 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 - [ ] 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 --------- Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
import type { ColumnProperties } from "../component/Constants";
fix: null check before accessing accessing properties in table and phone input widget (#22218) ## Description Fixes #22207 Fixes #22209 The [sentry](https://github.com/appsmithorg/appsmith/issues/22207) issue occurred because the code was trying to access the `sticky` property of a column that did not exist in the table widget. Hence to mitigate this I have added an optional chaining check. This PR also fixes #22209 by adding optional chaining while accessing the `text` prop in the phone input widget ## Type of change - Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? - Manual - Check that the console error is not thrown similar to the above sentry issue. ### 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 - [x] I have performed a self-review of my own code - [ ] 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 - [ ] 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-04-11 14:23:14 +00:00
import { StickyType } from "../component/Constants";
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com> ## Description This PR upgrades Prettier to v2 + enforces TypeScript’s [`import type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export) syntax where applicable. It’s submitted as a separate PR so we can merge it easily. As a part of this PR, we reformat the codebase heavily: - add `import type` everywhere where it’s required, and - re-format the code to account for Prettier 2’s breaking changes: https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes This PR is submitted against `release` to make sure all new code by team members will adhere to new formatting standards, and we’ll have fewer conflicts when merging `bundle-optimizations` into `release`. (I’ll merge `release` back into `bundle-optimizations` once this PR is merged.) ### Why is this needed? This PR is needed because, for the Lodash optimization from https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3, we need to use `import type`. Otherwise, `babel-plugin-lodash` complains that `LoDashStatic` is not a lodash function. However, just using `import type` in the current codebase will give you this: <img width="962" alt="Screenshot 2023-03-08 at 17 45 59" src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png"> That’s because Prettier 1 can’t parse `import type` at all. To parse it, we need to upgrade to Prettier 2. ### Why enforce `import type`? Apart from just enabling `import type` support, this PR enforces specifying `import type` everywhere it’s needed. (Developers will get immediate TypeScript and ESLint errors when they forget to do so.) I’m doing this because I believe `import type` improves DX and makes refactorings easier. Let’s say you had a few imports like below. Can you tell which of these imports will increase the bundle size? (Tip: it’s not all of them!) ```ts // app/client/src/workers/Linting/utils.ts import { Position } from "codemirror"; import { LintError as JSHintError, LintOptions } from "jshint"; import { get, isEmpty, isNumber, keys, last, set } from "lodash"; ``` It’s pretty hard, right? What about now? ```ts // app/client/src/workers/Linting/utils.ts import type { Position } from "codemirror"; import type { LintError as JSHintError, LintOptions } from "jshint"; import { get, isEmpty, isNumber, keys, last, set } from "lodash"; ``` Now, it’s clear that only `lodash` will be bundled. This helps developers to see which imports are problematic, but it _also_ helps with refactorings. Now, if you want to see where `codemirror` is bundled, you can just grep for `import \{.*\} from "codemirror"` – and you won’t get any type-only imports. This also helps (some) bundlers. Upon transpiling, TypeScript erases type-only imports completely. In some environment (not ours), this makes the bundle smaller, as the bundler doesn’t need to bundle type-only imports anymore. ## Type of change - Chore (housekeeping or task changes that don't impact user perception) ## How Has This Been Tested? This was tested to not break the build. ### 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 - [ ] 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 - [ ] 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 --------- Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
import { CellAlignmentTypes } from "../component/Constants";
import type { TableWidgetProps } from "../constants";
import { ColumnTypes, InlineEditingSaveOptions } from "../constants";
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 11:42:46 +00:00
import _, { findIndex, get, isBoolean } from "lodash";
import { Colors } from "constants/Colors";
import {
combineDynamicBindings,
getDynamicBindings,
} from "utils/DynamicBindingUtils";
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 11:42:46 +00:00
import {
createEditActionColumn,
generateNewColumnOrderFromStickyValue,
} from "./utilities";
chore: Move the widget config to widget class (#26073) ## Description - Remove the config objects from widget and config maps from the widget factory. - Introduce methods in widget development API to dynamically fetch this items. - freeze the widget configuration. #### PR fixes following issue(s) Fixes https://github.com/appsmithorg/appsmith/issues/26008 > 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 - [ ] Jest - [ ] 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 - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] 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: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [x] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [x] 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
2023-09-06 12:15:04 +00:00
import type { PropertyUpdates } from "WidgetProvider/constants";
import { MenuItemsSource } from "widgets/MenuButtonWidget/constants";
import type { ValidationConfig } from "constants/PropertyControlConstants";
import type { ValidationResponse } from "constants/WidgetValidation";
export function totalRecordsCountValidation(
value: unknown,
props: TableWidgetProps,
_?: any,
) {
const ERROR_MESSAGE = "This value must be a number";
const defaultValue = 0;
/*
* Undefined, null and empty string
*/
if (_.isNil(value) || value === "") {
return {
isValid: true,
parsed: defaultValue,
messages: [],
};
} else if (
(!_.isFinite(value) && !_.isString(value)) ||
(_.isString(value) && !/^\d+\.?\d*$/.test(value as string))
) {
/*
* objects, array, string (but not cast-able to number type)
*/
return {
isValid: false,
parsed: defaultValue,
messages: [{ name: "ValidationError", message: ERROR_MESSAGE }],
};
} else {
/*
* Number or number type cast-able
*/
return {
isValid: true,
parsed: Number(value),
messages: [],
};
}
}
export function uniqueColumnNameValidation(
value: unknown,
props: TableWidgetProps,
_?: any,
) {
const tableColumnLabels = _.map(value, "label");
const duplicates = tableColumnLabels.find(
(val: string, index: number, arr: string[]) => arr.indexOf(val) !== index,
);
if (value && !!duplicates) {
return {
isValid: false,
parsed: value,
messages: ["Column names should be unique."],
};
} else {
return {
isValid: true,
parsed: value,
messages: [""],
};
}
}
export function uniqueColumnAliasValidation(
value: unknown,
props: TableWidgetProps,
_?: any,
) {
const aliases = _.map(Object.values(props.primaryColumns), "alias");
const duplicates = aliases.find(
(val: string, index: number, arr: string[]) => arr.indexOf(val) !== index,
);
if (!value) {
return {
isValid: false,
parsed: value,
messages: ["Property name should not be empty."],
};
} else if (value && !!duplicates) {
return {
isValid: false,
parsed: value,
messages: ["Property names should be unique."],
};
} else {
return {
isValid: true,
parsed: value,
messages: [""],
};
}
}
/*
* Hook to update all column styles, when global table styles are updated.
*/
export const updateColumnStyles = (
props: TableWidgetProps,
propertyPath: string,
propertyValue: any,
): Array<{ propertyPath: string; propertyValue: any }> | undefined => {
const { primaryColumns = {} } = props;
const propertiesToUpdate: Array<{
propertyPath: string;
propertyValue: any;
}> = [];
const styleName = propertyPath.split(".").shift();
// TODO: Figure out how propertyPaths will work when a nested property control is updating another property
if (primaryColumns && styleName) {
Object.values(primaryColumns).map((column: ColumnProperties) => {
const propertyPath = `primaryColumns.${column.id}.${styleName}`;
const notADynamicBinding =
!props.dynamicBindingPathList ||
props.dynamicBindingPathList.findIndex(
(item) => item.key === propertyPath,
) === -1;
if (notADynamicBinding) {
propertiesToUpdate.push({
propertyPath,
propertyValue,
});
}
});
if (propertiesToUpdate.length > 0) {
return propertiesToUpdate;
}
} else {
return;
}
};
// Select default Icon Alignment when an icon is chosen
export function updateIconAlignment(
props: TableWidgetProps,
propertyPath: string,
propertyValue: string,
) {
const property = getBasePropertyPath(propertyPath);
const iconAlign = get(props, `${property}.iconAlign`, "");
const propertiesToUpdate = [{ propertyPath, propertyValue }];
if (iconAlign) {
propertiesToUpdate.push({
propertyPath: "iconAlign",
propertyValue: Alignment.LEFT,
});
}
return propertiesToUpdate;
}
/*
* Hook that updates columns order when a new column
* gets added to the primaryColumns
*/
export const updateColumnOrderHook = (
props: TableWidgetProps,
propertyPath: string,
propertyValue: any,
): Array<{ propertyPath: string; propertyValue: any }> | undefined => {
const propertiesToUpdate: Array<{
propertyPath: string;
propertyValue: any;
}> = [];
if (props && propertyValue && /^primaryColumns\.\w+$/.test(propertyPath)) {
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 11:42:46 +00:00
const newColumnOrder = [...(props.columnOrder || [])];
const rightColumnIndex = findIndex(
newColumnOrder,
fix: null check before accessing accessing properties in table and phone input widget (#22218) ## Description Fixes #22207 Fixes #22209 The [sentry](https://github.com/appsmithorg/appsmith/issues/22207) issue occurred because the code was trying to access the `sticky` property of a column that did not exist in the table widget. Hence to mitigate this I have added an optional chaining check. This PR also fixes #22209 by adding optional chaining while accessing the `text` prop in the phone input widget ## Type of change - Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? - Manual - Check that the console error is not thrown similar to the above sentry issue. ### 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 - [x] I have performed a self-review of my own code - [ ] 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 - [ ] 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-04-11 14:23:14 +00:00
(colName: string) =>
props.primaryColumns[colName]?.sticky === StickyType.RIGHT,
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 11:42:46 +00:00
);
if (rightColumnIndex !== -1) {
newColumnOrder.splice(rightColumnIndex, 0, propertyValue.id);
} else {
newColumnOrder.splice(newColumnOrder.length, 0, propertyValue.id);
}
propertiesToUpdate.push({
propertyPath: "columnOrder",
propertyValue: newColumnOrder,
});
const newId = propertyValue.id;
if (newId) {
// sets default value for some properties
propertyValue.labelColor = Colors.WHITE;
propertiesToUpdate.push({
propertyPath: `primaryColumns.${newId}`,
propertyValue,
});
}
}
if (propertiesToUpdate.length > 0) {
return propertiesToUpdate;
} else {
return;
}
};
const EDITABLITY_PATH_REGEX = /^primaryColumns\.(\w+)\.isEditable$/;
function isMatchingEditablePath(propertyPath: string) {
return (
EDITABLITY_PATH_REGEX.test(propertyPath) ||
CELL_EDITABLITY_PATH_REGEX.test(propertyPath)
);
}
export const updateInlineEditingOptionDropdownVisibilityHook = (
props: TableWidgetProps,
propertyPath: string,
propertyValue: any,
chore: Make use of widget methods to get binding properties in sniping mode (#25429) ## Description - Refactoring sniping mode code to fix abstraction leak and to optimise the process further. #### PR fixes following issue(s) Fixes #24737 #### 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 - Chore (housekeeping or task changes that don't impact user perception) > > > ## 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 > 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 - [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 - [ ] 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/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#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
2023-07-26 05:38:11 +00:00
): Array<PropertyUpdates> | undefined => {
let propertiesToUpdate = [];
if (
props &&
!props.showInlineEditingOptionDropdown &&
propertyValue &&
isMatchingEditablePath(propertyPath)
) {
propertiesToUpdate.push({
propertyPath: `showInlineEditingOptionDropdown`,
propertyValue: true,
});
}
if (
props &&
isMatchingEditablePath(propertyPath) &&
props.inlineEditingSaveOption === InlineEditingSaveOptions.ROW_LEVEL &&
isBoolean(propertyValue)
) {
if (propertyValue) {
const editActionsColumn = Object.values(props.primaryColumns).find(
(column) => column.columnType === ColumnTypes.EDIT_ACTIONS,
);
if (!editActionsColumn) {
propertiesToUpdate = [
...propertiesToUpdate,
...createEditActionColumn(props),
];
}
} else {
const regex = /^primaryColumns\.(\w+)\.(\w+)$/;
const columnIdMatcher = propertyPath.match(regex);
const columnId = columnIdMatcher && columnIdMatcher[1];
const isAtleastOneColumnEditablePresent = Object.values(
props.primaryColumns,
).some((column) => column.id !== columnId && column.isEditable);
if (!isAtleastOneColumnEditablePresent) {
const columnsArray = Object.values(props.primaryColumns);
const edtiActionColumn = columnsArray.find(
(column) => column.columnType === ColumnTypes.EDIT_ACTIONS,
);
if (edtiActionColumn && edtiActionColumn.id) {
const newColumnOrder = _.difference(props.columnOrder, [
edtiActionColumn.id,
]);
propertiesToUpdate = [
...propertiesToUpdate,
{
propertyPath: `primaryColumns.${edtiActionColumn.id}`,
shouldDeleteProperty: true,
},
{
propertyPath: "columnOrder",
propertyValue: newColumnOrder,
},
];
}
}
}
}
if (propertiesToUpdate.length) {
return propertiesToUpdate;
}
return;
};
const CELL_EDITABLITY_PATH_REGEX = /^primaryColumns\.(\w+)\.isCellEditable$/;
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 11:42:46 +00:00
/**
* Hook that updates frozen column's old indices and also adds columns to the frozen positions.
*/
export const updateColumnOrderWhenFrozen = (
props: TableWidgetProps,
propertyPath: string,
propertyValue: string,
) => {
if (props && props.columnOrder) {
const newColumnOrder = generateNewColumnOrderFromStickyValue(
props.primaryColumns,
props.columnOrder,
propertyPath.split(".")[1],
propertyValue,
);
return [
{
propertyPath: "columnOrder",
propertyValue: newColumnOrder,
},
];
}
};
/*
* Hook that updates column level editability when cell level editability is
* updaed.
*/
export const updateColumnLevelEditability = (
props: TableWidgetProps,
propertyPath: string,
propertyValue: any,
): Array<{ propertyPath: string; propertyValue: any }> | undefined => {
if (
props &&
CELL_EDITABLITY_PATH_REGEX.test(propertyPath) &&
isBoolean(propertyValue)
) {
const match = CELL_EDITABLITY_PATH_REGEX.exec(propertyPath) || [];
const columnIdHash = match[1];
if (columnIdHash) {
return [
{
propertyPath: `primaryColumns.${columnIdHash}.isEditable`,
propertyValue: propertyValue,
},
];
} else {
return;
}
} else {
return;
}
};
/*
* Gets the base property path excluding the current property.
* For example, for `primaryColumns[5].computedValue` it will return
* `primaryColumns[5]`
*/
export const getBasePropertyPath = (
propertyPath: string,
): string | undefined => {
const propertyPathRegex = /^(.*)\.\w+$/g;
const matches = [...propertyPath.matchAll(propertyPathRegex)][0];
if (matches && _.isArray(matches) && matches.length === 2) {
return matches[1];
} else {
return;
}
};
/*
* Function to check if column should be hidden, based on
* the given columnTypes
*/
export const hideByColumnType = (
props: TableWidgetProps,
propertyPath: string,
columnTypes: ColumnTypes[],
shouldUsePropertyPath?: boolean,
) => {
let baseProperty;
if (shouldUsePropertyPath) {
baseProperty = propertyPath;
} else {
baseProperty = getBasePropertyPath(propertyPath);
}
const columnType = get(props, `${baseProperty}.columnType`, "");
return !columnTypes.includes(columnType);
};
/*
* Function to check if column should be shown, based on
* the given columnTypes
*/
export const showByColumnType = (
props: TableWidgetProps,
propertyPath: string,
columnTypes: ColumnTypes[],
shouldUsePropertyPath?: boolean,
) => {
let baseProperty;
if (shouldUsePropertyPath) {
baseProperty = propertyPath;
} else {
baseProperty = getBasePropertyPath(propertyPath);
}
const columnType = get(props, `${baseProperty}.columnType`, "");
return columnTypes.includes(columnType);
};
export const SelectColumnOptionsValidations = (
value: unknown,
props: any,
_?: any,
) => {
let isValid = true;
let parsed = value;
let message = "";
const expectedMessage = "value should be an array of string";
if (typeof value === "string" && value.trim() !== "") {
/*
* when value is a string
*/
try {
/*
* when the value is an array of string
*/
value = JSON.parse(value);
} catch (e) {
/*
* when the value is an comma seperated strings
*/
value = (value as string).split(",").map((str) => str.trim());
}
}
/*
* when value is null, undefined and empty string
*/
if (_.isNil(value) || value === "") {
isValid = true;
parsed = [];
} else if (_.isArray(value)) {
const hasStringOrNumber = (value as []).every(
(item) => _.isString(item) || _.isFinite(item),
);
isValid = hasStringOrNumber;
parsed = value;
message = hasStringOrNumber ? "" : expectedMessage;
} else if (typeof value === "number") {
isValid = true;
parsed = [value];
} else {
isValid = false;
parsed = value;
message = expectedMessage;
}
return {
isValid,
parsed,
messages: [message],
};
};
/*
* Hook that updates column isDiabled binding when columnType is
* changed to ColumnTypes.EDIT_ACTIONS.
*/
export const updateInlineEditingSaveOptionHook = (
props: TableWidgetProps,
propertyPath: string,
propertyValue: any,
chore: Make use of widget methods to get binding properties in sniping mode (#25429) ## Description - Refactoring sniping mode code to fix abstraction leak and to optimise the process further. #### PR fixes following issue(s) Fixes #24737 #### 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 - Chore (housekeeping or task changes that don't impact user perception) > > > ## 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 > 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 - [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 - [ ] 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/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#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
2023-07-26 05:38:11 +00:00
): Array<PropertyUpdates> | undefined => {
if (propertyValue !== InlineEditingSaveOptions.ROW_LEVEL) {
const columnsArray = Object.values(props.primaryColumns);
const edtiActionColumn = columnsArray.find(
(column) => column.columnType === ColumnTypes.EDIT_ACTIONS,
);
if (edtiActionColumn && edtiActionColumn.id) {
const newColumnOrder = _.difference(props.columnOrder, [
edtiActionColumn.id,
]);
return [
{
propertyPath: `primaryColumns.${edtiActionColumn.id}`,
shouldDeleteProperty: true,
},
{
propertyPath: "columnOrder",
propertyValue: newColumnOrder,
},
];
}
} else {
const columnIdMatcher = propertyPath.match(EDITABLITY_PATH_REGEX);
const columnId = columnIdMatcher && columnIdMatcher[1];
const isAtleastOneEditableColumnPresent = Object.values(
props.primaryColumns,
).some((column) => column.id !== columnId && column.isEditable);
if (isAtleastOneEditableColumnPresent) {
return createEditActionColumn(props);
}
}
};
export const updateNumberColumnTypeTextAlignment = (
props: TableWidgetProps,
propertyPath: string,
propertyValue: any,
): Array<{ propertyPath: string; propertyValue: any }> | undefined => {
const baseProperty = getBasePropertyPath(propertyPath);
if (propertyValue === ColumnTypes.NUMBER) {
return [
{
propertyPath: `${baseProperty}.horizontalAlignment`,
propertyValue: CellAlignmentTypes.RIGHT,
},
];
} else {
return [
{
propertyPath: `${baseProperty}.horizontalAlignment`,
propertyValue: CellAlignmentTypes.LEFT,
},
];
}
return;
};
/**
* updates theme stylesheets
*
* @param props
* @param propertyPath
* @param propertyValue
*/
export function updateThemeStylesheetsInColumns(
props: TableWidgetProps,
propertyPath: string,
propertyValue: any,
chore: Make use of widget methods to get binding properties in sniping mode (#25429) ## Description - Refactoring sniping mode code to fix abstraction leak and to optimise the process further. #### PR fixes following issue(s) Fixes #24737 #### 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 - Chore (housekeeping or task changes that don't impact user perception) > > > ## 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 > 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 - [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 - [ ] 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/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#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
2023-07-26 05:38:11 +00:00
): Array<PropertyUpdates> | undefined {
const regex = /^primaryColumns\.(\w+)\.(.*)$/;
const matches = propertyPath.match(regex);
const columnId = matches?.[1];
const columnProperty = matches?.[2];
if (columnProperty === "columnType") {
chore: Make use of widget methods to get binding properties in sniping mode (#25429) ## Description - Refactoring sniping mode code to fix abstraction leak and to optimise the process further. #### PR fixes following issue(s) Fixes #24737 #### 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 - Chore (housekeeping or task changes that don't impact user perception) > > > ## 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 > 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 - [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 - [ ] 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/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#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
2023-07-26 05:38:11 +00:00
const propertiesToUpdate: Array<PropertyUpdates> = [];
const oldColumnType = get(props, `primaryColumns.${columnId}.columnType`);
const newColumnType = propertyValue;
const propertiesToRemove = Object.keys(
props.childStylesheet[oldColumnType] || {},
);
const propertiesToAdd = Object.keys(
props.childStylesheet[newColumnType] || {},
);
propertiesToRemove.forEach((propertyKey) => {
propertiesToUpdate.push({
propertyPath: `primaryColumns.${columnId}.${propertyKey}`,
shouldDeleteProperty: true,
});
});
propertiesToAdd.forEach((propertyKey) => {
const { jsSnippets, stringSegments } = getDynamicBindings(
props.childStylesheet[newColumnType][propertyKey],
);
const js = combineDynamicBindings(jsSnippets, stringSegments);
propertiesToUpdate.push({
propertyPath: `primaryColumns.${columnId}.${propertyKey}`,
propertyValue: `{{${props.widgetName}.processedTableData.map((currentRow, currentIndex) => ( ${js}))}}`,
});
});
if (propertiesToUpdate.length) {
/*
* Temporary patch to make evaluations to compute inverseDependencyMap when
* column type is changed.
* TODO(Balaji): remove once https://github.com/appsmithorg/appsmith/issues/14436 gets fixed
*/
propertiesToUpdate.push({
propertyPath: `primaryColumns.${columnId}.customAlias`,
propertyValue: "",
});
return propertiesToUpdate;
}
}
}
/**
* A function for updateHook to remove the boxShadowColor property post migration.
* @param props
* @param propertyPath
* @param propertyValue
*/
export const removeBoxShadowColorProp = (
props: TableWidgetProps,
propertyPath: string,
) => {
const boxShadowColorPath = replacePropertyName(
propertyPath,
"boxShadowColor",
);
return [
{
propertyPath: boxShadowColorPath,
propertyValue: undefined,
},
];
};
/**
* This function will replace the property present at the end of the propertyPath with the targetPropertyName.
* e.g.
* propertyPath = primaryColumns.action.boxShadow
* Running this function will give the new propertyPath like below:
* propertyPath = primaryColumns.action.boxShadowColor
*
* @param propertyPath The property path inside a widget
* @param targetPropertyName Target property name
* @returns New property path with target property name at the end.
*/
export const replacePropertyName = (
propertyPath: string,
targetPropertyName: string,
) => {
const path = propertyPath.split(".");
path.pop();
return `${path.join(".")}.${targetPropertyName}`;
};
export const updateCustomColumnAliasOnLabelChange = (
props: TableWidgetProps,
propertyPath: string,
propertyValue: unknown,
chore: Make use of widget methods to get binding properties in sniping mode (#25429) ## Description - Refactoring sniping mode code to fix abstraction leak and to optimise the process further. #### PR fixes following issue(s) Fixes #24737 #### 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 - Chore (housekeeping or task changes that don't impact user perception) > > > ## 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 > 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 - [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 - [ ] 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/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#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
2023-07-26 05:38:11 +00:00
): Array<PropertyUpdates> | undefined => {
// alias will be updated along with label change only for custom columns
const regex = /^primaryColumns\.(customColumn\d+)\.label$/;
if (propertyPath?.length && regex.test(propertyPath)) {
return [
{
propertyPath: propertyPath.replace("label", "alias"),
propertyValue: propertyValue,
},
];
}
};
export const allowedFirstDayOfWeekRange = (value: number) => {
const allowedValues = [0, 1, 2, 3, 4, 5, 6];
const isValid = allowedValues.includes(Number(value));
return {
isValid: isValid,
parsed: isValid ? Number(value) : 0,
messages: isValid ? [] : ["Number should be between 0-6."],
};
};
export const hideByMenuItemsSource = (
props: TableWidgetProps,
propertyPath: string,
menuItemsSource: MenuItemsSource,
) => {
const baseProperty = getBasePropertyPath(propertyPath);
const currentMenuItemsSource = get(
props,
`${baseProperty}.menuItemsSource`,
"",
);
return currentMenuItemsSource === menuItemsSource;
};
export const hideIfMenuItemsSourceDataIsFalsy = (
props: TableWidgetProps,
propertyPath: string,
) => {
const baseProperty = getBasePropertyPath(propertyPath);
const sourceData = get(props, `${baseProperty}.sourceData`, "");
return !sourceData;
};
export const updateMenuItemsSource = (
props: TableWidgetProps,
propertyPath: string,
propertyValue: unknown,
): Array<{ propertyPath: string; propertyValue: unknown }> | undefined => {
const propertiesToUpdate: Array<{
propertyPath: string;
propertyValue: unknown;
}> = [];
const baseProperty = getBasePropertyPath(propertyPath);
const menuItemsSource = get(props, `${baseProperty}.menuItemsSource`);
if (propertyValue === ColumnTypes.MENU_BUTTON && !menuItemsSource) {
// Sets the default value for menuItemsSource to static when
// selecting the menu button column type for the first time
propertiesToUpdate.push({
propertyPath: `${baseProperty}.menuItemsSource`,
propertyValue: MenuItemsSource.STATIC,
});
} else {
const sourceData = get(props, `${baseProperty}.sourceData`);
const configureMenuItems = get(props, `${baseProperty}.configureMenuItems`);
const isMenuItemsSourceChangedFromStaticToDynamic =
menuItemsSource === MenuItemsSource.STATIC &&
propertyValue === MenuItemsSource.DYNAMIC;
if (isMenuItemsSourceChangedFromStaticToDynamic) {
if (!sourceData) {
propertiesToUpdate.push({
propertyPath: `${baseProperty}.sourceData`,
propertyValue: [],
});
}
if (!configureMenuItems) {
propertiesToUpdate.push({
propertyPath: `${baseProperty}.configureMenuItems`,
propertyValue: {
feat: [epic] appsmith design system version 2 deduplication (#22030) ## Description ### Fixes - [x] https://github.com/appsmithorg/appsmith/issues/19383 - [x] https://github.com/appsmithorg/appsmith/issues/19384 - [x] https://github.com/appsmithorg/appsmith/issues/19385 - [x] https://github.com/appsmithorg/appsmith/issues/19386 - [x] https://github.com/appsmithorg/appsmith/issues/19387 - [x] https://github.com/appsmithorg/appsmith/issues/19388 - [x] https://github.com/appsmithorg/appsmith/issues/19389 - [x] https://github.com/appsmithorg/appsmith/issues/19390 - [x] https://github.com/appsmithorg/appsmith/issues/19391 - [x] https://github.com/appsmithorg/appsmith/issues/19392 - [x] https://github.com/appsmithorg/appsmith/issues/19393 - [x] https://github.com/appsmithorg/appsmith/issues/19394 - [x] https://github.com/appsmithorg/appsmith/issues/19395 - [x] https://github.com/appsmithorg/appsmith/issues/19396 - [x] https://github.com/appsmithorg/appsmith/issues/19397 - [x] https://github.com/appsmithorg/appsmith/issues/19398 - [x] https://github.com/appsmithorg/appsmith/issues/19399 - [x] https://github.com/appsmithorg/appsmith/issues/19400 - [x] https://github.com/appsmithorg/appsmith/issues/19401 - [x] https://github.com/appsmithorg/appsmith/issues/19402 - [x] https://github.com/appsmithorg/appsmith/issues/19403 - [x] https://github.com/appsmithorg/appsmith/issues/19404 - [x] https://github.com/appsmithorg/appsmith/issues/19405 - [x] https://github.com/appsmithorg/appsmith/issues/19406 - [x] https://github.com/appsmithorg/appsmith/issues/19407 - [x] https://github.com/appsmithorg/appsmith/issues/19408 - [x] https://github.com/appsmithorg/appsmith/issues/19409 Fixes # (issue) > 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 ## How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Provide instructions, so we can reproduce. > Please also list any relevant details for your test configuration. > Delete anything that is not important - Manual - Jest - 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 - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] 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 --------- Co-authored-by: Ankita Kinger <ankita@appsmith.com> Co-authored-by: akash-codemonk <67054171+akash-codemonk@users.noreply.github.com> Co-authored-by: Tanvi Bhakta <tanvi@appsmith.com> Co-authored-by: Arsalan <arsalanyaldram0211@outlook.com> Co-authored-by: Aman Agarwal <aman@appsmith.com> Co-authored-by: Rohit Agarwal <rohit_agarwal@live.in> Co-authored-by: Nilesh Sarupriya <nilesh@appsmith.com> Co-authored-by: Nilesh Sarupriya <20905988+nsarupr@users.noreply.github.com> Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com> Co-authored-by: Aishwarya UR <aishwarya@appsmith.com> Co-authored-by: Parthvi Goswami <parthvigoswami@Parthvis-MacBook-Pro.local> Co-authored-by: Vijetha-Kaja <vijetha@appsmith.com> Co-authored-by: Parthvi <80334441+Parthvi12@users.noreply.github.com> Co-authored-by: Apple <nandan@thinkify.io> Co-authored-by: Saroj <43822041+sarojsarab@users.noreply.github.com> Co-authored-by: Sangeeth Sivan <74818788+berzerkeer@users.noreply.github.com> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Aishwarya-U-R <91450662+Aishwarya-U-R@users.noreply.github.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: Preet Sidhu <preetsidhu.bits@gmail.com> Co-authored-by: Vijetha-Kaja <119562824+Vijetha-Kaja@users.noreply.github.com> Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
2023-05-19 18:37:06 +00:00
label: "Configure menu items",
id: "config",
config: {
id: "config",
label: "Menu Item",
isVisible: true,
isDisabled: false,
},
},
});
}
}
}
return propertiesToUpdate?.length ? propertiesToUpdate : undefined;
};
feat: Table widget currency column (#27819) ## Description Adds a new currency column type on the table widget. #### PR fixes following issue(s) Fixes #5632 > 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 - New feature (non-breaking change which adds functionality) > > > ## 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 - [ ] JUnit - [ ] Jest - [x] Cypress > > #### Test Plan > https://github.com/appsmithorg/TestSmith/issues/2447 > > #### 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 - [x] 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/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#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
2023-11-06 05:35:26 +00:00
export const updateCurrencyDefaultValues = (
props: TableWidgetProps,
propertyPath: string,
propertyValue: unknown,
): Array<{ propertyPath: string; propertyValue: unknown }> | undefined => {
const propertiesToUpdate: Array<{
propertyPath: string;
propertyValue: unknown;
}> = [];
const baseProperty = getBasePropertyPath(propertyPath);
if (propertyValue === ColumnTypes.CURRENCY) {
if (!get(props, `${baseProperty}.currencyCode`)) {
propertiesToUpdate.push({
propertyPath: `${baseProperty}.currencyCode`,
propertyValue: "USD",
});
}
if (get(props, `${baseProperty}.decimals`) === undefined) {
propertiesToUpdate.push({
propertyPath: `${baseProperty}.decimals`,
propertyValue: 0,
});
}
if (get(props, `${baseProperty}.notation`) === undefined) {
propertiesToUpdate.push({
propertyPath: `${baseProperty}.notation`,
propertyValue: "standard",
});
}
if (get(props, `${baseProperty}.thousandSeparator`) === undefined) {
propertiesToUpdate.push({
propertyPath: `${baseProperty}.thousandSeparator`,
propertyValue: true,
});
}
}
return propertiesToUpdate?.length ? propertiesToUpdate : undefined;
};
export function selectColumnOptionsValidation(
value: unknown,
props: TableWidgetProps,
_?: any,
) {
let _isValid = true,
_parsed,
_message = "";
let uniqueValues: Set<unknown>;
fix: add null check for select options in table widget (#24902) ## Description This PR passes a `[]` to the select component when some values in the select options that are passed to the select cell component are `null`. This fixes issue where the table widget breaks when select options for the select column type contains `{{null}}` or `{{[null, null]}}` #### PR fixes following issue(s) Fixes #24857 #### Type of change - Bug fix (non-breaking change which fixes an issue) ## Testing #### How Has This Been Tested? - [x] Manual - To test that table widget does not break when `{{[null]}}`, `{{[null, null]}}`, `{{null}}` is passed to select options or new row select options. - To test that table widget does not break when select options or new row select options contains API binding that does not have any data - [ ] Jest - [x] Cypress - should test that select column dropdown has no results found string when select option is {{null}} - should test that select column dropdown has no results found string when select option is {{[null, null]}} #### 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 - [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 - [ ] 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/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#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
2023-06-29 07:07:41 +00:00
const invalidArrayValueMessage = `This value does not evaluate to type: { "label": string | number, "value": string | number | boolean }`;
const invalidMessage = `This value does not evaluate to type Array<{ "label": string | number, "value": string | number | boolean }>`;
const allowedValueTypes = ["string", "number", "boolean"];
const allowedLabelTypes = ["string", "number"];
const generateErrorMessagePrefix = (
rowIndex: number | null,
optionIndex: number,
) => {
return `Invalid entry at${
rowIndex !== null ? ` Row: ${rowIndex}` : ""
} index: ${optionIndex}.`;
};
fix: add null check for select options in table widget (#24902) ## Description This PR passes a `[]` to the select component when some values in the select options that are passed to the select cell component are `null`. This fixes issue where the table widget breaks when select options for the select column type contains `{{null}}` or `{{[null, null]}}` #### PR fixes following issue(s) Fixes #24857 #### Type of change - Bug fix (non-breaking change which fixes an issue) ## Testing #### How Has This Been Tested? - [x] Manual - To test that table widget does not break when `{{[null]}}`, `{{[null, null]}}`, `{{null}}` is passed to select options or new row select options. - To test that table widget does not break when select options or new row select options contains API binding that does not have any data - [ ] Jest - [x] Cypress - should test that select column dropdown has no results found string when select option is {{null}} - should test that select column dropdown has no results found string when select option is {{[null, null]}} #### 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 - [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 - [ ] 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/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#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
2023-06-29 07:07:41 +00:00
const generateInvalidArrayValueMessage = (
rowIndex: number | null,
optionIndex: number,
) =>
`${generateErrorMessagePrefix(
rowIndex,
optionIndex,
)} ${invalidArrayValueMessage}`;
const validateOption = (
option: any,
rowIndex: number | null,
optionIndex: number,
) => {
/*
* Option should
* 1. be an object
* 2. have label property
* 3. label should be of type string | number
* 4. have value property
* 5. value should be of type string | number | boolean
* 6. value should be unique amoig the options array
*/
if (!_.isObject(option)) {
// 1
return `${generateErrorMessagePrefix(
rowIndex,
optionIndex,
)} This value does not evaluate to type: { "label": string | number, "value": string | number | boolean }`;
}
if (!option.hasOwnProperty("label")) {
// 2
return `${generateErrorMessagePrefix(
rowIndex,
optionIndex,
)} Missing required key: label`;
}
if (!allowedLabelTypes.includes(typeof option.label)) {
// 3
return `${generateErrorMessagePrefix(
rowIndex,
optionIndex,
)} label does not evaluate to type ${allowedLabelTypes.join(" | ")}`;
}
if (!option.hasOwnProperty("value")) {
// 4
return `${generateErrorMessagePrefix(
rowIndex,
optionIndex,
)} Missing required key: value`;
}
if (!allowedValueTypes.includes(typeof option.value)) {
// 5
return `${generateErrorMessagePrefix(
rowIndex,
optionIndex,
)} value does not evaluate to type ${allowedValueTypes.join(" | ")}`;
}
if (uniqueValues.has(option.value)) {
// 6
return `Duplicate values found for the following properties, in the array entries, that must be unique -- value.`;
} else {
uniqueValues.add(option.value);
}
return "";
};
try {
if (value === "" || _.isNil(value)) {
// empty values
return {
isValid: true,
parsed: [],
messages: [""],
};
} else if (typeof value === "string") {
// json string
const _value = JSON.parse(value);
if (Array.isArray(_value)) {
value = _value;
} else {
_isValid = false;
_message = invalidMessage;
}
}
if (Array.isArray(value)) {
if (value.length) {
//when value is array of option json string
if (value.every((d) => _.isString(d))) {
value = value.map((d) => JSON.parse(d));
}
if (Array.isArray(value) && Array.isArray(value[0])) {
// value is array of array of label, value
//Value should be an array of array
if (!value.every((d) => Array.isArray(d))) {
_parsed = [];
_isValid = false;
_message = invalidMessage;
} else {
_parsed = value;
_isValid = true;
for (let i = 0; i < value.length; i++) {
uniqueValues = new Set();
for (let j = 0; j < value[i].length; j++) {
fix: add null check for select options in table widget (#24902) ## Description This PR passes a `[]` to the select component when some values in the select options that are passed to the select cell component are `null`. This fixes issue where the table widget breaks when select options for the select column type contains `{{null}}` or `{{[null, null]}}` #### PR fixes following issue(s) Fixes #24857 #### Type of change - Bug fix (non-breaking change which fixes an issue) ## Testing #### How Has This Been Tested? - [x] Manual - To test that table widget does not break when `{{[null]}}`, `{{[null, null]}}`, `{{null}}` is passed to select options or new row select options. - To test that table widget does not break when select options or new row select options contains API binding that does not have any data - [ ] Jest - [x] Cypress - should test that select column dropdown has no results found string when select option is {{null}} - should test that select column dropdown has no results found string when select option is {{[null, null]}} #### 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 - [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 - [ ] 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/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#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
2023-06-29 07:07:41 +00:00
if (_.isNil(value[i][j])) {
_isValid = false;
_message = generateInvalidArrayValueMessage(i, j);
_parsed = [];
break;
}
if ((_message = validateOption(value[i][j], i, j))) {
_isValid = false;
break;
}
}
if (!_isValid) {
break;
}
}
}
} else {
uniqueValues = new Set();
_parsed = value;
_isValid = true;
for (let i = 0; i < (value as Array<unknown>).length; i++) {
fix: add null check for select options in table widget (#24902) ## Description This PR passes a `[]` to the select component when some values in the select options that are passed to the select cell component are `null`. This fixes issue where the table widget breaks when select options for the select column type contains `{{null}}` or `{{[null, null]}}` #### PR fixes following issue(s) Fixes #24857 #### Type of change - Bug fix (non-breaking change which fixes an issue) ## Testing #### How Has This Been Tested? - [x] Manual - To test that table widget does not break when `{{[null]}}`, `{{[null, null]}}`, `{{null}}` is passed to select options or new row select options. - To test that table widget does not break when select options or new row select options contains API binding that does not have any data - [ ] Jest - [x] Cypress - should test that select column dropdown has no results found string when select option is {{null}} - should test that select column dropdown has no results found string when select option is {{[null, null]}} #### 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 - [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 - [ ] 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/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#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
2023-06-29 07:07:41 +00:00
if (_.isNil((value as Array<unknown>)[i])) {
_isValid = false;
_message = generateInvalidArrayValueMessage(null, i);
_parsed = [];
break;
}
if (
(_message = validateOption((value as Array<unknown>)[i], null, i))
) {
_isValid = false;
break;
}
}
}
} else {
_isValid = true;
_parsed = [];
}
} else {
_parsed = [];
_isValid = false;
_message = invalidMessage;
}
} catch (e) {
_parsed = [];
_isValid = false;
_message = invalidMessage;
}
return {
isValid: _isValid,
parsed: _parsed,
messages: [_message],
};
}
export const getColumnPath = (propPath: string) =>
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com> ## Description This PR upgrades Prettier to v2 + enforces TypeScript’s [`import type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export) syntax where applicable. It’s submitted as a separate PR so we can merge it easily. As a part of this PR, we reformat the codebase heavily: - add `import type` everywhere where it’s required, and - re-format the code to account for Prettier 2’s breaking changes: https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes This PR is submitted against `release` to make sure all new code by team members will adhere to new formatting standards, and we’ll have fewer conflicts when merging `bundle-optimizations` into `release`. (I’ll merge `release` back into `bundle-optimizations` once this PR is merged.) ### Why is this needed? This PR is needed because, for the Lodash optimization from https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3, we need to use `import type`. Otherwise, `babel-plugin-lodash` complains that `LoDashStatic` is not a lodash function. However, just using `import type` in the current codebase will give you this: <img width="962" alt="Screenshot 2023-03-08 at 17 45 59" src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png"> That’s because Prettier 1 can’t parse `import type` at all. To parse it, we need to upgrade to Prettier 2. ### Why enforce `import type`? Apart from just enabling `import type` support, this PR enforces specifying `import type` everywhere it’s needed. (Developers will get immediate TypeScript and ESLint errors when they forget to do so.) I’m doing this because I believe `import type` improves DX and makes refactorings easier. Let’s say you had a few imports like below. Can you tell which of these imports will increase the bundle size? (Tip: it’s not all of them!) ```ts // app/client/src/workers/Linting/utils.ts import { Position } from "codemirror"; import { LintError as JSHintError, LintOptions } from "jshint"; import { get, isEmpty, isNumber, keys, last, set } from "lodash"; ``` It’s pretty hard, right? What about now? ```ts // app/client/src/workers/Linting/utils.ts import type { Position } from "codemirror"; import type { LintError as JSHintError, LintOptions } from "jshint"; import { get, isEmpty, isNumber, keys, last, set } from "lodash"; ``` Now, it’s clear that only `lodash` will be bundled. This helps developers to see which imports are problematic, but it _also_ helps with refactorings. Now, if you want to see where `codemirror` is bundled, you can just grep for `import \{.*\} from "codemirror"` – and you won’t get any type-only imports. This also helps (some) bundlers. Upon transpiling, TypeScript erases type-only imports completely. In some environment (not ours), this makes the bundle smaller, as the bundler doesn’t need to bundle type-only imports anymore. ## Type of change - Chore (housekeeping or task changes that don't impact user perception) ## How Has This Been Tested? This was tested to not break the build. ### 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 - [ ] 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 - [ ] 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 --------- Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
propPath.split(".").slice(0, 2).join(".");
chore: Address misc one click binding feedbacks (#24735) ## Description Fixes miscellaneous feedback in the one-click binding feature. - Order of queries - show select queries on top and order by last executed query - Converting from JS to dropdown should be possible for the following cases - {{Query.data}} - Improve query names to be generated using the data table or collection we use - undefined table data value should show an error on the property pane - Download option should be disabled when table is generated using one click binding - Remove the insert binding option from the dropdown #### PR fixes following issue(s) Fixes https://github.com/appsmithorg/appsmith/issues/24605 > 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 > 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 - [x] I have performed a self-review of my own code - [ ] 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/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#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
2023-06-29 13:53:25 +00:00
export const tableDataValidation = (
value: unknown,
props: TableWidgetProps,
_?: any,
) => {
const invalidResponse = {
isValid: false,
parsed: [],
messages: [
{
name: "TypeError",
message: `This value does not evaluate to type Array<Object>}`,
},
],
};
if (value === "") {
return {
isValid: true,
parsed: [],
};
}
if (value === undefined || value === null) {
return {
isValid: false,
parsed: [],
messages: [
{
name: "ValidationError",
message: "Data is undefined, re-run your query or fix the data",
},
],
};
}
if (!_.isString(value) && !Array.isArray(value)) {
return invalidResponse;
}
let parsed = value;
if (_.isString(value)) {
try {
parsed = JSON.parse(value as string);
} catch (e) {
return invalidResponse;
}
}
if (Array.isArray(parsed)) {
if (parsed.length === 0) {
return {
isValid: true,
parsed: [],
};
}
for (let i = 0; i < parsed.length; i++) {
if (!_.isPlainObject(parsed[i])) {
return {
isValid: false,
parsed: [],
messages: [
{
name: "ValidationError",
message: `Invalid object at index ${i}`,
},
],
};
}
}
return { isValid: true, parsed };
}
return invalidResponse;
};
export function textForEachRowValidation(
value: unknown,
props: TableWidgetProps,
_: any,
): ValidationResponse {
const generateResponseAndReturn = (
isValid = false,
message = { name: "", message: "" },
) => {
return {
isValid,
parsed: isValid ? value : [],
messages: [message],
};
};
const DEFAULT_MESSAGE = {
name: "TypeError",
message: "The evaluated value should be either a string or a number.",
};
if (
_.isString(value) ||
_.isNumber(value) ||
Array.isArray(value) ||
value === undefined
) {
if (Array.isArray(value)) {
const isValid = value.every((item) => {
if (_.isString(item) || _.isNumber(item) || item === undefined) {
return true;
}
if (Array.isArray(item)) {
return item.every(
(subItem) =>
_.isString(subItem) ||
_.isNumber(subItem) ||
subItem === undefined,
);
}
return false;
});
return isValid
? generateResponseAndReturn(true)
: generateResponseAndReturn(false, DEFAULT_MESSAGE);
}
return generateResponseAndReturn(true);
}
return generateResponseAndReturn(false, DEFAULT_MESSAGE);
}
export function booleanForEachRowValidation(
value: unknown,
): ValidationResponse {
const generateResponseAndReturn = (
isValid = false,
message = { name: "", message: "" },
) => {
return {
isValid,
parsed: isValid ? value : true,
messages: [message],
};
};
const isBoolean = (value: unknown) => {
const isABoolean = value === true || value === false;
const isStringTrueFalse = value === "true" || value === "false";
return isABoolean || isStringTrueFalse || value === undefined;
};
const DEFAULT_MESSAGE = {
name: "TypeError",
message: "The evaluated value should be a boolean.",
};
if (isBoolean(value)) {
return generateResponseAndReturn(true);
}
if (Array.isArray(value)) {
const isValid = value.every((item) => {
if (isBoolean(item)) {
return true;
}
if (Array.isArray(item)) {
return item.every((subItem) => isBoolean(subItem));
}
return false;
});
return isValid
? generateResponseAndReturn(true)
: generateResponseAndReturn(false, DEFAULT_MESSAGE);
}
return generateResponseAndReturn(false, DEFAULT_MESSAGE);
}
export function iconNamesForEachRowValidation(
value: unknown,
props: TableWidgetProps,
_: any,
moment: any,
propertyPath: string,
config: ValidationConfig,
): ValidationResponse {
const generateResponseAndReturn = (
isValid = false,
message = { name: "", message: "" },
) => {
return {
isValid,
parsed: isValid ? value : true,
messages: [message],
};
};
const DEFAULT_MESSAGE = {
name: "TypeError",
message:
"The evaluated value should either be an icon name, undefined, null, or an empty string. We currently use the icons from the Blueprint library. You can see the list of icons at https://blueprintjs.com/docs/#icons",
};
const isIconName = (value: unknown) => {
return (
config?.params?.allowedValues?.includes(value as string) ||
value === undefined ||
value === null ||
value === ""
);
};
if (isIconName(value)) {
return generateResponseAndReturn(true);
}
if (Array.isArray(value)) {
const isValid = value.every((item) => {
if (isIconName(item)) {
return true;
}
if (Array.isArray(item)) {
return item.every((subItem) => isIconName(subItem));
}
return false;
});
return isValid
? generateResponseAndReturn(true)
: generateResponseAndReturn(false, DEFAULT_MESSAGE);
}
return generateResponseAndReturn(false, DEFAULT_MESSAGE);
}
export function iconPositionForEachRowValidation(
value: unknown,
props: TableWidgetProps,
_: any,
moment: any,
propertyPath: string,
config: ValidationConfig,
): ValidationResponse {
const generateResponseAndReturn = (
isValid = false,
message = { name: "", message: "" },
) => {
return {
isValid,
parsed: isValid ? value : true,
messages: [message],
};
};
const DEFAULT_MESSAGE = {
name: "TypeError",
message: `The evaluated value should be one of the allowed values => ${config?.params?.allowedValues?.join(
", ",
)}, undefined, null, or an empty string`,
};
const isIconPosition = (value: unknown) => {
return (
config?.params?.allowedValues?.includes(value as string) ||
value === undefined ||
value === null ||
value === ""
);
};
if (isIconPosition(value)) {
return generateResponseAndReturn(true);
}
if (Array.isArray(value)) {
const isValid = value.every((item) => {
if (isIconPosition(item)) {
return true;
}
if (Array.isArray(item)) {
return item.every((subItem) => isIconPosition(subItem));
}
return false;
});
return isValid
? generateResponseAndReturn(true)
: generateResponseAndReturn(false, DEFAULT_MESSAGE);
}
return generateResponseAndReturn(false, DEFAULT_MESSAGE);
}
export function colorForEachRowValidation(
value: unknown,
props: TableWidgetProps,
_: any,
moment: any,
propertyPath: string,
config: ValidationConfig,
): ValidationResponse {
const generateResponseAndReturn = (
isValid = false,
message = { name: "", message: "" },
) => {
return {
isValid,
parsed: isValid ? value : true,
messages: [message],
};
};
const DEFAULT_MESSAGE = {
name: "TypeError",
message: `The evaluated value should match ${config?.params?.regex}`,
};
const isColor = (value: unknown) => {
return config?.params?.regex?.test(value as string);
};
if (isColor(value)) {
return generateResponseAndReturn(true);
}
if (Array.isArray(value)) {
const isValid = value.every((item) => {
if (isColor(item)) {
return true;
}
if (Array.isArray(item)) {
return item.every((subItem) => isColor(subItem));
}
return false;
});
return isValid
? generateResponseAndReturn(true)
: generateResponseAndReturn(false, DEFAULT_MESSAGE);
}
return generateResponseAndReturn(false, DEFAULT_MESSAGE);
}