Skip to content

Commit

Permalink
Merge pull request #121 from quadratichq/prettier-format
Browse files Browse the repository at this point in the history
format with prettier
  • Loading branch information
davidkircos authored Sep 14, 2022
2 parents be6d818 + 795f639 commit 52afe64
Show file tree
Hide file tree
Showing 58 changed files with 823 additions and 1,149 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/prettier-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ jobs:
with:
node-version: '17'
cache: 'npm'
- run: cd src
- run: npx prettier --check .
- run: npx prettier --check src/*
10 changes: 5 additions & 5 deletions src/atoms/gridInteractionStateAtom.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { atom } from "recoil";
import CellReference from "../core/gridGL/types/cellReference";
import { atom } from 'recoil';
import CellReference from '../core/gridGL/types/cellReference';
export interface GridInteractionState {
keyboardMovePosition: CellReference,
keyboardMovePosition: CellReference;
cursorPosition: CellReference;
showMultiCursor: boolean;
multiCursorPosition: {
Expand All @@ -13,7 +13,7 @@ export interface GridInteractionState {
}

export const gridInteractionStateAtom = atom({
key: "gridInteractionState", // unique ID (with respect to other atoms/selectors)
key: 'gridInteractionState', // unique ID (with respect to other atoms/selectors)
default: {
keyboardMovePosition: { x: 0, y: 0 },
cursorPosition: { x: 0, y: 0 },
Expand All @@ -23,6 +23,6 @@ export const gridInteractionStateAtom = atom({
terminalPosition: { x: 0, y: 0 },
},
showInput: false,
inputInitialValue: "",
inputInitialValue: '',
} as GridInteractionState,
});
13 changes: 5 additions & 8 deletions src/contexts/LoadingContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createContext, useContext, useState, ReactNode, useEffect, useCallback } from "react";
import { createContext, useContext, useState, ReactNode, useEffect, useCallback } from 'react';
type LoadingProviderProps = { children: ReactNode };

const LOAD_COUNT = 2;
Expand All @@ -10,14 +10,13 @@ export type LoadingContextType = {

export const LoadingContext = createContext<LoadingContextType>({
loading: true,
incrementLoadingCount: () =>
console.warn("useLoading must be used within LoadingProvider1"),
incrementLoadingCount: () => console.warn('useLoading must be used within LoadingProvider1'),
});

export function useLoading() {
const context = useContext(LoadingContext);
if (!context) {
throw new Error("useLoading must be used within LoadingProvider");
throw new Error('useLoading must be used within LoadingProvider');
}
return context;
}
Expand All @@ -27,7 +26,7 @@ export function LoadingProvider({ children }: LoadingProviderProps) {
const [loadingCount, setLoadingCount] = useState(0);

const incrementLoadingCount = useCallback(() => {
setLoadingCount(count => count + 1);
setLoadingCount((count) => count + 1);
}, [setLoadingCount]);

const value = { loading, incrementLoadingCount };
Expand All @@ -38,7 +37,5 @@ export function LoadingProvider({ children }: LoadingProviderProps) {
}
}, [loadingCount]);

return (
<LoadingContext.Provider value={value}>{children}</LoadingContext.Provider>
);
return <LoadingContext.Provider value={value}>{children}</LoadingContext.Provider>;
}
5 changes: 1 addition & 4 deletions src/core/actions/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ export const pasteFromClipboard = (pasteToCell: CellReference) => {
});
};

export const copyToClipboard = async (
cell0: CellReference,
cell1: CellReference
) => {
export const copyToClipboard = async (cell0: CellReference, cell1: CellReference) => {
// write selected cells to clipboard

const cWidth = Math.abs(cell1.x - cell0.x) + 1;
Expand Down
15 changes: 6 additions & 9 deletions src/core/actions/deleteCellsRange.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { GetCellsDB } from "../gridDB/Cells/GetCellsDB";
import { DeleteCellsDB } from "../gridDB/Cells/DeleteCellsDB";
import { GetDGraphDB } from "../gridDB/DGraph/GetDGraphDB";
import { UpdateDGraphDB } from "../gridDB/DGraph/UpdateDGraphDB";
import CellReference from "../gridGL/types/cellReference";
import { GetCellsDB } from '../gridDB/Cells/GetCellsDB';
import { DeleteCellsDB } from '../gridDB/Cells/DeleteCellsDB';
import { GetDGraphDB } from '../gridDB/DGraph/GetDGraphDB';
import { UpdateDGraphDB } from '../gridDB/DGraph/UpdateDGraphDB';
import CellReference from '../gridGL/types/cellReference';

export const deleteCellsRange = async (
p0: CellReference,
p1: CellReference
) => {
export const deleteCellsRange = async (p0: CellReference, p1: CellReference) => {
const cells = await GetCellsDB(p0.x, p0.y, p1.x, p1.y);
let dgraph = await GetDGraphDB();

Expand Down
2 changes: 1 addition & 1 deletion src/core/actions/gridFile/GridFileSchema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Cell } from "../../gridDB/db";
import { Cell } from '../../gridDB/db';
export interface GridFileSchema {
cells: Cell[];
dgraph: string;
Expand Down
12 changes: 6 additions & 6 deletions src/core/actions/gridFile/SaveGridFile.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { GridFileSchema } from "./GridFileSchema";
import { GetCellsDB } from "../../gridDB/Cells/GetCellsDB";
import { GetDGraphDB } from "../../gridDB/DGraph/GetDGraphDB";
import { GridFileSchema } from './GridFileSchema';
import { GetCellsDB } from '../../gridDB/Cells/GetCellsDB';
import { GetDGraphDB } from '../../gridDB/DGraph/GetDGraphDB';

function downloadFile(filename: string, data: string) {
const blob = new Blob([data], { type: "text/csv" });
const blob = new Blob([data], { type: 'text/csv' });
//@ts-expect-error
if (window.navigator.msSaveOrOpenBlob) {
//@ts-expect-error
window.navigator.msSaveBlob(blob, filename);
} else {
const elem = window.document.createElement("a");
const elem = window.document.createElement('a');
elem.href = window.URL.createObjectURL(blob);
elem.download = filename;
document.body.appendChild(elem);
Expand All @@ -30,7 +30,7 @@ export const SaveGridFile = async (autoDownload = false) => {
} as GridFileSchema);

// autodownload file
if (autoDownload) downloadFile("quadraticFile.grid", file_j);
if (autoDownload) downloadFile('quadraticFile.grid', file_j);

return file_j;
};
31 changes: 6 additions & 25 deletions src/core/actions/updateCellAndDCells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,13 @@ export const updateCellAndDCells = async (cell: Cell) => {

// get current cell from db
let cell = (
await GetCellsDB(
ref_cell_to_update[0],
ref_cell_to_update[1],
ref_cell_to_update[0],
ref_cell_to_update[1]
)
await GetCellsDB(ref_cell_to_update[0], ref_cell_to_update[1], ref_cell_to_update[0], ref_cell_to_update[1])
)[0];

if (cell === undefined) continue;

// remove old deps from graph
if (cell.dependent_cells)
dgraph.remove_dependencies_from_graph(cell.dependent_cells, [
[cell.x, cell.y],
]);
if (cell.dependent_cells) dgraph.remove_dependencies_from_graph(cell.dependent_cells, [[cell.x, cell.y]]);

// clear old array cells created by this cell
if (cell.array_cells) {
Expand All @@ -65,10 +57,7 @@ export const updateCellAndDCells = async (cell: Cell) => {
if (cell.type === 'PYTHON') {
// run cell and format results
let result = await runPython(cell.python_code || '');
let consoleOut = [
result.input_python_stack_trace,
result.input_python_std_out,
].join('\n');
let consoleOut = [result.input_python_stack_trace, result.input_python_std_out].join('\n');

if (consoleOut[0] === '\n') consoleOut = consoleOut.substring(1);

Expand All @@ -82,19 +71,14 @@ export const updateCellAndDCells = async (cell: Cell) => {
// add new cell deps to graph
if (result.cells_accessed.length) {
// add new deps to graph
dgraph.add_dependencies_to_graph(result.cells_accessed, [
[cell.x, cell.y],
]);
dgraph.add_dependencies_to_graph(result.cells_accessed, [[cell.x, cell.y]]);
}

let array_cells_to_output: Cell[] = [];

// if array output
if (result.array_output) {
if (
result.array_output[0][0] !== undefined &&
typeof result.array_output[0] !== 'string'
) {
if (result.array_output[0][0] !== undefined && typeof result.array_output[0] !== 'string') {
// 2d array
let y_offset = 0;
for (const row of result.array_output) {
Expand Down Expand Up @@ -139,10 +123,7 @@ export const updateCellAndDCells = async (cell: Cell) => {
}

// keep track of array cells updated by this cell
cell.array_cells = array_cells_to_output.map((a_cell) => [
a_cell.x,
a_cell.y,
]);
cell.array_cells = array_cells_to_output.map((a_cell) => [a_cell.x, a_cell.y]);

cell.last_modified = new Date().toISOString();

Expand Down
8 changes: 3 additions & 5 deletions src/core/computations/python/runPython.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { runPythonReturnType } from "./types";
import { runPythonReturnType } from './types';

export async function runPython(
python_code: string
): Promise<runPythonReturnType> {
const output = await window.pyodide.globals.get("run_python")(python_code);
export async function runPython(python_code: string): Promise<runPythonReturnType> {
const output = await window.pyodide.globals.get('run_python')(python_code);

return Object.fromEntries(output.toJs()) as runPythonReturnType;
}
6 changes: 3 additions & 3 deletions src/core/dgraph/QuadraticDependencyGraph.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import QuadraticDependencyGraph from "./QuadraticDependencyGraph";
import QuadraticDependencyGraph from './QuadraticDependencyGraph';

test("test QuadraticDependencyGraph", () => {
test('test QuadraticDependencyGraph', () => {
let dg = new QuadraticDependencyGraph();

dg.add_dependency_to_graph(
Expand Down Expand Up @@ -147,7 +147,7 @@ test("test QuadraticDependencyGraph", () => {
// dg.add_dependency_to_graph([1, 2], [[3, 3]]);
});

test("QuadraticDependencyGraph.add_dependencies_to_graph", () => {
test('QuadraticDependencyGraph.add_dependencies_to_graph', () => {
let dg = new QuadraticDependencyGraph();

dg.add_dependencies_to_graph(
Expand Down
24 changes: 5 additions & 19 deletions src/core/dgraph/QuadraticDependencyGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ export default class QuadraticDependencyGraph {
this._dgraph.import(igraph);
}

add_dependency_to_graph(
cell: [number, number],
dependent_cells: [number, number][]
) {
add_dependency_to_graph(cell: [number, number], dependent_cells: [number, number][]) {
this._dgraph.addVertex(cell_to_string(cell), undefined);

for (const dcell of dependent_cells) {
Expand All @@ -75,10 +72,7 @@ export default class QuadraticDependencyGraph {
// TODO detect circular reference
}

add_dependencies_to_graph(
input_cells: [number, number][],
dependent_cells: [number, number][]
) {
add_dependencies_to_graph(input_cells: [number, number][], dependent_cells: [number, number][]) {
// TODO: untested
// console.log(
// "add_dependencies_to_graph",
Expand All @@ -97,21 +91,15 @@ export default class QuadraticDependencyGraph {
// TODO detect circular reference
}

remove_dependency_from_graph(
cell: [number, number],
dependent_cells: [number, number][]
) {
remove_dependency_from_graph(cell: [number, number], dependent_cells: [number, number][]) {
for (const dcell of dependent_cells) {
this._dgraph.removeEdge(cell_to_string(cell), cell_to_string(dcell));
}

// TODO remove any orphans from the graph
}

remove_dependencies_from_graph(
input_cells: [number, number][],
dependent_cells: [number, number][]
) {
remove_dependencies_from_graph(input_cells: [number, number][], dependent_cells: [number, number][]) {
// console.log("remove_dependencies_from_graph", input_cells, JSON.stringify(dependent_cells));
for (const icell of input_cells) {
for (const dcell of dependent_cells) {
Expand All @@ -122,9 +110,7 @@ export default class QuadraticDependencyGraph {

get_children_cells(cell: [number, number]) {
let result = new Array<[number, number]>();
this._dgraph.traverseBfs(cell_to_string(cell), (key: string) =>
result.push(string_to_cell(key))
);
this._dgraph.traverseBfs(cell_to_string(cell), (key: string) => result.push(string_to_cell(key)));
return result.slice(1);
}
}
10 changes: 3 additions & 7 deletions src/core/dgraph/primatives/directedGraph/directedGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Modified by David Kircos Feb 2022
*/

import Queue from "../queue/queue";
import Queue from '../queue/queue';

/**
* @class
Expand Down Expand Up @@ -101,7 +101,7 @@ export class DirectedGraph {
}

if (weight && Number.isNaN(+weight)) {
throw new Error("addEdge: expects a numberic weight");
throw new Error('addEdge: expects a numberic weight');
}

const w = Number.isNaN(+weight) ? 1 : +weight;
Expand All @@ -118,11 +118,7 @@ export class DirectedGraph {
* @returns {boolean}
*/
hasEdge(srcKey, destKey) {
return (
this.hasVertex(srcKey) &&
this.hasVertex(destKey) &&
this._edges.get(srcKey).has(destKey)
);
return this.hasVertex(srcKey) && this.hasVertex(destKey) && this._edges.get(srcKey).has(destKey);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/core/dgraph/primatives/directedGraph/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const { DirectedGraph } = require("./directedGraph");
const { DirectedGraph } = require('./directedGraph');

exports.DirectedGraph = DirectedGraph;
Loading

0 comments on commit 52afe64

Please sign in to comment.