-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into replace-bleach-with-nh3
- Loading branch information
Showing
9 changed files
with
92 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,42 @@ | ||
import $ from "jquery"; | ||
import PropTypes from "prop-types"; | ||
import React, {createRef, useEffect} from "react"; | ||
import React, {createRef, useEffect, useState} from "react"; | ||
import Loading from "shared/components/Loading"; | ||
|
||
const DataTableWrapper = ({children, className, data, columns}) => { | ||
const ref = createRef(), | ||
[loading, setLoading] = useState(true), | ||
dtProps = {autoWidth: false, order: [], pageLength: 10}; | ||
|
||
// check that either children or data exist | ||
if (children) { | ||
// do nothing | ||
} else if (data && columns) { | ||
dtProps.data = data; | ||
dtProps.columns = columns; | ||
} else { | ||
console.error("Invalid props passed to DataTableWrapper"); | ||
} | ||
|
||
const DataTableWrapper = ({children}) => { | ||
const ref = createRef(); | ||
$.DataTable = require("datatables.net"); | ||
useEffect(() => { | ||
const table = $(ref.current.firstElementChild).DataTable({order: [], pageLength: 10}); | ||
const table = $(ref.current.firstElementChild).DataTable(dtProps); | ||
setLoading(false); | ||
return () => table.destroy(); | ||
}); | ||
return <div ref={ref}>{children}</div>; | ||
return ( | ||
<> | ||
{loading ? <Loading /> : null} | ||
<div ref={ref}>{children ? children : <table className={className}></table>}</div> | ||
</> | ||
); | ||
}; | ||
|
||
DataTableWrapper.propTypes = { | ||
children: PropTypes.node, | ||
className: PropTypes.string, | ||
data: PropTypes.array, | ||
columns: PropTypes.array, | ||
}; | ||
|
||
export default DataTableWrapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div id="htmx-error-banner" hidden class="row px-3"> | ||
<div class="col-12 alert alert-danger" role="alert"> | ||
<h4 id="htmx-alert" class="alert-heading"></h4> | ||
<span>Please check your network connection and refresh this page. Please <a href="{% url 'contact' %}">contact us</a> if the issue contiues to occur.</span> | ||
</div> | ||
</div> |