-
Notifications
You must be signed in to change notification settings - Fork 2
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
fix requestId race condition and actually dispatch bool columnMeta #211
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,25 +148,22 @@ export const useContextFilterQueryManagement = ( | |
<T extends CommonResult>( | ||
result: T, | ||
collectionId: string | undefined | ||
): { filterData?: T['data']; context?: FilterContext } => { | ||
): { filterData?: T['data'] } => { | ||
if (result.isError) { | ||
const err = parseError(result.error); | ||
if (err.name !== 'AbortError') | ||
toast('Filter Loading failed: ' + parseError(result.error).message); | ||
} | ||
const context = result.requestId | ||
? requestContext.current[result.requestId] | ||
: undefined; | ||
if (!collectionId || !result?.data || !context || result.isError) | ||
return {}; | ||
return { filterData: result.data, context }; | ||
Comment on lines
-157
to
-162
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed unnescary hacky context state (requestContext) that was causing issues, prefer just canceling the requests when the context changes (line 317) |
||
|
||
if (!collectionId || !result?.data || result.isError) return {}; | ||
return { filterData: result.data }; | ||
}, | ||
[] | ||
); | ||
|
||
const handleTableFilters = useCallback( | ||
<T extends typeof genomeResult | typeof sampleResult>(result: T) => { | ||
const { filterData, context } = handleResult(result, collectionId); | ||
const { filterData } = handleResult(result, collectionId); | ||
if (!filterData || !collectionId || !context) return; | ||
dispatch(clearFiltersAndColumnMeta([collectionId, context])); | ||
filterData.columns.forEach((column) => { | ||
|
@@ -215,35 +212,37 @@ export const useContextFilterQueryManagement = ( | |
} | ||
}); | ||
}, | ||
[collectionId, dispatch, handleResult] | ||
[collectionId, dispatch, handleResult, context] | ||
); | ||
|
||
const handleHeatmapFilters = useCallback( | ||
<T extends typeof biologResult | typeof microtraitResult>(result: T) => { | ||
const { filterData, context } = handleResult(result, collectionId); | ||
const { filterData } = handleResult(result, collectionId); | ||
if (!filterData || !collectionId || !context) return; | ||
dispatch(clearFiltersAndColumnMeta([collectionId, context])); | ||
filterData.categories.forEach((category) => { | ||
category.columns.forEach((column) => { | ||
const current = | ||
filtersRef.current && filtersRef.current[column.col_id]; | ||
if (column.type === 'bool') { | ||
setColumnMeta([ | ||
collectionId, | ||
context, | ||
column.col_id, | ||
{ | ||
type: 'bool', | ||
key: column.col_id, | ||
max_value: undefined, | ||
min_value: undefined, | ||
category: category.category, | ||
description: column.description, | ||
display_name: column.name, | ||
filter_strategy: undefined, | ||
enum_values: undefined, | ||
}, | ||
]); | ||
dispatch( | ||
setColumnMeta([ | ||
collectionId, | ||
context, | ||
column.col_id, | ||
{ | ||
type: 'bool', | ||
key: column.col_id, | ||
max_value: undefined, | ||
min_value: undefined, | ||
category: category.category, | ||
description: column.description, | ||
display_name: column.name, | ||
filter_strategy: undefined, | ||
enum_values: undefined, | ||
}, | ||
]) | ||
); | ||
Comment on lines
+228
to
+245
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The filters were not showing up because I forgot the dispatch... |
||
dispatch( | ||
setFilter([ | ||
collectionId, | ||
|
@@ -253,7 +252,9 @@ export const useContextFilterQueryManagement = ( | |
type: 'bool', | ||
value: | ||
current?.type === column.type | ||
? Boolean(current.value) | ||
? typeof current.value !== 'undefined' | ||
? Boolean(current.value) | ||
: undefined | ||
Comment on lines
+255
to
+257
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixes accidentally setting all filters to |
||
: undefined, | ||
}, | ||
]) | ||
|
@@ -291,7 +292,7 @@ export const useContextFilterQueryManagement = ( | |
}); | ||
}); | ||
}, | ||
[collectionId, dispatch, handleResult] | ||
[collectionId, dispatch, handleResult, context] | ||
); | ||
|
||
// When the context (or collection) changes, set the filter context and trigger appropriate query | ||
|
@@ -311,8 +312,6 @@ export const useContextFilterQueryManagement = ( | |
} else { | ||
throw new Error(`No filter query matches filter context "${context}"`); | ||
} | ||
requestContext.current[request.requestId] = context; | ||
|
||
return () => { | ||
// Abort request if context changes while running (prevents race conditions) | ||
if (request) { | ||
|
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.
fixes infinite render loop
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.
Oh very nice thank you for catching that