Skip to content

Commit

Permalink
Sort enroll and manage fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikescops committed Mar 4, 2024
1 parent c452d3d commit 339a883
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions website/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import dashlaneIcon from "../../public/dashlane.svg";
import enrollIcon from "../../public/enroll.svg";
import manageIcon from "../../public/manage.svg";

type SortedField = "domain" | "name";
type SortedField = "domain" | "name" | "enroll" | "manage";

const Page = () => {
const [searchTerm, setSearchTerm] = useState("");
Expand All @@ -30,8 +30,8 @@ const Page = () => {

const sortedData = sortedField
? [...filteredData].sort((a, b) => {
const fieldA = a[sortedField].toLowerCase();
const fieldB = b[sortedField].toLowerCase();
const fieldA = { ...a.endpoints, ...a }[sortedField].toLowerCase();
const fieldB = { ...b.endpoints, ...b }[sortedField].toLowerCase();

if (fieldA < fieldB) return sortedAscending ? -1 : 1;
if (fieldA > fieldB) return sortedAscending ? 1 : -1;
Expand Down Expand Up @@ -86,7 +86,7 @@ const Page = () => {
>
Domain
{sortedField === "domain" && (
<span className="ml-1">{sortedAscending ? "" : ""}</span>
<span className="ml-1">{sortedAscending ? "" : ""}</span>
)}
</th>
<th
Expand All @@ -95,17 +95,29 @@ const Page = () => {
>
Name
{sortedField === "name" && (
<span className="ml-1">{sortedAscending ? "" : ""}</span>
<span className="ml-1">{sortedAscending ? "" : ""}</span>
)}
</th>
<th className="px-6 py-3 bg-gray-50 dark:bg-slate-700 dark:text-white text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
Description
</th>
<th className="px-6 py-3 bg-gray-50 dark:bg-slate-700 dark:text-white text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
<th
className="px-6 py-3 bg-gray-50 dark:bg-slate-700 dark:text-white text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider cursor-pointer"
onClick={() => sortData("enroll")}
>
Enroll
{sortedField === "enroll" && (
<span className="ml-1">{sortedAscending ? "▼" : "▲"}</span>
)}
</th>
<th className="px-6 py-3 bg-gray-50 dark:bg-slate-700 dark:text-white text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
<th
className="px-6 py-3 bg-gray-50 dark:bg-slate-700 dark:text-white text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider cursor-pointer"
onClick={() => sortData("manage")}
>
Manage
{sortedField === "manage" && (
<span className="ml-1">{sortedAscending ? "▼" : "▲"}</span>
)}
</th>
</tr>
</thead>
Expand Down

0 comments on commit 339a883

Please sign in to comment.