analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
1 lines • 3.86 kB
Source Map (JSON)
{"version":3,"sources":["../src/components/TypeSelector/TypeSelector.tsx"],"sourcesContent":["import { useCallback, useMemo } from 'react';\nimport { useNavigate } from 'react-router-dom';\nimport Select, {\n SelectTrigger,\n SelectValue,\n SelectContent,\n SelectItem,\n} from '../Select/Select';\nimport {\n type ActivityCategory,\n type ActiveTab,\n type TypeConfig,\n getTabPath,\n} from './TypeSelector.types';\nimport { useModules } from '../../hooks/useModules';\nimport { ExamActivityCategory } from '../../types/examDrafts';\n\n/**\n * Props for the TypeSelector component\n */\nexport interface TypeSelectorProps {\n /** Current activity type selected */\n value: ActivityCategory;\n /** Current active tab (to preserve when switching types) */\n currentTab: ActiveTab;\n /** Configuration for activity types (routes and labels) */\n config: Record<ActivityCategory, TypeConfig>;\n /**\n * Optional filter to include only specific categories.\n * If not provided, automatically calculated based on hasExams flag from useModules.\n * Only use this prop for special cases where you need to override the default behavior.\n */\n allowedCategories?: ActivityCategory[];\n}\n\n/**\n * Type selector dropdown for switching between Atividades and Provas\n * Navigates to the corresponding route while preserving the current tab\n */\nexport const TypeSelector = ({\n value,\n currentTab,\n config,\n allowedCategories: allowedCategoriesProp,\n}: TypeSelectorProps) => {\n const navigate = useNavigate();\n const { hasExams } = useModules();\n\n // Calculate allowed categories based on exams module\n const allowedCategories = useMemo(() => {\n // If prop is explicitly provided, use it\n if (allowedCategoriesProp) {\n return allowedCategoriesProp;\n }\n\n // Otherwise, calculate based on hasExams flag\n const categories: ActivityCategory[] = [ExamActivityCategory.ATIVIDADE];\n if (hasExams) {\n categories.push(ExamActivityCategory.PROVA);\n }\n return categories;\n }, [hasExams, allowedCategoriesProp]);\n\n const handleTypeChange = useCallback(\n (newType: string) => {\n if (newType === value) return;\n\n const typeConfig = config[newType as ActivityCategory];\n const tabPath = getTabPath(currentTab);\n navigate(`${typeConfig.routes.base}${tabPath}`);\n },\n [value, currentTab, navigate, config]\n );\n\n const selectItems = allowedCategories.map((category) => (\n <SelectItem key={category} value={category}>\n {config[category].labels.selectorLabel}\n </SelectItem>\n ));\n\n return (\n <Select value={value} onValueChange={handleTypeChange} size=\"small\">\n <SelectTrigger className=\"w-[160px] h-8 bg-background\" variant=\"outlined\">\n <SelectValue placeholder=\"Tipo\" />\n </SelectTrigger>\n <SelectContent>{selectItems}</SelectContent>\n </Select>\n );\n};\n\nexport default TypeSelector;\n"],"mappings":";;;;;;;;;;;;;;;AAAA,SAAS,aAAa,eAAe;AACrC,SAAS,mBAAmB;AA0ExB,cAMA,YANA;AApCG,IAAM,eAAe,CAAC;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA,mBAAmB;AACrB,MAAyB;AACvB,QAAM,WAAW,YAAY;AAC7B,QAAM,EAAE,SAAS,IAAI,WAAW;AAGhC,QAAM,oBAAoB,QAAQ,MAAM;AAEtC,QAAI,uBAAuB;AACzB,aAAO;AAAA,IACT;AAGA,UAAM,aAAiC,4BAA+B;AACtE,QAAI,UAAU;AACZ,iBAAW,wBAA+B;AAAA,IAC5C;AACA,WAAO;AAAA,EACT,GAAG,CAAC,UAAU,qBAAqB,CAAC;AAEpC,QAAM,mBAAmB;AAAA,IACvB,CAAC,YAAoB;AACnB,UAAI,YAAY,MAAO;AAEvB,YAAM,aAAa,OAAO,OAA2B;AACrD,YAAM,UAAU,WAAW,UAAU;AACrC,eAAS,GAAG,WAAW,OAAO,IAAI,GAAG,OAAO,EAAE;AAAA,IAChD;AAAA,IACA,CAAC,OAAO,YAAY,UAAU,MAAM;AAAA,EACtC;AAEA,QAAM,cAAc,kBAAkB,IAAI,CAAC,aACzC,oBAAC,cAA0B,OAAO,UAC/B,iBAAO,QAAQ,EAAE,OAAO,iBADV,QAEjB,CACD;AAED,SACE,qBAAC,kBAAO,OAAc,eAAe,kBAAkB,MAAK,SAC1D;AAAA,wBAAC,iBAAc,WAAU,+BAA8B,SAAQ,YAC7D,8BAAC,eAAY,aAAY,QAAO,GAClC;AAAA,IACA,oBAAC,iBAAe,uBAAY;AAAA,KAC9B;AAEJ;AAEA,IAAO,uBAAQ;","names":[]}