-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add property filters to sessions #1835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
if ( | ||
!values.selectedDate || | ||
values.selectedDate.format('YYYY-MM-DD') !== newDate.format('YYYY-MM-DD') || | ||
JSON.stringify(properties || {}) !== JSON.stringify(values.filters) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There already exists an objectsEqual
method in frontend/src/lib/utils.js, perhaps we should use that?
if ( | ||
!values.selectedDate || | ||
values.selectedDate.format('YYYY-MM-DD') !== newDate.format('YYYY-MM-DD') || | ||
JSON.stringify(properties || {}) !== JSON.stringify(values.filters) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: JSON.stringfy(x) is dependent on key order, this means:
JSON.stringify({ a: 1, b: 2 }) !== JSON.stringify({ b: 2, a: 1 })
Is that relevant in this case?
previousDay: true, | ||
nextDay: true, | ||
setFilters: (filters: Record<string, any>, selectedDate: Moment | null) => ({ filters, selectedDate }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usage of any
is generally discouraged within ts, but I guess to type this properly we'd need to port PropertyFilters.js and some other code as well as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would definitely be cool to have a completely typed filter! Indeed lots of "legacy" code to upgrade to make this work well. Until then any
is probably fine here. There's also unknown
, but that's a small difference.
actions.setNextOffset(null) | ||
actions.loadSessions(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the action order change significant here?
@timgl we worked together on this at the offsite to try to avoid the situation where the request in I now came upon an extremely simple solution that would solve all problems without any of the hacks we implemented: export const sessionsTableLogic = kea<sessionsTableLogicType<Moment, SessionType>>({
loaders: ({ actions, values, props }) => ({
sessions: {
__default: [] as SessionType[],
loadSessions: async (_: any, breakpoint) => {
const { selectedDateURLparam } = values
const params = toParams({
date_from: selectedDateURLparam,
date_to: selectedDateURLparam,
offset: 0,
distinct_id: props.personIds ? props.personIds[0] : '',
properties: values.filters,
})
// add this!
await breakpoint(10)
const response = await api.get(`api/insight/session/?${params}`)
breakpoint()
if (response.offset) {
actions.setNextOffset(response.offset)
}
return response.result
},
},
})
)} Adding a simple breakpoint before the Not saying it's needed to redo this PR, but something to definitely keep in mind for the future :). |
@macobo @mariusandra Thanks both. Marius, I've implemented your suggestion which made things a lot easier. I'm now also using PropertyFilter's built in urlToAction which means back and forward history navigation works too! |
Great! One comment (nit, feel free to ignore) coming back to what Karl said. It might be a good idea to replace all those filter types export type PropertyFilterType = Record<string, any> It can be converted into a real type some time later. This will however already help future refactors. |
Fixed! Also cleaned up filters/properties confusion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Changes
Please describe.
If this affects the front-end, include screenshots.
Checklist