Skip to content

Commit

Permalink
Only request basket counts and display in_basket filter toggle for no…
Browse files Browse the repository at this point in the history
…n-guest users (#346)
  • Loading branch information
dmfalke authored Jul 6, 2023
1 parent 2177d08 commit 8d240ed
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function TranscriptViewFilter({
requestTranscriptFilterUpdate,
inBasketFilterEnabled,
updateInBasketFilter,
isGuest,
}) {
const display = displayTotalCount === 1 ? displayName : displayNamePlural;
const nativeDisplay =
Expand Down Expand Up @@ -116,18 +117,20 @@ function TranscriptViewFilter({
</div>
</>
)}
<div>
<input
id={basketToggleId}
type="checkbox"
checked={inBasketFilterEnabled}
onChange={(e) => updateInBasketFilter(e.currentTarget.checked)}
/>
<label htmlFor={basketToggleId}>
<BasketIcon enabled />
&nbsp;&nbsp; Show only the {displayNamePlural} in my basket.
</label>
</div>
{!isGuest && (
<div>
<input
id={basketToggleId}
type="checkbox"
checked={inBasketFilterEnabled}
onChange={(e) => updateInBasketFilter(e.currentTarget.checked)}
/>
<label htmlFor={basketToggleId}>
<BasketIcon enabled />
&nbsp;&nbsp; Show only the {displayNamePlural} in my basket.
</label>
</div>
)}
</div>
);
}
Expand All @@ -143,6 +146,7 @@ const ConnectedTranscriptViewFilter = connect(
['resultTableSummaryView', props.viewId, 'globalViewFilters'],
{}
),
isGuest: get(state, ['globalData', 'user', 'isGuest'], true),
}),
(dispatch, props) => ({
requestTranscriptFilterUpdate: (...args) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,24 @@ export function useSendToBasketConfig(
| undefined {
const dispatch = useDispatch();

useEffect(() => {
if (!clearFirst) {
dispatch(requestBasketCounts());
const basketCount = useSelector((state: RootState) => {
if (resultType.type === 'step') {
return state.basket.counts?.[resultType.step.recordClassName] ?? 0;
}
}, [clearFirst, dispatch]);

const basketCounts = useSelector((state: RootState) => state.basket.counts);
return 0;
});

const isGuest = useWdkService(
async (wdkService) => (await wdkService.getCurrentUser()).isGuest,
[]
);

useEffect(() => {
if (!clearFirst && !(isGuest ?? true)) {
dispatch(requestBasketCounts());
}
}, [clearFirst, dispatch, isGuest]);

return useMemo(
() =>
isGeneListStep(resultType)
Expand All @@ -115,11 +120,7 @@ export function useSendToBasketConfig(
Basket (
{clearFirst
? 'replace'
: 'add to ' +
basketCounts?.[
resultType.step.recordClassName
].toLocaleString() +
' genes'}
: 'add to ' + basketCount.toLocaleString() + ' genes'}
)
</span>
</div>
Expand All @@ -132,7 +133,7 @@ export function useSendToBasketConfig(
onSelectionFulfillment: dispatch,
}
: undefined,
[resultType, clearFirst, dispatch, isGuest, basketCounts]
[resultType, clearFirst, dispatch, isGuest, basketCount]
);
}

Expand Down

0 comments on commit 8d240ed

Please sign in to comment.