2021-07-08 12:02:08 +00:00
|
|
|
import React, { useRef, useState } from "react";
|
2022-03-30 09:51:07 +00:00
|
|
|
import styled, { createGlobalStyle, css } from "styled-components";
|
2021-11-03 03:54:19 +00:00
|
|
|
import Interweave from "interweave";
|
2020-02-12 08:23:50 +00:00
|
|
|
import {
|
|
|
|
|
IButtonProps,
|
|
|
|
|
MaybeElement,
|
2020-03-30 08:55:52 +00:00
|
|
|
Button,
|
2021-08-24 13:53:15 +00:00
|
|
|
Alignment,
|
2021-08-17 11:26:05 +00:00
|
|
|
Position,
|
2022-03-30 09:51:07 +00:00
|
|
|
Classes,
|
2020-02-12 08:23:50 +00:00
|
|
|
} from "@blueprintjs/core";
|
2021-11-03 03:54:19 +00:00
|
|
|
import { Popover2 } from "@blueprintjs/popover2";
|
2021-08-24 13:53:15 +00:00
|
|
|
import { IconName } from "@blueprintjs/icons";
|
|
|
|
|
|
2021-09-09 15:10:22 +00:00
|
|
|
import { ComponentProps } from "widgets/BaseComponent";
|
|
|
|
|
|
2022-01-31 15:55:58 +00:00
|
|
|
import { useScript, ScriptStatus, AddScriptTo } from "utils/hooks/useScript";
|
2020-10-12 13:01:19 +00:00
|
|
|
import {
|
|
|
|
|
GOOGLE_RECAPTCHA_KEY_ERROR,
|
|
|
|
|
GOOGLE_RECAPTCHA_DOMAIN_ERROR,
|
2021-03-13 14:24:45 +00:00
|
|
|
createMessage,
|
2022-02-11 18:08:46 +00:00
|
|
|
} from "@appsmith/constants/messages";
|
2023-01-23 03:50:47 +00:00
|
|
|
import { Toaster, Variant } from "design-system-old";
|
2021-09-09 15:10:22 +00:00
|
|
|
|
2021-07-08 12:02:08 +00:00
|
|
|
import ReCAPTCHA from "react-google-recaptcha";
|
2022-04-12 10:50:01 +00:00
|
|
|
import { Colors } from "constants/Colors";
|
2021-09-07 13:12:04 +00:00
|
|
|
import _ from "lodash";
|
2021-08-24 13:53:15 +00:00
|
|
|
import {
|
2022-05-04 09:45:57 +00:00
|
|
|
ButtonPlacement,
|
2021-09-09 15:10:22 +00:00
|
|
|
ButtonVariant,
|
|
|
|
|
ButtonVariantTypes,
|
2022-01-02 16:27:39 +00:00
|
|
|
RecaptchaType,
|
|
|
|
|
RecaptchaTypes,
|
2021-09-09 15:10:22 +00:00
|
|
|
} from "components/constants";
|
2021-10-06 12:57:05 +00:00
|
|
|
import {
|
|
|
|
|
getCustomBackgroundColor,
|
|
|
|
|
getCustomBorderColor,
|
2021-12-08 13:11:13 +00:00
|
|
|
getCustomJustifyContent,
|
|
|
|
|
getAlignText,
|
2022-05-04 09:45:57 +00:00
|
|
|
getComplementaryGrayscaleColor,
|
2021-10-06 12:57:05 +00:00
|
|
|
} from "widgets/WidgetUtils";
|
2022-03-13 17:21:04 +00:00
|
|
|
import { DragContainer } from "./DragContainer";
|
|
|
|
|
import { buttonHoverActiveStyles } from "./utils";
|
chore: import common variables from design system (#17600)
* Delete CommonComponentProps, Classes, import them from design-system
* Delete Icon.test.tsx
* Remove color utils, add import from design-system
* Remove Variant, add import from design-system
* Remove unused toast parameters from common
* use design-system version 28-alpha-7
* Move ThemeProp from ads/common to widgets/constants
* fix import
* Delete index.ts
* feat: migrated form group from ads folder to design system repository (#17400)
* feat: migrated form group from ads folder to design system repo
* fix: formGroup label color fix
* DS version updated
* Updated Label Config
* chore: Flapdoodle version upgrade to 3.5.0 (#17609)
* chore: code split tenant API CE (#17596)
## Description
We shouldn't expose tenant config on CE , so on CE, we should only return the necessary user permissions hard coded on the saga.
## Type of change
- New feature (non-breaking change which adds functionality)
## How Has This Been Tested?
- Manual
## Checklist:
- [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
* chore: BaseAppsmithRepo code split (#17614)
* chore: Updating the tenant API to return the complete object instead of just the configuration (#17615)
* Fix sandbox iframe default setting (#17618)
* feat: upgrade hooks | audit logs (#17525)
* feat: Text Widget Reskinning (#17298)
* feat: Use truncate button color from theme
* fix: Update Truncate Button Color validation regex
* feat: Maintain Focus and Context Phase 1 (#16317)
* fix: update regex and test case for organisation website (#17612)
* chore: Add properties to analytics event (#17621)
* feat: enabled setTimeout/clearTimeout APIs (#17445)
* Update top contributors
* fix: ms sql default port updated to 1433 (#17342)
* fix: removed global style from design system dropdown component (#17392)
* bug: removed global style from design system dropdown component
* changed design system package version
* fix: Dropdown background fix - design system
* design-system - dropdown background color fix
* DS version updated
* chore: Fixing broken client build (#17634)
## Description
EE client build is broken due to not following proper code splitting strategy; one file in particularly didn't get split earlier and changes to that file broke the client build on EE.
This PR fixes the issues.
* Fix/16994 refactor common datatype handling (#17429)
* fix:Add array datatype to execute request
* feat: Consume and store type of array elements in Param class (#16994)
* Append param instead of clientDataType in varargs (#16994)
* Refactor common data type handling w.r.t newer structure (#16994)
This commit takes care of the following items:
- It minimizes the number of usage to the older stringToKnownDataTypeConverter method
- Modifies the existing test cases to conform to the newer structure
- Marks stringToKnownDataTypeConverter method as deprecated to discourage further use
* Remove comma delimited numbers from valid test cases (#16994)
* Fix extracting clientDataType from varargs in MySQL (#16994)
* Pass param as a dedicated parameter in json smart replacement (#16994)
* Remove varargs from json smart replacement method (#16994)
* Move BsonType to mongoplugin module (#16994)
* Introduce NullArrayType and refactor BsonType test cases (#16994)
* Add new test cases on numeric string with leading zero (#16994)
* Refactor test case name (#16994)
* Add comment on the ordering of Json and Bson types (#16994)
* Add comment on the ordering of Json and Bson types (#16994)
* Add NullArrayType in Postgres and introduce postgres-specific types (#16994)
* Add data type test cases for Postgres and change as per review comments (#16994)
Co-authored-by: ChandanBalajiBP <chandan@appsmith.com>
* feat: Update invite modal submit when we have tabs in modal (#17608)
## Description
> Update invite modal submit when we have tabs in modal.
Fixes [#16741](https://github.com/appsmithorg/appsmith/issues/16741)
## Type of change
- New feature (non-breaking change which adds functionality)
## How Has This Been Tested?
> Tested it locally.
## Checklist:
- [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
* feat: AST based entity refactor (#17434)
* task: AST based entity refactor
* implemented refactor logic
* jest cases with string manipulation using AST logic
* comments and indentation
* added evalVersion to request
* chore: Added feature flag for datasource environments (#17657)
chore: Added Feature flag for datasource environments
* chore: Corrected analytics event for instance setting events (#17622)
* Update top contributors
* Fix typo in cloud-hosting check and NPE from Segment (#17692)
Signed-off-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
* fix: remove file references on click of cancel button (#17664)
* fix: table does not show data issue fixed (#17459)
* chore: Add recommended indexes (#17704)
Signed-off-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
* chore: Added workspace details to user invite analytic event (#17644)
## Description
This PR adds the workspace details to user invite analytics event
## Type of change
- New feature (non-breaking change which adds functionality)
## How Has This Been Tested?
- Manually on local
## Checklist:
- [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
- [x] New and existing unit tests pass locally with my changes
* chore: Correct the toast font on windows (#17671)
* fix: JS option missing for Label Font Style in Input widget (#17631)
* fix: replace time based action to event based (#17586)
* fix: replace time based action to event based
- The delete datasource button was getting reset to it's original state after a static time of 2200ms
- Replaced this to reset on completion of deletion instead
* fix: removed unused functions
* fix: updated the condition to show confirm delete icon
* Updated Label Config
* test: Add cypress tests for template phase 2 (#17036)
Co-authored-by: Parthvi Goswami <parthvigoswami@Parthvis-MacBook-Pro.local>
* Change Segment CDN to our proxy (#17714)
* chore: Fixing prettier formatting for AnalyticsUtil.tsx
* chore: Adding base repository function to add user permissions to generic domain object (#17733)
## Description
Adding base function to set the user permissions for a user in any domain object.
As part of this, we also add default permission group to the `SeedMongoData`. Without this fix, the JUnit tests go into an infinite loop. Also fixing the `ExampleWorkspaceClonerTest` file.
## Type of change
- Bug fix (non-breaking change which fixes an issue)
## How Has This Been Tested?
- JUnit
## Checklist:
- [ ] 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
* Update top contributors
Signed-off-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
Co-authored-by: Nikhil Nandagopal <nikhil.nandagopal@gmail.com>
Co-authored-by: Nidhi <nidhi@appsmith.com>
Co-authored-by: Sangeeth Sivan <74818788+berzerkeer@users.noreply.github.com>
Co-authored-by: Trisha Anand <trisha@appsmith.com>
Co-authored-by: Arpit Mohan <mohanarpit@users.noreply.github.com>
Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
Co-authored-by: f0c1s <anubhav@appsmith.com>
Co-authored-by: Dhruvik Neharia <dhruvik@appsmith.com>
Co-authored-by: Hetu Nandu <hetu@appsmith.com>
Co-authored-by: Nilesh Sarupriya <nilesh@appsmith.com>
Co-authored-by: Anagh Hegde <anagh@appsmith.com>
Co-authored-by: arunvjn <32433245+arunvjn@users.noreply.github.com>
Co-authored-by: Appsmith Bot <74705725+appsmith-bot@users.noreply.github.com>
Co-authored-by: Vaibhav Tanwar <40293928+vaibh1297@users.noreply.github.com>
Co-authored-by: subratadeypappu <subrata@appsmith.com>
Co-authored-by: ChandanBalajiBP <chandan@appsmith.com>
Co-authored-by: Ankita Kinger <ankita@appsmith.com>
Co-authored-by: ChandanBalajiBP <104058110+ChandanBalajiBP@users.noreply.github.com>
Co-authored-by: Vishnu Gp <vishnu@appsmith.com>
Co-authored-by: Keyur Paralkar <keyur@appsmith.com>
Co-authored-by: sneha122 <sneha@appsmith.com>
Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com>
Co-authored-by: sanjus-robotic-studio <58104863+sanjus-robotic-studio@users.noreply.github.com>
Co-authored-by: Ayush Pahwa <ayush@appsmith.com>
Co-authored-by: Parthvi <80334441+Parthvi12@users.noreply.github.com>
Co-authored-by: Parthvi Goswami <parthvigoswami@Parthvis-MacBook-Pro.local>
Co-authored-by: Arpit Mohan <arpit@appsmith.com>
Signed-off-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
Co-authored-by: albinAppsmith <87797149+albinAppsmith@users.noreply.github.com>
Co-authored-by: Nikhil Nandagopal <nikhil.nandagopal@gmail.com>
Co-authored-by: Nidhi <nidhi@appsmith.com>
Co-authored-by: Sangeeth Sivan <74818788+berzerkeer@users.noreply.github.com>
Co-authored-by: Trisha Anand <trisha@appsmith.com>
Co-authored-by: Arpit Mohan <mohanarpit@users.noreply.github.com>
Co-authored-by: Shrikant Sharat Kandula <shrikant@appsmith.com>
Co-authored-by: f0c1s <anubhav@appsmith.com>
Co-authored-by: Dhruvik Neharia <dhruvik@appsmith.com>
Co-authored-by: Hetu Nandu <hetu@appsmith.com>
Co-authored-by: Nilesh Sarupriya <nilesh@appsmith.com>
Co-authored-by: Anagh Hegde <anagh@appsmith.com>
Co-authored-by: arunvjn <32433245+arunvjn@users.noreply.github.com>
Co-authored-by: Appsmith Bot <74705725+appsmith-bot@users.noreply.github.com>
Co-authored-by: Vaibhav Tanwar <40293928+vaibh1297@users.noreply.github.com>
Co-authored-by: subratadeypappu <subrata@appsmith.com>
Co-authored-by: ChandanBalajiBP <chandan@appsmith.com>
Co-authored-by: Ankita Kinger <ankita@appsmith.com>
Co-authored-by: ChandanBalajiBP <104058110+ChandanBalajiBP@users.noreply.github.com>
Co-authored-by: Vishnu Gp <vishnu@appsmith.com>
Co-authored-by: Keyur Paralkar <keyur@appsmith.com>
Co-authored-by: sneha122 <sneha@appsmith.com>
Co-authored-by: sanjus-robotic-studio <58104863+sanjus-robotic-studio@users.noreply.github.com>
Co-authored-by: Ayush Pahwa <ayush@appsmith.com>
Co-authored-by: Parthvi <80334441+Parthvi12@users.noreply.github.com>
Co-authored-by: Parthvi Goswami <parthvigoswami@Parthvis-MacBook-Pro.local>
Co-authored-by: Arpit Mohan <arpit@appsmith.com>
2022-10-31 01:24:47 +00:00
|
|
|
import { ThemeProp } from "widgets/constants";
|
2021-08-24 13:53:15 +00:00
|
|
|
|
|
|
|
|
const RecaptchaWrapper = styled.div`
|
|
|
|
|
position: relative;
|
|
|
|
|
.grecaptcha-badge {
|
|
|
|
|
visibility: hidden;
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2021-08-17 11:26:05 +00:00
|
|
|
const ToolTipWrapper = styled.div`
|
|
|
|
|
height: 100%;
|
2021-11-03 03:54:19 +00:00
|
|
|
&& .bp3-popover2-target {
|
2021-08-17 11:26:05 +00:00
|
|
|
height: 100%;
|
2021-11-03 03:54:19 +00:00
|
|
|
width: 100%;
|
2021-08-17 11:26:05 +00:00
|
|
|
& > div {
|
|
|
|
|
height: 100%;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2021-11-03 03:54:19 +00:00
|
|
|
const TooltipStyles = createGlobalStyle`
|
|
|
|
|
.btnTooltipContainer {
|
|
|
|
|
.bp3-popover2-content {
|
|
|
|
|
max-width: 350px;
|
|
|
|
|
overflow-wrap: anywhere;
|
|
|
|
|
padding: 10px 12px;
|
|
|
|
|
border-radius: 0px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2022-03-30 09:51:07 +00:00
|
|
|
const buttonBaseStyle = css<ThemeProp & ButtonStyleProps>`
|
2022-05-04 09:45:57 +00:00
|
|
|
height: 100%;
|
|
|
|
|
background-image: none !important;
|
|
|
|
|
font-weight: ${(props) => props.theme.fontWeights[2]};
|
|
|
|
|
outline: none;
|
|
|
|
|
padding: 0px 10px;
|
|
|
|
|
gap: 8px;
|
2019-10-21 15:12:45 +00:00
|
|
|
|
2022-12-30 14:52:11 +00:00
|
|
|
&:hover, &:active, &:focus {
|
2022-05-04 09:45:57 +00:00
|
|
|
${buttonHoverActiveStyles}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
${({ buttonColor, buttonVariant, theme }) => `
|
|
|
|
|
background: ${
|
|
|
|
|
getCustomBackgroundColor(buttonVariant, buttonColor) !== "none"
|
|
|
|
|
? getCustomBackgroundColor(buttonVariant, buttonColor)
|
|
|
|
|
: buttonVariant === ButtonVariantTypes.PRIMARY
|
|
|
|
|
? theme.colors.button.primary.primary.bgColor
|
|
|
|
|
: "none"
|
|
|
|
|
} !important;
|
2022-03-13 17:21:04 +00:00
|
|
|
|
2021-08-24 13:53:15 +00:00
|
|
|
|
2022-03-30 09:51:07 +00:00
|
|
|
&:disabled, &.${Classes.DISABLED} {
|
2022-05-04 09:45:57 +00:00
|
|
|
cursor: not-allowed;
|
2022-09-30 11:24:21 +00:00
|
|
|
background-color: ${buttonVariant !== ButtonVariantTypes.TERTIARY &&
|
|
|
|
|
"var(--wds-color-bg-disabled)"} !important;
|
|
|
|
|
color: var(--wds-color-text-disabled) !important;
|
2022-05-04 09:45:57 +00:00
|
|
|
box-shadow: none !important;
|
|
|
|
|
pointer-events: none;
|
2022-09-30 11:24:21 +00:00
|
|
|
border-color: var(--wds-color-border-disabled) !important;
|
2022-05-04 09:45:57 +00:00
|
|
|
|
|
|
|
|
> span {
|
2022-09-30 11:24:21 +00:00
|
|
|
color: var(--wds-color-text-disabled) !important;
|
2021-08-24 13:53:15 +00:00
|
|
|
}
|
2022-05-04 09:45:57 +00:00
|
|
|
}
|
2021-08-24 13:53:15 +00:00
|
|
|
|
2022-05-04 09:45:57 +00:00
|
|
|
border: ${
|
|
|
|
|
getCustomBorderColor(buttonVariant, buttonColor) !== "none"
|
|
|
|
|
? `1px solid ${getCustomBorderColor(buttonVariant, buttonColor)}`
|
|
|
|
|
: buttonVariant === ButtonVariantTypes.SECONDARY
|
|
|
|
|
? `1px solid ${theme.colors.button.primary.secondary.borderColor}`
|
|
|
|
|
: "none"
|
|
|
|
|
} !important;
|
|
|
|
|
|
|
|
|
|
& > * {
|
|
|
|
|
margin-right: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
& > span {
|
|
|
|
|
max-height: 100%;
|
|
|
|
|
max-width: 99%;
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
display: -webkit-box;
|
|
|
|
|
-webkit-line-clamp: 1;
|
|
|
|
|
-webkit-box-orient: vertical;
|
|
|
|
|
line-height: normal;
|
|
|
|
|
|
|
|
|
|
color: ${
|
|
|
|
|
buttonVariant === ButtonVariantTypes.PRIMARY
|
|
|
|
|
? getComplementaryGrayscaleColor(buttonColor)
|
|
|
|
|
: getCustomBackgroundColor(ButtonVariantTypes.PRIMARY, buttonColor)
|
2021-08-24 13:53:15 +00:00
|
|
|
} !important;
|
2022-05-04 09:45:57 +00:00
|
|
|
}
|
|
|
|
|
`}
|
2021-08-24 13:53:15 +00:00
|
|
|
|
2022-05-04 09:45:57 +00:00
|
|
|
border-radius: ${({ borderRadius }) => borderRadius};
|
|
|
|
|
box-shadow: ${({ boxShadow }) => `${boxShadow ?? "none"}`} !important;
|
|
|
|
|
|
|
|
|
|
${({ placement }) =>
|
|
|
|
|
placement
|
|
|
|
|
? `
|
|
|
|
|
justify-content: ${getCustomJustifyContent(placement)};
|
|
|
|
|
& > span.bp3-button-text {
|
|
|
|
|
flex: unset !important;
|
2019-10-21 15:12:45 +00:00
|
|
|
}
|
2022-05-04 09:45:57 +00:00
|
|
|
`
|
|
|
|
|
: ""}
|
2021-08-24 13:53:15 +00:00
|
|
|
`;
|
2019-10-21 15:12:45 +00:00
|
|
|
|
2022-05-04 09:45:57 +00:00
|
|
|
export const StyledButton = styled((props) => (
|
2022-03-30 09:51:07 +00:00
|
|
|
<Button
|
|
|
|
|
{..._.omit(props, [
|
|
|
|
|
"borderRadius",
|
|
|
|
|
"boxShadow",
|
|
|
|
|
"boxShadowColor",
|
|
|
|
|
"buttonColor",
|
|
|
|
|
"buttonVariant",
|
|
|
|
|
])}
|
|
|
|
|
/>
|
|
|
|
|
))<ThemeProp & ButtonStyleProps>`
|
|
|
|
|
${buttonBaseStyle}
|
|
|
|
|
`;
|
|
|
|
|
|
2022-03-13 17:21:04 +00:00
|
|
|
export type ButtonStyleProps = {
|
2021-08-24 13:53:15 +00:00
|
|
|
buttonColor?: string;
|
|
|
|
|
buttonVariant?: ButtonVariant;
|
2022-05-04 09:45:57 +00:00
|
|
|
boxShadow?: string;
|
2021-08-24 13:53:15 +00:00
|
|
|
boxShadowColor?: string;
|
2022-05-04 09:45:57 +00:00
|
|
|
borderRadius?: string;
|
2021-08-24 13:53:15 +00:00
|
|
|
iconName?: IconName;
|
|
|
|
|
iconAlign?: Alignment;
|
2021-12-08 13:11:13 +00:00
|
|
|
placement?: ButtonPlacement;
|
2019-10-21 15:12:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// To be used in any other part of the app
|
2021-04-28 10:28:39 +00:00
|
|
|
export function BaseButton(props: IButtonProps & ButtonStyleProps) {
|
2021-08-24 13:53:15 +00:00
|
|
|
const {
|
|
|
|
|
borderRadius,
|
|
|
|
|
boxShadow,
|
|
|
|
|
boxShadowColor,
|
|
|
|
|
buttonColor,
|
|
|
|
|
buttonVariant,
|
|
|
|
|
className,
|
|
|
|
|
disabled,
|
|
|
|
|
icon,
|
|
|
|
|
iconAlign,
|
|
|
|
|
iconName,
|
|
|
|
|
loading,
|
|
|
|
|
onClick,
|
2021-12-08 13:11:13 +00:00
|
|
|
placement,
|
2021-08-24 13:53:15 +00:00
|
|
|
rightIcon,
|
|
|
|
|
text,
|
|
|
|
|
} = props;
|
|
|
|
|
|
2021-12-08 13:11:13 +00:00
|
|
|
const isRightAlign = iconAlign === Alignment.RIGHT;
|
2021-08-24 13:53:15 +00:00
|
|
|
|
|
|
|
|
return (
|
2022-03-13 17:21:04 +00:00
|
|
|
<DragContainer
|
2021-08-24 13:53:15 +00:00
|
|
|
buttonColor={buttonColor}
|
|
|
|
|
buttonVariant={buttonVariant}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
loading={loading}
|
|
|
|
|
onClick={onClick}
|
2022-04-04 07:13:04 +00:00
|
|
|
showInAllModes
|
2022-03-13 17:21:04 +00:00
|
|
|
>
|
2022-04-04 07:13:04 +00:00
|
|
|
<StyledButton
|
|
|
|
|
alignText={getAlignText(isRightAlign, iconName)}
|
|
|
|
|
borderRadius={borderRadius}
|
|
|
|
|
boxShadow={boxShadow}
|
|
|
|
|
boxShadowColor={boxShadowColor}
|
|
|
|
|
buttonColor={buttonColor}
|
|
|
|
|
buttonVariant={buttonVariant}
|
|
|
|
|
className={className}
|
|
|
|
|
data-test-variant={buttonVariant}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
fill
|
|
|
|
|
icon={isRightAlign ? icon : iconName || icon}
|
|
|
|
|
loading={loading}
|
|
|
|
|
onClick={onClick}
|
|
|
|
|
placement={placement}
|
|
|
|
|
rightIcon={isRightAlign ? iconName || rightIcon : rightIcon}
|
|
|
|
|
text={text}
|
|
|
|
|
/>
|
2022-03-13 17:21:04 +00:00
|
|
|
</DragContainer>
|
2021-08-24 13:53:15 +00:00
|
|
|
);
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|
2019-10-21 15:12:45 +00:00
|
|
|
|
|
|
|
|
BaseButton.defaultProps = {
|
2021-09-23 15:14:24 +00:00
|
|
|
buttonColor: Colors.GREEN,
|
2021-10-12 08:04:51 +00:00
|
|
|
buttonVariant: ButtonVariantTypes.PRIMARY,
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
disabled: false,
|
2019-10-21 15:12:45 +00:00
|
|
|
text: "Button Text",
|
|
|
|
|
minimal: true,
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-06 09:45:21 +00:00
|
|
|
export enum ButtonType {
|
|
|
|
|
SUBMIT = "submit",
|
|
|
|
|
RESET = "reset",
|
|
|
|
|
BUTTON = "button",
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-12 13:01:19 +00:00
|
|
|
interface RecaptchaProps {
|
|
|
|
|
googleRecaptchaKey?: string;
|
|
|
|
|
clickWithRecaptcha: (token: string) => void;
|
2021-08-03 13:36:03 +00:00
|
|
|
handleRecaptchaV2Loading?: (isLoading: boolean) => void;
|
2022-01-02 16:27:39 +00:00
|
|
|
recaptchaType?: RecaptchaType;
|
2020-10-12 13:01:19 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-24 13:53:15 +00:00
|
|
|
interface ButtonComponentProps extends ComponentProps {
|
2020-01-03 13:40:31 +00:00
|
|
|
text?: string;
|
2021-08-24 13:53:15 +00:00
|
|
|
icon?: IconName | MaybeElement;
|
2021-08-17 11:26:05 +00:00
|
|
|
tooltip?: string;
|
2019-10-21 15:12:45 +00:00
|
|
|
onClick?: (event: React.MouseEvent<HTMLElement>) => void;
|
2021-08-24 13:53:15 +00:00
|
|
|
isDisabled?: boolean;
|
2019-12-03 04:41:10 +00:00
|
|
|
isLoading: boolean;
|
2020-02-12 08:23:50 +00:00
|
|
|
rightIcon?: IconName | MaybeElement;
|
2020-03-06 09:45:21 +00:00
|
|
|
type: ButtonType;
|
2021-08-24 13:53:15 +00:00
|
|
|
buttonColor?: string;
|
|
|
|
|
buttonVariant?: ButtonVariant;
|
2022-05-04 09:45:57 +00:00
|
|
|
borderRadius?: string;
|
|
|
|
|
boxShadow?: string;
|
2021-08-24 13:53:15 +00:00
|
|
|
boxShadowColor?: string;
|
|
|
|
|
iconName?: IconName;
|
|
|
|
|
iconAlign?: Alignment;
|
2021-12-08 13:11:13 +00:00
|
|
|
placement?: ButtonPlacement;
|
2022-07-14 07:02:35 +00:00
|
|
|
className?: string;
|
2019-10-21 15:12:45 +00:00
|
|
|
}
|
|
|
|
|
|
2022-07-14 07:02:35 +00:00
|
|
|
type RecaptchaV2ComponentPropType = {
|
|
|
|
|
children: any;
|
|
|
|
|
className?: string;
|
|
|
|
|
isDisabled?: boolean;
|
|
|
|
|
recaptchaType?: RecaptchaType;
|
|
|
|
|
isLoading: boolean;
|
|
|
|
|
handleError: (event: React.MouseEvent<HTMLElement>, error: string) => void;
|
|
|
|
|
};
|
|
|
|
|
|
2021-07-08 12:02:08 +00:00
|
|
|
function RecaptchaV2Component(
|
2022-07-14 07:02:35 +00:00
|
|
|
props: RecaptchaV2ComponentPropType & RecaptchaProps,
|
2021-04-28 10:28:39 +00:00
|
|
|
) {
|
2021-07-08 12:02:08 +00:00
|
|
|
const recaptchaRef = useRef<ReCAPTCHA>(null);
|
|
|
|
|
const [isInvalidKey, setInvalidKey] = useState(false);
|
2021-08-03 13:36:03 +00:00
|
|
|
const handleRecaptchaLoading = (isloading: boolean) => {
|
|
|
|
|
props.handleRecaptchaV2Loading && props.handleRecaptchaV2Loading(isloading);
|
|
|
|
|
};
|
2021-07-08 12:02:08 +00:00
|
|
|
const handleBtnClick = async (event: React.MouseEvent<HTMLElement>) => {
|
2022-03-22 06:52:39 +00:00
|
|
|
if (props.isDisabled) return;
|
2022-05-03 05:25:31 +00:00
|
|
|
if (props.isLoading) return;
|
2021-07-08 12:02:08 +00:00
|
|
|
if (isInvalidKey) {
|
|
|
|
|
// Handle incorrent google recaptcha site key
|
|
|
|
|
props.handleError(event, createMessage(GOOGLE_RECAPTCHA_KEY_ERROR));
|
|
|
|
|
} else {
|
2021-08-03 13:36:03 +00:00
|
|
|
handleRecaptchaLoading(true);
|
2021-07-08 12:02:08 +00:00
|
|
|
try {
|
2021-08-03 13:36:03 +00:00
|
|
|
await recaptchaRef?.current?.reset();
|
2021-07-08 12:02:08 +00:00
|
|
|
const token = await recaptchaRef?.current?.executeAsync();
|
|
|
|
|
if (token) {
|
|
|
|
|
props.clickWithRecaptcha(token);
|
|
|
|
|
} else {
|
|
|
|
|
// Handle incorrent google recaptcha site key
|
|
|
|
|
props.handleError(event, createMessage(GOOGLE_RECAPTCHA_KEY_ERROR));
|
|
|
|
|
}
|
2021-08-03 13:36:03 +00:00
|
|
|
handleRecaptchaLoading(false);
|
2021-07-08 12:02:08 +00:00
|
|
|
} catch (err) {
|
2021-08-03 13:36:03 +00:00
|
|
|
handleRecaptchaLoading(false);
|
2021-07-08 12:02:08 +00:00
|
|
|
// Handle error due to google recaptcha key of different domain
|
|
|
|
|
props.handleError(event, createMessage(GOOGLE_RECAPTCHA_DOMAIN_ERROR));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return (
|
2022-07-14 07:02:35 +00:00
|
|
|
<RecaptchaWrapper className={props.className} onClick={handleBtnClick}>
|
2021-07-08 12:02:08 +00:00
|
|
|
{props.children}
|
|
|
|
|
<ReCAPTCHA
|
|
|
|
|
onErrored={() => setInvalidKey(true)}
|
|
|
|
|
ref={recaptchaRef}
|
|
|
|
|
sitekey={props.googleRecaptchaKey || ""}
|
|
|
|
|
size="invisible"
|
|
|
|
|
/>
|
|
|
|
|
</RecaptchaWrapper>
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-05-20 19:28:02 +00:00
|
|
|
|
2022-07-14 07:02:35 +00:00
|
|
|
type RecaptchaV3ComponentPropType = {
|
|
|
|
|
children: any;
|
|
|
|
|
className?: string;
|
|
|
|
|
isDisabled?: boolean;
|
|
|
|
|
recaptchaType?: RecaptchaType;
|
|
|
|
|
isLoading: boolean;
|
|
|
|
|
handleError: (event: React.MouseEvent<HTMLElement>, error: string) => void;
|
|
|
|
|
};
|
|
|
|
|
|
2021-07-08 12:02:08 +00:00
|
|
|
function RecaptchaV3Component(
|
2022-07-14 07:02:35 +00:00
|
|
|
props: RecaptchaV3ComponentPropType & RecaptchaProps,
|
2021-07-08 12:02:08 +00:00
|
|
|
) {
|
2021-05-20 19:28:02 +00:00
|
|
|
// Check if a string is a valid JSON string
|
|
|
|
|
const checkValidJson = (inputString: string): boolean => {
|
2021-08-09 12:18:58 +00:00
|
|
|
return !inputString.includes('"');
|
2021-05-20 19:28:02 +00:00
|
|
|
};
|
|
|
|
|
|
2021-07-08 12:02:08 +00:00
|
|
|
const handleBtnClick = (event: React.MouseEvent<HTMLElement>) => {
|
2022-03-22 06:52:39 +00:00
|
|
|
if (props.isDisabled) return;
|
2022-05-03 05:25:31 +00:00
|
|
|
if (props.isLoading) return;
|
2021-07-08 12:02:08 +00:00
|
|
|
if (status === ScriptStatus.READY) {
|
|
|
|
|
(window as any).grecaptcha.ready(() => {
|
|
|
|
|
try {
|
|
|
|
|
(window as any).grecaptcha
|
|
|
|
|
.execute(props.googleRecaptchaKey, {
|
|
|
|
|
action: "submit",
|
|
|
|
|
})
|
|
|
|
|
.then((token: any) => {
|
|
|
|
|
props.clickWithRecaptcha(token);
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
// Handle incorrent google recaptcha site key
|
|
|
|
|
props.handleError(
|
|
|
|
|
event,
|
|
|
|
|
createMessage(GOOGLE_RECAPTCHA_KEY_ERROR),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
// Handle error due to google recaptcha key of different domain
|
|
|
|
|
props.handleError(
|
|
|
|
|
event,
|
|
|
|
|
createMessage(GOOGLE_RECAPTCHA_DOMAIN_ERROR),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-20 19:28:02 +00:00
|
|
|
let validGoogleRecaptchaKey = props.googleRecaptchaKey;
|
2021-08-09 12:18:58 +00:00
|
|
|
if (validGoogleRecaptchaKey && !checkValidJson(validGoogleRecaptchaKey)) {
|
2021-05-20 19:28:02 +00:00
|
|
|
validGoogleRecaptchaKey = undefined;
|
|
|
|
|
}
|
2020-10-12 13:01:19 +00:00
|
|
|
const status = useScript(
|
2021-05-20 19:28:02 +00:00
|
|
|
`https://www.google.com/recaptcha/api.js?render=${validGoogleRecaptchaKey}`,
|
2022-01-31 15:55:58 +00:00
|
|
|
AddScriptTo.HEAD,
|
2020-10-12 13:01:19 +00:00
|
|
|
);
|
2022-07-14 07:02:35 +00:00
|
|
|
return (
|
|
|
|
|
<div className={props.className} onClick={handleBtnClick}>
|
|
|
|
|
{props.children}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|
2020-10-12 13:01:19 +00:00
|
|
|
|
2023-02-03 05:47:40 +00:00
|
|
|
const Wrapper = styled.div`
|
|
|
|
|
height: 100%;
|
|
|
|
|
`;
|
|
|
|
|
|
2021-04-28 10:28:39 +00:00
|
|
|
function BtnWrapper(
|
2020-10-12 13:01:19 +00:00
|
|
|
props: {
|
|
|
|
|
children: any;
|
2022-07-14 07:02:35 +00:00
|
|
|
className?: string;
|
2022-03-22 06:52:39 +00:00
|
|
|
isDisabled?: boolean;
|
2022-05-03 05:25:31 +00:00
|
|
|
isLoading: boolean;
|
2020-10-12 13:01:19 +00:00
|
|
|
onClick?: (event: React.MouseEvent<HTMLElement>) => void;
|
|
|
|
|
} & RecaptchaProps,
|
2021-04-28 10:28:39 +00:00
|
|
|
) {
|
2022-05-03 05:25:31 +00:00
|
|
|
if (!props.googleRecaptchaKey) {
|
|
|
|
|
return (
|
2023-02-03 05:47:40 +00:00
|
|
|
<Wrapper
|
2022-07-14 07:02:35 +00:00
|
|
|
className={props.className}
|
2022-05-03 05:25:31 +00:00
|
|
|
onClick={(e: React.MouseEvent<HTMLElement>) =>
|
|
|
|
|
props.onClick && !props.isLoading && props.onClick(e)
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{props.children}
|
2023-02-03 05:47:40 +00:00
|
|
|
</Wrapper>
|
2022-05-03 05:25:31 +00:00
|
|
|
);
|
|
|
|
|
} else {
|
2021-07-08 12:02:08 +00:00
|
|
|
const handleError = (
|
|
|
|
|
event: React.MouseEvent<HTMLElement>,
|
|
|
|
|
error: string,
|
|
|
|
|
) => {
|
|
|
|
|
Toaster.show({
|
|
|
|
|
text: error,
|
|
|
|
|
variant: Variant.danger,
|
|
|
|
|
});
|
2022-05-03 05:25:31 +00:00
|
|
|
props.onClick && !props.isLoading && props.onClick(event);
|
2021-07-08 12:02:08 +00:00
|
|
|
};
|
2022-01-02 16:27:39 +00:00
|
|
|
if (props.recaptchaType === RecaptchaTypes.V2) {
|
2021-07-08 12:02:08 +00:00
|
|
|
return <RecaptchaV2Component {...props} handleError={handleError} />;
|
|
|
|
|
} else {
|
|
|
|
|
return <RecaptchaV3Component {...props} handleError={handleError} />;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|
2020-10-12 13:01:19 +00:00
|
|
|
|
2019-10-21 15:12:45 +00:00
|
|
|
// To be used with the canvas
|
2021-08-24 13:53:15 +00:00
|
|
|
function ButtonComponent(props: ButtonComponentProps & RecaptchaProps) {
|
2021-08-17 11:26:05 +00:00
|
|
|
const btnWrapper = (
|
2020-10-12 13:01:19 +00:00
|
|
|
<BtnWrapper
|
2022-07-14 07:02:35 +00:00
|
|
|
className={props.className}
|
2020-10-12 13:01:19 +00:00
|
|
|
clickWithRecaptcha={props.clickWithRecaptcha}
|
2021-04-28 10:28:39 +00:00
|
|
|
googleRecaptchaKey={props.googleRecaptchaKey}
|
2021-08-03 13:36:03 +00:00
|
|
|
handleRecaptchaV2Loading={props.handleRecaptchaV2Loading}
|
2022-03-22 06:52:39 +00:00
|
|
|
isDisabled={props.isDisabled}
|
2022-05-03 05:25:31 +00:00
|
|
|
isLoading={props.isLoading}
|
2019-11-13 07:00:25 +00:00
|
|
|
onClick={props.onClick}
|
2022-01-02 16:27:39 +00:00
|
|
|
recaptchaType={props.recaptchaType}
|
2020-10-12 13:01:19 +00:00
|
|
|
>
|
2022-03-13 17:21:04 +00:00
|
|
|
<BaseButton
|
|
|
|
|
borderRadius={props.borderRadius}
|
|
|
|
|
boxShadow={props.boxShadow}
|
|
|
|
|
boxShadowColor={props.boxShadowColor}
|
|
|
|
|
buttonColor={props.buttonColor}
|
|
|
|
|
buttonVariant={props.buttonVariant}
|
|
|
|
|
disabled={props.isDisabled}
|
|
|
|
|
icon={props.icon}
|
|
|
|
|
iconAlign={props.iconAlign}
|
|
|
|
|
iconName={props.iconName}
|
|
|
|
|
loading={props.isLoading}
|
|
|
|
|
placement={props.placement}
|
|
|
|
|
rightIcon={props.rightIcon}
|
|
|
|
|
text={props.text}
|
|
|
|
|
type={props.type}
|
|
|
|
|
/>
|
2020-10-12 13:01:19 +00:00
|
|
|
</BtnWrapper>
|
2019-10-21 15:12:45 +00:00
|
|
|
);
|
2021-08-17 11:26:05 +00:00
|
|
|
if (props.tooltip) {
|
|
|
|
|
return (
|
|
|
|
|
<ToolTipWrapper>
|
2021-11-03 03:54:19 +00:00
|
|
|
<TooltipStyles />
|
|
|
|
|
<Popover2
|
|
|
|
|
autoFocus={false}
|
|
|
|
|
content={<Interweave content={props.tooltip} />}
|
2021-08-17 11:26:05 +00:00
|
|
|
hoverOpenDelay={200}
|
2021-11-03 03:54:19 +00:00
|
|
|
interactionKind="hover"
|
|
|
|
|
portalClassName="btnTooltipContainer"
|
2021-08-17 11:26:05 +00:00
|
|
|
position={Position.TOP}
|
|
|
|
|
>
|
|
|
|
|
{btnWrapper}
|
2021-11-03 03:54:19 +00:00
|
|
|
</Popover2>
|
2021-08-17 11:26:05 +00:00
|
|
|
</ToolTipWrapper>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
return btnWrapper;
|
|
|
|
|
}
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|
2019-10-21 15:12:45 +00:00
|
|
|
|
2021-08-24 13:53:15 +00:00
|
|
|
export default ButtonComponent;
|