gpt-engineer-app[bot] commited on
Commit
861b88c
·
2 Parent(s): bc6510051848c0

Added inline validation UI

Browse files

X-Lovable-Edit-ID: edt-95787337-ec9b-4f5a-9ed8-fef3ac80cb6f

Files changed (1) hide show
  1. src/routes/dashboard.branch-debug.tsx +75 -18
src/routes/dashboard.branch-debug.tsx CHANGED
@@ -944,10 +944,46 @@ function loadJiraConfig(): JiraConfig {
944
  return { ...fallback, baseUrl: oldBase };
945
  }
946
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
947
  function ExportButtons({ result, mode }: { result: DebugResult; mode: "diff" | "snippet" | "unknown" }) {
948
  const stamp = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
949
  const [jiraOpen, setJiraOpen] = useState(false);
950
  const [jira, setJira] = useState<JiraConfig>(() => loadJiraConfig());
 
 
951
 
952
  const download = (filename: string, content: string, mime: string) => {
953
  const blob = new Blob([content], { type: mime });
@@ -1084,9 +1120,11 @@ function ExportButtons({ result, mode }: { result: DebugResult; mode: "diff" | "
1084
  };
1085
 
1086
  const createJiraTicket = async () => {
1087
- if (!jira.baseUrl) { toast.error("Jira base URL is required"); return; }
 
 
 
1088
  persistJira();
1089
- // Also download the report files so the user can attach them after Jira opens
1090
  exportMarkdown();
1091
  exportJson();
1092
  try {
@@ -1100,7 +1138,10 @@ function ExportButtons({ result, mode }: { result: DebugResult; mode: "diff" | "
1100
  };
1101
 
1102
  const copyJiraLink = async () => {
1103
- if (!jira.baseUrl) { toast.error("Jira base URL is required"); return; }
 
 
 
1104
  persistJira();
1105
  try {
1106
  await navigator.clipboard.writeText(buildJiraUrl());
@@ -1161,18 +1202,31 @@ function ExportButtons({ result, mode }: { result: DebugResult; mode: "diff" | "
1161
  </p>
1162
 
1163
  <div className="grid grid-cols-2 gap-2">
1164
- {textFields.map((f) => (
1165
- <label key={f.key} className={f.key === "baseUrl" ? "col-span-2 block" : "block"}>
1166
- <span className="text-[10px] font-mono uppercase tracking-widest text-muted-foreground">{f.label}</span>
1167
- <input
1168
- type="text"
1169
- value={jira[f.key]}
1170
- onChange={(e) => setJira({ ...jira, [f.key]: e.target.value })}
1171
- placeholder={f.placeholder}
1172
- className="mt-1 w-full h-8 px-2 rounded-md bg-[#080c10] border border-border text-xs font-mono text-foreground focus:border-[#2684ff] outline-none"
1173
- />
1174
- </label>
1175
- ))}
 
 
 
 
 
 
 
 
 
 
 
 
 
1176
  </div>
1177
 
1178
  <label className="block">
@@ -1210,14 +1264,17 @@ function ExportButtons({ result, mode }: { result: DebugResult; mode: "diff" | "
1210
  </button>
1211
  <button
1212
  onClick={copyJiraLink}
1213
- className="h-8 px-3 rounded-md border border-[#2684ff]/40 bg-[#2684ff]/10 hover:bg-[#2684ff]/20 text-[#2684ff] text-[10px] font-mono uppercase tracking-widest flex items-center gap-1"
1214
- title="Copy the full Jira create-issue URL with all parameters"
 
1215
  >
1216
  <Link2 className="h-3 w-3" /> Copy link
1217
  </button>
1218
  <button
1219
  onClick={createJiraTicket}
1220
- className="h-8 px-3 rounded-md bg-[#2684ff] hover:bg-[#2684ff]/90 text-white text-[10px] font-mono uppercase tracking-widest flex items-center gap-1"
 
 
1221
  >
1222
  <ExternalLink className="h-3 w-3" /> Open in Jira
1223
  </button>
 
944
  return { ...fallback, baseUrl: oldBase };
945
  }
946
 
947
+ const ALLOWED_ISSUE_TYPES = ["Bug", "Task", "Story", "Incident", "Epic", "Sub-task", "Improvement", "New Feature"];
948
+
949
+ function validateJira(j: JiraConfig): { baseUrl?: string; issueType?: string } {
950
+ const errors: { baseUrl?: string; issueType?: string } = {};
951
+ const raw = j.baseUrl.trim();
952
+ if (!raw) {
953
+ errors.baseUrl = "Base URL is required";
954
+ } else {
955
+ try {
956
+ const u = new URL(raw);
957
+ if (u.protocol !== "https:" && u.protocol !== "http:") {
958
+ errors.baseUrl = "Must start with https:// or http://";
959
+ } else if (!u.hostname.includes(".")) {
960
+ errors.baseUrl = "Enter a full hostname (e.g. acme.atlassian.net)";
961
+ } else if (u.search || u.hash || (u.pathname && u.pathname !== "/" && u.pathname !== "")) {
962
+ errors.baseUrl = "Use the base URL only — no path, query, or hash";
963
+ }
964
+ } catch {
965
+ errors.baseUrl = "Not a valid URL";
966
+ }
967
+ }
968
+ const it = j.issueType.trim();
969
+ if (it) {
970
+ if (it.length > 60) {
971
+ errors.issueType = "Issue type is too long";
972
+ } else if (!/^[A-Za-z][A-Za-z0-9 \-]*$/.test(it)) {
973
+ errors.issueType = "Letters, numbers, spaces and hyphens only";
974
+ } else if (!ALLOWED_ISSUE_TYPES.some((t) => t.toLowerCase() === it.toLowerCase())) {
975
+ errors.issueType = `Unknown type. Try: ${ALLOWED_ISSUE_TYPES.slice(0, 4).join(", ")}…`;
976
+ }
977
+ }
978
+ return errors;
979
+ }
980
+
981
  function ExportButtons({ result, mode }: { result: DebugResult; mode: "diff" | "snippet" | "unknown" }) {
982
  const stamp = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
983
  const [jiraOpen, setJiraOpen] = useState(false);
984
  const [jira, setJira] = useState<JiraConfig>(() => loadJiraConfig());
985
+ const jiraErrors = validateJira(jira);
986
+ const hasJiraErrors = Object.keys(jiraErrors).length > 0;
987
 
988
  const download = (filename: string, content: string, mime: string) => {
989
  const blob = new Blob([content], { type: mime });
 
1120
  };
1121
 
1122
  const createJiraTicket = async () => {
1123
+ if (hasJiraErrors) {
1124
+ toast.error(jiraErrors.baseUrl || jiraErrors.issueType || "Fix the highlighted fields");
1125
+ return;
1126
+ }
1127
  persistJira();
 
1128
  exportMarkdown();
1129
  exportJson();
1130
  try {
 
1138
  };
1139
 
1140
  const copyJiraLink = async () => {
1141
+ if (hasJiraErrors) {
1142
+ toast.error(jiraErrors.baseUrl || jiraErrors.issueType || "Fix the highlighted fields");
1143
+ return;
1144
+ }
1145
  persistJira();
1146
  try {
1147
  await navigator.clipboard.writeText(buildJiraUrl());
 
1202
  </p>
1203
 
1204
  <div className="grid grid-cols-2 gap-2">
1205
+ {textFields.map((f) => {
1206
+ const err = f.key === "baseUrl" ? jiraErrors.baseUrl : f.key === "issueType" ? jiraErrors.issueType : undefined;
1207
+ const isLong = f.key === "baseUrl";
1208
+ return (
1209
+ <label key={f.key} className={isLong ? "col-span-2 block" : "block"}>
1210
+ <span className="text-[10px] font-mono uppercase tracking-widest text-muted-foreground">{f.label}</span>
1211
+ <input
1212
+ type="text"
1213
+ value={jira[f.key]}
1214
+ onChange={(e) => setJira({ ...jira, [f.key]: e.target.value })}
1215
+ placeholder={f.placeholder}
1216
+ aria-invalid={!!err}
1217
+ aria-describedby={err ? `jira-${f.key}-err` : undefined}
1218
+ className={`mt-1 w-full h-8 px-2 rounded-md bg-[#080c10] border text-xs font-mono text-foreground outline-none ${
1219
+ err ? "border-red-500/60 focus:border-red-500" : "border-border focus:border-[#2684ff]"
1220
+ }`}
1221
+ />
1222
+ {err && (
1223
+ <span id={`jira-${f.key}-err`} className="mt-1 block text-[10px] font-mono text-red-400">
1224
+ {err}
1225
+ </span>
1226
+ )}
1227
+ </label>
1228
+ );
1229
+ })}
1230
  </div>
1231
 
1232
  <label className="block">
 
1264
  </button>
1265
  <button
1266
  onClick={copyJiraLink}
1267
+ disabled={hasJiraErrors}
1268
+ className="h-8 px-3 rounded-md border border-[#2684ff]/40 bg-[#2684ff]/10 hover:bg-[#2684ff]/20 text-[#2684ff] text-[10px] font-mono uppercase tracking-widest flex items-center gap-1 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-[#2684ff]/10"
1269
+ title={hasJiraErrors ? "Fix the highlighted fields first" : "Copy the full Jira create-issue URL with all parameters"}
1270
  >
1271
  <Link2 className="h-3 w-3" /> Copy link
1272
  </button>
1273
  <button
1274
  onClick={createJiraTicket}
1275
+ disabled={hasJiraErrors}
1276
+ className="h-8 px-3 rounded-md bg-[#2684ff] hover:bg-[#2684ff]/90 text-white text-[10px] font-mono uppercase tracking-widest flex items-center gap-1 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-[#2684ff]"
1277
+ title={hasJiraErrors ? "Fix the highlighted fields first" : undefined}
1278
  >
1279
  <ExternalLink className="h-3 w-3" /> Open in Jira
1280
  </button>