Skip to content

Commit

Permalink
Fix OverlayPanel Toast (#5236)
Browse files Browse the repository at this point in the history
* Fix OverlayPanel Toast

* Refactor

---------

Co-authored-by: “Selen <“[email protected]”>
  • Loading branch information
SelenKockar and “Selen authored Nov 3, 2023
1 parent fde9a58 commit 17b82c9
Showing 1 changed file with 24 additions and 30 deletions.
54 changes: 24 additions & 30 deletions components/doc/overlaypanel/datatabledoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ export function DataTableDoc(props) {
const toast = useRef(null);
const isMounted = useRef(false);

useEffect(() => {
if (isMounted.current && selectedProduct) {
op.current.hide();
toast.current.show({ severity: 'info', summary: 'Product Selected', detail: selectedProduct.name, life: 3000 });
}
}, [selectedProduct]); // eslint-disable-line react-hooks/exhaustive-deps
const productSelect = (e) => {
op.current.hide();
toast.current.show({ severity: 'info', summary: 'Product Selected', detail: e.data.name, life: 3000 });
};

useEffect(() => {
isMounted.current = true;
Expand Down Expand Up @@ -99,12 +97,10 @@ export default function DataTableDemo() {
const toast = useRef(null);
const isMounted = useRef(false);
useEffect(() => {
if (isMounted.current && selectedProduct) {
op.current.hide();
toast.current.show({ severity: 'info', summary: 'Product Selected', detail: selectedProduct.name, life: 3000 });
}
}, [selectedProduct]);
const productSelect = (e) => {
op.current.hide();
toast.current.show({ severity: 'info', summary: 'Product Selected', detail:e.data.name, life: 3000 });
};
useEffect(() => {
isMounted.current = true;
Expand Down Expand Up @@ -133,11 +129,11 @@ export default function DataTableDemo() {
<Button type="button" icon="pi pi-search" label="Search" onClick={(e) => op.current.toggle(e)} />
{selectedProductContent}
<OverlayPanel ref={op} showCloseIcon closeOnEscape dismissable={false}>
<DataTable value={products} selectionMode="single" paginator rows={5} selection={selectedProduct} onSelectionChange={(e) => setSelectedProduct(e.value)}>
<Column field="name" header="Name" sortable style={{minWidth: '12rem'}} />
<Column header="Image" body={imageBody} />
<Column field="price" header="Price" sortable body={priceBody} style={{minWidth: '8rem'}} />
</DataTable>
<DataTable value={products} selectionMode="single" paginator rows={5} selection={selectedProduct} onSelectionChange={(e) => setSelectedProduct(e.value)} onRowClick={productSelect}>
<Column field="name" header="Name" sortable style={{ minWidth: '12rem' }} />
<Column header="Image" body={imageBody} />
<Column field="price" header="Price" sortable body={priceBody} style={{minWidth: '8rem'}} />
</DataTable>
</OverlayPanel>
</div>
);
Expand Down Expand Up @@ -172,13 +168,11 @@ export default function DataTableDemo() {
<span className="text-600">{selectedProduct.category}</span>
</div>
);
useEffect(() => {
if (isMounted.current && selectedProduct) {
op.current.hide();
toast.current.show({ severity: 'info', summary: 'Product Selected', detail: selectedProduct.name, life: 3000 });
}
}, [selectedProduct]);
const productSelect = (e) => {
op.current.hide();
toast.current.show({ severity: 'info', summary: 'Product Selected', detail:e.data.name, life: 3000 });
};
useEffect(() => {
isMounted.current = true;
Expand Down Expand Up @@ -207,11 +201,11 @@ export default function DataTableDemo() {
<Button type="button" icon="pi pi-search" label="Search" onClick={(e) => op.current.toggle(e)} />
{selectedProductContent}
<OverlayPanel ref={op} showCloseIcon closeOnEscape dismissable={false}>
<DataTable value={products} selectionMode="single" paginator rows={5} selection={selectedProduct} onSelectionChange={(e) => setSelectedProduct(e.value)}>
<Column field="name" header="Name" sortable style={{minWidth: '12rem'}} />
<Column header="Image" body={imageBody} />
<Column field="price" header="Price" sortable body={priceBody} style={{minWidth: '8rem'}} />
</DataTable>
<DataTable value={products} selectionMode="single" paginator rows={5} selection={selectedProduct} onSelectionChange={(e) => setSelectedProduct(e.value)} onRowClick={productSelect}>
<Column field="name" header="Name" sortable style={{ minWidth: '12rem' }} />
<Column header="Image" body={imageBody} />
<Column field="price" header="Price" sortable body={priceBody} style={{minWidth: '8rem'}} />
</DataTable>
</OverlayPanel>
</div>
);
Expand Down Expand Up @@ -248,7 +242,7 @@ export default function DataTableDemo() {
<Button type="button" icon="pi pi-search" label="Search" onClick={(e) => op.current.toggle(e)} />
{selectedProductContent}
<OverlayPanel ref={op} showCloseIcon closeOnEscape dismissable={false}>
<DataTable value={products} selectionMode="single" paginator rows={5} selection={selectedProduct} onSelectionChange={(e) => setSelectedProduct(e.value)}>
<DataTable value={products} selectionMode="single" paginator rows={5} selection={selectedProduct} onSelectionChange={(e) => setSelectedProduct(e.value)} onRowClick={productSelect}>
<Column field="name" header="Name" sortable style={{ minWidth: '12rem' }} />
<Column header="Image" body={imageBody} />
<Column field="price" header="Price" sortable body={priceBody} style={{ minWidth: '8rem' }} />
Expand Down

0 comments on commit 17b82c9

Please sign in to comment.