UNPKG

analytica-frontend-lib

Version:

Repositório público dos componentes utilizados nas plataformas da Analytica Ensino

1 lines 14 kB
{"version":3,"sources":["../../../src/types/common.ts","../../../src/types/recommendedLessons.ts"],"sourcesContent":["/**\n * Common Type Definitions\n * Shared types used across multiple features (activities, goals, etc.)\n */\n\n/**\n * Generic API status for activities and goals\n * Used by backend endpoints for status filtering\n */\nexport enum GenericApiStatus {\n A_VENCER = 'A_VENCER',\n VENCIDA = 'VENCIDA',\n CONCLUIDA = 'CONCLUIDA',\n}\n\n/**\n * Generic display status for UI components\n * Used for Badge and status display in tables\n */\nexport enum GenericDisplayStatus {\n ATIVA = 'ATIVA',\n VENCIDA = 'VENCIDA',\n CONCLUIDA = 'CONCLUÍDA',\n}\n\n/**\n * Badge action types for status visualization\n * Maps to Badge component action prop\n */\nexport enum BadgeActionType {\n SUCCESS = 'success',\n WARNING = 'warning',\n ERROR = 'error',\n}\n\n/**\n * Get badge action based on display status\n * @param status - Display status value\n * @returns Badge action type for styling\n */\nexport const getStatusBadgeAction = (\n status: GenericDisplayStatus\n): BadgeActionType => {\n const actionMap: Record<GenericDisplayStatus, BadgeActionType> = {\n [GenericDisplayStatus.CONCLUIDA]: BadgeActionType.SUCCESS,\n [GenericDisplayStatus.ATIVA]: BadgeActionType.WARNING,\n [GenericDisplayStatus.VENCIDA]: BadgeActionType.ERROR,\n };\n return actionMap[status] ?? BadgeActionType.WARNING;\n};\n\n/**\n * Map API status to display status\n * @param apiStatus - Status from backend API\n * @returns Formatted status for UI display\n */\nexport const mapApiStatusToDisplay = (\n apiStatus: GenericApiStatus\n): GenericDisplayStatus => {\n const statusMap: Record<GenericApiStatus, GenericDisplayStatus> = {\n [GenericApiStatus.A_VENCER]: GenericDisplayStatus.ATIVA,\n [GenericApiStatus.VENCIDA]: GenericDisplayStatus.VENCIDA,\n [GenericApiStatus.CONCLUIDA]: GenericDisplayStatus.CONCLUIDA,\n };\n return statusMap[apiStatus];\n};\n","/**\n * Recommended Lessons / Goals (Aulas Recomendadas) Type Definitions\n * Based on /recommended-class/history endpoint\n */\n\nimport {\n GenericApiStatus,\n GenericDisplayStatus,\n BadgeActionType,\n getStatusBadgeAction,\n} from './common';\n\n/**\n * Goal status from backend API\n * Re-exported from common for backward compatibility\n */\nexport { GenericApiStatus as GoalApiStatus } from './common';\n\n/**\n * Goal status for display in UI (Badge component)\n * Re-exported from common for backward compatibility\n */\nexport { GenericDisplayStatus as GoalDisplayStatus } from './common';\n\n/**\n * Badge action types for goal status visualization\n * Re-exported from common for backward compatibility\n */\nexport { BadgeActionType as GoalBadgeActionType } from './common';\n\n/**\n * Subject info from API response\n */\nexport interface GoalSubject {\n id: string;\n name: string;\n}\n\n/**\n * Creator info from API response\n */\nexport interface GoalCreator {\n id: string;\n name: string;\n}\n\n/**\n * Goal stats from API response\n */\nexport interface GoalStats {\n totalStudents: number;\n completedCount: number;\n completionPercentage: number;\n}\n\n/**\n * Class breakdown info from API response\n */\nexport interface GoalBreakdown {\n classId: string;\n className: string;\n schoolId: string;\n schoolName: string;\n studentCount: number;\n completedCount: number;\n}\n\n/**\n * Goal data from API response\n */\nexport interface GoalData {\n id: string;\n title: string;\n startDate: string | null;\n finalDate: string | null;\n createdAt: string;\n progress: number;\n totalLessons: number;\n}\n\n/**\n * Goal history item from /recommended-class/history endpoint\n */\nexport interface GoalHistoryItem {\n goal: GoalData;\n subject: GoalSubject | null;\n creator: GoalCreator | null;\n stats: GoalStats;\n breakdown: GoalBreakdown[];\n}\n\n/**\n * Goal table item interface for goals list table\n */\nexport interface GoalTableItem extends Record<string, unknown> {\n id: string;\n startDate: string | null;\n deadline: string | null;\n title: string;\n school: string;\n year: string;\n subject: string;\n class: string;\n status: GenericDisplayStatus;\n completionPercentage: number;\n}\n\n/**\n * Goals history API complete response from /recommended-class/history\n */\nexport interface GoalsHistoryApiResponse {\n message: string;\n data: {\n goals: GoalHistoryItem[];\n total: number;\n };\n}\n\n/**\n * Goal history filters for API query parameters\n */\nexport interface GoalHistoryFilters {\n page?: number;\n limit?: number;\n status?: GenericApiStatus;\n search?: string;\n startDate?: string;\n finalDate?: string;\n subjectId?: string;\n schoolId?: string;\n schoolIds?: string[];\n classId?: string;\n classIds?: string[];\n studentIds?: string[];\n sortBy?: 'createdAt' | 'finalDate' | 'title' | 'completionPercentage';\n sortOrder?: 'asc' | 'desc';\n}\n\n/**\n * Pagination info for goals history\n */\nexport interface GoalHistoryPagination {\n total: number;\n page: number;\n limit: number;\n totalPages: number;\n}\n\n/**\n * Filter option for dropdowns\n * Extends with index signature to be compatible with CheckBoxGroup Item type\n */\nexport interface GoalFilterOption {\n id: string;\n name: string;\n [key: string]: unknown;\n}\n\n/**\n * User data for filter options (schools, classes, subjects)\n */\nexport interface GoalUserFilterData {\n schools?: Array<{ id: string; name: string }>;\n classes?: Array<{ id: string; name: string; schoolId?: string }>;\n subjects?: Array<{ id: string; name: string }>;\n schoolYears?: Array<{ id: string; name: string }>;\n}\n\n/**\n * Get status badge action based on goal display status\n * @param status - Goal display status\n * @returns Badge action type for styling\n */\nexport const getGoalStatusBadgeAction = (\n status: GenericDisplayStatus\n): BadgeActionType => getStatusBadgeAction(status);\n\n/**\n * Goal status options for filter (Vencida and Ativa)\n */\nexport const GOAL_FILTER_STATUS_OPTIONS: GoalFilterOption[] = [\n { id: GenericApiStatus.VENCIDA, name: 'Vencida' },\n { id: GenericApiStatus.A_VENCER, name: 'Ativa' },\n];\n\n/**\n * All goal status options\n */\nexport const GOAL_STATUS_OPTIONS: GoalFilterOption[] = [\n { id: GenericApiStatus.A_VENCER, name: 'A Vencer' },\n { id: GenericApiStatus.VENCIDA, name: 'Vencida' },\n { id: GenericApiStatus.CONCLUIDA, name: 'Concluída' },\n];\n\n// ============================================\n// Recommended Lesson Details Types\n// Based on /goals/{id} and /goals/{id}/details endpoints\n// ============================================\n\n/**\n * Student status for display in UI\n */\nexport enum StudentLessonStatus {\n A_INICIAR = 'A INICIAR',\n EM_ANDAMENTO = 'EM ANDAMENTO',\n NAO_FINALIZADO = 'NÃO FINALIZADO',\n CONCLUIDO = 'CONCLUÍDO',\n}\n\n/**\n * Badge action type for student status\n */\nexport const getStudentStatusBadgeAction = (\n status: StudentLessonStatus\n): 'success' | 'warning' | 'error' | 'info' => {\n const actionMap: Record<\n StudentLessonStatus,\n 'success' | 'warning' | 'error' | 'info'\n > = {\n [StudentLessonStatus.CONCLUIDO]: 'success',\n [StudentLessonStatus.EM_ANDAMENTO]: 'info',\n [StudentLessonStatus.A_INICIAR]: 'warning',\n [StudentLessonStatus.NAO_FINALIZADO]: 'error',\n };\n return actionMap[status] ?? 'warning';\n};\n\n/**\n * Checks if a deadline has passed\n * @param deadline - ISO date string of the deadline\n * @returns true if deadline has passed, false otherwise\n */\nexport const isDeadlinePassed = (deadline: string | null): boolean => {\n if (!deadline) return false;\n return new Date(deadline) < new Date();\n};\n\n/**\n * Derives student display status from progress, completedAt, and deadline\n * @param progress - Student progress percentage (0-100)\n * @param completedAt - ISO date string when student completed, or null\n * @param deadline - ISO date string of the goal deadline, or null\n * @returns The appropriate StudentLessonStatus\n */\nexport const deriveStudentStatus = (\n progress: number,\n completedAt: string | null,\n deadline?: string | null\n): StudentLessonStatus => {\n // If completed (either by completedAt or 100% progress), it's CONCLUIDO\n if (completedAt) return StudentLessonStatus.CONCLUIDO;\n if (progress === 100) return StudentLessonStatus.CONCLUIDO;\n\n // If deadline passed and not completed, it's NAO_FINALIZADO\n if (isDeadlinePassed(deadline ?? null) && progress < 100) {\n return StudentLessonStatus.NAO_FINALIZADO;\n }\n\n // Otherwise, derive from progress\n if (progress === 0) return StudentLessonStatus.A_INICIAR;\n if (progress > 0) return StudentLessonStatus.EM_ANDAMENTO;\n return StudentLessonStatus.A_INICIAR;\n};\n\n/**\n * Formats days to complete as a readable string\n */\nexport const formatDaysToComplete = (\n daysToComplete: number | null\n): string | null => {\n if (daysToComplete === null) return null;\n if (daysToComplete === 1) return '1 dia';\n return `${daysToComplete} dias`;\n};\n\n// ============================================\n// API Response Types - /goals/{id}/details\n// ============================================\n\n/**\n * Student data from /goals/{id}/details endpoint\n */\nexport interface GoalDetailStudent {\n userInstitutionId: string;\n userId: string;\n name: string;\n progress: number;\n completedAt: string | null;\n avgScore: number | null;\n daysToComplete: number | null;\n}\n\n/**\n * Aggregated stats from /goals/{id}/details endpoint\n */\nexport interface GoalDetailAggregated {\n completionPercentage: number;\n avgScore: number | null;\n}\n\n/**\n * Content performance item from /goals/{id}/details endpoint\n */\nexport interface GoalDetailContentPerformanceItem {\n contentId: string;\n contentName: string;\n rate: number;\n}\n\n/**\n * Content performance from /goals/{id}/details endpoint\n */\nexport interface GoalDetailContentPerformance {\n best: GoalDetailContentPerformanceItem | null;\n worst: GoalDetailContentPerformanceItem | null;\n}\n\n/**\n * Response data from /goals/{id}/details endpoint\n */\nexport interface GoalDetailsData {\n students: GoalDetailStudent[];\n aggregated: GoalDetailAggregated;\n contentPerformance: GoalDetailContentPerformance;\n}\n\n/**\n * Full API response from /goals/{id}/details endpoint\n */\nexport interface GoalDetailsApiResponse {\n message: string;\n data: GoalDetailsData;\n}\n\n// ============================================\n// API Response Types - /goals/{id}\n// ============================================\n\n/**\n * Subject info from lesson in /goals/{id} response\n */\nexport interface GoalLessonSubject {\n id: string;\n name: string;\n color: string;\n icon: string;\n}\n\n/**\n * Lesson info from /goals/{id} response\n */\nexport interface GoalLesson {\n id: string;\n content: { id: string; name: string };\n subtopic: { id: string; name: string };\n topic: { id: string; name: string };\n subject: GoalLessonSubject;\n}\n\n/**\n * Lesson progress from /goals/{id} response\n */\nexport interface GoalLessonProgress {\n id: string;\n userId: string;\n lessonId: string;\n progress: number;\n lesson: GoalLesson;\n}\n\n/**\n * Lesson goal item from /goals/{id} response\n */\nexport interface GoalLessonGoalItem {\n goalId: string;\n supLessonsProgressId: string;\n supLessonsProgress: GoalLessonProgress;\n}\n\n/**\n * Goal metadata from /goals/{id} endpoint\n */\nexport interface GoalMetadata {\n id: string;\n title: string;\n startDate: string;\n finalDate: string;\n progress: number;\n lessonsGoals: GoalLessonGoalItem[];\n}\n\n/**\n * Full API response from /goals/{id} endpoint\n */\nexport interface GoalApiResponse {\n message: string;\n data: GoalMetadata;\n}\n\n// ============================================\n// Combined Data for Component\n// ============================================\n\n/**\n * Combined data structure for RecommendedLessonDetails component\n * Combines data from /goals/{id}, /goals/{id}/details, and breakdown info\n */\nexport interface LessonDetailsData {\n /** Goal metadata from /goals/{id} */\n goal: GoalMetadata;\n /** Details from /goals/{id}/details */\n details: GoalDetailsData;\n /** Optional breakdown info from /recommended-class/history */\n breakdown?: GoalBreakdown;\n}\n"],"mappings":";AASO,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,kBAAA,cAAW;AACX,EAAAA,kBAAA,aAAU;AACV,EAAAA,kBAAA,eAAY;AAHF,SAAAA;AAAA,GAAA;AAUL,IAAK,uBAAL,kBAAKC,0BAAL;AACL,EAAAA,sBAAA,WAAQ;AACR,EAAAA,sBAAA,aAAU;AACV,EAAAA,sBAAA,eAAY;AAHF,SAAAA;AAAA,GAAA;AAUL,IAAK,kBAAL,kBAAKC,qBAAL;AACL,EAAAA,iBAAA,aAAU;AACV,EAAAA,iBAAA,aAAU;AACV,EAAAA,iBAAA,WAAQ;AAHE,SAAAA;AAAA,GAAA;AAWL,IAAM,uBAAuB,CAClC,WACoB;AACpB,QAAM,YAA2D;AAAA,IAC/D,CAAC,8BAA8B,GAAG;AAAA,IAClC,CAAC,mBAA0B,GAAG;AAAA,IAC9B,CAAC,uBAA4B,GAAG;AAAA,EAClC;AACA,SAAO,UAAU,MAAM,KAAK;AAC9B;;;AC4HO,IAAM,2BAA2B,CACtC,WACoB,qBAAqB,MAAM;AAK1C,IAAM,6BAAiD;AAAA,EAC5D,EAAE,6BAA8B,MAAM,UAAU;AAAA,EAChD,EAAE,+BAA+B,MAAM,QAAQ;AACjD;AAKO,IAAM,sBAA0C;AAAA,EACrD,EAAE,+BAA+B,MAAM,WAAW;AAAA,EAClD,EAAE,6BAA8B,MAAM,UAA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