diff --git a/app/components/ChangeLog.tsx b/app/components/ChangeLog.tsx index 57e14a21b..d739f73c1 100644 --- a/app/components/ChangeLog.tsx +++ b/app/components/ChangeLog.tsx @@ -1,14 +1,18 @@ import { useMemo, useState } from "react"; -import Card from "react-bootstrap/Card"; import Table from "react-bootstrap/Table"; +import Accordion from "react-bootstrap/Accordion"; import { formatDateTime } from "@/utils/formatters"; -import ChangeLogDetails from "./ChangeLogDetails"; +import ChangeLogDetails from "@/components/ChangeLogDetails"; import { ChangeLogEntry, ChangeLogDiff, ChangeLogEntryEnriched, } from "@/types/changeLog"; +// used to track the accordion expanded state of the change log +const localStorageKey = "crashHistoryCardExpandedItem"; +const recordHistoryItemName = "recordHistory"; + const KEYS_TO_IGNORE = ["updated_at", "updated_by", "position"]; /** @@ -77,59 +81,73 @@ const isNewRecordEvent = (change: ChangeLogEntryEnriched) => export default function ChangeLog({ logs }: { logs: ChangeLogEntry[] }) { const [selectedChange, setSelectedChange] = useState(null); + // tracks the accordion expanded state, if null then the accordion is closed + const [expandedItem, setExpandedItem] = useState( + localStorage.getItem(localStorageKey) + ); const changes = useChangeLogData(logs); return ( - - Record history - - - - - - - - - - - - - {changes.length === 0 && ( - // this should only happen in local dev where change log is not downloaded from replica + { + const localStorageValue = String(eventKey); // local storage value must be a string type + localStorage.setItem(localStorageKey, localStorageValue); + setExpandedItem(localStorageValue); + }} + > + + Record history + +
Record typeEventAffected fieldsEdited byDate
+ - - - )} - {changes.map((change) => ( - setSelectedChange(change)} - style={{ cursor: "pointer" }} - > - - - - - + + + + + - ))} - -
- No changes found -
{change.record_type}{change.operation_type} - {isNewRecordEvent(change) - ? "" - : change.affected_fields.join(", ")} - {change.created_by}{formatDateTime(change.created_at)}Record typeEventAffected fieldsEdited byDate
- {/* Modal with change details table */} - {selectedChange && ( - - )} -
-
+ + + {changes.length === 0 && ( + // this should only happen in local dev where change log is not downloaded from replica + + + No changes found + + + )} + {changes.map((change) => ( + setSelectedChange(change)} + style={{ cursor: "pointer" }} + > + {change.record_type} + {change.operation_type} + + {isNewRecordEvent(change) + ? "" + : change.affected_fields.join(", ")} + + {change.created_by} + {formatDateTime(change.created_at)} + + ))} + + + {/* Modal with change details table */} + {selectedChange && ( + + )} + + + ); } diff --git a/app/components/SidebarLayout.tsx b/app/components/SidebarLayout.tsx index 5279ea765..1afc6b6a1 100644 --- a/app/components/SidebarLayout.tsx +++ b/app/components/SidebarLayout.tsx @@ -33,9 +33,9 @@ export default function SidebarLayout({ children }: { children: ReactNode }) { const toggleSidebar = useCallback( () => - setIsCollapsed((prevSate) => { - localStorage.setItem(localStorageKey, String(!prevSate)); - return !prevSate; + setIsCollapsed((prevState) => { + localStorage.setItem(localStorageKey, String(!prevState)); + return !prevState; }), [] );