Skip to content

Commit 01dd62e

Browse files
authored
Disable app cases (#198)
* disable component in all non-sql classic mode pages * default to app enable flag first
1 parent eaad41e commit 01dd62e

File tree

5 files changed

+99
-37
lines changed

5 files changed

+99
-37
lines changed

apps/src/metabase/appState.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export class MetabaseState extends DefaultAppState<MetabaseAppState> {
8181
isEnabled: toolEnabledNew,
8282
toolContext: {
8383
...oldState.toolContext,
84-
pageType
84+
pageType,
85+
url
8586
}
8687
}));
8788
const dbId = await getSelectedDbId();
@@ -331,7 +332,7 @@ function shouldEnable(elements: DOMQueryMapResponse, url: string) {
331332
}))
332333
const SQLQueryURL = new URL(url).origin + '/question#' + hash;
333334
const MBQLURL = new URL(url).origin + '/question/notebook';
334-
const reason = `To enable MinusX on Metabase, head over to the SQL query [page](${SQLQueryURL}) or the Question Builder [page](${MBQLURL})!`
335+
const reason = `To use MinusX on Metabase, head over to the [SQL query](${SQLQueryURL}), [Question Builder](${MBQLURL}) or any of your Dashboard pages!`
335336
const metabasePageType = determineMetabasePageType(elements, url);
336337
if (metabasePageType === 'unknown') {
337338
return {

web/src/components/common/App.tsx

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import {
88
Tooltip,
99
Spacer,
1010
Button,
11-
Link
11+
Link,
12+
Box,
13+
Flex
1214
} from '@chakra-ui/react'
1315
import logo from '../../assets/img/logo.svg'
1416
import React, { forwardRef, useEffect, useState } from 'react'
@@ -39,7 +41,7 @@ import { captureEvent, GLOBAL_EVENTS } from '../../tracking'
3941
import NotificationHandler from './NotificationHandler'
4042
import notificationService from '../../services/notificationService'
4143
import { useSocketIO } from '../../hooks/useSocketIO'
42-
44+
import { DisabledOverlay } from './DisabledOverlay'
4345

4446
const useAppStore = getApp().useStore()
4547

@@ -50,6 +52,8 @@ const AppInstructions = () => {
5052
const addonsActivate = `${configs.WEB_URL}/screenshots/addons-activate.png`
5153
const addonsUnavailable = `${configs.WEB_URL}/screenshots/addons-unavailable.png`
5254
const addOnStatus = useAppStore((state) => state.addOnStatus)
55+
const width = getParsedIframeInfo().width
56+
5357
useEffect(() => {
5458
if (addOnStatus == 'activated') {
5559
toggleMinusXRoot('closed', true)
@@ -285,35 +289,6 @@ const AppLoggedIn = forwardRef((_props, ref) => {
285289
)
286290
})
287291

288-
const width = getParsedIframeInfo().width
289-
function DisabledOverlayComponent({ toolEnabledReason }: { toolEnabledReason: string }) {
290-
const isDevToolsOpen = useSelector((state: RootState) => state.settings.isDevToolsOpen)
291-
return <div style={{
292-
position: 'absolute',
293-
top: 0,
294-
right: 0,
295-
width: isDevToolsOpen ? '850px' : `${width}px`, // Hack to fix Disabled Overlay
296-
height: '100%',
297-
backgroundColor: 'rgba(255, 255, 255, 0.8)',
298-
zIndex: 1000,
299-
display: 'flex',
300-
alignItems: 'center',
301-
justifyContent: 'center'
302-
}}>
303-
<span style={{
304-
fontSize: '1rem',
305-
fontWeight: 'bold',
306-
color: '#fff',
307-
padding: '10px 30px',
308-
margin: '10px',
309-
backgroundColor: '#16a085',
310-
borderRadius: '5px',
311-
textAlign: 'center'
312-
}}>
313-
<Markdown content={toolEnabledReason}/>
314-
</span>
315-
</div>
316-
}
317292

318293
const AppBody = forwardRef((_props, ref) => {
319294
const auth = useSelector((state: RootState) => state.auth)
@@ -365,7 +340,7 @@ const AppBody = forwardRef((_props, ref) => {
365340
return (
366341
<>
367342
{isDevToolsOpen && <DevToolsBox />}
368-
{!toolEnabled.value && <DisabledOverlayComponent toolEnabledReason={toolEnabled.reason} />}
343+
{!toolEnabled.value && <DisabledOverlay toolEnabledReason={toolEnabled.reason} />}
369344
<AppLoggedIn ref={ref}/>
370345
</>
371346
)

web/src/components/common/Chat.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export const ChatSection = () => {
192192
const activeThread = useSelector((state: RootState) => state.chat.threads[thread])
193193
const messages = activeThread.messages
194194
const tasks = activeThread.tasks
195-
const href = getParsedIframeInfo().href
195+
const url = useAppStore((state) => state.toolContext)?.url || ''
196196

197197
useEffect(() => {
198198
setTimeout(() => {
@@ -214,7 +214,7 @@ export const ChatSection = () => {
214214
}
215215
})
216216
const Chats = isEmpty(messagesWithStatus) ?
217-
(getDemoIDX(href) == -1 ? <HelperMessage /> : <DemoHelperMessage url={href}/>) :
217+
(getDemoIDX(url) == -1 ? <HelperMessage /> : <DemoHelperMessage url={url}/>) :
218218
messagesWithStatus.map((message, key) => (<Chat key={key} {...message} />))
219219

220220
return (
@@ -226,7 +226,7 @@ export const ChatSection = () => {
226226
<div style={{ height: '10px', width: '100%' }} />
227227
<div ref={messagesEndRef} />
228228
</HStack>
229-
<DemoSuggestions url={href}/>
229+
<DemoSuggestions url={url}/>
230230
</VStack>
231231
)
232232
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import React from 'react'
2+
import { useSelector } from 'react-redux'
3+
import {
4+
Icon,
5+
Box,
6+
Flex
7+
} from '@chakra-ui/react'
8+
import { getParsedIframeInfo } from '../../helpers/origin'
9+
import { RootState } from '../../state/store'
10+
import { Markdown } from './Markdown'
11+
import { BsFillLightningFill } from 'react-icons/bs'
12+
13+
14+
export function DisabledOverlay({ toolEnabledReason }: { toolEnabledReason: string }) {
15+
const isDevToolsOpen = useSelector((state: RootState) => state.settings.isDevToolsOpen)
16+
const width = getParsedIframeInfo().width
17+
18+
19+
return (
20+
<Box
21+
position="absolute"
22+
top={0}
23+
right={0}
24+
width={isDevToolsOpen ? '850px' : `${width}px`}
25+
height="100%"
26+
bg="rgba(255, 255, 255, 0.5)"
27+
backdropFilter="blur(4px)"
28+
zIndex={1000}
29+
display="flex"
30+
alignItems="center"
31+
justifyContent="center"
32+
>
33+
<Flex
34+
direction="column"
35+
align="center"
36+
justify="center"
37+
bg="white"
38+
borderRadius="xl"
39+
boxShadow="2xl"
40+
p={8}
41+
mx={6}
42+
maxWidth="400px"
43+
border="1px solid"
44+
borderColor="gray.200"
45+
transform="scale(1)"
46+
transition="all 0.2s ease-in-out"
47+
_hover={{
48+
transform: 'scale(1.02)',
49+
boxShadow: '3xl'
50+
}}
51+
>
52+
<Box
53+
width="60px"
54+
height="60px"
55+
borderRadius="full"
56+
bg="minusxGreen.100"
57+
display="flex"
58+
alignItems="center"
59+
justifyContent="center"
60+
mb={4}
61+
>
62+
<Icon as={BsFillLightningFill} boxSize={6} color="white" />
63+
</Box>
64+
65+
<Box
66+
fontSize="md"
67+
fontWeight="medium"
68+
color="gray.700"
69+
textAlign="center"
70+
lineHeight="1.6"
71+
>
72+
<Markdown content={toolEnabledReason} />
73+
</Box>
74+
</Flex>
75+
</Box>
76+
)
77+
}

web/src/components/common/TaskUI.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import { toast } from '../../app/toast'
5757
import { NUM_RELEVANT_TABLES, resetRelevantTables } from './TablesCatalog'
5858
import { setupCollectionsAndModels } from '../../state/settings/availableCatalogsListener'
5959
import { Notify } from './Notify'
60+
import { DisabledOverlay } from './DisabledOverlay'
6061

6162

6263

@@ -84,6 +85,7 @@ const TaskUI = forwardRef<HTMLTextAreaElement>((_props, ref) => {
8485

8586
const selectedCatalog = useSelector((state: RootState) => state.settings.selectedCatalog)
8687
const toolContext: MetabaseContext = useAppStore((state) => state.toolContext)
88+
const isAppEnabled: boolean = useAppStore((state) => state.isEnabled)?.value || false
8789
const selectedModels = useSelector((state: RootState) => state.settings.selectedModels)
8890

8991
const tableDiff = useSelector((state: RootState) => state.settings.tableDiff)
@@ -323,7 +325,13 @@ const TaskUI = forwardRef<HTMLTextAreaElement>((_props, ref) => {
323325
});
324326
}
325327

328+
const shouldBeEnabled = drMode || toolContext.pageType === 'sql'
329+
326330
return (
331+
<>
332+
{
333+
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!"}/>
334+
}
327335
<VStack
328336
justifyContent="space-between"
329337
alignItems="stretch"
@@ -516,6 +524,7 @@ const TaskUI = forwardRef<HTMLTextAreaElement>((_props, ref) => {
516524
</Stack>
517525
</VStack>
518526
</VStack>
527+
</>
519528
)
520529
})
521530

0 commit comments

Comments
 (0)