Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/main/atao60/fse-cli-…
Browse files Browse the repository at this point in the history
…0.1.9
  • Loading branch information
nelsonni authored Aug 23, 2023
2 parents fb1f7c4 + 2b91496 commit 27ae5cf
Show file tree
Hide file tree
Showing 10 changed files with 804 additions and 714 deletions.
901 changes: 512 additions & 389 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
},
"devDependencies": {
"@atao60/fse-cli": "^0.1.9",
"@electron-forge/cli": "^6.3.0",
"@electron-forge/maker-deb": "^6.3.0",
"@electron-forge/maker-dmg": "^6.3.0",
"@electron-forge/maker-rpm": "^6.3.0",
"@electron-forge/maker-squirrel": "^6.3.0",
"@electron-forge/plugin-webpack": "6.3.0",
"@electron-forge/cli": "^6.4.0",
"@electron-forge/maker-deb": "^6.4.0",
"@electron-forge/maker-dmg": "^6.4.0",
"@electron-forge/maker-rpm": "^6.4.0",
"@electron-forge/maker-squirrel": "^6.4.0",
"@electron-forge/plugin-webpack": "6.4.0",
"@testing-library/dom": "^9.3.1",
"@testing-library/jest-dom": "^6.0.0",
"@testing-library/react": "^14.0.0",
Expand Down Expand Up @@ -75,12 +75,12 @@
"@vercel/webpack-asset-relocator-loader": "1.7.3",
"casual": "^1.6.2",
"css-loader": "^6.8.1",
"electron": "25.5.0",
"electron": "26.0.0",
"electron-devtools-installer": "^3.2.0",
"eslint": "^8.47.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-jsdoc": "^46.4.6",
"eslint-plugin-jsdoc": "^46.5.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-testing-library": "^6.0.0",
"file-loader": "^6.2.0",
Expand Down Expand Up @@ -140,7 +140,7 @@
"react-redux": "^8.1.2",
"react-transition-group": "^4.4.5",
"react-use": "^17.4.0",
"reactflow": "^11.8.1",
"reactflow": "^11.8.3",
"redux": "^4.2.1",
"redux-logger": "^3.0.6",
"redux-persist": "^6.0.0",
Expand Down
1 change: 0 additions & 1 deletion src/components/Canvas/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ const Canvas = ({ children }: PropsWithChildren) => {
console.log(`CARDS [${Object.keys(cards).length}]`, cards);
console.log(`FILETYPES [${filetypes.length}]`, filetypes);
console.log(`METAFILES [${metafiles.length}]`, metafiles);
// console.log(`CACHE [${cache.length}]`, cache);
console.log(`REPOS [${repos.length}]`, repos);
console.log(`BRANCHES [${branches.length}]`, branches);
console.log(`COMMITS [${commits.length}]`, commits);
Expand Down
12 changes: 8 additions & 4 deletions src/components/GitGraph/GitGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ReactFlow, {
} from 'reactflow';
import 'reactflow/dist/style.css';
import layoutGraph from '../../containers/graph-layout';
import { GitGraph, useGitGraph } from '../../containers/hooks/useGitGraph';
import { BranchLookup, GitGraph, useGitGraph } from '../../containers/hooks/useGitGraph';
import { UUID } from '../../store/types';
import { nodeTypes } from './GitNode';
import useToggle from '../../containers/hooks/useToggle';
Expand All @@ -34,6 +34,7 @@ const Flow = ({
onEdgesChange,
onConnect,
graph,
branchLookup,
printGraph,
calculateLayout
}: {
Expand All @@ -45,6 +46,7 @@ const Flow = ({
onEdgesChange: OnEdgesChange | undefined;
onConnect: OnConnect | undefined;
graph: GitGraph;
branchLookup: BranchLookup;
printGraph: () => void;
calculateLayout: () => void;
}) => {
Expand All @@ -58,7 +60,9 @@ const Flow = ({
const handleKeyDown = (event: React.KeyboardEvent) => {
if (event.key === 'Enter') {
event.preventDefault();
const vertex = graph.get(searchText);
const branchOid = branchLookup.get(searchText);
const vertex =
branchOid && graph.has(branchOid) ? graph.get(branchOid) : graph.get(searchText);

if (vertex) {
const { nodeInternals } = store.getState();
Expand Down Expand Up @@ -154,7 +158,7 @@ const SearchTextField = styled(TextField)(({ theme }) => ({
}));

const GitGraph = ({ repo }: { repo: UUID }) => {
const { graph, topological, printGraph } = useGitGraph(repo);
const { graph, topological, branchLookup, printGraph } = useGitGraph(repo);
const [nodes, setNodes, onNodesChange] = useNodesState([]);
const [edges, setEdges, onEdgesChange] = useEdgesState([]);
const onConnect = useCallback(
Expand All @@ -163,7 +167,6 @@ const GitGraph = ({ repo }: { repo: UUID }) => {
);

const calculateLayout = useCallback(() => {
console.log({ graph, topological });
const rfElements = layoutGraph(graph, topological);
setNodes(rfElements.filter(isNode));
setEdges(rfElements.filter(isEdge));
Expand All @@ -182,6 +185,7 @@ const GitGraph = ({ repo }: { repo: UUID }) => {
onEdgesChange={onEdgesChange}
onConnect={onConnect}
graph={graph}
branchLookup={branchLookup}
printGraph={printGraph}
calculateLayout={calculateLayout}
/>
Expand Down
22 changes: 14 additions & 8 deletions src/components/GitGraph/GitGraphSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useState } from 'react';
import { shallowEqual } from 'react-redux';
import { useAppDispatch, useAppSelector } from '../../store/hooks';
import repoSelectors from '../../store/selectors/repos';
Expand All @@ -15,15 +15,21 @@ const GitGraphSelect = () => {
);
const dispatch = useAppDispatch();

const handleChange = (event: SelectChangeEvent) => setSelected(event.target.value);

useEffect(() => {
const handleChange = (event: SelectChangeEvent) => {
if (graphs.length > 0) graphs.map(graph => dispatch(modalRemoved(graph.id)));
const selectedRepo = repos.find(r => r.id === selected);
setSelected(event.target.value);
const selectedRepo = repos.find(r => r.id === event.target.value);
if (selectedRepo)
dispatch(modalAdded({ id: window.api.uuid(), type: 'GitGraph', repo: selected }));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [repos, selected]);
dispatch(modalAdded({ id: window.api.uuid(), type: 'GitGraph', repo: selectedRepo.id }));
};

// useEffect(() => {
// if (graphs.length > 0) graphs.map(graph => dispatch(modalRemoved(graph.id)));
// const selectedRepo = repos.find(r => r.id === selected);
// if (selectedRepo)
// dispatch(modalAdded({ id: window.api.uuid(), type: 'GitGraph', repo: selected }));
// // eslint-disable-next-line react-hooks/exhaustive-deps
// }, [repos, selected]);

return (
<StyledFormContainer>
Expand Down
10 changes: 9 additions & 1 deletion src/components/GitGraph/GitNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ const GitNode = (props: GitNodeProps) => {
const borderStyle = props.selected ? 'solid' : props.data.staged ? 'dashed' : '';
const opacity = props.data.staged ? '0.6' : '1.0';

const copyToClipboard = (text: string) => {
window.api.clipboard.writeText(text);
};

return (
<>
<GraphTooltip disabled={!isHovering} content={tooltip} placement="bottom" />
Expand All @@ -60,7 +64,11 @@ const GitNode = (props: GitNodeProps) => {
opacity={opacity}
onMouseEnter={() => toggleHovering(true)}
onMouseLeave={() => toggleHovering(false)}
onClick={() => console.log({ props, color, borderStyle, opacity })}
onClick={() => {
copyToClipboard(props.id);
const node = props.data;
console.log(node);
}}
onContextMenu={handleMenu}
>
<StyledHandle type="target" position={Position.Top} />
Expand Down
2 changes: 1 addition & 1 deletion src/containers/git/git-cat-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const processCatFileOutput = (output: string | undefined, oid: SHA1): Com
* [9] commit message (e.g. `Merge branch 'feature' into main`)
*/
const linePattern = new RegExp(
'^(?:tree (.*)\\r?\\n)((?:parent \\w*\\r?\\n)+)?(?:author (?:(.*?) \\<(.*?)\\> (\\d*) (?:-\\d*))\\r?\\n)(?:committer (?:(.*?) \\<(.*?)\\> (\\d*) (?:-\\d*))\\r?\\n)?(?:gpgsig .*[\\s\\S]* -----END PGP SIGNATURE-----\\r?\\n \\r?\\n)?(?:\\r?\\n(.*[\\s\\S]*))$',
'^(?:tree (.*)\\r?\\n)((?:parent \\w*\\r?\\n)+)?(?:author (?:(.*?) \\<(.*?)\\> (\\d*) (?:[-+]\\d*))\\r?\\n)(?:committer (?:(.*?) \\<(.*?)\\> (\\d*) (?:[-+]\\d*))\\r?\\n)?(?:gpgsig .*[\\s\\S]* -----END PGP SIGNATURE-----\\r?\\n \\r?\\n)?(?:\\r?\\n(.*[\\s\\S]*))$',
'gm'
);

Expand Down
74 changes: 43 additions & 31 deletions src/containers/hooks/useGitGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ export type CommitVertex = Commit & {
staged: boolean;
};
export type GitGraph = Map<SHA1, CommitVertex>;
export type BranchLookup = Map<string, SHA1>;

export type useGitGraphHook = {
graph: GitGraph;
topological: UUID[];
branchLookup: BranchLookup;
printGraph: () => void;
};

export const useGitGraph = (id: UUID): useGitGraphHook => {
const graph = useMap<SHA1, CommitVertex>([]);
const branchLookup = useMap<string, SHA1>([]);
const [topological, setTopological] = useState<UUID[]>([]);
const branches = useAppSelector(state => branchSelectors.selectByRepo(state, id, true));
const previous = usePrevious(branches);
Expand Down Expand Up @@ -271,46 +274,55 @@ export const useGitGraph = (id: UUID): useGitGraphHook => {
);

const processChanges = useCallback(
(previous: Branch[] | undefined, branches: Branch[]) => {
async (previous: Branch[] | undefined, branches: Branch[]) => {
const { added, modified, removed } = changeFilter(previous, branches, [
'id',
'head',
'status',
'linked',
'commits'
]);
added.forEach(async branch => {
branch.commits.forEach(async oid => await updateVertex(oid.toString(), branch));
await updatePlaceholders(branch);
});
removed.forEach(async branch => {
branch.commits.forEach(async oid => await removeVertex(oid.toString(), branch));
await updatePlaceholders(branch);
});
modified.forEach(async mod => {
if (mod.changed.includes('commits')) {
const [added, , removed] = symmetrical(
mod.branch.commits,
mod.prev.commits,
(a, b) => a === b
);
added.forEach(async oid => await updateVertex(oid.toString(), mod.branch));
removed.forEach(async oid => await removeVertex(oid.toString(), mod.branch));
await updatePlaceholders(mod.branch);
}
if (
!mod.changed.includes('commits') &&
(mod.changed.includes('status') || mod.changed.includes('head'))
) {
if (mod.branch.commits.includes(mod.prev.head))
await updateVertex(mod.prev.head, mod.branch);
await updatePlaceholders(mod.branch);
}
});
await Promise.all(
added.map(async branch => {
branch.commits.forEach(async oid => await updateVertex(oid.toString(), branch));
await updatePlaceholders(branch);
branchLookup.set(`${branch.scope}/${branch.ref}`, branch.head);
})
);
await Promise.all(
removed.map(async branch => {
branch.commits.forEach(async oid => await removeVertex(oid.toString(), branch));
await updatePlaceholders(branch);
branchLookup.delete(`${branch.scope}/${branch.ref}`);
})
);
await Promise.all(
modified.map(async mod => {
if (mod.changed.includes('commits')) {
const [added, , removed] = symmetrical(
mod.branch.commits,
mod.prev.commits,
(a, b) => a === b
);
added.forEach(async oid => await updateVertex(oid.toString(), mod.branch));
removed.forEach(async oid => await removeVertex(oid.toString(), mod.branch));
await updatePlaceholders(mod.branch);
}
if (
!mod.changed.includes('commits') &&
(mod.changed.includes('status') || mod.changed.includes('head'))
) {
if (mod.branch.commits.includes(mod.prev.head))
await updateVertex(mod.prev.head, mod.branch);
await updatePlaceholders(mod.branch);
}
branchLookup.set(`${mod.branch.scope}/${mod.branch.ref}`, mod.branch.head);
})
);
link();
topologicalSort(graph);
},
[graph, link, removeVertex, topologicalSort, updatePlaceholders, updateVertex]
[branchLookup, graph, link, removeVertex, topologicalSort, updatePlaceholders, updateVertex]
);

useEffect(() => {
Expand All @@ -327,7 +339,7 @@ export const useGitGraph = (id: UUID): useGitGraphHook => {
console.groupEnd();
};

return { graph, topological, printGraph };
return { graph, topological, branchLookup, printGraph };
};

const changeFilter = <BranchProps extends keyof Branch>(
Expand Down
14 changes: 10 additions & 4 deletions src/store/thunks/branches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ export const fetchBranches = createAppAsyncThunk<{ local: Branch[]; remote: Bran
async (root, thunkAPI) => {
const branches = (
await Promise.all(
(
await window.api.git.showBranch({ dir: root, all: true })
)
(await window.api.git.showBranch({ dir: root, all: true }))
.filter(branch => branch.ref !== 'HEAD')
.map(branch =>
thunkAPI
Expand Down Expand Up @@ -175,8 +173,16 @@ export const buildBranch = createAppAsyncThunk<Branch, BranchIdentifiers>(
const bare = revBare?.toLowerCase() === 'true';
const merging = (await window.api.git.fetchMergingBranches(root))?.compare;

const repo = dir ? repoSelectors.selectByRoot(thunkAPI.getState(), dir) : undefined;
const repoHas = (branch: UUID): boolean =>
repo ? repo.local.includes(branch) || repo.remote.includes(branch) : false;
const existing = Object.values(thunkAPI.getState().branches.entities)
.filter(branch => branch?.scope === identifiers.scope && branch?.ref === identifiers.ref)
.filter(
branch =>
branch?.scope === identifiers.scope &&
branch?.ref === identifiers.ref &&
repoHas(branch.id)
)
.filter(isDefined)[0];

const base = {
Expand Down
Loading

0 comments on commit 27ae5cf

Please sign in to comment.