Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: GH-87 fix scan dialog inconsistencies #94

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Upcoming changes...

## [0.6.1] 2025-02-19

### Fixed
- Fix scan dialog animation not working when clicking "Scan With Options"
- Fix path building when selecting scan root
- Fix scan dialog resetting to default values when opening

### Changed
- Use a single function to get all scan root derived paths in ScanDialog (results path, settings path, etc)

## [0.6.0] 2024-02-03

### Added
Expand Down Expand Up @@ -54,4 +64,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0


[0.5.0]: https://github.com/scanoss/scanoss.cc/compare/v0.4.0...v0.5.0
[0.6.0]: https://github.com/scanoss/scanoss.cc/compare/v0.5.0...v0.6.0
[0.6.0]: https://github.com/scanoss/scanoss.cc/compare/v0.5.0...v0.6.0
[0.6.1]: https://github.com/scanoss/scanoss.cc/compare/v0.6.0...v0.6.1
5 changes: 5 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package main
import (
"context"
"fmt"
"path/filepath"
"slices"

"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -212,3 +213,7 @@ func (a *App) SetResultFilePath(path string) {
func (a *App) SetScanSettingsFilePath(path string) {
a.cfg.SetScanSettingsFilePath(path)
}

func (a *App) JoinPaths(elements []string) string {
return filepath.Join(elements...)
}
47 changes: 33 additions & 14 deletions frontend/src/components/ScanDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { withErrorHandling } from '@/lib/errors';
import useResultsStore from '@/modules/results/stores/useResultsStore';
import useConfigStore from '@/stores/useConfigStore';

import { GetScanRoot, SelectDirectory } from '../../wailsjs/go/main/App';
import { GetScanRoot, JoinPaths, SelectDirectory } from '../../wailsjs/go/main/App';
import { entities } from '../../wailsjs/go/models';
import { GetScanArgs, ScanStream } from '../../wailsjs/go/service/ScanServicePythonImpl';
import { EventsOn } from '../../wailsjs/runtime/runtime';
Expand All @@ -51,12 +51,14 @@ interface OutputLine {
type ScanStatus = 'idle' | 'scanning' | 'completed' | 'failed';

interface ScanDialogProps {
open: boolean;
onOpenChange: () => void;
}

export default function ScanDialog({ onOpenChange }: ScanDialogProps) {
export default function ScanDialog({ open, onOpenChange }: ScanDialogProps) {
const { toast } = useToast();

const initialScanRoot = useConfigStore((state) => state.scanRoot);
const setScanRoot = useConfigStore((state) => state.setScanRoot);

const [output, setOutput] = useState<OutputLine[]>([]);
Expand All @@ -71,15 +73,16 @@ export default function ScanDialog({ onOpenChange }: ScanDialogProps) {
const { reset: resetResults } = useResults();
const setSelectedResults = useResultsStore((state) => state.setSelectedResults);

const handleSelectDirectory = withErrorHandling({
const handleSelectScanRoot = withErrorHandling({
asyncFn: async () => {
const selectedDir = await SelectDirectory();
if (selectedDir) {
setDirectory(selectedDir);
setOptions((prev) => ({ ...prev, output: `${selectedDir}/.scanoss/results.json`, settings: `${selectedDir}/scanoss.json` }));
updatePathWhenScanRootChanges(selectedDir);
}
},
onError: () => {
onError: (error) => {
console.error('Failed to select scan root:', error);
toast({
title: 'Error',
description: 'An error occurred while selecting the directory. Please try again.',
Expand All @@ -88,6 +91,27 @@ export default function ScanDialog({ onOpenChange }: ScanDialogProps) {
},
});

const updatePathWhenScanRootChanges = withErrorHandling({
asyncFn: async (selectedDir: string) => {
const defaultOutputPath = await JoinPaths([selectedDir, '.scanoss', 'results.json']);
const defaultSettingsPath = await JoinPaths([selectedDir, 'scanoss.json']);

setOptions((prev) => ({
...prev,
output: defaultOutputPath,
settings: defaultSettingsPath,
}));
},
onError: (error) => {
console.error('Failed to update paths:', error);
toast({
title: 'Error',
description: 'An error occurred. Please try again.',
variant: 'destructive',
});
},
});

const handleScan = withErrorHandling({
asyncFn: async () => {
setScanStatus('scanning');
Expand Down Expand Up @@ -170,14 +194,9 @@ export default function ScanDialog({ onOpenChange }: ScanDialogProps) {
});
setOptions(initialOptions);

// Set default directory and paths
const dir = await GetScanRoot();
setDirectory(dir);
setOptions((prev) => ({
...prev,
output: `${dir}/.scanoss/results.json`,
settings: `${dir}/scanoss.json`,
}));
await updatePathWhenScanRootChanges(dir);
} catch (error) {
console.error('Failed to initialize scan dialog:', error);
toast({
Expand All @@ -188,7 +207,7 @@ export default function ScanDialog({ onOpenChange }: ScanDialogProps) {
}
}
initialize();
}, [toast]);
}, [initialScanRoot]);

useEffect(() => {
const subs = [
Expand Down Expand Up @@ -220,7 +239,7 @@ export default function ScanDialog({ onOpenChange }: ScanDialogProps) {
const coreOptions = scanArgs.filter((arg) => arg.IsCore);

return (
<Dialog open onOpenChange={onOpenChange}>
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent>
<DialogHeader>
<DialogTitle>Scan With Options</DialogTitle>
Expand All @@ -232,7 +251,7 @@ export default function ScanDialog({ onOpenChange }: ScanDialogProps) {
<Label htmlFor="directory">Directory to scan</Label>
<div className="flex gap-2">
<Input id="directory" value={directory} readOnly placeholder="Select a directory" className="text-sm" />
<Button type="button" onClick={handleSelectDirectory} variant="secondary" size="icon">
<Button type="button" onClick={handleSelectScanRoot} variant="secondary" size="icon">
<Folder className="h-4 w-4" />
</Button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default function Root() {
<StatusBar />
</div>
<KeyboardShortcutsDialog open={showKeyboardShortcuts} onOpenChange={() => setShowKeyboardShortcuts(false)} />
{scanModal && <ScanDialog onOpenChange={handleCloseScanModal} />}
<ScanDialog open={scanModal} onOpenChange={handleCloseScanModal} />
</div>
);
}
2 changes: 2 additions & 0 deletions frontend/wailsjs/go/main/App.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export function GetScanSettingsFilePath():Promise<string>;

export function Init(arg1:context.Context,arg2:service.ScanossSettingsService,arg3:service.KeyboardService):Promise<void>;

export function JoinPaths(arg1:Array<string>):Promise<string>;

export function SelectDirectory():Promise<string>;

export function SelectFile(arg1:string):Promise<string>;
Expand Down
4 changes: 4 additions & 0 deletions frontend/wailsjs/go/main/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export function Init(arg1, arg2, arg3) {
return window['go']['main']['App']['Init'](arg1, arg2, arg3);
}

export function JoinPaths(arg1) {
return window['go']['main']['App']['JoinPaths'](arg1);
}

export function SelectDirectory() {
return window['go']['main']['App']['SelectDirectory']();
}
Expand Down
Loading