From 719da070ee21b0a754cacb07b33d007327a306ec Mon Sep 17 00:00:00 2001 From: Annika Hannig Date: Fri, 26 Jan 2024 14:19:43 +0100 Subject: [PATCH] global community search and examples --- .../components/filters/CommunitiesSelect.js | 13 ++--- .../components/search/SearchGlobalInput.js | 58 +++++++++++++++++++ ui/src/app/context/bgp.js | 4 ++ ui/src/scss/components/lookup.scss | 34 +++++++++++ 4 files changed, 100 insertions(+), 9 deletions(-) diff --git a/ui/src/app/components/filters/CommunitiesSelect.js b/ui/src/app/components/filters/CommunitiesSelect.js index 5bd8806..da23158 100644 --- a/ui/src/app/components/filters/CommunitiesSelect.js +++ b/ui/src/app/components/filters/CommunitiesSelect.js @@ -108,15 +108,6 @@ const CommunitiesSelect = () => { const filtersNotAvailable = filters.notAvailable; const isDisabled = filtersNotAvailable.includes("communities"); - if (isDisabled) { - return ( -
- Due to a large number of results, filtering by BGP communities - becomes availble only after selecting a route server. -
- ); - } - const hasAvailable = communitiesFilters.filters.available.length > 0 || extCommunitiesFilters.filters.available.length > 0 || @@ -186,6 +177,10 @@ const CommunitiesSelect = () => { {appliedCommunities} {appliedExtCommunities} {appliedLargeCommunities} + {isDisabled &&
+ Due to a large number of results, selecting BGP communities + becomes availble only after selecting a route server. +
} {hasAvailable && diff --git a/ui/src/app/components/search/SearchGlobalInput.js b/ui/src/app/components/search/SearchGlobalInput.js index a51a049..5c88d51 100644 --- a/ui/src/app/components/search/SearchGlobalInput.js +++ b/ui/src/app/components/search/SearchGlobalInput.js @@ -5,11 +5,67 @@ import { useRef import { useQuery } from 'app/context/query'; +import { useContent } + from 'app/context/content'; import Content from 'app/components/content/Content'; import SearchQueryInput from 'app/components/search/SearchQueryInput'; +import BgpCommunityLabel + from 'app/components/routes/BgpCommunityLabel'; + +/** + * Lookup Example + */ +const LookupExample = ({example}) => { + const type = example[0]; + const value = example.slice(1); + + const communityURL = (value) => + "/search?q=" + encodeURIComponent(`#${value.join(":")}`); + + switch (type) { + case "community": + return ( +
  • + + + +
  • + ); + default: + return ( +
  • + + {value} + +
  • + ); + }; +} + +/** + * Lookup Examples + */ +const LookupExamples = () => { + const content = useContent(); + + let examples = content.lookup?.examples; + if (!examples) { + return null; + } + + return ( +
    +

    Some Examples

    + +
    + ) +} /** @@ -28,8 +84,10 @@ const Help = () => {
  • Prefixes,
  • Peers by entering their name and
  • ASNs by prefixing them with 'AS'
  • +
  • Communities by prefixing them with '#'
  • Just start typing!

    + ); } diff --git a/ui/src/app/context/bgp.js b/ui/src/app/context/bgp.js index 0bab9ea..7c70283 100644 --- a/ui/src/app/context/bgp.js +++ b/ui/src/app/context/bgp.js @@ -51,6 +51,9 @@ const resolveCommunity = (base, community) => { } lookup = res; } + if (typeof(lookup) !== "string") { + return null; + } return lookup; } @@ -97,6 +100,7 @@ export const useRejectCandidate = (route) => { const getReadableCommunity = (communities, community) => { const label = resolveCommunity(communities, community); + console.log(label); return expandVars(label, community); } diff --git a/ui/src/scss/components/lookup.scss b/ui/src/scss/components/lookup.scss index ca482e3..bd92be9 100644 --- a/ui/src/scss/components/lookup.scss +++ b/ui/src/scss/components/lookup.scss @@ -40,3 +40,37 @@ } } +.lookup-examples { + + > ul { + display: flex; + list-style: none; + padding: 0px; + margin: 0px; + width: 50%; + flex-wrap: wrap; + + li { + flex: 1; + padding: 0px; + + .label { + display: flex; + margin: 5px; + line-height: inherit; + font-size: 1.4rem; + box-shadow: 0 1px 1px rgba(0,0,0,.2); + } + + .label-default { + background-color: #ffffff; + color: #222; + } + + a { + text-decoration: none; + } + } + } +} +