Skip to content

Commit 1fb37e2

Browse files
authored
Seed questions (#323)
* handle overflow * fix readability on context * fix rendering on team memory * helper msg and seed qs work
1 parent ce0c6ce commit 1fb37e2

File tree

6 files changed

+106
-95
lines changed

6 files changed

+106
-95
lines changed

web/src/components/common/Chat.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { Markdown } from './Markdown';
1515
import { Tasks } from './Tasks'
1616
import { TasksLite } from './TasksLite'
1717
import { getParsedIframeInfo } from '../../helpers/origin'
18-
import { DemoHelperMessage, DemoSuggestions, getDemoIDX } from './DemoComponents';
18+
import { DemoHelperMessage, DemoSuggestions } from './DemoComponents';
1919
import { configs } from '../../constants'
2020
import { setMinusxMode } from '../../app/rpc'
2121

@@ -208,16 +208,6 @@ const Chat: React.FC<ReturnType<typeof addToolInfoToActionPlanMessages>[number]>
208208

209209
const useAppStore = getApp().useStore()
210210

211-
const HelperMessage = () => {
212-
const helperMessage = useAppStore((state) => state.helperMessage)
213-
if (!helperMessage) {
214-
return null
215-
}
216-
// return <Chat role='user' index={-1} content={{type: 'DEFAULT', text: helperMessage, images: []}} />
217-
return <SettingsBlock title={"Welcome"} ariaLabel="welcome-message"><Markdown content={helperMessage}/></SettingsBlock>
218-
219-
}
220-
221211
export const ChatSection = () => {
222212
const lastMessageRef = useRef<HTMLDivElement>(null);
223213
const thread = useSelector((state: RootState) => state.chat.activeThread)
@@ -260,7 +250,7 @@ export const ChatSection = () => {
260250
return returnValue
261251
})
262252
const Chats = isEmpty(messagesWithStatus) ?
263-
(getDemoIDX(url) == -1 ? <HelperMessage /> : <DemoHelperMessage url={url}/>) :
253+
<DemoHelperMessage url={url}/>:
264254
messagesWithStatus.map((message, key) => (
265255
<Chat key={key} {...message}/>
266256
))

web/src/components/common/DemoComponents.tsx

Lines changed: 28 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,93 +4,53 @@ import { SettingsBlock } from './SettingsBlock'
44
import { Markdown } from './Markdown';
55
import { useSelector } from 'react-redux';
66
import { RootState } from '../../state/store';
7+
import { getApp } from '../../helpers/app';
78

89

9-
const DEMO_SLUGS = [
10-
"/138-demo-sql",
11-
"/139-demo-mbql",
12-
"/1-e-commerce-insights",
13-
"/35-us-green-card",
14-
]
15-
16-
const MESSAGES = [
17-
`Hey there! Welcome to the **MinusX SQL Demo**. Try any of the suggested questions, or ask something of your own!
18-
19-
---
20-
\`[badge]Protip: \` Click the **[Context](https://docs.minusx.ai/en/articles/11166007-default-tables)** quick action to control the tables MinusX can see!`,
21-
`Hey there! Welcome to the **[MinusX Question Builder Demo](https://docs.minusx.ai/en/articles/11637221-metabase-gui-question-builder)**. Try any of the suggested questions, or ask something of your own!
22-
23-
---
24-
\`[badge]Protip: \` Click the MinusX logo on the left to toggle the side panel`,
25-
`Hey there! Welcome to the **[MinusX Dashboard Demo](https://docs.minusx.ai/en/articles/11496071-q-a-on-dashboards)**. Try any of the suggested questions, or ask something of your own!
26-
27-
---
28-
\`[badge]Protip: \` Install MinusX on your own Metabase with a [simple Chrome Extension](https://minusx.ai/chrome-extension/)`,
29-
`Welcome to MinusX! Use this chat to ask any questions about the data.
30-
31-
---
32-
\`[badge]Protip: \` Install MinusX on your own Metabase with a [simple Chrome Extension](https://minusx.ai/chrome-extension/)`
33-
]
34-
35-
const MESSAGE_TITLES = [
36-
"SQL Demo",
37-
"MBQL Demo",
38-
"Dashboard Q&A",
39-
"Green Cards"
40-
]
41-
42-
const ALL_SUGGESTIONS = [
43-
[
44-
"show me monthly category wise sales but i want 2023 and 2024 in separate columns, with a col for % change",
45-
"bar plot this!",
46-
],
47-
[
48-
"filter for this year, sort by orders",
49-
"pick top 15?"
50-
],
51-
[
52-
"what's the total non gizmo order %?"
53-
],
54-
[
55-
"Show me the top 10th percentile of income for H1Bs",
56-
"Show me the top 10 most popular green card visa categories",
57-
"How many green card applications were certified in 2024?"
58-
]
59-
]
60-
61-
export const getDemoIDX = (url: string) => {
62-
return DEMO_SLUGS.findIndex(slug => url.includes(slug))
63-
}
10+
const useAppStore = getApp().useStore()
6411

6512
export const DemoHelperMessage = ({url}: {url: string}) => {
66-
const demoIDX = getDemoIDX(url)
67-
if (demoIDX === -1) {
68-
return null
69-
}
13+
const availableAssets = useSelector((state: RootState) => state.settings.availableAssets)
14+
const selectedAssetId = useSelector((state: RootState) => state.settings.selectedAssetId)
15+
const useTeamMemory = useSelector((state: RootState) => state.settings.useTeamMemory)
16+
const selectedAsset = availableAssets.find(asset => asset.slug === selectedAssetId) ||
17+
(availableAssets.length > 0 ? availableAssets[0] : null)
7018

71-
const message = MESSAGES[demoIDX]
72-
return <SettingsBlock title={MESSAGE_TITLES[demoIDX]} ariaLabel="welcome-message"><Markdown content={message}/></SettingsBlock>
19+
const teamHelperMessage = (selectedAsset && useTeamMemory && selectedAsset.content?.isActive) ? selectedAsset.content?.helpertexts?.filter(text => text.url === url && text.is_published).map(t => t.text)?.[0] : null
20+
21+
const helperMessage = useAppStore((state) => state.helperMessage)
22+
if (!helperMessage && !teamHelperMessage) {
23+
return null
24+
}
25+
return <SettingsBlock title={"Welcome"} ariaLabel="welcome-message"><Markdown content={teamHelperMessage || helperMessage}/></SettingsBlock>
7326

7427
}
7528

7629
export const DemoSuggestions = ({url}: {url: string}) => {
7730
const thread = useSelector((state: RootState) => state.chat.activeThread)
7831
const activeThread = useSelector((state: RootState) => state.chat.threads[thread])
7932
const taskInProgress = !(activeThread.status == 'FINISHED')
33+
const savedQuestions = useSelector((state: RootState) => state.settings.savedQuestions)
34+
const showSavedQuestions = useSelector((state: RootState) => state.settings.suggestQueries)
35+
const availableAssets = useSelector((state: RootState) => state.settings.availableAssets)
36+
const selectedAssetId = useSelector((state: RootState) => state.settings.selectedAssetId)
37+
const useTeamMemory = useSelector((state: RootState) => state.settings.useTeamMemory)
38+
const selectedAsset = availableAssets.find(asset => asset.slug === selectedAssetId) ||
39+
(availableAssets.length > 0 ? availableAssets[0] : null)
40+
41+
const personalQuestions = showSavedQuestions ? savedQuestions : []
42+
const teamQuestions = (selectedAsset && useTeamMemory && selectedAsset.content?.isActive) ? selectedAsset.content?.questions?.filter(q => q.is_published && q.source_url === url).map(q => q.content) : []
43+
const allQuestions = [...personalQuestions, ...teamQuestions]
44+
8045

81-
const [clickedSuggestions, setClickedSuggestions] = useState<Set<string>>(new Set())
82-
const demoIDX = getDemoIDX(url)
83-
if (demoIDX === -1) {
84-
return null
85-
}
8646

87-
const suggestions = ALL_SUGGESTIONS[demoIDX] || []
47+
const [clickedSuggestions, setClickedSuggestions] = useState<Set<string>>(new Set())
8848

8949
const handleSuggestionClick = (suggestion: string) => {
9050
setClickedSuggestions(prev => new Set([...prev, suggestion]))
9151
}
9252

93-
const visibleSuggestions = suggestions.filter(suggestion => !clickedSuggestions.has(suggestion))
53+
const visibleSuggestions = allQuestions.filter(suggestion => !clickedSuggestions.has(suggestion))
9454

9555
if (visibleSuggestions.length === 0) {
9656
return null

web/src/components/common/FilterableTable.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import {
1818
Collapse,
1919
Flex,
2020
Spacer,
21-
HStack
21+
HStack,
22+
Tooltip
2223
} from "@chakra-ui/react";
2324
import { ChevronDownIcon, ChevronRightIcon } from '@chakra-ui/icons';
2425
import { FormattedTable, MetabaseModel } from 'apps/types';
@@ -138,7 +139,9 @@ const Node: FC<FixedSizeNodeComponentProps<TreeData>> = ({
138139
variant="subtle"
139140
mr={2}
140141
/>
141-
<Text fontWeight="bold">schema: <Badge color="minusxGreen.600">{name}</Badge></Text>
142+
<Tooltip label={name} hasArrow placement="top">
143+
<Text fontWeight="bold">schema: <Badge color="minusxGreen.600">{name.length > 10 ? `${name.slice(0, 10)}...` : name}</Badge></Text>
144+
</Tooltip>
142145
<Spacer />
143146
<Badge color="minusxGreen.600">{numTables} tables</Badge>
144147
</Flex>

web/src/components/common/SettingsBlock.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const SettingsHeader = ({ text }: { text: string }) => (
1111
)
1212

1313
export const SettingsBlock = ({title, ariaLabel, children}: {title: string, ariaLabel?: string, children: React.ReactNode}) => (
14-
<VStack borderRadius={10} bg="minusxBW.300" alignItems={"stretch"} padding={3} aria-label={ariaLabel}>
14+
<VStack borderRadius={10} bg="minusxBW.300" alignItems={"stretch"} padding={3} aria-label={ariaLabel} w={"100%"}>
1515
<SettingsHeader text={title} />
1616
{children}
1717
</VStack>

web/src/components/common/TaskUI.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ const TaskUI = forwardRef<HTMLTextAreaElement>((_props, ref) => {
110110
const analystMode = useSelector((state: RootState) => state.settings.analystMode)
111111
const proUser = useSelector((state: RootState) => state.billing.isSubscribed)
112112
const enterpriseUser = useSelector((state: RootState) => state.billing.isEnterpriseCustomer)
113-
const savedQuestions = useSelector((state: RootState) => state.settings.savedQuestions)
114-
const showSavedQuestions = useSelector((state: RootState) => state.settings.suggestQueries)
115113

116114
const creditsExhausted = () => (credits <= 0 && infoLoaded)
117115
const creditsLow = () => (credits <= LOW_CREDITS_THRESHOLD && infoLoaded)
@@ -577,10 +575,10 @@ const TaskUI = forwardRef<HTMLTextAreaElement>((_props, ref) => {
577575
<Thumbnails thumbnails={thumbnails} />
578576
<UserConfirmation/>
579577
<Clarification/>
580-
{
578+
{/* {
581579
savedQuestions.length > 0 && !taskInProgress && showSavedQuestions &&
582580
<Suggestions title="Saved Questions" suggestions={savedQuestions} />
583-
}
581+
} */}
584582

585583
{
586584
appEnabledStatus.alert.type &&
@@ -742,7 +740,7 @@ const TaskUI = forwardRef<HTMLTextAreaElement>((_props, ref) => {
742740
<Text fontSize="xs" fontWeight="medium">Team Memory</Text>
743741
</HStack>
744742
<HStack spacing={1} alignItems="center">
745-
<Text fontSize="xs" color="gray.500">{useTeamMemory ? selectedAssetName : 'Disabled'}</Text>
743+
<Text fontSize="xs" color="gray.500">{useTeamMemory ? (selectedAssetName.length > 8 ? `${selectedAssetName.slice(0, 8)}...` : selectedAssetName) : 'Disabled'}</Text>
746744
<Icon
747745
as={useTeamMemory ? BiSolidCheckCircle : BiSolidXCircle}
748746
size={10}

web/src/components/devtools/TeamMemory.tsx

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ import { DisabledOverlay } from '../common/DisabledOverlay';
1111
import { Markdown } from '../common/Markdown';
1212
import { Notify } from '../common/Notify';
1313

14+
15+
interface Question {
16+
content: string;
17+
source_url: string;
18+
is_published: boolean;
19+
}
20+
21+
interface HelperText {
22+
text: string;
23+
url: string;
24+
is_published: boolean;
25+
}
26+
1427
export const TeamMemory: React.FC = () => {
1528
const tool = getParsedIframeInfo().tool
1629
const availableAssets = useSelector((state: RootState) => state.settings.availableAssets)
@@ -31,6 +44,7 @@ export const TeamMemory: React.FC = () => {
3144
const selectedAsset = availableAssets.find(asset => asset.slug === selectedAssetId) ||
3245
(availableAssets.length > 0 ? availableAssets[0] : null)
3346

47+
3448
if (tool != 'metabase') {
3549
return <Text>Coming soon!</Text>
3650
}
@@ -310,22 +324,68 @@ const AssetContentDisplay: React.FC<{ asset: any }> = ({ asset }) => {
310324
<Text fontSize="sm" fontWeight="semibold" color="gray.700">
311325
Saved Questions ({asset.content.questions.length})
312326
</Text>
313-
{asset.content.questions.map((question: any, index: number) => (
314-
<HStack
327+
{asset.content.questions.map((question: Question, index: number) => (
328+
<VStack
315329
key={index}
316330
p={3}
317331
border="1px solid"
318332
borderColor="gray.200"
319333
borderRadius="md"
320-
spacing={3}
321-
justify="flex-start"
334+
spacing={2}
335+
align="flex-start"
322336
>
323-
{question && (
337+
{question.content && (
324338
<Text fontSize="sm" fontWeight="medium" color="gray.800">
325-
{question}
339+
{question.content}
326340
</Text>
327341
)}
328-
</HStack>
342+
{question.source_url && (
343+
<Text fontSize="xs" color="blue.600" textDecoration="underline">
344+
{question.source_url}
345+
</Text>
346+
)}
347+
{question.is_published !== undefined && (
348+
<Badge colorScheme={question.is_published ? "green" : "orange"} variant="subtle" fontSize="xs">
349+
{question.is_published ? "Published" : "Draft"}
350+
</Badge>
351+
)}
352+
</VStack>
353+
))}
354+
</VStack>
355+
)}
356+
357+
{
358+
asset.content.helpertexts && asset.content.helpertexts.length > 0 && (
359+
<VStack align="stretch" spacing={3} borderTop="1px solid" borderColor="gray.300" pt={5}>
360+
<Text fontSize="sm" fontWeight="semibold" color="gray.700">
361+
Helper Texts ({asset.content.helpertexts.length})
362+
</Text>
363+
{asset.content.helpertexts.map((helperText: HelperText, index: number) => (
364+
<VStack
365+
key={index}
366+
p={3}
367+
border="1px solid"
368+
borderColor="gray.200"
369+
borderRadius="md"
370+
spacing={2}
371+
align="flex-start"
372+
>
373+
{helperText.text && (
374+
<Text fontSize="sm" fontWeight="medium" color="gray.800">
375+
{helperText.text}
376+
</Text>
377+
)}
378+
{helperText.url && (
379+
<Text fontSize="xs" color="blue.600" textDecoration="underline">
380+
{helperText.url}
381+
</Text>
382+
)}
383+
{helperText.is_published !== undefined && (
384+
<Badge colorScheme={helperText.is_published ? "green" : "orange"} variant="subtle" fontSize="xs">
385+
{helperText.is_published ? "Published" : "Draft"}
386+
</Badge>
387+
)}
388+
</VStack>
329389
))}
330390
</VStack>
331391
)}

0 commit comments

Comments
 (0)