Skip to content

Commit

Permalink
Fix recurrenceInfo issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad Amer committed Jan 23, 2025
1 parent 1b20a5a commit 03f4bba
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 28 deletions.
2 changes: 1 addition & 1 deletion samples/react-calendar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Each category has its own color that is generated in the load.

The Web Part checks the user's permissions for the View, Add, Edit, and Delete events.

![calendar](assets/react-calendar-categories.mp4)
![calendar](assets/react-calendar-categories.png)

![calendar](assets/animatevideo.gif)

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions samples/react-calendar/assets/sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
],
"thumbnails": [
{
"type": "video",
"type": "image",
"order": 100,
"url": "https://raw.githubusercontent.com/pnp/sp-dev-fx-webparts/refs/heads/main/samples/react-calendar/assets/react-calendar-categories.mp4",
"url": "raw.githubusercontent.com/pnp/sp-dev-fx-webparts/refs/heads/main/samples/react-calendar/assets/react-calendar-categories.png",
"alt": "Calendar"
},
{
Expand Down
45 changes: 25 additions & 20 deletions samples/react-calendar/src/controls/Event/event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -816,49 +816,56 @@ export class Event extends React.Component<IEventProps, IEventState> {
* @memberof Event
*/
private async returnExceptionRecurrenceInfo(recurrenceData: string) {
const parser = new XMLParser();
// Configure the XML parser
const parser = new XMLParser({
ignoreAttributes: false, // Include attributes in the parsed JSON
attributeNamePrefix: "", // Do not prefix attributes with @
isArray: (name) => ["rule", "repeat", "daily", "weekly", "monthly", "monthlyByDay", "yearly", "yearlyByDay"].includes(name), // Explicitly set nodes to be arrays
});

try {
// Parse the XML string into a JSON object
const promise = parser.parse(recurrenceData);

const recurrenceInfo: any = await promise;
if (recurrenceInfo != null) {
let keys = Object.keys(recurrenceInfo.recurrence.rule[0].repeat[0]);
// Parse the XML string
const recurrenceInfo: any = parser.parse(recurrenceData);

// Check if parsed data contains expected structure
if (recurrenceInfo?.recurrence?.rule?.[0]?.repeat?.[0]) {
// Access repeat keys
const repeat = recurrenceInfo.recurrence.rule[0].repeat[0];
const keys = Object.keys(repeat);

// Supported recurrence types
const recurrenceTypes = ["daily", "weekly", "monthly", "monthlyByDay", "yearly", "yearlyByDay"];
for (var key of keys) {
const rule = recurrenceInfo.recurrence.rule[0].repeat[0][key][0]['$'];

for (const key of keys) {
const rule = repeat[key]?.[0]?.["$"];
if (!rule) continue; // Skip if the rule is not present

switch (recurrenceTypes.indexOf(key)) {
case 0:
return this.parseDailyRule(rule);
break;
case 1:
return this.parseWeeklyRule(rule);
break;
case 2:
return this.parseMonthlyRule(rule);
break;
case 3:
return this.parseMonthlyByDayRule(rule);
break;
case 4:
return this.parseYearlyRule(rule);
break;
case 5:
return this.parseYearlyByDayRule(rule);
break;
default:
continue;
}
}
} else {
return "Invalid recurrence format";
}

} catch (error) {
// Handle parsing errors by rejecting the promise
// Handle parsing errors
throw new Error(`Error parsing recurrence data: ${error.message}`);
}
}


/**
*
*
Expand All @@ -868,8 +875,6 @@ export class Event extends React.Component<IEventProps, IEventState> {
*/
public async returnRecurrenceInfo(startDate: Date, recurrenceData: string) {
this.returnedRecurrenceInfo = { recurrenceData: recurrenceData, eventDate: startDate, endDate: moment().add(20, 'years').toDate() };
//this.setState({ editRecurrenceSeries:false})
//console.log(this.returnedRecurrenceInfo);
}


Expand Down
8 changes: 3 additions & 5 deletions samples/react-calendar/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@
"webpack-env"
],
"lib": [
"es5",
"dom",
"es2015.collection",
"es2015.promise"
]
"es2016",
"dom"
],
},
"include": [
"src/**/*.ts",
Expand Down

0 comments on commit 03f4bba

Please sign in to comment.