Skip to content

Commit

Permalink
Merge branch 'qa' of github.com:quadratichq/quadratic into ayush/2075
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushAgrawal-A2 committed Jan 3, 2025
2 parents 5476d8c + 6272495 commit 2ffd134
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 104 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"pixi",
"pixiapp",
"Plotly",
"proptest",
"pulumi",
"pyimport",
"rects",
Expand All @@ -68,6 +69,7 @@
"relcells",
"reqwest",
"rustup",
"rfind",
"scrollend",
"selfhost",
"selfhosted",
Expand Down
5 changes: 5 additions & 0 deletions quadratic-client/src/app/gridGL/HTMLGrid/EmptyGridMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useFileImport } from '@/app/ui/hooks/useFileImport';
import { useFileRouteLoaderData } from '@/shared/hooks/useFileRouteLoaderData';
import { Button } from '@/shared/shadcn/ui/button';
import { useEffect, useRef, useState } from 'react';
import { isMobile } from 'react-device-detect';
import { useSetRecoilState } from 'recoil';

const fileHasData = () => sheets.sheets.filter((sheet) => sheet.bounds.type === 'nonEmpty').length > 0;
Expand Down Expand Up @@ -48,6 +49,10 @@ export function EmptyGridMessage() {
return null;
}

if (isMobile) {
return null;
}

return (
<div className="absolute bottom-4 right-4 flex w-72 flex-col items-center rounded border border-border bg-background p-4 text-center shadow-md">
<div className="flex gap-4 pb-8 pt-10">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ export function drawDashedRectangle(options: { g: Graphics; color: number; isSel
return;
}

const boundedRight = Math.min(selectionRect.right, bounds.right);
const boundedBottom = Math.min(selectionRect.bottom, bounds.bottom);

g.lineStyle({
width: CURSOR_THICKNESS,
color,
alignment: 0.5,
texture: generatedTextures.dashedHorizontal,
});
g.moveTo(selectionRect.left, selectionRect.top);
g.lineTo(Math.min(selectionRect.right, bounds.right), selectionRect.top);
g.lineTo(boundedRight, selectionRect.top);
if (selectionRect.bottom <= bounds.bottom) {
g.moveTo(Math.min(selectionRect.right, bounds.right), selectionRect.bottom);
g.moveTo(boundedRight, selectionRect.bottom);
g.lineTo(selectionRect.left, selectionRect.bottom);
}

Expand All @@ -34,10 +37,10 @@ export function drawDashedRectangle(options: { g: Graphics; color: number; isSel
alignment: 0.5,
texture: generatedTextures.dashedVertical,
});
g.moveTo(selectionRect.left, Math.min(selectionRect.bottom, bounds.bottom));
g.moveTo(selectionRect.left, boundedBottom);
g.lineTo(selectionRect.left, selectionRect.top);
if (selectionRect.right <= bounds.right) {
g.moveTo(selectionRect.right, Math.min(selectionRect.bottom, bounds.bottom));
g.moveTo(selectionRect.right, boundedBottom);
g.lineTo(selectionRect.right, selectionRect.top);
}

Expand All @@ -50,8 +53,8 @@ export function drawDashedRectangle(options: { g: Graphics; color: number; isSel
g.drawRect(
selectionRect.left,
selectionRect.top,
Math.min(selectionRect.right, bounds.right) - selectionRect.left,
Math.min(selectionRect.bottom, bounds.bottom) - selectionRect.top
boundedRight - selectionRect.left,
boundedBottom - selectionRect.top
);
g.endFill();
}
Expand Down Expand Up @@ -79,6 +82,9 @@ export function drawDashedRectangleMarching(options: {
const maxX = selectionRect.right - offset;
const maxY = selectionRect.bottom - offset;

const boundedRight = Math.min(maxX, bounds.right);
const boundedBottom = Math.min(maxY, bounds.bottom);

if (!noFill) {
g.clear();
}
Expand All @@ -88,7 +94,7 @@ export function drawDashedRectangleMarching(options: {
});
if (!noFill) {
g.beginFill(color, FILL_ALPHA);
g.drawRect(minX, minY, maxX - minX, maxY - minY);
g.drawRect(minX, minY, boundedRight - minX, boundedBottom - minY);
g.endFill();
}

Expand All @@ -111,34 +117,38 @@ export function drawDashedRectangleMarching(options: {
let wrapAmount = 0;

// draw top line
for (let x = minX + march; x <= maxX - DASHED / 2; x += DASHED) {
g.moveTo(clamp(x, minX, maxX), minY);
g.lineTo(clamp(x + DASHED / 2, minX, maxX), minY);
wrapAmount = x - (maxX - DASHED / 2);
for (let x = minX + march; x <= boundedRight - DASHED / 2; x += DASHED) {
g.moveTo(clamp(x, minX, boundedRight), minY);
g.lineTo(clamp(x + DASHED / 2, minX, boundedRight), minY);
wrapAmount = x - (boundedRight - DASHED / 2);
}

// draw right line
for (let y = minY + wrapAmount; y <= maxY - DASHED / 2; y += DASHED) {
if (y + DASHED / 2 > minY + DASHED_THICKNESS) {
g.moveTo(maxX, clamp(y, minY, maxY));
g.lineTo(maxX, clamp(y + DASHED / 2, minY, maxY));
wrapAmount = y + DASHED / 2 - maxY;
if (maxX <= boundedRight) {
// draw right line
for (let y = minY + wrapAmount; y <= boundedBottom - DASHED / 2; y += DASHED) {
if (y + DASHED / 2 > minY + DASHED_THICKNESS) {
g.moveTo(boundedRight, clamp(y, minY, boundedBottom));
g.lineTo(boundedRight, clamp(y + DASHED / 2, minY, boundedBottom));
wrapAmount = y + DASHED / 2 - boundedBottom;
}
}
}

// draw bottom line
for (let x = maxX - wrapAmount; x >= minX + DASHED / 2; x -= DASHED) {
if (x - DASHED / 2 < maxX - DASHED_THICKNESS) {
g.moveTo(clamp(x - DASHED / 2, minX, maxX - DASHED_THICKNESS), maxY - DASHED_THICKNESS);
g.lineTo(clamp(x, minX, maxX), maxY - DASHED_THICKNESS);
if (maxY <= boundedBottom) {
// draw bottom line
for (let x = boundedRight - wrapAmount; x >= minX + DASHED / 2; x -= DASHED) {
if (x - DASHED / 2 < boundedRight - DASHED_THICKNESS) {
g.moveTo(clamp(x - DASHED / 2, minX, boundedRight - DASHED_THICKNESS), boundedBottom - DASHED_THICKNESS);
g.lineTo(clamp(x, minX, boundedRight), boundedBottom - DASHED_THICKNESS);
}
wrapAmount = minX - x - DASHED / 2;
}
wrapAmount = minX - x - DASHED / 2;
}

// draw left line
for (let y = maxY - wrapAmount; y >= minY + DASHED / 2; y -= DASHED) {
g.moveTo(minX + DASHED_THICKNESS, clamp(y - DASHED / 2, minY, maxY));
g.lineTo(minX + DASHED_THICKNESS, clamp(y, minY, maxY));
for (let y = boundedBottom - wrapAmount; y >= minY + DASHED / 2; y -= DASHED) {
g.moveTo(minX + DASHED_THICKNESS, clamp(y - DASHED / 2, minY, boundedBottom));
g.lineTo(minX + DASHED_THICKNESS, clamp(y, minY, boundedBottom));
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ declare var self: WorkerGlobalScope & typeof globalThis & {};
class PythonClient {
private id = 0;
private waitingForResponse: Record<number, Function> = {};
env: Record<string, string> = {};
private _env: Record<string, string> = {};

get env() {
return this._env;
}

start() {
self.onmessage = this.handleMessage;
Expand All @@ -38,6 +42,7 @@ class PythonClient {
break;

case 'clientPythonInit':
this._env = e.data.env;
return;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ export function GlobalSnackbarProvider({ children }: { children: React.ReactElem
backgroundColor: 'hsl(var(--foreground))',
color: 'hsl(var(--background))',
},
// Override this so it sits over the sheetbar
'&.MuiSnackbar-anchorOriginBottomCenter': {
bottom: '66px !important',
},
}}
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
autoHideDuration={stayOpen ? null : DURATION}
Expand Down
12 changes: 6 additions & 6 deletions quadratic-core/src/controller/execution/run_code/get_cells.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,31 +514,31 @@ mod test {
let result = gc
.calculation_get_cells_a1(transaction_id.to_string(), "B:".to_string(), None)
.unwrap();
assert_eq!(result.two_dimensional, true);
assert!(result.two_dimensional);

let result = gc
.calculation_get_cells_a1(transaction_id.to_string(), "B".to_string(), None)
.unwrap();
assert_eq!(result.two_dimensional, false);
assert!(!result.two_dimensional);

let result = gc
.calculation_get_cells_a1(transaction_id.to_string(), "2:".to_string(), None)
.unwrap();
assert_eq!(result.two_dimensional, true);
assert!(result.two_dimensional);

let result = gc
.calculation_get_cells_a1(transaction_id.to_string(), "2".to_string(), None)
.unwrap();
assert_eq!(result.two_dimensional, false);
assert!(!result.two_dimensional);

let result = gc
.calculation_get_cells_a1(transaction_id.to_string(), "D5:E5".to_string(), None)
.unwrap();
assert_eq!(result.two_dimensional, false);
assert!(!result.two_dimensional);

let result = gc
.calculation_get_cells_a1(transaction_id.to_string(), "D5:".to_string(), None)
.unwrap();
assert_eq!(result.two_dimensional, true);
assert!(result.two_dimensional);
}
}
2 changes: 1 addition & 1 deletion quadratic-core/src/controller/execution/run_code/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl GridController {
transaction.add_from_code_run(sheet_id, pos, &old_code_run);
transaction.add_from_code_run(sheet_id, pos, &new_code_run);

self.send_updated_bounds_rect(&sheet_rect, false);
self.send_updated_bounds(sheet_rect.sheet_id);
transaction.add_dirty_hashes_from_sheet_rect(sheet_rect);
if transaction.is_user() {
if let Some(sheet) = self.try_sheet(sheet_id) {
Expand Down
16 changes: 0 additions & 16 deletions quadratic-core/src/controller/send_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,22 +213,6 @@ impl GridController {
}
}

pub fn send_updated_bounds_rect(&mut self, sheet_rect: &SheetRect, format: bool) {
let recalculated = if let Some(sheet) = self.try_sheet_mut(sheet_rect.sheet_id) {
sheet.recalculate_add_bounds((*sheet_rect).into(), format)
} else {
false
};

if cfg!(target_family = "wasm") && recalculated {
if let Some(sheet) = self.try_sheet(sheet_rect.sheet_id) {
if let Ok(sheet_info) = serde_json::to_string(&SheetBounds::from(sheet)) {
crate::wasm_bindings::js::jsSheetBoundsUpdate(sheet_info);
}
}
};
}

/// Recalculates sheet bounds, and if changed then sends to TS.
pub fn send_updated_bounds(&mut self, sheet_id: SheetId) {
let recalculated = if let Some(sheet) = self.try_sheet_mut(sheet_id) {
Expand Down
55 changes: 1 addition & 54 deletions quadratic-core/src/grid/sheet/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,6 @@ impl Sheet {
|| old_format_bounds != self.format_bounds.to_bounds_rect()
}

/// Adds a SheetRect to the bounds of the sheet.
///
/// Returns whether any of the sheet's bounds has changed
pub fn recalculate_add_bounds(&mut self, rect: Rect, format: bool) -> bool {
if format {
let old_format_bounds = self.format_bounds.to_bounds_rect();
self.format_bounds.add(rect.min);
self.format_bounds.add(rect.max);
old_format_bounds != self.format_bounds.to_bounds_rect()
} else {
let old_data_bounds = self.format_bounds.to_bounds_rect();
self.data_bounds.add(rect.min);
self.data_bounds.add(rect.max);
old_data_bounds != self.data_bounds.to_bounds_rect()
}
}

/// Returns whether the sheet is completely empty.
pub fn is_empty(&self) -> bool {
self.data_bounds.is_empty() && self.format_bounds.is_empty()
Expand Down Expand Up @@ -521,7 +504,7 @@ mod test {
},
CellAlign, CellWrap, CodeCellLanguage, GridBounds, Sheet,
},
A1Selection, Array, CellValue, Pos, Rect, SheetPos, SheetRect,
A1Selection, Array, CellValue, Pos, Rect, SheetPos,
};
use proptest::proptest;
use std::collections::HashMap;
Expand Down Expand Up @@ -924,42 +907,6 @@ mod test {
assert_eq!(sheet.row_bounds(2, false), Some((1, 1)));
}

#[test]
fn send_updated_bounds_rect() {
let mut gc = GridController::test();
let sheet_id = gc.sheet_ids()[0];
gc.set_cell_value(
SheetPos {
x: 1,
y: 2,
sheet_id,
},
"test".to_string(),
None,
);
let sheet = gc.sheet(sheet_id);
assert_eq!(
sheet.data_bounds,
GridBounds::NonEmpty(Rect::from_numbers(1, 2, 1, 1))
);
gc.set_bold(
&A1Selection::from_rect(SheetRect::from_numbers(3, 5, 1, 1, sheet_id)),
true,
None,
)
.unwrap();

let sheet = gc.sheet(sheet_id);
assert_eq!(
sheet.bounds(true),
GridBounds::NonEmpty(Rect::from_numbers(1, 2, 1, 1))
);
assert_eq!(
sheet.bounds(false),
GridBounds::NonEmpty(Rect::from_numbers(1, 2, 3, 4))
);
}

#[test]
fn test_row_bounds_with_formats() {
let mut gc = GridController::test();
Expand Down

0 comments on commit 2ffd134

Please sign in to comment.