From cffeca8c45fb0cc8188934b2b89f02a364e00980 Mon Sep 17 00:00:00 2001 From: David Figatner Date: Sun, 10 Nov 2024 08:08:32 -0800 Subject: [PATCH 1/3] fix bug with custom dates closing when editing in format menu --- quadratic-client/src/app/ui/components/DateFormat.tsx | 4 ++++ .../Validations/Validation/ValidationUI/ValidationInput.tsx | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/quadratic-client/src/app/ui/components/DateFormat.tsx b/quadratic-client/src/app/ui/components/DateFormat.tsx index a5a5ed64ae..bc73db2e0b 100644 --- a/quadratic-client/src/app/ui/components/DateFormat.tsx +++ b/quadratic-client/src/app/ui/components/DateFormat.tsx @@ -230,6 +230,10 @@ export const DateFormat = (props: DateFormatProps) => { onChange={changeCustom} value={custom ?? ''} onEnter={closeMenu} + onKeyDown={(e) => { + // ensures that the menu does not close when the user presses keys like arrow + e.stopPropagation(); + }} />

Learn custom date and time formatting{' '} diff --git a/quadratic-client/src/app/ui/menus/Validations/Validation/ValidationUI/ValidationInput.tsx b/quadratic-client/src/app/ui/menus/Validations/Validation/ValidationUI/ValidationInput.tsx index 33f2ced399..8d44f2e1b0 100644 --- a/quadratic-client/src/app/ui/menus/Validations/Validation/ValidationUI/ValidationInput.tsx +++ b/quadratic-client/src/app/ui/menus/Validations/Validation/ValidationUI/ValidationInput.tsx @@ -1,6 +1,6 @@ import { Input } from '@/shared/shadcn/ui/input'; import { cn } from '@/shared/shadcn/utils'; -import { FocusEvent, forwardRef, Ref, useCallback, useEffect, useRef } from 'react'; +import { FocusEvent, forwardRef, KeyboardEvent, Ref, useCallback, useEffect, useRef } from 'react'; interface ValidationInputProps { className?: string; @@ -15,7 +15,7 @@ interface ValidationInputProps { // used to update whenever the input is changed (ie, a character is changes within the input box) onInput?: (value: string) => void; - + onKeyDown?: (e: KeyboardEvent) => void; onEnter?: () => void; footer?: string | JSX.Element; @@ -46,6 +46,7 @@ export const ValidationInput = forwardRef((props: ValidationInputProps, ref: Ref readOnly, type, clear, + onKeyDown, } = props; const parentRef = useRef(null); @@ -109,6 +110,7 @@ export const ValidationInput = forwardRef((props: ValidationInputProps, ref: Ref e.preventDefault(); e.stopPropagation(); } + onKeyDown?.(e); }} /> From 381826c5a9fce830b5aaf66972195d0c06fc4b8b Mon Sep 17 00:00:00 2001 From: David Figatner Date: Sun, 10 Nov 2024 08:15:44 -0800 Subject: [PATCH 2/3] possibly fix bug --- quadratic-client/src/app/ui/components/DateFormat.tsx | 8 ++++++-- .../Validation/ValidationUI/ValidationInput.tsx | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/quadratic-client/src/app/ui/components/DateFormat.tsx b/quadratic-client/src/app/ui/components/DateFormat.tsx index bc73db2e0b..1d9dfe2c41 100644 --- a/quadratic-client/src/app/ui/components/DateFormat.tsx +++ b/quadratic-client/src/app/ui/components/DateFormat.tsx @@ -227,9 +227,13 @@ export const DateFormat = (props: DateFormatProps) => { { + changeCustom(value); + apply(); + closeMenu(); + }} onKeyDown={(e) => { // ensures that the menu does not close when the user presses keys like arrow e.stopPropagation(); diff --git a/quadratic-client/src/app/ui/menus/Validations/Validation/ValidationUI/ValidationInput.tsx b/quadratic-client/src/app/ui/menus/Validations/Validation/ValidationUI/ValidationInput.tsx index 8d44f2e1b0..982fd712f4 100644 --- a/quadratic-client/src/app/ui/menus/Validations/Validation/ValidationUI/ValidationInput.tsx +++ b/quadratic-client/src/app/ui/menus/Validations/Validation/ValidationUI/ValidationInput.tsx @@ -16,7 +16,7 @@ interface ValidationInputProps { // used to update whenever the input is changed (ie, a character is changes within the input box) onInput?: (value: string) => void; onKeyDown?: (e: KeyboardEvent) => void; - onEnter?: () => void; + onEnter?: (value: string) => void; footer?: string | JSX.Element; height?: string; @@ -106,7 +106,8 @@ export const ValidationInput = forwardRef((props: ValidationInputProps, ref: Ref } // timeout is needed to ensure the state updates before the onEnter function is called - setTimeout(onEnter, 0); + const savedValue = e.currentTarget.value; + setTimeout(() => onEnter?.(savedValue), 0); e.preventDefault(); e.stopPropagation(); } From 7264bbd7989f13735b8c0b6ed1fc2fe0127b1d68 Mon Sep 17 00:00:00 2001 From: David Figatner Date: Tue, 12 Nov 2024 05:03:48 -0800 Subject: [PATCH 3/3] fix bug with a '%' in rust code --- quadratic-core/src/date_time.rs | 6 +++++- quadratic-rust-client/src/lib.rs | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/quadratic-core/src/date_time.rs b/quadratic-core/src/date_time.rs index c929db9939..b2396dd98b 100644 --- a/quadratic-core/src/date_time.rs +++ b/quadratic-core/src/date_time.rs @@ -97,7 +97,11 @@ fn find_items_date_start(items: &[Item<'_>]) -> Option { /// Converts a NaiveDateTime to a date and time string using a strftime format string. pub fn date_time_to_date_time_string(date_time: NaiveDateTime, format: Option) -> String { let format = format.map_or(DEFAULT_DATE_TIME_FORMAT.to_string(), |f| f); - date_time.format(&format).to_string() + let strftime_items = StrftimeItems::new(&format); + let Ok(items) = strftime_items.parse() else { + return date_time.format(DEFAULT_DATE_TIME_FORMAT).to_string(); + }; + date_time.format_with_items(items.iter()).to_string() } /// Converts a NaiveDateTime to a date-only string using a strftime format string. diff --git a/quadratic-rust-client/src/lib.rs b/quadratic-rust-client/src/lib.rs index e4e5920177..562bf8d512 100644 --- a/quadratic-rust-client/src/lib.rs +++ b/quadratic-rust-client/src/lib.rs @@ -25,3 +25,8 @@ impl SheetOffsetsWasm { SheetOffsets::default() } } + +#[wasm_bindgen(start)] +pub fn start() { + console_error_panic_hook::set_once(); +}