Skip to content
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

Style dash #45

Merged
merged 4 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dashboard-react/app/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const Home = () => {
<FilterControls />
</div>
<div style={{ minWidth: "1000px" }}>
<h1>CFTP Field Test Results Dashboard</h1>
<Dashboard />
</div>
</main>
Expand Down
29 changes: 21 additions & 8 deletions dashboard-react/components/DropdownCheckbox.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
"use client";
import React from "react";
import React, { useRef } from "react";
import { useSnapshot } from "valtio";
import state from "@/lib/state";
import { closeOpenedDetails } from "@/lib/utils";

export default function DropdownCheckbox({
const DropdownCheckbox = React.memo(function DropdownCheckbox({
options,
selectedOptions,
filterKey,
title,
}) {
const snap = useSnapshot(state);
const divRef = useRef(null);

const onSummaryClick = () => {
closeOpenedDetails(`summary-${filterKey}`);
};

const handleCheckboxChange = (key, value) => (event) => {
const checked = event.target.checked;
console.log(`checked for ${key} ${value}`);
console.log(checked);
// console.log(`checked for ${key} ${value}`);
// console.log(checked);
if (checked) {
state.setFilterValue(key, [...snap.filters[key], value]);
state.setFilterValue(key, [...filtersSnap[key], value]);
} else {
console.log("removing");
// console.log("removing");
state.setFilterValue(
key,
snap.filters[key].filter((item) => item !== value)
Expand Down Expand Up @@ -55,7 +61,12 @@ export default function DropdownCheckbox({
</div>
<div className="divider m-0"></div>
<details className="dropdown">
<summary className="btn m-1">
<summary
className="btn m-1"
onClick={onSummaryClick}
ref={divRef}
id={`summary-${filterKey}`}
>
{isAllSelected
? "All Selected"
: selectedOptions.length > 0
Expand All @@ -81,4 +92,6 @@ export default function DropdownCheckbox({
</details>
</>
);
}
});

export default DropdownCheckbox;
15 changes: 13 additions & 2 deletions dashboard-react/components/DropdownSingleSelect.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
"use client";
import React from "react";
import React, { useRef } from "react";
import { useSnapshot } from "valtio";
import state from "@/lib/state";
import { invertDictionary } from "@/lib/constants";
import { closeOpenedDetails } from "@/lib/utils";

export default function DropdownSingleSelect({ options, title, filterKey }) {
const snap = useSnapshot(state);
const divRef = useRef(null);

const onSummaryClick = () => {
closeOpenedDetails(`summary-${filterKey}`);
};

const handleSelectionChange = (key, value) => {
console.log(key, value);
Expand All @@ -18,7 +24,12 @@ export default function DropdownSingleSelect({ options, title, filterKey }) {
<>
<h2>{title}</h2>
<details className="dropdown">
<summary className="btn m-1">
<summary
className="btn m-1"
onClick={onSummaryClick}
ref={divRef}
id={`summary-${filterKey}`}
>
{col2options[snap.filters[filterKey]]}
</summary>
<ul className="menu dropdown-content bg-base-100 rounded-box z-[1] w-52 p-2 shadow">
Expand Down
23 changes: 17 additions & 6 deletions dashboard-react/components/FilterControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,27 @@ export default function FilterControls() {
}
}, [snap.options]);

useEffect(() => {
const summaries = document.querySelectorAll("summary");

summaries.forEach((summary) => {
summary.addEventListener("click", closeOpenedDetails);
});

function closeOpenedDetails() {
summaries.forEach((summary) => {
let detail = summary.parentNode;
if (detail != this.parentNode) {
detail.removeAttribute("open");
}
});
}
}, [snap.options]);

if (!snap.filters.initialized) {
return <div>Loading...</div>;
}

console.log("snap.options");
console.log(snap.options);

console.log("snap.filters");
console.log(snap.filters);

return (
<>
<div className="h-[100vh] overflow-y-auto">
Expand Down
6 changes: 6 additions & 0 deletions dashboard-react/lib/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ const state = proxy({
setFilterValue: (key, value) => {
state.filters[key] = value;
},

expandedMenu: null,

setExpandedMenu: (menu) => {
state.expandedMenu = menu;
},
});

const fetchData = async () => {
Expand Down
9 changes: 9 additions & 0 deletions dashboard-react/lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const closeOpenedDetails = (id) => {
const summaries = document.querySelectorAll("summary");
summaries.forEach((summary) => {
if (summary.id !== id) {
const detail = summary.parentElement;
detail.removeAttribute("open");
}
});
};
Loading