Updates
This commit is contained in:
@@ -9,7 +9,10 @@ import Row from "@/src/components/twui/layout/Row";
|
||||
import Stack from "@/src/components/twui/layout/Stack";
|
||||
import ClientFormModal from "../(partials)/client-form-modal";
|
||||
import { useAdminCrudGet } from "@/src/hooks/use-admin-crud-get";
|
||||
import type { BUN_SQLITE_WGUI_CLIENTS } from "@/db/types/db";
|
||||
import type {
|
||||
BUN_SQLITE_WGUI_CLIENTS,
|
||||
BUN_SQLITE_WGUI_CLIENT_RULES,
|
||||
} from "@/db/types/db";
|
||||
|
||||
type Props = {
|
||||
addOpen: boolean;
|
||||
@@ -33,6 +36,32 @@ export default function ClientsTableSection({ addOpen, setAddOpen }: Props) {
|
||||
},
|
||||
});
|
||||
|
||||
const { res: client_rules } = useAdminCrudGet<BUN_SQLITE_WGUI_CLIENT_RULES>({
|
||||
table: "client_rules",
|
||||
sql_query: {
|
||||
limit: 500,
|
||||
},
|
||||
});
|
||||
|
||||
const rules_by_client_id = useMemo(() => {
|
||||
const map = new Map<number, BUN_SQLITE_WGUI_CLIENT_RULES[]>();
|
||||
|
||||
for (let i = 0; i < (client_rules || []).length; i++) {
|
||||
const rule = client_rules?.[i];
|
||||
const client_id = Number(rule?.client_id);
|
||||
|
||||
if (!rule || !client_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const existing = map.get(client_id) || [];
|
||||
existing.push(rule);
|
||||
map.set(client_id, existing);
|
||||
}
|
||||
|
||||
return map;
|
||||
}, [client_rules]);
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
const clients = res || [];
|
||||
const q = query.trim().toLowerCase();
|
||||
@@ -80,15 +109,26 @@ export default function ClientsTableSection({ addOpen, setAddOpen }: Props) {
|
||||
<th className={thClass}>Client</th>
|
||||
<th className={thClass}>Tunnel IP</th>
|
||||
<th className={thClass}>Allowed IPs</th>
|
||||
<th className={thClass}>Access</th>
|
||||
<th className={thClass}>Public key</th>
|
||||
<th className={thRightClass}>Created</th>
|
||||
<th className={thRightClass}>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{filtered.map((client) => (
|
||||
<ClientRow key={client.id} client={client} />
|
||||
))}
|
||||
{filtered.map((client) => (
|
||||
<ClientRow
|
||||
key={client.id}
|
||||
client={client}
|
||||
rules={
|
||||
client.id
|
||||
? rules_by_client_id.get(
|
||||
Number(client.id),
|
||||
)
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user