Use object IDs instead of array indices as keys

This commit is contained in:
Tanner Collin 2020-01-18 01:36:53 +00:00
parent cb8ac3cf63
commit 08bd52704b
9 changed files with 23 additions and 22 deletions

View File

@ -185,8 +185,8 @@ export function AdminMemberCards(props) {
<Header size='small'>Current Cards</Header> <Header size='small'>Current Cards</Header>
{cards.length ? {cards.length ?
cards.map((x, i) => cards.map(x =>
<AdminCardDetail key={i} card={x} {...props} /> <AdminCardDetail key={x.id} card={x} {...props} />
) )
: :
<p>None</p> <p>None</p>

View File

@ -28,8 +28,8 @@ export function Cards(props) {
</Table.Header> </Table.Header>
<Table.Body> <Table.Body>
{user.cards.map((x, i) => {user.cards.map(x =>
<Table.Row key={i}> <Table.Row key={x.id}>
<Table.Cell>{x.card_number}</Table.Cell> <Table.Cell>{x.card_number}</Table.Cell>
<Table.Cell>{x.notes}</Table.Cell> <Table.Cell>{x.notes}</Table.Cell>
<Table.Cell>{x.last_seen_at}</Table.Cell> <Table.Cell>{x.last_seen_at}</Table.Cell>

View File

@ -25,8 +25,8 @@ function ClassTable(props) {
<Table.Body> <Table.Body>
{classes.length ? {classes.length ?
classes.map((x, i) => classes.map(x =>
<Table.Row key={i}> <Table.Row key={x.id}>
<Table.Cell>{x.course_name}</Table.Cell> <Table.Cell>{x.course_name}</Table.Cell>
<Table.Cell> <Table.Cell>
<Link to={'/classes/'+x.id}> <Link to={'/classes/'+x.id}>
@ -182,7 +182,7 @@ export function ClassDetail(props) {
{(isAdmin(user) || clazz.instructor === user.id) && {(isAdmin(user) || clazz.instructor === user.id) &&
<Segment padded> <Segment padded>
<InstructorClassAttendance clazz={clazz} {...props} /> <InstructorClassAttendance clazz={clazz} refreshClass={refreshClass} {...props} />
</Segment> </Segment>
} }

View File

@ -40,8 +40,8 @@ export function Courses(props) {
<Table.Body> <Table.Body>
{courses.length ? {courses.length ?
courses.map((x, i) => courses.map(x =>
<Table.Row key={i}> <Table.Row key={x.id}>
<Table.Cell> <Table.Cell>
<Link to={'/courses/'+x.id}>{x.name}</Link> <Link to={'/courses/'+x.id}>{x.name}</Link>
</Table.Cell> </Table.Cell>
@ -115,8 +115,8 @@ export function CourseDetail(props) {
<Table.Body> <Table.Body>
{course.sessions.length ? {course.sessions.length ?
course.sessions.sort((a, b) => a.datetime < b.datetime ? 1 : -1).slice(0,10).map((x, i) => course.sessions.sort((a, b) => a.datetime < b.datetime ? 1 : -1).slice(0,10).map(x =>
<Table.Row key={i}> <Table.Row key={x.id}>
<Table.Cell> <Table.Cell>
<Link to={'/classes/'+x.id}> <Link to={'/classes/'+x.id}>
{moment.utc(x.datetime).local().format('ll')} {moment.utc(x.datetime).local().format('ll')}

View File

@ -81,8 +81,8 @@ function MemberInfo(props) {
<BasicTable> <BasicTable>
<Table.Body> <Table.Body>
{lastTrans.length ? {lastTrans.length ?
lastTrans.map((x, i) => lastTrans.map(x =>
<Table.Row key={i}> <Table.Row key={x.id}>
<Table.Cell> <Table.Cell>
<Link to={'/transactions/'+x.id}>{x.date}</Link> <Link to={'/transactions/'+x.id}>{x.date}</Link>
</Table.Cell> </Table.Cell>

View File

@ -8,7 +8,7 @@ import { Button, Container, Checkbox, Divider, Dropdown, Form, Grid, Header, Ico
import { BasicTable, staticUrl, requester } from './utils.js'; import { BasicTable, staticUrl, requester } from './utils.js';
function AttendanceRow(props) { function AttendanceRow(props) {
const { student, token } = props; const { student, token, refreshClass } = props;
const [training, setTraining] = useState(student); const [training, setTraining] = useState(student);
const [error, setError] = useState(false); const [error, setError] = useState(false);
@ -17,6 +17,7 @@ function AttendanceRow(props) {
requester('/training/'+training.id+'/', 'PATCH', token, data) requester('/training/'+training.id+'/', 'PATCH', token, data)
.then(res => { .then(res => {
setTraining(res); setTraining(res);
refreshClass();
setError(false); setError(false);
}) })
.catch(err => { .catch(err => {
@ -74,8 +75,8 @@ export function InstructorClassAttendance(props) {
<Header size='small'>Mark Attendance</Header> <Header size='small'>Mark Attendance</Header>
{clazz.students.length ? {clazz.students.length ?
clazz.students.map((x, i) => clazz.students.map(x =>
<p><AttendanceRow key={i} student={x} {...props} /></p> <p><AttendanceRow key={x.id} student={x} {...props} /></p>
) )
: :
<p>No students yet.</p> <p>No students yet.</p>

View File

@ -50,8 +50,8 @@ export function Members(props) {
{response ? {response ?
<Item.Group unstackable divided> <Item.Group unstackable divided>
{response.results.length ? {response.results.length ?
response.results.map((x, i) => response.results.map(x =>
<Item key={i} as={Link} to={'/members/'+x.member.id}> <Item key={x.member.id} as={Link} to={'/members/'+x.member.id}>
<Item.Image size='tiny' src={x.member.photo_small ? staticUrl + '/' + x.member.photo_small : '/nophoto.png'} /> <Item.Image size='tiny' src={x.member.photo_small ? staticUrl + '/' + x.member.photo_small : '/nophoto.png'} />
<Item.Content verticalAlign='top'> <Item.Content verticalAlign='top'>
<Item.Header>{x.member.preferred_name} {x.member.last_name}</Item.Header> <Item.Header>{x.member.preferred_name} {x.member.last_name}</Item.Header>

View File

@ -25,8 +25,8 @@ export function Training(props) {
</Table.Header> </Table.Header>
<Table.Body> <Table.Body>
{user.training.map((x, i) => {user.training.map(x =>
<Table.Row key={i}> <Table.Row key={x.id}>
<Table.Cell>{x.session.course_name}</Table.Cell> <Table.Cell>{x.session.course_name}</Table.Cell>
<Table.Cell> <Table.Cell>
<Link to={'/classes/'+x.session.id}>{moment(x.session.datetime).format('MMMM Do YYYY')}</Link> <Link to={'/classes/'+x.session.id}>{moment(x.session.datetime).format('MMMM Do YYYY')}</Link>

View File

@ -24,8 +24,8 @@ export function Transactions(props) {
<Table.Body> <Table.Body>
{user.transactions.length ? {user.transactions.length ?
user.transactions.slice().reverse().map((x, i) => user.transactions.slice().reverse().map(x =>
<Table.Row key={i}> <Table.Row key={x.id}>
<Table.Cell> <Table.Cell>
<Link to={'/transactions/'+x.id}>{x.date}</Link> <Link to={'/transactions/'+x.id}>{x.date}</Link>
</Table.Cell> </Table.Cell>