Skip to content

Commit

Permalink
Merge pull request #42 from MetabobProject/edge-case-empty-identified…
Browse files Browse the repository at this point in the history
…-problems

fix: edge case where no problem detected should be shown
  • Loading branch information
AviGopal authored Apr 1, 2024
2 parents 6d76640 + 197dc39 commit fcee31b
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 5 deletions.
3 changes: 2 additions & 1 deletion ext-src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export interface AnalysisEvents {
| 'FIX_SUGGESTION'
| 'CURRENT_FILE'
| 'CURRENT_PROJECT'
| 'INIT_DATA_UPON_NEW_FILE_OPEN';
| 'INIT_DATA_UPON_NEW_FILE_OPEN'
| 'Analysis_Completed_Empty_Problems';
data: any;
}

Expand Down
18 changes: 18 additions & 0 deletions ext-src/helpers/HandleDocumentAnalyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,24 @@ export const handleDocumentAnalyze = async (
}

await analyzeState.set(results);

if (problems.length === 0) {
getExtensionEventEmitter().fire({
type: 'Analysis_Completed_Empty_Problems',
data: { shouldResetRecomendation: true, shouldMoveToAnalyzePage: true, ...results },
});

getExtensionEventEmitter().fire({
type: 'CURRENT_PROJECT',
data: {
name: currentWorkSpaceFolder
},
});

return verifiedResponse
}


getExtensionEventEmitter().fire({
type: 'Analysis_Completed',
data: { shouldResetRecomendation: true, shouldMoveToAnalyzePage: true, ...results },
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "metabob",
"displayName": "Metabob: Debug and Refactor with AI",
"description": "Generative AI to automate debugging and refactoring Python code",
"version": "1.2.0",
"version": "1.2.1",
"icon": "media/extension-icon.png",
"repository": {
"url": "https://github.com/MetabobProject/metabob-vscode",
Expand Down
20 changes: 17 additions & 3 deletions src/components/Analyze/ProblemList/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ describe('ProblemList component', () => {
test('renders correctly with detectedProblems', () => {
const { getByText } = render(
<RecoilRoot>
<ProblemList detectedProblems={3} otherFileWithProblems={[]} />
<ProblemList
detectedProblems={3}
otherFileWithProblems={[]}
isEmptyIdentifiedProblemDetected={false}
/>
</RecoilRoot>,
);
expect(getByText('3 Problems Detected')).toBeInTheDocument();
Expand All @@ -36,9 +40,14 @@ describe('ProblemList component', () => {
const otherFileWithProblems = [{ name: 'file1.txt' }, { name: 'file2.txt' }];
const { getByText, getAllByText } = render(
<RecoilRoot>
<ProblemList detectedProblems={0} otherFileWithProblems={otherFileWithProblems} />
<ProblemList
detectedProblems={0}
otherFileWithProblems={otherFileWithProblems}
isEmptyIdentifiedProblemDetected={true}
/>
</RecoilRoot>,
);
expect(getByText('No Problems Detected')).toBeInTheDocument();
expect(getByText('Other files with problems')).toBeInTheDocument();
otherFileWithProblems.forEach(({ name }) => {
expect(getAllByText(name)).toHaveLength(1); // Ensure each file name is rendered once
Expand All @@ -49,9 +58,14 @@ describe('ProblemList component', () => {
const otherFileWithProblems = [{ name: 'file1.txt' }];
const { getByText } = render(
<RecoilRoot>
<ProblemList detectedProblems={0} otherFileWithProblems={otherFileWithProblems} />
<ProblemList
detectedProblems={0}
otherFileWithProblems={otherFileWithProblems}
isEmptyIdentifiedProblemDetected={true}
/>
</RecoilRoot>,
);
expect(getByText('No Problems Detected')).toBeInTheDocument();
fireEvent.click(getByText('Open'));
expect(vscode.postMessage).toHaveBeenCalledWith({
type: 'OPEN_FILE_IN_NEW_TAB',
Expand Down
8 changes: 8 additions & 0 deletions src/components/Analyze/ProblemList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import { useCallback } from 'react';
export interface ProblemsListProps {
detectedProblems?: number;
otherFileWithProblems?: Array<{ name: string }>;
isEmptyIdentifiedProblemDetected: boolean;
}

export const ProblemList = ({
otherFileWithProblems,
detectedProblems,
isEmptyIdentifiedProblemDetected,
}: ProblemsListProps): JSX.Element => {
const theme = useTheme();

Expand All @@ -42,6 +44,12 @@ export const ProblemList = ({
</Typography>
)}

{isEmptyIdentifiedProblemDetected === true && (
<Typography variant='h6' sx={ProblemListHeading(theme)}>
No Problems Detected
</Typography>
)}

{otherFileWithProblems && otherFileWithProblems.length > 0 && (
<>
<Typography sx={ListHeaderTypography}>Other files with problems</Typography>
Expand Down
2 changes: 2 additions & 0 deletions src/components/Analyze/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const AnalyzePage = ({
const identifiedProblems = useRecoilValue(State.identifiedProblems);
const currentEditor = useRecoilValue(State.currentEditor);
const currentWorkSpaceProject = useRecoilValue(State.currentWorkSpaceProject);
const isEmptyIdentifiedProblemDetected = useRecoilValue(State.isEmptyIdentifiedProblemDetected);

const otherFileWithProblems: Array<{ name: string }> | undefined = useMemo(() => {
if (!identifiedProblems) return undefined;
Expand Down Expand Up @@ -186,6 +187,7 @@ export const AnalyzePage = ({
<ProblemList
detectedProblems={detectedProblems}
otherFileWithProblems={otherFileWithProblems}
isEmptyIdentifiedProblemDetected={isEmptyIdentifiedProblemDetected}
/>
)}
</>
Expand Down
20 changes: 20 additions & 0 deletions src/context/UserContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const AccountSettingProvider = ({ children }: Props): JSX.Element => {
const setAnalysisLoading = useSetRecoilState(State.isAnalysisLoading);
const setCurrentEditor = useSetRecoilState(State.currentEditor);
const setCurrentWorkSpaceProject = useSetRecoilState(State.currentWorkSpaceProject);
const setIsEmptyIdentifiedProblemDetected = useSetRecoilState(
State.isEmptyIdentifiedProblemDetected,
);

const handleMessagesFromExtension = useCallback(
(event: MessageEvent<MessageType>) => {
Expand All @@ -51,8 +54,25 @@ const AccountSettingProvider = ({ children }: Props): JSX.Element => {
case EventDataType.ANALYSIS_ERROR:
setIsAnalysisLoading(false);
break;
case EventDataType.ANALYSIS_COMPLETED_EMPTY_PROBLEMS: {
const { shouldResetRecomendation, shouldMoveToAnalyzePage, ...problem } = payload;
setIsEmptyIdentifiedProblemDetected(true);
if (problem) {
setIdentifiedProblems(problem as AnalyzeState);
}
if (shouldMoveToAnalyzePage) {
setIdentifiedSuggestion(undefined);
setApplicationState(ApplicationWebviewState.ANALYZE_MODE);
}
if (shouldResetRecomendation) {
setIdentifiedRecommendation(undefined);
}
setIsAnalysisLoading(false);
break;
}
case EventDataType.ANALYSIS_COMPLETED:
const { shouldResetRecomendation, shouldMoveToAnalyzePage, ...problem } = payload;
setIsEmptyIdentifiedProblemDetected(false);
if (problem) {
setIdentifiedProblems(problem as AnalyzeState);
}
Expand Down
5 changes: 5 additions & 0 deletions src/state/atoms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export const identifiedProblems = atom<AnalyzeState | undefined>({
effects_UNSTABLE: [persistAtom]
});

export const isEmptyIdentifiedProblemDetected = atom<boolean>({
default: false,
key: "Metabob:isEmptyIdentifiedProblemDetected"
})

export const currentEditor = atom<string | undefined>({
default: undefined,
key: 'Metabob:currentEditor',
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export enum EventDataType {
CURRENT_FILE = 'CURRENT_FILE',
CURRENT_PROJECT = 'CURRENT_PROJECT',
INIT_DATA_UPON_NEW_FILE_OPEN = 'INIT_DATA_UPON_NEW_FILE_OPEN',
ANALYSIS_COMPLETED_EMPTY_PROBLEMS = 'Analysis_Completed_Empty_Problems'
}

export enum ApplicationWebviewState {
Expand Down

0 comments on commit fcee31b

Please sign in to comment.