[OPIK-4473] [FE] Update Traces table default columns#5257
[OPIK-4473] [FE] Update Traces table default columns#5257YarivHashaiComet wants to merge 3 commits intomainfrom
Conversation
Update default visible columns for new users on the Traces tab: Start time, Input, Output, Errors, Duration, Total tokens, Estimated cost, Tags, Comments. Also split shared defaults into separate trace/span constants so each view can have its own defaults. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
aadereiko
left a comment
There was a problem hiding this comment.
This solution is ok but we should also take into account that users already have some columns in local storages, and it will work when they open it newly
Set default columnsOrder to match ticket-specified visual order using v2 key migration. Existing users with custom orders are preserved, while users with default (empty) orders get the new ordering. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
apps/opik-frontend/src/lib/table.ts
Outdated
| const oldData = localStorage.getItem(oldStorageKey); | ||
|
|
||
| if (oldData !== null) { | ||
| const parsed = JSON.parse(oldData); | ||
| if (Array.isArray(parsed) && parsed.length > 0) { | ||
| return parsed; |
There was a problem hiding this comment.
migrateColumnsOrder JSON.parses ${type}-columns-order without guarding, so a corrupted or manually edited value throws during TracesSpansTab initialization and the table fails to render; can we wrap this parse in a try/catch and fall back to the default order instead?
| const oldData = localStorage.getItem(oldStorageKey); | |
| if (oldData !== null) { | |
| const parsed = JSON.parse(oldData); | |
| if (Array.isArray(parsed) && parsed.length > 0) { | |
| return parsed; | |
| const oldData = localStorage.getItem(oldStorageKey); | |
| if (oldData !== null) { | |
| try { | |
| const parsed = JSON.parse(oldData); | |
| if (Array.isArray(parsed) && parsed.length > 0) { | |
| return parsed; | |
| } | |
| } catch { | |
| // Ignore malformed JSON and fall back to defaultOrder | |
| } |
Finding type: Logical Bugs
- Apply fix with Baz
There was a problem hiding this comment.
Commit 7d7652f addressed this comment by wrapping the JSON.parse(oldData) call in a try/catch inside migrateColumnsOrder. On parse failure it now ignores the malformed value and falls back to defaultOrder, preventing TracesSpansTab initialization from crashing due to corrupted localStorage.
Existing users with saved v2 preferences now get the new default columns. Also adds try/catch to migrateColumnsOrder for robustness. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| const [selectedColumns, setSelectedColumns] = useLocalStorageState<string[]>( | ||
| `${type}-${SELECTED_COLUMNS_KEY_V2_SUFFIX}`, | ||
| `${type}-${SELECTED_COLUMNS_KEY_V3_SUFFIX}`, | ||
| { | ||
| defaultValue: migrateSelectedColumns( | ||
| `${type}-${SELECTED_COLUMNS_KEY_SUFFIX}`, | ||
| DEFAULT_TRACES_PAGE_COLUMNS, | ||
| [COLUMN_ID_ID, "start_time"], | ||
| ), | ||
| defaultValue: | ||
| type === TRACE_DATA_TYPE.traces | ||
| ? DEFAULT_TRACES_COLUMNS | ||
| : DEFAULT_SPANS_COLUMNS, | ||
| }, |
There was a problem hiding this comment.
Switched to ${type}-selected-columns-v3 with hardcoded defaults but no migration, so every user who had custom selections under the previous ${type}-selected-columns(-v2) keys loses their visibility setup; can we migrate the old localStorage data instead of unconditionally falling back to the new defaults?
Finding type: Logical Bugs
- Apply fix with Baz
Other fix methods
Prompt for AI Agents:
In apps/opik-frontend/src/components/pages/TracesPage/TracesSpansTab/TracesSpansTab.tsx
around lines 503 to 510, the selectedColumns initialization (useLocalStorageState) was
switched to `${type}-${SELECTED_COLUMNS_KEY_V3_SUFFIX}` with hardcoded defaults but no
migration. Modify this initialization to attempt to migrate any existing values from the
older keys (`${type}-${SELECTED_COLUMNS_KEY_SUFFIX}` and
`${type}-${SELECTED_COLUMNS_KEY_V2_SUFFIX}`) into the new v3 key before falling back to
the defaults; implement this by reading localStorage (or using an existing migration
helper like migrateColumnsOrder/migrateSelectedColumns if available), normalizing the
stored column arrays, writing the migrated value into the v3 key, and passing that
migrated array as defaultValue to useLocalStorageState. Ensure this runs once on
initialization so users keep their prior custom selections.
Details
Update default visible columns for new users on the Traces tab. Previously showed: ID, Name, Start time, Input, Output, Duration, Comments, User Feedback. Now shows: Start time, Input, Output, Errors, Duration, Total tokens, Estimated cost, Tags, Comments.
Also split the shared
DEFAULT_TRACES_PAGE_COLUMNSinto separateDEFAULT_TRACES_COLUMNSandDEFAULT_SPANS_COLUMNSconstants so each view can have independent defaults.Existing users with saved column preferences are not affected (localStorage takes precedence).
Change checklist
Issues
Testing
Documentation
N/A