Skip to content

Commit

Permalink
Implemented Processing indicator for queries
Browse files Browse the repository at this point in the history
Signed-off-by: Omkar Phansopkar <[email protected]>
  • Loading branch information
OmkarPh committed Jun 19, 2023
1 parent fcf0c80 commit 221c382
Show file tree
Hide file tree
Showing 18 changed files with 492 additions and 373 deletions.
41 changes: 40 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"style-loader": "^3.3.1",
"svg-url-loader": "^8.0.0",
"ts-loader": "^9.4.1",
"typescript": "~4.8.4"
"typescript": "~4.8.4",
"worker-loader": "^3.0.8"
},
"dependencies": {
"@electron/remote": "^2.0.8",
Expand Down
16 changes: 5 additions & 11 deletions src/components/FileTree/FileTree.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import RcTree from "rc-tree";
import { DataNode, Key } from "rc-tree/lib/interface";
import React, { useEffect, useState } from "react";
import { Element, scroller } from "react-scroll";
import { Element } from "react-scroll";

import EllipticLoader from "../EllipticLoader";
import { PathType, useWorkbenchDB } from "../../contexts/dbContext";

import SwitcherIcon from "./SwitcherIcon";
import { scrollToDomElement } from "../../utils/dom";

import "./FileTree.css";

Expand Down Expand Up @@ -56,19 +55,15 @@ const FileTree = (props: React.HTMLProps<HTMLDivElement>) => {
useEffect(() => {
if (!initialized || !db || !importedSqliteFilePath) return;

db.sync.then(() => {
db.findAllJSTree().then((treeData) => {
db.findAllJSTree()
.then((treeData) => {
console.log("Filetree data", treeData);

// Wrap with react-scroll wrapper
function wrapNode(node: DataNode) {
const key = String(node.key);
node.title = (
<Element
key={key}
name={key}
className="filetree-node-wrapper"
>
<Element key={key} name={key} className="filetree-node-wrapper">
<span>{String(node.title)}</span>
{/* <span id={key}>{String(node.title)}</span> */}
</Element>
Expand All @@ -77,8 +72,7 @@ const FileTree = (props: React.HTMLProps<HTMLDivElement>) => {
}
treeData.forEach(wrapNode);
setTreeData(treeData as unknown as DataNode[]);
});
});
})
}, [importedSqliteFilePath]);

function selectPath(path: string, pathType: PathType) {
Expand Down
78 changes: 48 additions & 30 deletions src/components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
import React from 'react'
import { useLocation } from 'react-router-dom';
import React, { useEffect } from "react";
import { useLocation } from "react-router-dom";

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

import Navbar from '../Navbar/Navbar';
import FileTree from '../FileTree/FileTree'
import ImportFallback from '../ImportFallback/ImportFallback';
import Navbar from "../Navbar/Navbar";
import FileTree from "../FileTree/FileTree";
import ImportFallback from "../ImportFallback/ImportFallback";

import { useWorkbenchDB } from '../../contexts/dbContext';
import { FILE_TREE_ROUTES, IMPORT_FALLBACK_ROUTES } from '../../constants/routes';
import ProgressLoader from '../ProgressLoader/ProgressLoader';
import { useWorkbenchDB } from "../../contexts/dbContext";
import {
FILE_TREE_ROUTES,
IMPORT_FALLBACK_ROUTES,
} from "../../constants/routes";
import ProgressLoader from "../ProgressLoader/ProgressLoader";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faGear } from "@fortawesome/free-solid-svg-icons";

import "allotment/dist/style.css";
import './layout.css';
import "./layout.css";

const Layout = (props: React.PropsWithChildren) => {
const { pathname } = useLocation();
const { initialized, loadingStatus } = useWorkbenchDB();

const isImportFallbackRoute = IMPORT_FALLBACK_ROUTES.find(route => pathname.includes(route)) !== undefined;
const showFileTree = FILE_TREE_ROUTES.find(route => pathname.includes(route)) !== undefined;

const { initialized, loadingStatus, processingQuery } = useWorkbenchDB();

const isImportFallbackRoute =
IMPORT_FALLBACK_ROUTES.find((route) => pathname.includes(route)) !==
undefined;
const showFileTree =
FILE_TREE_ROUTES.find((route) => pathname.includes(route)) !== undefined;

// useEffect(() => {
// console.log("Loader status", processingQuery ? "Showing" : "Hiding");
// }, [processingQuery]);

return (
<div className='d-flex flex-row'>
<div className="d-flex flex-row">
<Navbar />
<Allotment className='pane-container'>
<Allotment className="pane-container">
<Allotment.Pane
visible={showFileTree && initialized}
minSize={10}
Expand All @@ -35,21 +47,27 @@ const Layout = (props: React.PropsWithChildren) => {
>
<FileTree style={{ minHeight: "100vh" }} />
</Allotment.Pane>
<Allotment.Pane className='content-pane'>
<div className='content-container'>
{
isImportFallbackRoute && !initialized ? (
loadingStatus !== null ?
<ProgressLoader progress={loadingStatus} />
:
<ImportFallback />
) : props.children
}
<Allotment.Pane className="content-pane">
<div className="content-container">
{isImportFallbackRoute && !initialized ? (
loadingStatus !== null ? (
<ProgressLoader progress={loadingStatus} />
) : (
<ImportFallback />
)
) : (
props.children
)}
{processingQuery && (
<div className="query-processing-indicator">
Processing <FontAwesomeIcon icon={faGear} spin />
</div>
)}
</div>
</Allotment.Pane>
</Allotment>
</div>
)
}
);
};

export default Layout
export default Layout;
25 changes: 25 additions & 0 deletions src/components/Layout/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,37 @@
box-shadow: rgb(177 177 177) 1px 0px 18px -3px;
overflow: overlay !important;
}

.content-pane {
overflow-y: overlay !important;
}

.content-container {
padding: 10px;
padding-top: 5px;
padding-bottom: 5px;
min-height: 100%;
}

.query-processing-indicator {
position: fixed;
background: #f3f9ff;
padding: 10px;
right: 20px;
z-index: 999;
border-radius: 8px;
-webkit-box-shadow: 0px 3px 15px -2px rgba(0, 0, 0, 0.67);
box-shadow: 0px 3px 15px -2px rgba(0, 0, 0, 0.67);

/* Animate */
bottom: -100%;
opacity: 0;
animation: smooth-appear 0.5s ease forwards;
}

@keyframes smooth-appear {
to {
bottom: 20px;
opacity: 1;
}
}
30 changes: 20 additions & 10 deletions src/contexts/dbContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ interface BasicValueState {
interface WorkbenchContextProperties extends BasicValueState {
currentPath: string | null;
currentPathType: PathType;
loadingStatus: null | number;
processingQuery: boolean;
startImport: () => void;
abortImport: () => void;
loadingStatus: null | number;
startProcessing: () => void;
endProcessing: () => void;
sqliteParser: (sqliteFilePath: string, preventNavigation?: boolean) => void;
jsonParser: (
jsonFilePath: string,
Expand All @@ -55,16 +58,19 @@ interface WorkbenchContextProperties extends BasicValueState {
export const defaultWorkbenchContextValue: WorkbenchContextProperties = {
db: null,
initialized: false,
importedSqliteFilePath: null,
loadingStatus: null,
currentPath: null,
currentPathType: "directory",
importedSqliteFilePath: null,
loadingStatus: null,
processingQuery: false,
jsonParser: () => null,
sqliteParser: () => null,
importJsonFile: () => null,
updateLoadingStatus: () => null,
startImport: () => null,
abortImport: () => null,
startProcessing: () => null,
endProcessing: () => null,
updateCurrentPath: () => null,
goToFileInTableView: () => null,
updateWorkbenchDB: () => null,
Expand All @@ -80,6 +86,7 @@ export const WorkbenchDBProvider = (
const navigate = useNavigate();

const [loadingStatus, updateLoadingStatus] = useState<number | null>(null);
const [processingQuery, setProcessingQuery] = useState<boolean>(null);
const [value, setValue] = useState<BasicValueState>({
db: null,
initialized: false,
Expand All @@ -92,13 +99,13 @@ export const WorkbenchDBProvider = (
setCurrentPath(path);
setCurrentPathType(pathType);
}
function changeRouteOnImport(){

function changeRouteOnImport() {
navigate(DEFAULT_ROUTE_ON_IMPORT);
}

function goToFileInTableView(path: string){
updateCurrentPath(path, 'file');
function goToFileInTableView(path: string) {
updateCurrentPath(path, "file");
navigate("/" + ROUTES.TABLE_VIEW);
}

Expand Down Expand Up @@ -456,15 +463,18 @@ export const WorkbenchDBProvider = (
<WorkbenchContext.Provider
value={{
...value,
loadingStatus,
updateLoadingStatus,
currentPath,
currentPathType,
loadingStatus,
processingQuery,
updateLoadingStatus,
jsonParser,
sqliteParser,
importJsonFile,
startImport,
abortImport,
startProcessing: () => setProcessingQuery(true),
endProcessing: () => setProcessingQuery(false),
updateCurrentPath,
goToFileInTableView,
updateWorkbenchDB,
Expand All @@ -475,4 +485,4 @@ export const WorkbenchDBProvider = (
);
};

export const useWorkbenchDB = () => useContext(WorkbenchContext);
export const useWorkbenchDB = () => useContext(WorkbenchContext);
4 changes: 2 additions & 2 deletions src/pages/About/About.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { version } from "../../../package.json";
import packageInfo from "../../../package.json";

import "./about.css";

Expand All @@ -8,7 +8,7 @@ const About = () => {
<div className="help">
<h1>
About ScanCode Workbench
<span className="app-version">v{version}</span>
<span className="app-version">v{packageInfo.version}</span>
</h1>
<br />
<h3>Overview</h3>
Expand Down
9 changes: 6 additions & 3 deletions src/pages/FileInfoDash/FileInfoDash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import "./FileInfoDash.css";

const FileInfoDash = () => {
const workbenchDB = useWorkbenchDB();
const { db, initialized, currentPath, startProcessing, endProcessing } =
workbenchDB;

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

useEffect(() => {
const { db, initialized, currentPath } = workbenchDB;

if (!initialized || !db || !currentPath) return;

startProcessing();

db.sync
.then((db) => db.File.findOne({ where: { path: currentPath } }))
.then((root) => {
Expand Down Expand Up @@ -88,7 +90,8 @@ const FileInfoDash = () => {
const { chartData: mimeTypesChartData } =
formatChartData(fileMimeTypes);
setMimeTypesData(mimeTypesChartData);
});
})
.then(endProcessing);
}, [workbenchDB]);

return (
Expand Down
Loading

0 comments on commit 221c382

Please sign in to comment.