-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
webapp: put count/value data table into its own component
- Loading branch information
Showing
4 changed files
with
78 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// SPDX-FileCopyrightText: (C) 2023 Jason Ish <[email protected]> | ||
// SPDX-License-Identifier: MIT | ||
|
||
import { For, Show } from "solid-js"; | ||
import { SearchLink } from "../common/SearchLink"; | ||
|
||
// Creates a table where the first column is a count, and the second | ||
// column is value. | ||
export function CountValueDataTable(props: { | ||
title: string; | ||
label: string; | ||
searchField?: string; | ||
rows: { count: number; key: any }[]; | ||
}) { | ||
function searchLink(value: any) { | ||
if (props.searchField) { | ||
return ( | ||
<SearchLink value={value} field={props.searchField}> | ||
{value} | ||
</SearchLink> | ||
); | ||
} else { | ||
return <SearchLink value={value}>{value}</SearchLink>; | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<div class="card app-count-value-data-table"> | ||
<div class="card-header">{props.title}</div> | ||
<div class="card-body p-0"> | ||
<Show when={props.rows.length == 0}></Show> | ||
<Show when={props.rows.length > 0}> | ||
<table class="table mb-0"> | ||
<thead> | ||
<tr> | ||
<th style={"width: 6em;"}>#</th> | ||
<th>{props.label}</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<For each={props.rows}> | ||
{(row) => ( | ||
<tr> | ||
<td style={"width: 6em;"}>{row.count}</td> | ||
<td>{searchLink(row.key)}</td> | ||
</tr> | ||
)} | ||
</For> | ||
</tbody> | ||
</table> | ||
</Show> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} |
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