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

View File

@@ -94,9 +94,7 @@ function NamedRanges({
try {
updateDefinedName(
editingDefinedName.name,
editingDefinedName.scope !== undefined
? editingDefinedName.scope
: null,
editingDefinedName.scope ?? null,
name,
newScope,
formula,
@@ -119,7 +117,7 @@ function NamedRanges({
if (editingDefinedName) {
name = editingDefinedName.name;
scopeName =
editingDefinedName.scope !== undefined
editingDefinedName.scope != null
? worksheets[editingDefinedName.scope]?.name || "[unknown]"
: "[Global]";
formula = editingDefinedName.formula;
@@ -134,7 +132,7 @@ function NamedRanges({
return (
<Container>
<EditHeader>
<Tooltip title={t("name_manager_dialog.back")}>
<Tooltip title={t("name_manager_dialog.back_to_list")}>
<IconButtonWrapper
onClick={handleCancel}
onKeyDown={(e) => {
@@ -142,7 +140,7 @@ function NamedRanges({
handleCancel();
}
}}
aria-label={t("name_manager_dialog.back")}
aria-label={t("name_manager_dialog.back_to_list")}
tabIndex={0}
>
<ArrowLeft />
@@ -247,7 +245,7 @@ function NamedRanges({
<ListContainer>
{definedNameList.map((definedName) => {
const scopeName =
definedName.scope !== undefined
definedName.scope != null
? worksheets[definedName.scope]?.name || "[Unknown]"
: "[Global]";
const isSelected =
@@ -300,9 +298,7 @@ function NamedRanges({
if (deleteDefinedName) {
deleteDefinedName(
definedName.name,
definedName.scope !== undefined
? definedName.scope
: null,
definedName.scope ?? null,
);
}
}}
@@ -313,9 +309,7 @@ function NamedRanges({
if (deleteDefinedName) {
deleteDefinedName(
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 resizeHandleRef = useRef<HTMLDivElement>(null);
// Update local width when prop changes
useEffect(() => {
setDrawerWidth(width);
}, [width]);
const handleMouseDown = useCallback((e: ReactMouseEvent) => {
e.preventDefault();
setIsResizing(true);

View File

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

View File

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