Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix: reported issue

MonsPropreecb6e9f7ea44
diff --git a/apps/api/src/task/validate-task-fields.ts b/apps/api/src/task/validate-task-fields.ts
index bcda501b8..66f1fe899 100644
--- a/apps/api/src/task/validate-task-fields.ts
+++ b/apps/api/src/task/validate-task-fields.ts
@@ -3,6 +3,59 @@ import { HTTPException } from "hono/http-exception";
import db from "../database";
import { columnTable, customFieldDefinitionTable } from "../database/schema";
+export function validateCustomFieldValue(
+ value: string,
+ type: "number" | "boolean" | "date" | "dropdown",
+ fieldName: string,
+ options?: unknown,
+): string | null {
+ if (type === "number") {
+ const num = Number(value);
+ if (!Number.isFinite(num)) {
+ return `Custom field "${fieldName}" expects a finite number, got "${value}".`;
+ }
+ }
+
+ if (type === "boolean") {
+ if (!["true", "false"].includes(value)) {
+ return `Custom field "${fieldName}" expects "true" or "false", got "${value}".`;
+ }
+ }
+
+ if (type === "date") {
+ const timestamp = Date.parse(value);
+ if (Number.isNaN(timestamp)) {
+ return `Custom field "${fieldName}" expects a valid ISO 8601 date, got "${value}".`;
+ }
+
+ const isoMatch =
+ /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d{3})?(Z|[+-]\d{2}:\d{2})?)?$/.test(
+ value,
+ );
+ if (!isoMatch) {
+ return `Custom field "${fieldName}" expects a date in YYYY-MM-DD or ISO 8601 format, got "${value}".`;
+ }
+ }
+
+ if (type === "dropdown") {
+ let parsedOptions: string[] = Array.isArray(options) ? options : [];
+
+ if (typeof options === "string") {
+ try {
+ parsedOptions = JSON.parse(options);
+ } catch {
+ return `Custom field "${fieldName}" has invalid dropdown options.`;
+ }
+ }
+
+ if (!parsedOptions.includes(value.trim())) {
+ return `Custom field "${fieldName}" expects one of: ${parsedOptions.join(", ")}, got "${value}".`;
+ }
+ }
+
+ return null;
+}
+
export async function assertRequiredCustomFields(
projectId: string,
customFields: { fieldId: string; value: string }[] = [],
@@ -34,39 +87,15 @@ export async function assertRequiredCustomFields(
const def = allFields.find((f) => f.id === cf.fieldId);
if (!def) continue;
- if (def.type === "number" && Number.isNaN(Number(cf.value))) {
- throw new HTTPException(400, {
- message: `Custom field "${def.name}" expects a number, got "${cf.value}".`,
- });
- }
- if (def.type === "boolean" && !["true", "false"].includes(cf.value)) {
- throw new HTTPException(400, {
- message: `Custom field "${def.name}" expects "true" or "false", got "${cf.value}".`,
- });
- }
- if (def.type === "date" && Number.isNaN(Date.parse(cf.value))) {
- throw new HTTPException(400, {
- message: `Custom field "${def.name}" expects a valid ISO 8601 date, got "${cf.value}".`,
- });
- }
- if (def.type === "dropdown") {
- let options: string[] = Array.isArray(def.options) ? def.options : [];
-
- if (typeof def.options === "string") {
- try {
- options = JSON.parse(def.options);
- } catch {
- throw new HTTPException(400, {
- message: `Custom field "${def.name}" has invalid dropdown options.`,
- });
- }
- }
+ const error = validateCustomFieldValue(
+ cf.value,
+ def.type as "number" | "boolean" | "date" | "dropdown",
+ def.name,
+ def.options,
+ );
- if (!options.includes(cf.value.trim())) {
- throw new HTTPException(400, {
- message: `Custom field "${def.name}" expects one of: ${options.join(", ")}, got "${cf.value}".`,
- });
- }
+ if (error) {
+ throw new HTTPException(400, { message: error });
}
}
diff --git a/apps/web/src/components/backlog-list-view/backlog-task-row.tsx b/apps/web/src/components/backlog-list-view/backlog-task-row.tsx
index 0fea3087c..36c28e9b5 100644
--- a/apps/web/src/components/backlog-list-view/backlog-task-row.tsx
+++ b/apps/web/src/components/backlog-list-view/backlog-task-row.tsx
@@ -220,10 +220,24 @@ export default function BacklogTaskRow({ task }: BacklogTaskRowProps) {
{activeCustomFieldValues.length > 0 && (
<HoverCard openDelay={200} closeDelay={100}>
<HoverCardTrigger asChild>
- <span className="inline-flex items-center gap-1 rounded border border-border/70 bg-muted/55 px-2 py-1 text-[10px] font-medium text-muted-foreground cursor-default">
+ <button
+ type="button"
+ className="inline-flex items-center gap-1 rounded border border-border/70 bg-muted/55 px-2 py-1 text-[10px] font-medium text-muted-foreground cursor-default focus:outline-none focus:ring-2 focus:ring-ring/50 focus:ring-offset-1"
+ onClick={(e) => {
+ e.stopPropagation();
+ e.preventDefault();
+ }}
+ onPointerDown={(e) => {
+ e.stopPropagation();
+ e.preventDefault();
+ }}
+ aria-label={t("tasks:customFields.ariaLabel", {
+ count: activeCustomFieldValues.length,
+ })}
+ >
<SlidersHorizontal className="w-3 h-3" />
<span>{activeCustomFieldValues.length}</span>
- </span>
+ </button>
</HoverCardTrigger>
<HoverCardContent
className="w-fit p-2.5"
diff --git a/apps/web/src/components/kanban-board/task-card.tsx b/apps/web/src/components/kanban-board/task-card.tsx
index 6376f2ec9..7860a244f 100644
--- a/apps/web/src/components/kanban-board/task-card.tsx
+++ b/apps/web/src/components/kanban-board/task-card.tsx
@@ -276,10 +276,24 @@ function TaskCard({ task, disableDragDrop = false }: TaskCardProps) {
{activeCustomFieldValues.length > 0 && (
<HoverCard openDelay={200} closeDelay={100}>
<HoverCardTrigger asChild>
- <span className="inline-flex items-center gap-1 rounded border border-border/70 bg-muted/55 px-2 py-1 text-[10px] font-medium text-muted-foreground cursor-default">
+ <button
+ type="button"
+ className="inline-flex items-center gap-1 rounded border border-border/70 bg-muted/55 px-2 py-1 text-[10px] font-medium text-muted-foreground cursor-default focus:outline-none focus:ring-2 focus:ring-ring/50 focus:ring-offset-1"
+ onClick={(e) => {
+ e.stopPropagation();
+ e.preventDefault();
+ }}
+ onPointerDown={(e) => {
+ e.stopPropagation();
+ e.preventDefault();
+ }}
+ aria-label={t("tasks:customFields.ariaLabel", {
+ count: activeCustomFieldValues.length,
+ })}
+ >
<SlidersHorizontal className="w-3 h-3" />
<span>{activeCustomFieldValues.length}</span>
- </span>
+ </button>
</HoverCardTrigger>
<HoverCardContent
className="w-fit p-2.5"
diff --git a/apps/web/src/components/shared/modals/create-task-modal.tsx b/apps/web/src/components/shared/modals/create-task-modal.tsx
index c35e474ba..06be03c6c 100644
--- a/apps/web/src/components/shared/modals/create-task-modal.tsx
+++ b/apps/web/src/components/shared/modals/create-task-modal.tsx
@@ -264,19 +264,14 @@ function CreateTaskModal({
};
useEffect(() => {
- if (customFields && customFields.length > 0) {
- setCustomFieldValues((prev) => {
- const next = { ...prev };
- for (const field of customFields) {
- if (next[field.id] === undefined) {
- next[field.id] = field.defaultValue || "";
- }
- }
- return next;
- });
- } else {
- setCustomFieldValues({});
- }
+ setCustomFieldValues((previousValues) =>
+ Object.fromEntries(
+ customFields.map((field) => [
+ field.id,
+ previousValues[field.id] ?? field.defaultValue ?? "",
+ ]),
+ ),
+ );
}, [customFields]);
const filteredLabels = (() => {
@@ -511,13 +506,15 @@ function CreateTaskModal({
}
}
- for (const [fieldId, value] of Object.entries(customFieldValues)) {
- if (value) {
- await setCustomFieldValue({
- taskId: savedTask.id,
- fieldId,
- value: String(value),
- });
+ if (draftTask) {
+ for (const [fieldId, value] of Object.entries(customFieldValues)) {
+ if (value) {
+ await setCustomFieldValue({
+ taskId: savedTask.id,
+ fieldId,
+ value: String(value),
+ });
+ }
}
}
diff --git a/apps/web/src/components/task/task-details-content.tsx b/apps/web/src/components/task/task-details-content.tsx
index 2ee675bdc..cdcc80f33 100644
--- a/apps/web/src/components/task/task-details-content.tsx
+++ b/apps/web/src/components/task/task-details-content.tsx
@@ -138,6 +138,7 @@ export default function TaskDetailsContent({
toast.success(t("tasks:detail.customFieldUpdated", "Field updated"));
} catch (error) {
+ handleLocalChange(fieldId, existingVal);
toast.error(
error instanceof Error ? error.message : "Failed to update field",
);