Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[ui] Add a chip to indicate pro features #3358

Merged
merged 22 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ae1248e
fix: Remove error states
bharatkashyap Apr 5, 2024
ffd2da4
fix: Add paid feature badge
bharatkashyap Apr 5, 2024
a40fef0
fix: Missed reversing test changes
bharatkashyap Apr 5, 2024
1fe91e9
fix: Unnecessary
bharatkashyap Apr 5, 2024
54d1ec7
Merge branch 'master' into feat/pro-badge
bharatkashyap Apr 5, 2024
534f3e9
fix: Links and copy
bharatkashyap Apr 5, 2024
4e7b91e
Merge branch 'feat/pro-badge' of github.com:bharatkashyap/mui-toolpad…
bharatkashyap Apr 5, 2024
0080614
fix: Olivier review 1
bharatkashyap Apr 5, 2024
7d55f78
Merge branch 'master' into feat/pro-badge
bharatkashyap Apr 5, 2024
10f0ed5
Merge branch 'master' into feat/pro-badge
bharatkashyap Apr 8, 2024
5310c84
fix: Use chip instead of badge
bharatkashyap Apr 9, 2024
39b6c89
Merge branch 'feat/pro-badge' of github.com:bharatkashyap/mui-toolpad…
bharatkashyap Apr 9, 2024
a8238e4
Merge branch 'master' into feat/pro-badge
bharatkashyap Apr 9, 2024
b29a321
fix: Use a `<UpgradeNotification />` which scales better
bharatkashyap Apr 10, 2024
4a82701
Merge branch 'master' into feat/pro-badge
bharatkashyap Apr 10, 2024
354eda2
fix: Jan review
bharatkashyap Apr 10, 2024
9840986
Merge branch 'master' into feat/pro-badge
bharatkashyap Apr 10, 2024
4334145
fix reusability
Janpot Apr 10, 2024
6f572fa
configurable url
Janpot Apr 10, 2024
4588f46
fix: Better reusability patterns
bharatkashyap Apr 10, 2024
216aa53
fix: This should be abstracted
bharatkashyap Apr 10, 2024
7b1e08e
fix: Prefer `size` over `sx` for perf and readability
bharatkashyap Apr 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import invariant from 'invariant';
import { useAppState, useAppStateApi } from '../AppState';
import TabPanel from '../../components/TabPanel';
import AzureIcon from '../../components/icons/AzureIcon';
import { UpgradeAlert } from './UpgradeAlert';
import { UpgradeNotification } from './UpgradeNotification';

interface AuthProviderOption {
name: string;
Expand Down Expand Up @@ -153,7 +153,9 @@ export function AppAuthenticationEditor() {
<Checkbox checked={authProviders.indexOf(value as appDom.AuthProvider) > -1} />
{icon}
<Typography mx={1}>{name}</Typography>
{hasRoles && !isPaidPlan ? <UpgradeAlert type="warning" feature={name} /> : null}
{hasRoles && !isPaidPlan ? (
<UpgradeNotification variant="alert" type="warning" feature={name} />
) : null}
</Stack>
</MenuItem>
))}
Expand Down Expand Up @@ -184,19 +186,22 @@ export function AppAuthenticationEditor() {
placeholder="example.com"
/>
))}
{!isPaidPlan ? (
<UpgradeAlert
type="info"
feature="Using authentication with a few specific providers (Azure AD)"
sx={{ position: 'absolute', bottom: (theme) => theme.spacing(4) }}
/>
) : (
<UpgradeAlert
type="warning"
warning="You are using features that are not covered by our MIT License. You will have to buy a license to use them in production."
sx={{ position: 'absolute', bottom: (theme) => theme.spacing(4) }}
/>
)}
<div style={{ position: 'absolute', bottom: 0 }}>
{!isPaidPlan ? (
<UpgradeNotification
variant="alert"
type="info"
feature="Using authentication with a few specific providers (Azure AD)"
action
/>
) : (
<UpgradeNotification
variant="alert"
type="warning"
warning="You are using features that are not covered by our MIT License. You will have to buy a license to use them in production."
/>
)}
</div>
</Stack>
);
}
Expand Down Expand Up @@ -713,7 +718,7 @@ export default function AppAuthorizationDialog({ open, onClose }: AppAuthorizati
) : null}
</TabList>
</Box>
<DialogContent sx={{ minHeight: 480 }}>
<DialogContent sx={{ minHeight: 480, position: 'relative' }}>
<TabPanel disableGutters value="authentication">
<AppAuthenticationEditor />
</TabPanel>
Expand All @@ -729,7 +734,11 @@ export default function AppAuthorizationDialog({ open, onClose }: AppAuthorizati
<AppRolesEditor onRowUpdateError={handleRowUpdateError} />
</React.Fragment>
) : (
<UpgradeAlert type="info" feature="Role based access control" />
<UpgradeNotification
variant="alert"
type="info"
feature="Role based access control"
/>
)}
</TabPanel>
<TabPanel disableGutters value="roleMappings">
Expand All @@ -744,7 +753,7 @@ export default function AppAuthorizationDialog({ open, onClose }: AppAuthorizati
/>
</React.Fragment>
) : (
<UpgradeAlert type="info" feature="Role mapping" />
<UpgradeNotification variant="alert" type="info" feature="Role mapping" />
)}
</TabPanel>
</React.Fragment>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
Chip,
Stack,
Tooltip,
Typography,
Expand All @@ -21,6 +20,7 @@ import UrlQueryEditor from './UrlQueryEditor';
import NodeNameEditor from '../NodeNameEditor';
import PageTitleEditor from '../PageTitleEditor';
import PageDisplayNameEditor from '../PageDisplayNameEditor';
import { UpgradeNotification } from '../UpgradeNotification';

