- Introduced configuration history management in Filters and Recursive Routes pages, allowing users to view and restore previous configurations. - Updated state management to handle live data loading and error states more effectively, improving user experience during data fetching. - Added new components for displaying configuration history and integrated them into existing pages. - Enhanced API interactions to support fetching and applying configuration revisions, ensuring data consistency across the application. - Updated tests to cover new functionalities and ensure reliability. Co-authored-by: Cursor <cursoragent@cursor.com>
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
export const PRODUCT_NAME = "MikrotikManager"
|
|
export const LEGACY_PRODUCT_NAME = "RouterLists"
|
|
|
|
export function hasManagedCommentPrefix(comment: string): boolean {
|
|
const value = comment.trim()
|
|
return value.startsWith(`${PRODUCT_NAME}:`) || value.startsWith(`${LEGACY_PRODUCT_NAME}:`)
|
|
}
|
|
|
|
export function hasManagedRecursiveComment(comment: string): boolean {
|
|
const value = comment.trim()
|
|
return (
|
|
value.startsWith(`${PRODUCT_NAME}:recursive`) ||
|
|
value.startsWith(`${LEGACY_PRODUCT_NAME}:recursive`)
|
|
)
|
|
}
|
|
|
|
export function managedComment(label: string): string {
|
|
return `${PRODUCT_NAME}: ${label}`
|
|
}
|
|
|
|
export function managedRecursiveComment(comment?: string | null): string {
|
|
const stripped = stripManagedRecursiveComment(comment ?? "")
|
|
return stripped ? `${PRODUCT_NAME}:recursive ${stripped}` : `${PRODUCT_NAME}:recursive`
|
|
}
|
|
|
|
const LEGACY_RECURSIVE_PREFIX = /^recursive:\s*/i
|
|
|
|
export function stripManagedRecursiveComment(comment: string): string {
|
|
const value = comment.trim()
|
|
if (!value) return ""
|
|
const managedPrefixes = [
|
|
`${PRODUCT_NAME}:recursive`,
|
|
`${LEGACY_PRODUCT_NAME}:recursive`,
|
|
]
|
|
for (const prefix of managedPrefixes) {
|
|
if (value.startsWith(prefix)) return value.slice(prefix.length).trim()
|
|
}
|
|
if (LEGACY_RECURSIVE_PREFIX.test(value)) {
|
|
return value.replace(LEGACY_RECURSIVE_PREFIX, "").trim()
|
|
}
|
|
return value
|
|
}
|
|
|
|
/** Owned recursive route: MM/legacy prefix or old `recursive:` mask. */
|
|
export function isOwnedRecursiveComment(comment: string | undefined): boolean {
|
|
if (!comment) return false
|
|
const value = comment.trim()
|
|
return hasManagedRecursiveComment(value) || LEGACY_RECURSIVE_PREFIX.test(value)
|
|
}
|