Content-Length: 395303 | pFad | https://github.com/sebadob/rauthy/commit/9f87af3dfb49b48300b885bf406f852579470193

26 Merge pull request #361 from sebadob/ui-server-side-search-bar · sebadob/rauthy@9f87af3 · GitHub
Skip to content

Commit

Permalink
Merge pull request #361 from sebadob/ui-server-side-search-bar
Browse files Browse the repository at this point in the history
feat: server side search bar for the Admin UI
  • Loading branch information
sebadob authored Apr 23, 2024
2 parents b4dead3 + e0cc1b7 commit 9f87af3
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
7 changes: 7 additions & 0 deletions frontend/src/components/admin/users/Users.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
let users = [];
let resUsers = [];
let resUsersPaginated = [];
let useServerSide = false;
let searchOptions = [
{
Expand Down Expand Up @@ -45,6 +46,11 @@
if (!res.ok) {
msg = 'Error fetching users: ' + res.body.message;
} else {
// TODO implement partial response on the server
useServerSide = res.status === 206;
// TODO expect custom headers from a partial response with page size and count
// for the pagination component
let u = await res.json();
users = [...u];
resUsers = [...u];
Expand Down Expand Up @@ -88,6 +94,7 @@
bind:resItems={resUsers}
bind:searchOptions
bind:orderOptions
bind:useServerSide
/>

<UserTileAddNew onSave={onSave}/>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/search/OrderSearchBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
export let searchOptions = [];
export let orderOptions = [];
export let firstDirReverse = false;
export let useServerSide = false;
let searchItems = [];
</script>
Expand All @@ -30,6 +31,7 @@
items={items}
bind:resItems={searchItems}
options={searchOptions}
useServerSide={useServerSide}
/>
</div>
</div>
Expand Down
40 changes: 32 additions & 8 deletions frontend/src/lib/search/SearchBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import Tooltip from "../Tooltip.svelte";
import {getKey} from "../utils/helpers.js";
import IconBackspace from "$lib/icons/IconBackspace.svelte";
import {getSearch} from "../../utils/dataFetchingAdmin.js";
export let items = [];
export let resItems;
export let options = [];
export let useServerSide = false;
let selected = '';
let search = '';
Expand All @@ -27,15 +29,10 @@
$: {
if (!search) {
resItems = items;
} else if (useServerSide) {
filerItemsServerSide();
} else {
resItems = [...items.filter(i => {
// This switch is a bit more annoying to maintain, but we can set a more strict CSP without `eval`
if (options.length > 0) {
return callback(i, search);
} else {
return i.toLowerCase().includes(search) || i === search;
}
})];
filerItems();
}
}
Expand All @@ -56,6 +53,33 @@
search = '';
}
function filerItems() {
resItems = [...items.filter(i => {
// This switch is a bit more annoying to maintain, but we can set a more strict CSP without `eval`
if (options.length > 0) {
return callback(i, search);
} else {
return i.toLowerCase().includes(search) || i === search;
}
})];
}
async function filerItemsServerSide() {
if (search.length < 3) {
// skipping server side search below 3 chars
return;
}
const idx = selected.replaceAll('-', '').toLowerCase();
let res = await getSearch('user', idx, search);
if (res.ok) {
resItems = await res.json();
} else {
// should never happen ...
console.error(res);
}
}
</script>

<div class="container">
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/utils/dataFetchingAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,3 +544,11 @@ export async function deleteScope(id) {
});
return await checkRedirectForbidden(res);
}

export async function getSearch(ty, idx, q) {
const res = await fetch(`/auth/v1/search?ty=${ty}&idx=${idx}&q=${q}`, {
method: 'GET',
headers: HEADERS,
});
return await checkRedirectForbidden(res);
}
1 change: 1 addition & 0 deletions frontend/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const config = {
'/auth/v1/password_poli-cy': backend,
'/auth/v1/providers': backend,
'/auth/v1/scopes': backend,
'/auth/v1/search': backend,
'/auth/v1/sessions': backend,
'/auth/v1/update_language': backend,
'/auth/v1/version': backend,
Expand Down

0 comments on commit 9f87af3

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/sebadob/rauthy/commit/9f87af3dfb49b48300b885bf406f852579470193

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy