feat(dashboard): refactor widget processing to support dynamic tool selection
- Updated the widget processing API to accept tool names as an optional parameter. - Consolidated tool imports and created an `allTools` array for easier management. - Added a new ToolSelector component for selecting tools in the widget configuration modal. - Enhanced date difference and timezone conversion tools with improved descriptions and error handling. - Refactored types for widgets and dashboard to streamline the codebase and improve type safety. - Removed deprecated types and organized type definitions into separate files for better maintainability.
This commit is contained in:
parent
1f78b94243
commit
7253cbc89c
18 changed files with 513 additions and 247 deletions
|
|
@ -3,27 +3,27 @@ import { DateTime } from 'luxon';
|
|||
/**
|
||||
* Parses a date string using multiple Luxon formats with fallback to JavaScript Date parsing.
|
||||
* Preserves timezone information when available using setZone: true.
|
||||
*
|
||||
*
|
||||
* @param dateString - The date string to parse
|
||||
* @returns A parsed DateTime object
|
||||
*/
|
||||
export function parseDate(dateString: string): DateTime {
|
||||
// Try to parse as ISO format first (most common)
|
||||
let dateTime = DateTime.fromISO(dateString, { setZone: true });
|
||||
|
||||
|
||||
// If ISO parsing fails, try other common formats
|
||||
if (!dateTime.isValid) {
|
||||
dateTime = DateTime.fromRFC2822(dateString, { setZone: true });
|
||||
}
|
||||
|
||||
|
||||
if (!dateTime.isValid) {
|
||||
dateTime = DateTime.fromHTTP(dateString, { setZone: true });
|
||||
}
|
||||
|
||||
|
||||
if (!dateTime.isValid) {
|
||||
dateTime = DateTime.fromSQL(dateString, { setZone: true });
|
||||
}
|
||||
|
||||
|
||||
// If all parsing attempts fail, try JavaScript Date parsing as fallback
|
||||
if (!dateTime.isValid) {
|
||||
const jsDate = new Date(dateString);
|
||||
|
|
@ -31,22 +31,22 @@ export function parseDate(dateString: string): DateTime {
|
|||
dateTime = DateTime.fromJSDate(jsDate);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a standardized error message for date parsing failures.
|
||||
*
|
||||
*
|
||||
* @param dateString - The original date string that failed to parse
|
||||
* @param dateTime - The invalid DateTime object
|
||||
* @param fieldName - Optional field name for more specific error messages (e.g., "start date", "end date")
|
||||
* @returns A formatted error message
|
||||
*/
|
||||
export function getDateParseErrorMessage(
|
||||
dateString: string,
|
||||
dateTime: DateTime,
|
||||
fieldName: string = 'date'
|
||||
dateString: string,
|
||||
dateTime: DateTime,
|
||||
fieldName: string = 'date',
|
||||
): string {
|
||||
return `Error: Unable to parse ${fieldName} "${dateString}". Please provide a valid date format (ISO 8601, RFC 2822, SQL, or common date formats). Reason: ${dateTime.invalidReason}`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue