MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / Header

Function Header

ui/src/components/Header.tsx:25–185  ·  view source on GitHub ↗
({ user }: { user: User })

Source from the content-addressed store, hash-verified

23});
24
25function Header({ user }: { user: User }) {
26 const navigate = useNavigate();
27
28 const [settings, setSettings] = useState<SettingsResponse | undefined>(undefined);
29 const [searchResult, setSearchResult] = useState<GlobalSearchResponse | undefined>(undefined);
30
31 useEffect(() => {
32 InternalStore.settings((resp: SettingsResponse) => {
33 setSettings(resp);
34 });
35 }, [user]);
36
37 const onSearch = (search: string) => {
38 if (search.length < 3) {
39 return;
40 }
41
42 const req = new GlobalSearchRequest();
43 req.setLimit(20);
44 req.setSearch(search);
45
46 InternalStore.globalSearch(req, (resp: GlobalSearchResponse) => {
47 setSearchResult(resp);
48 });
49 };
50
51 const onSelect = (_: unknown, _option: unknown) => {
52 const option = _option as ReturnType<typeof renderItem>;
53 navigate(option.url);
54 };
55
56 const onLogout = () => {
57 if (settings === undefined) {
58 return;
59 }
60
61 const oidc = settings.getOpenidConnect()!;
62 const oAuth2 = settings.getOauth2()!;
63
64 if (oidc.getEnabled() && oidc.getLogoutUrl() !== "") {
65 SessionStore.logout(false, () => {
66 window.location.replace(oidc.getLogoutUrl());
67 });
68 } else if (oAuth2.getEnabled() && oAuth2.getLogoutUrl() !== "") {
69 SessionStore.logout(false, () => {
70 window.location.replace(oAuth2.getLogoutUrl());
71 });
72 } else {
73 SessionStore.logout(true, () => {
74 navigate("/login");
75 });
76 }
77 };
78
79 if (settings === undefined) {
80 return null;
81 }
82

Callers

nothing calls this directly

Calls 4

renderTitleFunction · 0.85
renderItemFunction · 0.85
settingsMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected