(project: string, targets: string[])
| 11 | import { applyPlanTitleToQuery } from "./title"; |
| 12 | |
| 13 | export const preCreateIssue = async (project: string, targets: string[]) => { |
| 14 | const type = "bb.plan.change-database"; |
| 15 | |
| 16 | const databaseNames: string[] = []; |
| 17 | for (const target of targets) { |
| 18 | if (isValidDatabaseGroupName(target)) { |
| 19 | const dbGroup = useAppStore.getState().getDBGroupByName(target); |
| 20 | databaseNames.push(dbGroup.title); |
| 21 | } else if (isValidDatabaseName(target)) { |
| 22 | const db = useAppStore.getState().getDatabaseByName(target); |
| 23 | databaseNames.push(extractDatabaseResourceName(db.name).databaseName); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | const isDatabaseGroup = targets.every((target) => |
| 28 | isValidDatabaseGroupName(target) |
| 29 | ); |
| 30 | |
| 31 | // Fetch project to check enforce_issue_title setting |
| 32 | const projectEntity = await useAppStore |
| 33 | .getState() |
| 34 | .getOrFetchProjectByName(project); |
| 35 | |
| 36 | // Navigate to plan detail page |
| 37 | const query: Record<string, string> = { |
| 38 | template: type, |
| 39 | }; |
| 40 | |
| 41 | if (isDatabaseGroup) { |
| 42 | const databaseGroupName = targets[0]; |
| 43 | query.databaseGroupName = databaseGroupName; |
| 44 | applyPlanTitleToQuery(query, projectEntity, () => |
| 45 | generatePlanTitle(type, [extractDatabaseGroupName(databaseGroupName)]) |
| 46 | ); |
| 47 | } else { |
| 48 | query.databaseList = targets.join(","); |
| 49 | applyPlanTitleToQuery(query, projectEntity, () => |
| 50 | generatePlanTitle( |
| 51 | type, |
| 52 | targets.map((db) => extractDatabaseResourceName(db).databaseName) |
| 53 | ) |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | router.push({ |
| 58 | name: PROJECT_V1_ROUTE_PLAN_DETAIL_SPEC_DETAIL, |
| 59 | params: { |
| 60 | projectId: extractProjectResourceName(project), |
| 61 | planId: "create", |
| 62 | specId: "placeholder", |
| 63 | }, |
| 64 | query, |
| 65 | }); |
| 66 | }; |
no test coverage detected