Skip to content

Commit f7a50a9

Browse files
authored
Alert manager (#259)
* handle all alerts in one place * text change
1 parent 6056ef1 commit f7a50a9

File tree

2 files changed

+88
-39
lines changed

2 files changed

+88
-39
lines changed

web/src/components/common/App.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import { captureEvent, GLOBAL_EVENTS } from '../../tracking'
4242
import NotificationHandler from './NotificationHandler'
4343
import notificationService from '../../services/notificationService'
4444
import { useSocketIO } from '../../hooks/useSocketIO'
45-
import { DisabledOverlay } from './DisabledOverlay'
4645
import { useCustomCSS } from '../../hooks/useCustomCSS'
4746

4847
const useAppStore = getApp().useStore()
@@ -311,8 +310,6 @@ const AppBody = forwardRef((_props, ref) => {
311310
const auth = useSelector((state: RootState) => state.auth)
312311
const appMode = useSelector((state: RootState) => state.settings.appMode)
313312
const isDevToolsOpen = useSelector((state: RootState) => state.settings.isDevToolsOpen)
314-
const demoMode = useSelector((state: RootState) => state.settings.demoMode)
315-
const toolEnabled = useAppStore((state) => state.isEnabled)
316313
const variant = getParsedIframeInfo().variant
317314

318315
// Apply custom CSS throughout the application
@@ -360,7 +357,6 @@ const AppBody = forwardRef((_props, ref) => {
360357
return (
361358
<>
362359
{isDevToolsOpen && <DevToolsBox />}
363-
{!toolEnabled.value && <DisabledOverlay toolEnabledReason={toolEnabled.reason} />}
364360
<AppLoggedIn ref={ref}/>
365361
</>
366362
)

web/src/components/common/TaskUI.tsx

Lines changed: 88 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ import { toast } from '../../app/toast'
6060
import { NUM_RELEVANT_TABLES, resetRelevantTables } from './TablesCatalog'
6161
import { setupCollectionsAndModels } from '../../state/settings/availableCatalogsListener'
6262
import { Notify } from './Notify'
63-
import { DisabledOverlay } from './DisabledOverlay'
6463
import { ContextCatalog } from '../../helpers/utils';
65-
import { dump } from 'js-yaml';
66-
64+
import { Markdown } from './Markdown'
6765

6866

6967
const useAppStore = getApp().useStore()
@@ -96,7 +94,7 @@ const TaskUI = forwardRef<HTMLTextAreaElement>((_props, ref) => {
9694

9795
const toolContext: MetabaseContext = useAppStore((state) => state.toolContext)
9896
const dbInfo = toolContext.dbInfo
99-
const isAppEnabled: boolean = useAppStore((state) => state.isEnabled)?.value || false
97+
const toolEnabled = useAppStore((state) => state.isEnabled)
10098
const selectedModels = useSelector((state: RootState) => state.settings.selectedModels)
10199
// only take models for the current db id
102100
const validSelectedModels = selectedModels.filter(model => model.dbId === dbInfo.id)
@@ -372,17 +370,88 @@ const TaskUI = forwardRef<HTMLTextAreaElement>((_props, ref) => {
372370
});
373371
}
374372

375-
const shouldBeEnabled = drMode || toolContext.pageType === 'sql'
376-
373+
const shouldBeEnabled = (drMode || toolContext.pageType === 'sql')
374+
375+
const getAlertStatus = () => {
376+
// 1. All cases when the input box should be disabled, and an alert shown
377+
if (!toolEnabled?.value || false){
378+
return {
379+
inputBox: false,
380+
alert: {
381+
message: toolEnabled.reason || "MinusX is not enabled for this app.",
382+
type: "error",
383+
title: "MinusX unavailable on this page!"
384+
}
385+
};
386+
387+
}
388+
if (!shouldBeEnabled) {
389+
return {
390+
inputBox: false,
391+
alert: {
392+
message: "You're currently using MinusX Classic, which only works on SQL Editor pages. [Find out](https://minusx.ai/demo) how to enable Agent mode and unlock all the features!",
393+
type: "error",
394+
title: "Try Agent Mode!"
395+
}
396+
};
397+
}
398+
399+
if (creditsExhausted()) {
400+
return {
401+
inputBox: false,
402+
alert: {
403+
message: "You've exhausted your credits for the week. You can either upgrade to a Pro subscription in settings or [talk to us](https://minusx.ai/demo) and get 1 month free Pro!",
404+
type: "error",
405+
title: "Uh Oh! Credits Exhausted"
406+
}
407+
};
408+
}
409+
410+
// 2. All cases when the input box should be enabled, but an alert shown
411+
if (toolContext.pageType === 'mbql'){
412+
return {
413+
inputBox: true,
414+
alert: {
415+
message: "Question Builder feature is new and still in progress. Some things might not work just yet.",
416+
type: "info",
417+
title: "Try Question Builder!"
418+
}
419+
}
420+
}
421+
if (!drMode) {
422+
return {
423+
inputBox: true,
424+
alert: {
425+
message: "You're currently using MinusX Classic. [Find out](https://minusx.ai/demo) how to switch to Agent Mode and unlock exciting new features!",
426+
type: "warning",
427+
title: "Try Agent Mode!"
428+
}
429+
};
430+
}
431+
if (creditsLow()) {
432+
return {
433+
inputBox: true,
434+
alert: {
435+
message: "Running low on credits. You can either upgrade to a Pro subscription in settings or [talk to us](https://minusx.ai/demo) and get 1 month free Pro!",
436+
type: "warning",
437+
title: "Uh Oh! Running Low on Credits"
438+
}
439+
};
440+
}
441+
442+
// 3. All cases when the input box should be enabled, and no alert shown
443+
return {
444+
inputBox: true,
445+
alert: {
446+
type: null,
447+
}
448+
};
449+
}
450+
451+
const appEnabledStatus = getAlertStatus()
377452

378453
return (
379454
<>
380-
{
381-
isAppEnabled && !shouldBeEnabled && <DisabledOverlay toolEnabledReason={"You're currently using MinusX Classic, which only works on SQL Editor pages. [Find out](https://minusx.ai/demo) how to enable Agent mode and unlock all the features!"}/>
382-
}
383-
{/* {
384-
analystMode && (toolContext.pageType != 'sql') && <DisabledOverlay toolEnabledReason={"You're currently using `[badge]Analyst Mode (alpha)`, which only works on SQL Editor pages for now!"}/>
385-
} */}
386455
<VStack
387456
justifyContent="space-between"
388457
alignItems="stretch"
@@ -509,27 +578,11 @@ const TaskUI = forwardRef<HTMLTextAreaElement>((_props, ref) => {
509578
}} colorScheme="minusxGreen" size="sm" disabled={taskInProgress}>feelin' lucky</Button>
510579
} */}
511580
{
512-
(toolContext.pageType === 'mbql' ) &&
513-
<Notify>
514-
<Text fontSize="xs" lineHeight={"1rem"}>Question Builder feature is new and still in progress. Some things might not work just yet.</Text>
515-
</Notify>
516-
}
517-
{
518-
!drMode &&
519-
<Notify title="Hi There!" notificationType='warning'>
520-
<Text fontSize="xs" lineHeight={"1rem"}>You're currently using MinusX Classic. <Link style={{textDecoration: 'underline'}} href="https://minusx.ai/demo" isExternal>Find out</Link> how to switch to Agent Mode and unlock exciting new features!</Text>
521-
</Notify>
522-
}
523-
{
524-
creditsExhausted() &&
525-
<Notify title="Uh oh, Credits Exhausted!" notificationType='error'>
526-
<Text fontSize="xs" lineHeight={"1rem"}>You've exhausted your credits for the week. You can either upgrade to a Pro subscription in <span onClick={() => openDevtoolTab("General Settings")} style={{textDecoration: 'underline', cursor: 'pointer'}}>settings</span> or <Link style={{textDecoration: 'underline'}} href="https://minusx.ai/demo" isExternal>talk to us</Link> and get 1 month free Pro!</Text>
527-
</Notify>
528-
}
529-
{
530-
creditsLow() &&
531-
<Notify title="Ooof, Running low on Credits!" notificationType='warning'>
532-
<Text fontSize="xs" lineHeight={"1rem"}>To get more, you can either upgrade to a Pro subscription in <span onClick={() => openDevtoolTab("General Settings")} style={{textDecoration: 'underline', cursor: 'pointer'}}>settings</span> or <Link style={{textDecoration: 'underline'}} href="https://minusx.ai/demo" isExternal>talk to us</Link> and get 1 month free Pro!</Text>
581+
appEnabledStatus.alert.type &&
582+
<Notify title={appEnabledStatus.alert.title} notificationType={appEnabledStatus.alert.type}>
583+
<Text fontSize="xs" lineHeight={"1rem"}>
584+
<Markdown content={appEnabledStatus.alert.message} />
585+
</Text>
533586
</Notify>
534587
}
535588
{ !taskInProgress &&
@@ -548,7 +601,7 @@ const TaskUI = forwardRef<HTMLTextAreaElement>((_props, ref) => {
548601
}
549602

550603
<VStack width={"100%"} alignItems={"stretch"} gap={0}>
551-
{ currentTool == 'metabase' && !taskInProgress && !creditsExhausted() &&
604+
{ currentTool == 'metabase' && !taskInProgress && appEnabledStatus.inputBox &&
552605
<HStack
553606
mb={-2}
554607
p={2}
@@ -590,7 +643,7 @@ const TaskUI = forwardRef<HTMLTextAreaElement>((_props, ref) => {
590643
}
591644

592645
<ReviewBox />
593-
{ !taskInProgress && !creditsExhausted() &&
646+
{ !taskInProgress && appEnabledStatus.inputBox &&
594647
<Stack aria-label="chat-input-area" position={"relative"}>
595648
<AutosizeTextarea
596649
ref={ref}

0 commit comments

Comments
 (0)