Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds a new event id accessor that is used as a react key, falls back to default #2693

Merged
merged 5 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,8 @@ class Calendar extends React.Component {
resourceIdAccessor: 'id',
resourceTitleAccessor: 'title',

eventIdAccessor: 'id',
cutterbl marked this conversation as resolved.
Show resolved Hide resolved

longPressThreshold: 250,
getNow: () => new Date(),
dayLayoutAlgorithm: 'overlap',
Expand All @@ -923,6 +925,7 @@ class Calendar extends React.Component {
resourceAccessor,
resourceIdAccessor,
resourceTitleAccessor,
eventIdAccessor,
eventPropGetter,
backgroundEventPropGetter,
slotPropGetter,
Expand Down Expand Up @@ -971,6 +974,7 @@ class Calendar extends React.Component {
resource: wrapAccessor(resourceAccessor),
resourceId: wrapAccessor(resourceIdAccessor),
resourceTitle: wrapAccessor(resourceTitleAccessor),
eventId: wrapAccessor(eventIdAccessor),
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/DayColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class DayColumn extends React.Component {
return styledEvents.map(({ event, style }, idx) => {
let end = accessors.end(event)
let start = accessors.start(event)
let key = accessors.eventId(event) || 'evt_' + idx
cutterbl marked this conversation as resolved.
Show resolved Hide resolved
let format = 'eventTimeRangeFormat'
let label

Expand All @@ -230,7 +231,7 @@ class DayColumn extends React.Component {
style={style}
event={event}
label={label}
key={'evt_' + idx}
key={key}
getters={getters}
rtl={rtl}
components={components}
Expand Down
10 changes: 10 additions & 0 deletions stories/props/eventIdAccessor.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Canvas, Story } from '@storybook/addon-docs'

# eventIdAccessor

- type: `string | function (event: Object) => string`
- default: 'id'

The id of the event. Must resolve to a string. Used as the key for the event in the DOM. If not provided, the event will be given a key of 'evt\_<index>'.
cutterbl marked this conversation as resolved.
Show resolved Hide resolved

<Story id="props--event-id-accessor" />
33 changes: 33 additions & 0 deletions stories/props/eventIdAccessor.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react'
import { Calendar } from '../../src'
import { accessorStoryArgs } from './storyDefaults'
import mdx from './eventIdAccessor.mdx'

export default {
title: 'props',
component: Calendar,
argTypes: {
localizer: { control: { type: null } },
events: { control: { type: null } },
defaultDate: {
control: {
type: null,
},
},
},
parameters: {
docs: {
page: mdx,
},
},
}

const Template = (args) => (
<div className="height600">
<Calendar {...args} />
</div>
)

export const EventIdAccessor = Template.bind({})
EventIdAccessor.storyName = 'eventIdAccessor'
EventIdAccessor.args = accessorStoryArgs
1 change: 1 addition & 0 deletions stories/props/storyDefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const accessorStoryArgs = {
titleAccessor: 'label',
tooltipAccessor: 'label',
startAccessor: 'startDate',
idAccessor: 'id',
}
/** END Specific to event key accessors */

Expand Down