Skip to content

Commit 52839e6

Browse files
committed
Implemented Processing indicator for queries
Signed-off-by: Omkar Phansopkar <[email protected]>
1 parent 53fa89b commit 52839e6

File tree

17 files changed

+440
-315
lines changed

17 files changed

+440
-315
lines changed

package-lock.json

Lines changed: 40 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
"style-loader": "^3.3.1",
7070
"svg-url-loader": "^8.0.0",
7171
"ts-loader": "^9.4.1",
72-
"typescript": "~4.8.4"
72+
"typescript": "~4.8.4",
73+
"worker-loader": "^3.0.8"
7374
},
7475
"dependencies": {
7576
"@electron/remote": "^2.0.8",

src/components/FileTree/FileTree.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ const FileTree = (props: React.HTMLProps<HTMLDivElement>) => {
4444
useEffect(() => {
4545
if (!initialized || !db || !importedSqliteFilePath) return;
4646

47-
db.sync.then(() => {
48-
db.findAllJSTree().then((treeData) => {
47+
db.findAllJSTree()
48+
.then((treeData) => {
4949
console.log("Filetree data", treeData);
5050

5151
// Wrap with react-scroll wrapper
@@ -60,8 +60,7 @@ const FileTree = (props: React.HTMLProps<HTMLDivElement>) => {
6060
}
6161
treeData.forEach(wrapNode);
6262
setTreeData(treeData as unknown as DataNode[]);
63-
});
64-
});
63+
})
6564
}, [importedSqliteFilePath]);
6665

6766
function selectPath(path: string, pathType: PathType) {

src/components/Layout/Layout.tsx

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,43 @@
1-
import React from 'react'
2-
import { useLocation } from 'react-router-dom';
1+
import React, { useEffect } from "react";
2+
import { useLocation } from "react-router-dom";
33

44
// eslint-disable-next-line import/namespace
5-
import { Allotment } from 'allotment';
5+
import { Allotment } from "allotment";
66

7-
import Navbar from '../Navbar/Navbar';
8-
import FileTree from '../FileTree/FileTree'
9-
import ImportFallback from '../ImportFallback/ImportFallback';
7+
import Navbar from "../Navbar/Navbar";
8+
import FileTree from "../FileTree/FileTree";
9+
import ImportFallback from "../ImportFallback/ImportFallback";
1010

11-
import { useWorkbenchDB } from '../../contexts/dbContext';
12-
import { FILE_TREE_ROUTES, IMPORT_FALLBACK_ROUTES } from '../../constants/routes';
13-
import ProgressLoader from '../ProgressLoader/ProgressLoader';
11+
import { useWorkbenchDB } from "../../contexts/dbContext";
12+
import {
13+
FILE_TREE_ROUTES,
14+
IMPORT_FALLBACK_ROUTES,
15+
} from "../../constants/routes";
16+
import ProgressLoader from "../ProgressLoader/ProgressLoader";
17+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
18+
import { faGear } from "@fortawesome/free-solid-svg-icons";
1419

1520
import "allotment/dist/style.css";
16-
import './layout.css';
21+
import "./layout.css";
1722

1823
const Layout = (props: React.PropsWithChildren) => {
1924
const { pathname } = useLocation();
20-
const { initialized, loadingStatus } = useWorkbenchDB();
21-
22-
const isImportFallbackRoute = IMPORT_FALLBACK_ROUTES.find(route => pathname.includes(route)) !== undefined;
23-
const showFileTree = FILE_TREE_ROUTES.find(route => pathname.includes(route)) !== undefined;
24-
25+
const { initialized, loadingStatus, processingQuery } = useWorkbenchDB();
26+
27+
const isImportFallbackRoute =
28+
IMPORT_FALLBACK_ROUTES.find((route) => pathname.includes(route)) !==
29+
undefined;
30+
const showFileTree =
31+
FILE_TREE_ROUTES.find((route) => pathname.includes(route)) !== undefined;
32+
33+
// useEffect(() => {
34+
// console.log("Loader status", processingQuery ? "Showing" : "Hiding");
35+
// }, [processingQuery]);
36+
2537
return (
26-
<div className='d-flex flex-row'>
38+
<div className="d-flex flex-row">
2739
<Navbar />
28-
<Allotment className='pane-container'>
40+
<Allotment className="pane-container">
2941
<Allotment.Pane
3042
visible={showFileTree && initialized}
3143
minSize={10}
@@ -35,21 +47,27 @@ const Layout = (props: React.PropsWithChildren) => {
3547
>
3648
<FileTree style={{ minHeight: "100vh" }} />
3749
</Allotment.Pane>
38-
<Allotment.Pane className='content-pane'>
39-
<div className='content-container'>
40-
{
41-
isImportFallbackRoute && !initialized ? (
42-
loadingStatus !== null ?
43-
<ProgressLoader progress={loadingStatus} />
44-
:
45-
<ImportFallback />
46-
) : props.children
47-
}
50+
<Allotment.Pane className="content-pane">
51+
<div className="content-container">
52+
{isImportFallbackRoute && !initialized ? (
53+
loadingStatus !== null ? (
54+
<ProgressLoader progress={loadingStatus} />
55+
) : (
56+
<ImportFallback />
57+
)
58+
) : (
59+
props.children
60+
)}
61+
{processingQuery && (
62+
<div className="query-processing-indicator">
63+
Processing <FontAwesomeIcon icon={faGear} spin />
64+
</div>
65+
)}
4866
</div>
4967
</Allotment.Pane>
5068
</Allotment>
5169
</div>
52-
)
53-
}
70+
);
71+
};
5472

55-
export default Layout
73+
export default Layout;

src/components/Layout/layout.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,37 @@
88
box-shadow: rgb(177 177 177) 1px 0px 18px -3px;
99
overflow: overlay !important;
1010
}
11+
1112
.content-pane {
1213
overflow-y: overlay !important;
1314
}
15+
1416
.content-container {
1517
padding: 10px;
1618
padding-top: 5px;
1719
padding-bottom: 5px;
1820
min-height: 100%;
21+
}
22+
23+
.query-processing-indicator {
24+
position: fixed;
25+
background: #f3f9ff;
26+
padding: 10px;
27+
right: 20px;
28+
z-index: 999;
29+
border-radius: 8px;
30+
-webkit-box-shadow: 0px 3px 15px -2px rgba(0, 0, 0, 0.67);
31+
box-shadow: 0px 3px 15px -2px rgba(0, 0, 0, 0.67);
32+
33+
/* Animate */
34+
bottom: -100%;
35+
opacity: 0;
36+
animation: smooth-appear 0.5s ease forwards;
37+
}
38+
39+
@keyframes smooth-appear {
40+
to {
41+
bottom: 20px;
42+
opacity: 1;
43+
}
1944
}

src/contexts/dbContext.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ interface BasicValueState {
3838
interface WorkbenchContextProperties extends BasicValueState {
3939
currentPath: string | null;
4040
currentPathType: PathType;
41+
loadingStatus: null | number;
42+
processingQuery: boolean;
4143
startImport: () => void;
4244
abortImport: () => void;
43-
loadingStatus: null | number;
45+
startProcessing: () => void;
46+
endProcessing: () => void;
4447
sqliteParser: (sqliteFilePath: string, preventNavigation?: boolean) => void;
4548
jsonParser: (
4649
jsonFilePath: string,
@@ -61,12 +64,15 @@ export const defaultWorkbenchContextValue: WorkbenchContextProperties = {
6164
loadingStatus: null,
6265
currentPath: null,
6366
currentPathType: "directory",
67+
processingQuery: false,
6468
jsonParser: () => null,
6569
sqliteParser: () => null,
6670
importJsonFile: () => null,
6771
updateLoadingStatus: () => null,
6872
startImport: () => null,
6973
abortImport: () => null,
74+
startProcessing: () => null,
75+
endProcessing: () => null,
7076
updateCurrentPath: () => null,
7177
goToFileInTableView: () => null,
7278
};
@@ -81,6 +87,7 @@ export const WorkbenchDBProvider = (
8187
const navigate = useNavigate();
8288

8389
const [loadingStatus, updateLoadingStatus] = useState<number | null>(null);
90+
const [processingQuery, setProcessingQuery] = useState<boolean>(null);
8491
const [value, setValue] = useState<BasicValueState>({
8592
db: null,
8693
initialized: false,
@@ -462,15 +469,18 @@ export const WorkbenchDBProvider = (
462469
<WorkbenchContext.Provider
463470
value={{
464471
...value,
465-
loadingStatus,
466-
updateLoadingStatus,
467472
currentPath,
468473
currentPathType,
474+
loadingStatus,
475+
processingQuery,
476+
updateLoadingStatus,
469477
jsonParser,
470478
sqliteParser,
471479
importJsonFile,
472480
startImport,
473481
abortImport,
482+
startProcessing: () => setProcessingQuery(true),
483+
endProcessing: () => setProcessingQuery(false),
474484
updateCurrentPath,
475485
goToFileInTableView,
476486
}}

src/pages/About/About.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import { version } from "../../../package.json";
2+
import packageInfo from "../../../package.json";
33

44
import "./about.css";
55

@@ -8,7 +8,7 @@ const About = () => {
88
<div className="help">
99
<h1>
1010
About ScanCode Workbench
11-
<span className="app-version">v{version}</span>
11+
<span className="app-version">v{packageInfo.version}</span>
1212
</h1>
1313
<br />
1414
<h3>Overview</h3>

src/pages/FileInfoDash/FileInfoDash.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import "./FileInfoDash.css";
1717

1818
const FileInfoDash = () => {
1919
const workbenchDB = useWorkbenchDB();
20+
const { db, initialized, currentPath, startProcessing, endProcessing } =
21+
workbenchDB;
2022

2123
const [progLangsData, setProgLangsData] = useState(null);
2224
const [mimeTypesData, setMimeTypesData] = useState(null);
@@ -27,10 +29,10 @@ const FileInfoDash = () => {
2729
});
2830

2931
useEffect(() => {
30-
const { db, initialized, currentPath } = workbenchDB;
31-
3232
if (!initialized || !db || !currentPath) return;
3333

34+
startProcessing();
35+
3436
db.sync
3537
.then((db) => db.File.findOne({ where: { path: currentPath } }))
3638
.then((root) => {
@@ -88,7 +90,8 @@ const FileInfoDash = () => {
8890
const { chartData: mimeTypesChartData } =
8991
formatChartData(fileMimeTypes);
9092
setMimeTypesData(mimeTypesChartData);
91-
});
93+
})
94+
.then(endProcessing);
9295
}, [workbenchDB]);
9396

9497
return (

src/pages/Home/Home.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import moment from "moment";
22
import electron from "electron";
33
import * as electronFs from "fs";
44
import { toast } from "react-toastify";
5-
import { useNavigate } from "react-router-dom";
65
import React, { useMemo, useState } from "react";
76

87
import {

0 commit comments

Comments
 (0)