fix: copilot suggestions
This commit is contained in:
committed by
Nicolás Hatcher Andrés
parent
aa4dd598b1
commit
ef6849e822
@@ -16,12 +16,21 @@ import type React from "react";
|
|||||||
import { theme } from "../../../theme";
|
import { theme } from "../../../theme";
|
||||||
import { Footer, NewButton } from "./NamedRanges";
|
import { Footer, NewButton } from "./NamedRanges";
|
||||||
|
|
||||||
|
export interface SaveError {
|
||||||
|
nameError?: string;
|
||||||
|
formulaError?: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface EditNamedRangeProps {
|
interface EditNamedRangeProps {
|
||||||
worksheets: WorksheetProperties[];
|
worksheets: WorksheetProperties[];
|
||||||
name: string;
|
name: string;
|
||||||
scope: string;
|
scope: string;
|
||||||
formula: string;
|
formula: string;
|
||||||
onSave: (name: string, scope: string, formula: string) => string | undefined;
|
onSave: (
|
||||||
|
name: string,
|
||||||
|
scope: string,
|
||||||
|
formula: string,
|
||||||
|
) => SaveError | undefined;
|
||||||
onCancel: () => void;
|
onCancel: () => void;
|
||||||
definedNameList?: DefinedName[];
|
definedNameList?: DefinedName[];
|
||||||
editingDefinedName?: DefinedName | null;
|
editingDefinedName?: DefinedName | null;
|
||||||
@@ -245,11 +254,11 @@ const EditNamedRange: React.FC<EditNamedRangeProps> = ({
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
const error = onSave(name.trim(), scope, formula);
|
const error = onSave(name.trim(), scope, formula);
|
||||||
if (error) {
|
if (error) {
|
||||||
const isFormulaError = /formula|reference|cell/i.test(error);
|
if (error.nameError) {
|
||||||
if (isFormulaError) {
|
setNameError(error.nameError);
|
||||||
setFormulaError(error);
|
}
|
||||||
} else {
|
if (error.formulaError) {
|
||||||
setNameError(error);
|
setFormulaError(error.formulaError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { theme } from "../../../theme";
|
import { theme } from "../../../theme";
|
||||||
import EditNamedRange from "./EditNamedRange";
|
import EditNamedRange, { type SaveError } from "./EditNamedRange";
|
||||||
|
|
||||||
const normalizeRangeString = (range: string): string => {
|
const normalizeRangeString = (range: string): string => {
|
||||||
return range.trim().replace(/['"]/g, "");
|
return range.trim().replace(/['"]/g, "");
|
||||||
@@ -72,7 +72,7 @@ const NamedRanges: React.FC<NamedRangesProps> = ({
|
|||||||
name: string,
|
name: string,
|
||||||
scope: string,
|
scope: string,
|
||||||
formula: string,
|
formula: string,
|
||||||
): string | undefined => {
|
): SaveError | undefined => {
|
||||||
if (isCreatingNew) {
|
if (isCreatingNew) {
|
||||||
if (!newDefinedName) return undefined;
|
if (!newDefinedName) return undefined;
|
||||||
|
|
||||||
@@ -83,7 +83,8 @@ const NamedRanges: React.FC<NamedRangesProps> = ({
|
|||||||
setIsCreatingNew(false);
|
setIsCreatingNew(false);
|
||||||
return undefined;
|
return undefined;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return `${e}`;
|
// Since name validation is done client-side, errors from model are formula errors
|
||||||
|
return { formulaError: `${e}` };
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!editingDefinedName || !updateDefinedName) return undefined;
|
if (!editingDefinedName || !updateDefinedName) return undefined;
|
||||||
@@ -101,7 +102,8 @@ const NamedRanges: React.FC<NamedRangesProps> = ({
|
|||||||
setEditingDefinedName(null);
|
setEditingDefinedName(null);
|
||||||
return undefined;
|
return undefined;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return `${e}`;
|
// Since name validation is done client-side, errors from model are formula errors
|
||||||
|
return { formulaError: `${e}` };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -269,6 +271,15 @@ const NamedRanges: React.FC<NamedRangesProps> = ({
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
handleListItemClick(definedName);
|
handleListItemClick(definedName);
|
||||||
}}
|
}}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter" || e.key === " ") {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
handleListItemClick(definedName);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
aria-label={t("name_manager_dialog.edit")}
|
||||||
|
tabIndex={0}
|
||||||
>
|
>
|
||||||
<PencilLine size={16} />
|
<PencilLine size={16} />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
@@ -284,6 +295,20 @@ const NamedRanges: React.FC<NamedRangesProps> = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter" || e.key === " ") {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
if (deleteDefinedName) {
|
||||||
|
deleteDefinedName(
|
||||||
|
definedName.name,
|
||||||
|
definedName.scope,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
aria-label={t("name_manager_dialog.delete")}
|
||||||
|
tabIndex={0}
|
||||||
>
|
>
|
||||||
<Trash2 size={16} />
|
<Trash2 size={16} />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|||||||
Reference in New Issue
Block a user