Newer
Older
import {
Heading,
VStack,
TableContainer,
Table,
Thead,
Tr,
Th,
Tbody,
Td,
Text,
TableCaption,
Tooltip,
HStack,
Icon,
IconButton,
} from '@chakra-ui/react'
import { FaEdit, FaEye, FaPlus, FaTrash } from 'react-icons/fa'
import { Link, routes } from '@redwoodjs/router'
import { patterns } from '.'
import { Pattern } from 'src/models'
import { GetPatternsQuery } from './query-builder'
const tableHeaders = ['Titulo', 'Descripcion', '#Implementaciones', '']
export const Patterns: React.FC = () => {
const patternsQuery = GetPatternsQuery.useQuery({})
<VStack alignItems="flex-start" spacing="0">
<Heading as="h2" px="6">
<TableContainer>
<Table variant="simple" size="lg">
<TableCaption>Patrones disponibles</TableCaption>
<Thead>
<Tr>
{tableHeaders.map((header, index) => (
<Th key={`th-${index}`}>{header}</Th>
))}
</Tr>
</Thead>
<Tbody>
{match(patternsQuery)
.with({ status: 'success', data: [] }, () => (
<Text>No se encontraron patrones</Text>
))
.with({ status: 'success' }, ({ data }) =>
data.map((pattern, index) => (
<Tr key={`pattern-${pattern.title}-${index}`}>
<Td>
<Link to={routes.pattern({ id: pattern.id })}>
{pattern.title}
</Link>
</Td>
<Td>
<Tooltip label={pattern.description} hasArrow>
<Text isTruncated maxW="sm">
{pattern.description}
</Text>
</Tooltip>
</Td>
<Td>
<Text textAlign="center">
{pattern.numberOfImplementations}
</Text>
</Td>
<Td>
<ActionsRow pattern={pattern} />
</Td>
</Tr>
))
)
.with({ status: 'loading' }, () => <Spinner />)
.otherwise(() => null)}
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
</Tbody>
</Table>
</TableContainer>
</VStack>
)
}
type ActionsRowProps = {
pattern: Pattern
}
const ActionsRow: React.FC<ActionsRowProps> = ({ pattern }) => {
return (
<HStack>
{/* Linter yells but is fine https://github.com/redwoodjs/redwood/issues/1742 */}
<Link to={routes.pattern({ id: pattern.id })}>
<IconButton
aria-label="view pattern"
variant="unstyled"
icon={<Icon as={FaEye} />}
/>
</Link>
<IconButton
aria-label="add pattern"
variant="unstyled"
icon={<Icon as={FaPlus} />}
/>
<IconButton
aria-label="edit pattern"
variant="unstyled"
icon={<Icon as={FaEdit} />}
/>
<IconButton
aria-label="delete pattern"
variant="unstyled"
icon={<Icon as={FaTrash} />}
/>
</HStack>