Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
feat: LEAP-572: Implement interface indicator for expired plans (#308)
Browse files Browse the repository at this point in the history
* feat: LEAP-572: Implement interface indicator for expired plans

* implements disabled tooltip

* Update src/components/Common/SDKButtons.js

Co-authored-by: yyassi-heartex <104568407+yyassi-heartex@users.noreply.github.com>

* fix validation to check if user is trial expired

* reorder imports

* add is_license_expired and current_period_end into consts

* create a component to handle disabled tooltip

---------

Co-authored-by: yyassi-heartex <104568407+yyassi-heartex@users.noreply.github.com>
  • Loading branch information
juliosgarbi and yyassi-heartex authored Feb 29, 2024
1 parent 3ce5849 commit 46f0549
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/components/Common/Tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { aroundTransition } from "../../../utils/transition";
import "./Tooltip.styl";

export const Tooltip = forwardRef(
({ title, children, defaultVisible, style }, ref) => {
({ title, children, defaultVisible, disabled, style }, ref) => {
const child = Children.only(children);
const triggerElement = ref ?? useRef();
const tooltipElement = useRef();
Expand Down Expand Up @@ -83,14 +83,20 @@ export const Tooltip = forwardRef(
[injected, offset, title, visibilityClasses, tooltipElement],
);

useEffect(() => {
if (disabled === true && visibility === "visible") performAnimation(false);
}, [disabled]);

const clone = cloneElement(child, {
...child.props,
ref: triggerElement,
onMouseEnter(e) {
if (disabled === true) return;
setInjected(true);
child.props.onMouseEnter?.(e);
},
onMouseLeave(e) {
if (disabled === true) return;
performAnimation(false);
child.props.onMouseLeave?.(e);
},
Expand Down
51 changes: 45 additions & 6 deletions src/components/DataManager/Toolbar/instruments.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { FaCaretDown, FaChevronDown } from "react-icons/fa";
import { FF_LOPS_E_10, isFF } from "../../../utils/feature-flags";
import { Block } from "../../../utils/bem";
import { FF_LOPS_E_10, FF_SELF_SERVE, isFF } from "../../../utils/feature-flags";
import { ErrorBox } from "../../Common/ErrorBox";
import { FieldsButton } from "../../Common/FieldsButton";
import { FiltersPane } from "../../Common/FiltersPane";
import { Icon } from "../../Common/Icon/Icon";
import { Interface } from "../../Common/Interface";
import { ExportButton, ImportButton } from "../../Common/SDKButtons";
import { Tooltip } from "../../Common/Tooltip/Tooltip";
import { ActionsButton } from "./ActionsButton";
import { GridWidthButton } from "./GridWidthButton";
import { LabelButton } from "./LabelButton";
Expand All @@ -14,9 +16,42 @@ import { OrderButton } from "./OrderButton";
import { RefreshButton } from "./RefreshButton";
import { ViewToggle } from "./ViewToggle";

const style = {
minWidth: '110px',
justifyContent: 'space-between',
const style = {
minWidth: '110px',
justifyContent: 'space-between',
};

// Check if user is on trial
const isTrialExpired = window.APP_SETTINGS.billing.checks.is_license_expired;
// Check the subscription period end date
const subscriptionPeriodEnd = window.APP_SETTINGS.subscription.current_period_end;
// Check if user is self-serve
const isSelfServe = isFF(FF_SELF_SERVE) && window.APP_SETTINGS.billing.enterprise;
// Check if user is self-serve and has expired trial
const isSelfServeExpiredTrial = isSelfServe && isTrialExpired && !subscriptionPeriodEnd;
// Check if user is self-serve and has expired subscription
const isSelfServeExpiredSubscription = isSelfServe && subscriptionPeriodEnd && new Date(subscriptionPeriodEnd) < new Date();
// Check if user is self-serve and has expired trial or subscription
const isSelfServeExpired = isSelfServeExpiredTrial || isSelfServeExpiredSubscription;

const WithDisabledTooltip = ({ children, ...props }) => {
if (!props.disabled) {
return children;
}

return (
<Tooltip
title={props.title}
style={{
maxWidth:200,
textAlign: "center",
}}>
<Block name="button-wrapper">
{children}
</Block>
</Tooltip>
);

};

export const instruments = {
Expand All @@ -26,7 +61,7 @@ export const instruments = {
'columns': ({ size }) => {
const iconProps = {};
const isNewUI = isFF(FF_LOPS_E_10);

if (isNewUI) {
iconProps.size = 12;
iconProps.style = {
Expand Down Expand Up @@ -71,7 +106,11 @@ export const instruments = {
'import-button': ({ size }) => {
return (
<Interface name="import">
<ImportButton size={size}>Import</ImportButton>
<WithDisabledTooltip
title="You must upgrade your plan to import data"
disabled={isSelfServeExpired}>
<ImportButton disabled={isSelfServeExpired} size={size}>Import</ImportButton>
</WithDisabledTooltip>
</Interface>
);
},
Expand Down
6 changes: 6 additions & 0 deletions src/utils/feature-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ export const FF_OPTIC_2 = "fflag_feat_optic_2_ensure_draft_saved_short";
*/
export const FF_LOPS_86 = "fflag_feat_front_lops_86_datasets_storage_edit_short";

/**
* Self Serve
* @link https://app.launchdarkly.com/default/test/features/fflag_feat_front_leap_482_self_serve_short/
*/
export const FF_SELF_SERVE = "fflag_feat_front_leap_482_self_serve_short";

// Customize flags
const flags = {};

Expand Down

0 comments on commit 46f0549

Please sign in to comment.