const PAGE_DISPLAY_OPTIONS: { value: appDom.PageDisplayMode; label: string }[] = [
{ value: 'shell', label: 'App shell' },
Expand Down Expand Up @@ -124,34 +124,7 @@ export default function PageOptionsPanel() {
<div>
<Typography variant="overline">
Authorization{' '}
{!isPaidPlan ? (
<Tooltip
title={
<Typography variant="inherit">
Only available in paid plans. Click to learn more.
</Typography>
}
>
<Chip
variant="outlined"
color="primary"
component={'a'}
href="https://mui.com/toolpad/studio/concepts/rbac/"
target="_blank"
rel="noopener"
sx={{
height: '1.5rem',
fontSize: 'inherit',
verticalAlign: 'inherit',
mx: '0.2rem',
'& :hover': {
cursor: 'pointer',
},
}}
label="Pro"
/>
</Tooltip>
) : null}
{!isPaidPlan ? <UpgradeNotification variant="chip" feature="Authorization" /> : null}
</Typography>

{isPaidPlan ? (
Expand Down
66 changes: 0 additions & 66 deletions packages/toolpad-studio/src/toolpad/AppEditor/UpgradeAlert.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import * as React from 'react';
import Alert, { AlertColor } from '@mui/material/Alert';
import Button from '@mui/material/Button';
import Chip from '@mui/material/Chip';
import Tooltip from '@mui/material/Tooltip';
import { SxProps, Theme } from '@mui/system';
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
import { UPGRADE_URL } from '../../constants';

export function UpgradeNotification({
type,
feature,
warning,
variant,
action,
sx,
}: {
type?: AlertColor;
feature?: string;
warning?: string;
variant?: 'alert' | 'chip';
Copy link
Member

Choose a reason for hiding this comment

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

Just export two components, an alert and a chip

action?: boolean;
sx?: SxProps<Theme>;
}) {
let message = `This feature requires a paid plan.`;

if (warning) {
message = warning;
}
if (feature) {
message = `${feature} requires a paid plan.`;
}

if (variant === 'alert') {
return (
<Alert
severity={type ?? 'info'}
sx={{ '.MuiAlert-action': { pt: 0 }, ...sx }}
action={
action ? (
<Button
variant="text"
sx={{ fontSize: 'inherit' }}
href={UPGRADE_URL}
target="_blank"
rel="noopener"
endIcon={<OpenInNewIcon fontSize="small" />}
>
Upgrade
</Button>
) : null
}
>
{message}
</Alert>
);
}
if (variant === 'chip') {
return (
<Tooltip title={`${message} Click to learn more.`}>
<Chip
variant="outlined"
color="primary"
component="a"
href={UPGRADE_URL}
target="_blank"
rel="noopener"
clickable
sx={{
height: '1.5rem',
fontSize: 'inherit',
verticalAlign: 'inherit',
mx: '0.2rem',
}}
label="Pro"
/>
</Tooltip>
);
}
}
Loading