From 5578f235dfde2feef90f4ec3fd80d8376887be26 Mon Sep 17 00:00:00 2001 From: Deep Sidhu Date: Tue, 1 Nov 2022 14:39:16 -0500 Subject: [PATCH 1/5] Fixed bug if a sample was added to the cart from the sample details viewer, then closed, reopened, it would still have an add to cart button until the page was refreshed. Updated previous refetch to refetchCart --- .../js/components/samples/SampleDetailViewer.tsx | 6 +++--- .../samples/components/SampleDetailsModal.tsx | 13 +++++++++---- .../samples/components/SampleDetailsWrapper.tsx | 6 +++--- .../components/samples/components/ViewerHeader.tsx | 12 ++++++++---- .../js/pages/cart/components/SampleRenderer.jsx | 2 +- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/main/webapp/resources/js/components/samples/SampleDetailViewer.tsx b/src/main/webapp/resources/js/components/samples/SampleDetailViewer.tsx index 4d53dd87b6d..7f9b618931f 100644 --- a/src/main/webapp/resources/js/components/samples/SampleDetailViewer.tsx +++ b/src/main/webapp/resources/js/components/samples/SampleDetailViewer.tsx @@ -9,7 +9,7 @@ export interface SampleDetailViewerProps { projectId: number; displayActions?: boolean; children: React.ReactElement; - refetch?: () => void; + refetchCart?: () => void; } /** @@ -26,7 +26,7 @@ export function SampleDetailViewer({ projectId, displayActions = true, children, - refetch, + refetchCart, }: SampleDetailViewerProps): JSX.Element { const [visible, setVisible] = useState(false); @@ -41,7 +41,7 @@ export function SampleDetailViewer({ sampleId={sampleId} projectId={projectId} displayActions={displayActions} - refetchSample={refetch} + refetchCart={refetchCart} setVisible={setVisible} visible={visible} /> diff --git a/src/main/webapp/resources/js/components/samples/components/SampleDetailsModal.tsx b/src/main/webapp/resources/js/components/samples/components/SampleDetailsModal.tsx index 6114280efbe..2c3bde06f5b 100644 --- a/src/main/webapp/resources/js/components/samples/components/SampleDetailsModal.tsx +++ b/src/main/webapp/resources/js/components/samples/components/SampleDetailsModal.tsx @@ -10,7 +10,7 @@ export interface DisplaySampleDetailsProps { sampleId: number; projectId: number; displayActions?: boolean; - refetch?: () => void; + refetchCart?: () => void; visible: boolean; setVisible: Dispatch>; } @@ -21,7 +21,7 @@ export default function SampleDetailsModal({ sampleId, projectId, displayActions, - refetch, + refetchCart, visible, setVisible, }: DisplaySampleDetailsProps) { @@ -29,7 +29,11 @@ export default function SampleDetailsModal({ const [component, setComponent] = React.useState("details"); // Get the sample ready to display - const { data: details = {}, isLoading } = useGetSampleDetailsQuery({ + const { + data: details = {}, + isLoading, + refetch: refetchSample, + } = useGetSampleDetailsQuery({ sampleId, projectId, }); @@ -85,7 +89,8 @@ export default function SampleDetailsModal({ tab={component} onMenuChange={setComponent} displayActions={!!displayActions} - refetch={refetch} + refetchCart={refetchCart} + refetchSample={refetchSample} />
void; + refetchCart?: () => void; visible: boolean; setVisible: Dispatch>; } @@ -16,7 +16,7 @@ export default function SampleDetailsWrapper({ sampleId, projectId, displayActions, - refetchSample, + refetchCart, visible, setVisible, }: SampleDetailsWrapperProps) { @@ -26,7 +26,7 @@ export default function SampleDetailsWrapper({ sampleId={sampleId} projectId={projectId} displayActions={displayActions} - refetch={refetchSample} + refetchCart={refetchCart} visible={visible} setVisible={setVisible} /> diff --git a/src/main/webapp/resources/js/components/samples/components/ViewerHeader.tsx b/src/main/webapp/resources/js/components/samples/components/ViewerHeader.tsx index e224afbe24d..0053603bce0 100644 --- a/src/main/webapp/resources/js/components/samples/components/ViewerHeader.tsx +++ b/src/main/webapp/resources/js/components/samples/components/ViewerHeader.tsx @@ -15,14 +15,16 @@ export const HEADER_HEIGHT_WITH_PADDING = 97; export default function ViewerHeader({ displayActions, projectId, - refetch, + refetchCart, + refetchSample, tab, onMenuChange, }: { displayActions: boolean; projectId: number; sampleId: number; - refetch: undefined | (() => void); + refetchCart: undefined | (() => void); + refetchSample: () => void; tab: ViewerTab; onMenuChange: Dispatch>; }): JSX.Element { @@ -84,7 +86,8 @@ export default function ViewerHeader({ danger onClick={() => { dispatch(removeSampleFromCartThunk()); - if (typeof refetch !== "undefined") refetch(); + if (typeof refetchCart !== "undefined") refetchCart(); + refetchSample(); }} > {i18n("SampleDetailsViewer.removeFromCart")} @@ -96,7 +99,8 @@ export default function ViewerHeader({ className="t-add-sample-to-cart" onClick={() => { dispatch(addSampleToCartThunk()); - if (typeof refetch !== "undefined") refetch(); + if (typeof refetchCart !== "undefined") refetchCart(); + refetchSample(); }} > {i18n("SampleDetailsViewer.addToCart")} diff --git a/src/main/webapp/resources/js/pages/cart/components/SampleRenderer.jsx b/src/main/webapp/resources/js/pages/cart/components/SampleRenderer.jsx index b6e239c1386..345d2d95877 100644 --- a/src/main/webapp/resources/js/pages/cart/components/SampleRenderer.jsx +++ b/src/main/webapp/resources/js/pages/cart/components/SampleRenderer.jsx @@ -41,7 +41,7 @@ export class SampleRenderer extends React.Component {