fix: nicos suggestions

This commit is contained in:
Daniel Gonzalez Albo
2025-11-12 22:21:22 +01:00
committed by Nicolás Hatcher Andrés
parent b2744efeb5
commit cbf75c059b
5 changed files with 18 additions and 37 deletions

View File

@@ -46,7 +46,7 @@ function EditNamedRange({
let counter = 1; let counter = 1;
let defaultName = `Range${counter}`; let defaultName = `Range${counter}`;
const scopeIndex = worksheets.findIndex((s) => s.name === initialScope); const scopeIndex = worksheets.findIndex((s) => s.name === initialScope);
const newScope = scopeIndex >= 0 ? scopeIndex : undefined; const newScope = scopeIndex >= 0 ? scopeIndex : null;
while ( while (
definedNameList.some( definedNameList.some(
@@ -62,17 +62,15 @@ function EditNamedRange({
const [name, setName] = useState(getDefaultName()); const [name, setName] = useState(getDefaultName());
const [scope, setScope] = useState(initialScope); const [scope, setScope] = useState(initialScope);
const [formula, setFormula] = useState(initialFormula); const [formula, setFormula] = useState(initialFormula);
const [nameError, setNameError] = useState<string | undefined>(undefined); const [nameError, setNameError] = useState<string>("");
const [formulaError, setFormulaError] = useState<string | undefined>( const [formulaError, setFormulaError] = useState<string>("");
undefined,
);
const isSelected = (value: string) => scope === value; const isSelected = (value: string) => scope === value;
// Validate name (format and duplicates) // Validate name (format and duplicates)
useEffect(() => { useEffect(() => {
const trimmed = name.trim(); const trimmed = name.trim();
let error: string | undefined; let error = "";
if (!trimmed) { if (!trimmed) {
error = t("name_manager_dialog.errors.range_name_required"); error = t("name_manager_dialog.errors.range_name_required");
@@ -85,7 +83,7 @@ function EditNamedRange({
} else { } else {
// Check for duplicates only if format is valid // Check for duplicates only if format is valid
const scopeIndex = worksheets.findIndex((s) => s.name === scope); const scopeIndex = worksheets.findIndex((s) => s.name === scope);
const newScope = scopeIndex >= 0 ? scopeIndex : undefined; const newScope = scopeIndex >= 0 ? scopeIndex : null;
const existing = definedNameList.find( const existing = definedNameList.find(
(dn) => (dn) =>
dn.name === trimmed && dn.name === trimmed &&
@@ -103,7 +101,7 @@ function EditNamedRange({
setNameError(error); setNameError(error);
}, [name, scope, definedNameList, editingDefinedName, worksheets]); }, [name, scope, definedNameList, editingDefinedName, worksheets]);
const hasAnyError = nameError !== undefined || formulaError !== undefined; const hasAnyError = nameError !== "" || formulaError !== "";
return ( return (
<Container> <Container>
@@ -219,7 +217,7 @@ function EditNamedRange({
value={formula} value={formula}
onChange={(e) => { onChange={(e) => {
setFormula(e.target.value); setFormula(e.target.value);
setFormulaError(undefined); setFormulaError("");
}} }}
onKeyDown={(e) => e.stopPropagation()} onKeyDown={(e) => e.stopPropagation()}
onClick={(e) => e.stopPropagation()} onClick={(e) => e.stopPropagation()}

View File

@@ -94,9 +94,7 @@ function NamedRanges({
try { try {
updateDefinedName( updateDefinedName(
editingDefinedName.name, editingDefinedName.name,
editingDefinedName.scope !== undefined editingDefinedName.scope ?? null,
? editingDefinedName.scope
: null,
name, name,
newScope, newScope,
formula, formula,
@@ -119,7 +117,7 @@ function NamedRanges({
if (editingDefinedName) { if (editingDefinedName) {
name = editingDefinedName.name; name = editingDefinedName.name;
scopeName = scopeName =
editingDefinedName.scope !== undefined editingDefinedName.scope != null
? worksheets[editingDefinedName.scope]?.name || "[unknown]" ? worksheets[editingDefinedName.scope]?.name || "[unknown]"
: "[Global]"; : "[Global]";
formula = editingDefinedName.formula; formula = editingDefinedName.formula;
@@ -134,7 +132,7 @@ function NamedRanges({
return ( return (
<Container> <Container>
<EditHeader> <EditHeader>
<Tooltip title={t("name_manager_dialog.back")}> <Tooltip title={t("name_manager_dialog.back_to_list")}>
<IconButtonWrapper <IconButtonWrapper
onClick={handleCancel} onClick={handleCancel}
onKeyDown={(e) => { onKeyDown={(e) => {
@@ -142,7 +140,7 @@ function NamedRanges({
handleCancel(); handleCancel();
} }
}} }}
aria-label={t("name_manager_dialog.back")} aria-label={t("name_manager_dialog.back_to_list")}
tabIndex={0} tabIndex={0}
> >
<ArrowLeft /> <ArrowLeft />
@@ -247,7 +245,7 @@ function NamedRanges({
<ListContainer> <ListContainer>
{definedNameList.map((definedName) => { {definedNameList.map((definedName) => {
const scopeName = const scopeName =
definedName.scope !== undefined definedName.scope != null
? worksheets[definedName.scope]?.name || "[Unknown]" ? worksheets[definedName.scope]?.name || "[Unknown]"
: "[Global]"; : "[Global]";
const isSelected = const isSelected =
@@ -300,9 +298,7 @@ function NamedRanges({
if (deleteDefinedName) { if (deleteDefinedName) {
deleteDefinedName( deleteDefinedName(
definedName.name, definedName.name,
definedName.scope !== undefined definedName.scope ?? null,
? definedName.scope
: null,
); );
} }
}} }}
@@ -313,9 +309,7 @@ function NamedRanges({
if (deleteDefinedName) { if (deleteDefinedName) {
deleteDefinedName( deleteDefinedName(
definedName.name, definedName.name,
definedName.scope !== undefined definedName.scope ?? null,
? definedName.scope
: null,
); );
} }
} }

View File

@@ -49,11 +49,6 @@ const RightDrawer = ({
const [isResizing, setIsResizing] = useState(false); const [isResizing, setIsResizing] = useState(false);
const resizeHandleRef = useRef<HTMLDivElement>(null); const resizeHandleRef = useRef<HTMLDivElement>(null);
// Update local width when prop changes
useEffect(() => {
setDrawerWidth(width);
}, [width]);
const handleMouseDown = useCallback((e: ReactMouseEvent) => { const handleMouseDown = useCallback((e: ReactMouseEvent) => {
e.preventDefault(); e.preventDefault();
setIsResizing(true); setIsResizing(true);

View File

@@ -753,13 +753,7 @@ const Workbook = (props: { model: Model; workbookState: WorkbookState }) => {
newScope: number | null, newScope: number | null,
newFormula: string, newFormula: string,
) => { ) => {
model.updateDefinedName( model.updateDefinedName(name, scope, newName, newScope, newFormula);
name,
scope ?? undefined,
newName,
newScope ?? undefined,
newFormula,
);
setRedrawId((id) => id + 1); setRedrawId((id) => id + 1);
}} }}
newDefinedName={( newDefinedName={(
@@ -767,11 +761,11 @@ const Workbook = (props: { model: Model; workbookState: WorkbookState }) => {
scope: number | null, scope: number | null,
formula: string, formula: string,
) => { ) => {
model.newDefinedName(name, scope ?? undefined, formula); model.newDefinedName(name, scope, formula);
setRedrawId((id) => id + 1); setRedrawId((id) => id + 1);
}} }}
deleteDefinedName={(name: string, scope: number | null) => { deleteDefinedName={(name: string, scope: number | null) => {
model.deleteDefinedName(name, scope ?? undefined); model.deleteDefinedName(name, scope);
setRedrawId((id) => id + 1); setRedrawId((id) => id + 1);
}} }}
selectedArea={() => { selectedArea={() => {

View File

@@ -111,7 +111,7 @@
"close": "Close dialog", "close": "Close dialog",
"delete": "Delete Range", "delete": "Delete Range",
"edit": "Edit Range", "edit": "Edit Range",
"back": "Back to list", "back_to_list": "Back to list",
"add_new_range": "Add a new range", "add_new_range": "Add a new range",
"edit_range": "Edit range", "edit_range": "Edit range",
"new_named_range": "New Named Range", "new_named_range": "New Named Range",