Skip to content

Commit

Permalink
[whois] endpoint configurable, add more options to input placeholder,…
Browse files Browse the repository at this point in the history
… remove obsolete responsible persons (#318)
  • Loading branch information
ArtieReus authored Apr 18, 2023
1 parent 2f1848e commit 5bd5129
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
5 changes: 5 additions & 0 deletions apps/whois/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
"value": "theme-dark",
"type": "optional",
"description": "Override the default theme. Possible values are theme-light or theme-dark (default)"
},
"endpoint": {
"value": "",
"type": "required",
"description": "Endpoint URL of the API"
}
}
}
4 changes: 2 additions & 2 deletions apps/whois/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const App = (props) => {
const [items, setItems] = React.useState(null)
const [error, setError] = React.useState(null)
const [statusCode, setStatusCode] = React.useState(null)
const { embedded } = props
const { embedded, endpoint } = props

const resultsShown = items !== null

Expand All @@ -59,7 +59,7 @@ const App = (props) => {
setProcessing(true)

// search
searchByInput(term, options)
searchByInput(endpoint, term, options)
.then((response) => {
// get status code from response
setStatusCode(response.status)
Expand Down
16 changes: 12 additions & 4 deletions apps/whois/src/ResultItem.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react"
import React, { useState, useMemo, useEffect } from "react"
import ReactJson from "react-json-view"
import { DateTime } from "luxon"
import { Icon, Stack } from "juno-ui-components"
Expand Down Expand Up @@ -39,7 +39,15 @@ const capitalize = (string) => {
const ResultItem = ({ content, expand }) => {
const [isExpanded, setIsExpanded] = useState(false)

React.useEffect(() => {
const responsibles = useMemo(() => {
if (!content?.responsibles) return null
// billing api do not return anymore following values. We extract them active and we leave the rest as it is.
const { controller, securityExpert, productOwner, ...rest } =
content.responsibles
return rest
}, [content.responsibles])

useEffect(() => {
setIsExpanded(expand)
}, [expand])

Expand All @@ -61,11 +69,11 @@ const ResultItem = ({ content, expand }) => {
{content.region && (
<div className="text-theme-light">{content.region}</div>
)}
{content.responsibles && (
{responsibles && (
<>
<h4 className="font-bold mt-3">Responsible Persons:</h4>
<Stack direction="vertical" gap="2">
{Object.entries(content.responsibles).map(
{Object.entries(responsibles).map(
([contactType, contactInfo]) => (
<div key={contactType}>
<h5>{capitalize(contactType)}:</h5>
Expand Down
2 changes: 1 addition & 1 deletion apps/whois/src/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const Search = ({ onSearch, resultsShown, value }) => {
className={`search ${searchClasses(resultsShown)}`}
>
<SearchInput
placeholder="IPs, IP lists, or IP ranges (CIDR)"
placeholder="IPs, IP lists, IP ranges (CIDR), project id, domain id or cost object"
className=""
variant="hero"
value={searchTerm}
Expand Down
9 changes: 6 additions & 3 deletions apps/whois/src/actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const ENDPOINT = "https://whois.global.cloud.sap/v1"
const DEFAULT_ENDPOINT = "https://whois.global.cloud.sap/v1"
// const ENDPOINT = "https://whois-staging.scaleout.eu-nl-1.cloud.sap/v1"

class HTTPError extends Error {
Expand Down Expand Up @@ -31,9 +31,12 @@ const checkStatus = (response) => {
}
}

export const search = (input, options) => {
export const search = (endpoint, input, options) => {
let newEndpoint = DEFAULT_ENDPOINT
if (endpoint && endpoint.length > 0) newEndpoint = endpoint

return fetch(
`${ENDPOINT}/query?input=${input}${encodeUrlParamsFromObject(options)}`,
`${newEndpoint}/query?input=${input}${encodeUrlParamsFromObject(options)}`,
{
method: "GET",
credentials: "same-origin",
Expand Down

0 comments on commit 5bd5129

Please sign in to comment.