Skip to content

Commit a4a16b9

Browse files
author
Keivan Vosoughi
committed
DSE-45878: Add Mute Checkbox for the Welcome Page
Fix Examples Table for Remote Templates Fix mute checkbox margin top Modify Examples Fix rendering examples based on the selected use case
1 parent d2fa5f4 commit a4a16b9

File tree

7 files changed

+106
-22
lines changed

7 files changed

+106
-22
lines changed

app/client/src/pages/DataGenerator/CustomPromptButton.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ const CustomPromptButton: React.FC<Props> = ({ model_id, inference_type, caii_en
5959
const [showModal, setShowModal] = useState(false);
6060
const [disabled, setDisabled] = useState(false);
6161
const custom_prompt_instructions = Form.useWatch('custom_prompt_instructions', { form, preserve: true });
62-
console.log('custom_prompt_instructions', custom_prompt_instructions);
6362

6463
const mutation = useMutation({
6564
mutationFn: fetchCustomPrompt

app/client/src/pages/DataGenerator/Examples.tsx

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import { useMutation } from "@tanstack/react-query";
99
import { useFetchExamples } from '../../api/api';
1010
import TooltipIcon from '../../components/TooltipIcon';
1111
import PCModalContent from './PCModalContent';
12-
import { File, QuestionSolution, WorkflowType } from './types';
12+
import { ExampleType, File, QuestionSolution, WorkflowType } from './types';
1313
import FileSelectorButton from './FileSelectorButton';
1414

15-
import { fetchFileContent } from './hooks';
15+
import { fetchFileContent, getExampleType, useGetExamplesByUseCase } from './hooks';
1616
import { useState } from 'react';
1717
import FreeFormExampleTable from './FreeFormExampleTable';
1818

19-
const { Title } = Typography;
19+
const { Title, Text } = Typography;
2020
const Container = styled.div`
2121
padding-bottom: 10px
2222
`
@@ -48,10 +48,7 @@ const StyledContainer = styled.div`
4848

4949
const MAX_EXAMPLES = 5;
5050

51-
enum ExampleType {
52-
FREE_FORM = 'freeform',
53-
PROMPT_COMPLETION = 'promptcompletion'
54-
}
51+
5552

5653
const Examples: React.FC = () => {
5754
const form = Form.useFormInstance();
@@ -90,13 +87,13 @@ const Examples: React.FC = () => {
9087
title: 'Prompts',
9188
dataIndex: 'question',
9289
ellipsis: true,
93-
render: (_text: QuestionSolution, record: QuestionSolution) => <>{record.question}</>
90+
render: (_text: QuestionSolution, record: QuestionSolution) => <Text>{record.question}</Text>
9491
},
9592
{
9693
title: 'Completions',
9794
dataIndex: 'solution',
9895
ellipsis: true,
99-
render: (_text: QuestionSolution, record: QuestionSolution) => <>{record.solution}</>
96+
render: (_text: QuestionSolution, record: QuestionSolution) => <Text>{record.solution}</Text>
10097
},
10198
{
10299
title: 'Actions',
@@ -178,13 +175,24 @@ const Examples: React.FC = () => {
178175
/>
179176
</Flex>
180177
)
181-
}},
178+
}
179+
},
182180
];
183181
const dataSource = Form.useWatch('examples', form);
184-
const { data: examples, loading: examplesLoading } = useFetchExamples(form.getFieldValue('use_case'));
182+
const { examples, exmpleFormat, isLoading: examplesLoading } =
183+
useGetExamplesByUseCase(form.getFieldValue('use_case'));
184+
185+
// update examples
185186
if (!dataSource && examples) {
186-
form.setFieldValue('examples', examples.examples)
187+
form.setFieldValue('examples', examples)
187188
}
189+
useEffect(() => {
190+
if (!isEmpty(examples) && !isEmpty(exmpleFormat)) {
191+
setExampleType(exmpleFormat as ExampleType);
192+
form.setFieldValue('examples', examples || []);
193+
}
194+
}, [examples, exmpleFormat]);
195+
188196
const rowLimitReached = form.getFieldValue('examples')?.length === MAX_EXAMPLES;
189197
const workflowType = form.getFieldValue('workflow_type');
190198

@@ -299,6 +307,8 @@ const Examples: React.FC = () => {
299307
</Header>
300308
{exampleType === ExampleType.FREE_FORM && !isEmpty(mutation.data) &&
301309
<FreeFormExampleTable data={mutation.data}/>}
310+
{exampleType === ExampleType.FREE_FORM && form.getFieldValue('use_case') === 'lending_data' &&
311+
<FreeFormExampleTable data={form.getFieldValue('examples')}/>}
302312
{exampleType === ExampleType.FREE_FORM && isEmpty(mutation.data) && !isEmpty(values.examples) &&
303313
<FreeFormExampleTable data={values.examples}/>}
304314
{exampleType === ExampleType.FREE_FORM && isEmpty(mutation.data) && isEmpty(values.examples) &&

app/client/src/pages/DataGenerator/UseCaseSelector.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,15 @@ interface Props {}
1010
const UseCaseSelector: FunctionComponent<Props> = () => {
1111
const [useCases, setUseCases] = useState<UseCase[]>([]);
1212
const useCasesReq = useGetUseCases();
13-
console.log('useCasesReq', useCasesReq);
1413

1514
useEffect(() => {
1615
if (useCasesReq.data) {
17-
console.log('useCasesReq.data', useCasesReq.data);
1816
let _useCases = get(useCasesReq, 'data.usecases', []);
1917
_useCases = _useCases.map((useCase: any) => ({
2018
...useCase,
2119
label: useCase.name,
2220
value: useCase.id
2321
}));
24-
console.log('_useCases', _useCases);
2522
setUseCases(_useCases);
2623
}
2724
}, [useCasesReq.data]);
@@ -34,7 +31,7 @@ const UseCaseSelector: FunctionComponent<Props> = () => {
3431
rules={[
3532
{ required: true }
3633
]}
37-
tooltip='A specialize template for generating your dataset'
34+
tooltip='A specialized template for generating your dataset'
3835
labelCol={{
3936
span: 8
4037
}}

app/client/src/pages/DataGenerator/hooks.ts

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import toNumber from 'lodash/toNumber';
44
import isEmpty from 'lodash/isEmpty';
55
import isString from 'lodash/isString';
66
import { useMutation, useQuery } from '@tanstack/react-query';
7-
import { WorkflowType } from './types';
7+
import { ExampleType, WorkflowType } from './types';
8+
import { first } from 'lodash';
89

910
const BASE_API_URL = import.meta.env.VITE_AMP_URL;
1011

@@ -257,7 +258,7 @@ export const useDatasetSize = (
257258
export const useGetUseCases = () => {
258259
const { data, isLoading, isError, error, isFetching } = useQuery(
259260
{
260-
queryKey: ['fetchUseCases', fetchUseCases],
261+
queryKey: ['useCases'],
261262
queryFn: () => fetchUseCases(),
262263
refetchOnWindowFocus: false,
263264
}
@@ -268,4 +269,59 @@ export const useGetUseCases = () => {
268269
isError,
269270
error
270271
};
271-
}
272+
}
273+
274+
export const fetchExamplesByUseCase = async (use_case: string) => {
275+
const resp = await fetch(`${BASE_API_URL}/${isEmpty(use_case) ? 'custom' : use_case}/gen_examples`, {
276+
method: 'GET'
277+
});
278+
const body = await resp.json();
279+
return body;
280+
}
281+
282+
export const useGetExamplesByUseCase = (use_case: string) => {
283+
const { data, isLoading, isError, error, isFetching } = useQuery(
284+
{
285+
queryKey: ['fetchUseCaseTopics', fetchExamplesByUseCase],
286+
queryFn: () => fetchExamplesByUseCase(use_case),
287+
refetchOnWindowFocus: false,
288+
}
289+
);
290+
291+
if (isError) {
292+
notification.error({
293+
message: 'Error',
294+
description: `An error occurred while fetching the use case examples.\n ${error?.message}`
295+
});
296+
}
297+
298+
299+
let examples = [];
300+
let exmpleFormat: ExampleType | null = null;
301+
if (!isEmpty(data) && !isEmpty(data?.examples)) {
302+
examples = get(data, 'examples', []);
303+
exmpleFormat = getExampleType(examples);
304+
}
305+
306+
return {
307+
data,
308+
isLoading: isLoading || isFetching,
309+
isError,
310+
error,
311+
examples,
312+
exmpleFormat
313+
};
314+
}
315+
316+
export const getExampleType = (data: object[]) => {
317+
if (!isEmpty(data)) {
318+
const row = first(data);
319+
const keys = Object.keys(row as object);
320+
if (keys.length === 2) {
321+
return ExampleType.PROMPT_COMPLETION;
322+
}
323+
return ExampleType.FREE_FORM;
324+
}
325+
return null;
326+
}
327+

app/client/src/pages/DataGenerator/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,9 @@ export enum TechniqueType {
119119
SFT = 'sft',
120120
CUSTOME_WORKFLOW = 'custom_workflow',
121121
FREE_FORM = 'freeform'
122+
}
123+
124+
export enum ExampleType {
125+
FREE_FORM = 'freeform',
126+
PROMPT_COMPLETION = 'promptcompletion'
122127
}

app/client/src/pages/Home/WelcomePage.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { Button, Col, Flex, Layout, Row, Image } from 'antd';
1+
import toString from 'lodash/toString';
2+
import { Button, Col, Flex, Layout, Row, Image, Checkbox } from 'antd';
23
import React from 'react';
34
import styled from 'styled-components';
45
import SDGIcon from '../../assets/sdg-landing.svg';
56
import LightBulbIcon from '../../assets/ic-lightbulb.svg';
67
import QueryPromptIcon from '../../assets/ic-query-prompt.svg';
78
import NumbersIcon from '../../assets/ic-numbers.svg';
9+
import { CheckboxChangeEvent } from 'antd/es/checkbox';
810

911
const { Content } = Layout;
1012

@@ -107,6 +109,11 @@ const InfoSection = styled.div`
107109

108110
const WelcomePage: React.FC = () => {
109111

112+
const onChange = (e: CheckboxChangeEvent) => {
113+
const checked = e.target.checked;
114+
window.localStorage.setItem('sds_mute_welcome_page', toString(checked));
115+
}
116+
110117
return (
111118
<Layout>
112119
<StyledContent>
@@ -148,6 +155,10 @@ const WelcomePage: React.FC = () => {
148155
<br/>
149156
<Flex style={{ marginTop: '32px' }}>
150157
<Button type="primary" href="/home">Get Started</Button>
158+
159+
<div style={{ marginLeft: '24px', marginTop: '8px' }}>
160+
<Checkbox onChange={onChange}>{`Don't show me this again`}</Checkbox>
161+
</div>
151162
</Flex>
152163
</LeftSection>
153164
</Col>

app/client/src/routes.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@ import EvaluationDetailsPage from "./pages/EvaluationDetails/EvaluationDetailsPa
1212
//import TelemetryDashboard from "./components/TelemetryDashboard";
1313

1414

15+
const isWelcomePageMuted = () => {
16+
return window.localStorage.getItem('sds_mute_welcome_page') === 'true';
17+
}
18+
1519
const router = createBrowserRouter([
1620
{
1721
path: '/',
1822
element: <Layout/>,
1923
children: [
2024
{
2125
path: '/', // Redirect root to Pages.WELCOME
22-
element: <Navigate to={Pages.WELCOME} replace />,
26+
element: isWelcomePageMuted() ? <HomePage key={Pages.HOME}/> :
27+
<Navigate to={Pages.WELCOME} replace />,
28+
errorElement: <ErrorPage />
2329
},
2430
{
2531
path: Pages.HOME,

0 commit comments

Comments
 (0)