Set up an unused method to illustrate type usage / communication between search frontend and backend
Signed-off-by: Eric Peterson <ericpeterson@spotify.com>
This commit is contained in:
@@ -15,3 +15,4 @@
|
||||
*/
|
||||
|
||||
export * from './service/router';
|
||||
export * from './types';
|
||||
|
||||
@@ -13,21 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2020 Spotify AB
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createServiceBuilder } from '@backstage/backend-common';
|
||||
import { Server } from 'http';
|
||||
@@ -51,7 +36,7 @@ export async function startStandaloneServer(
|
||||
|
||||
const service = createServiceBuilder(module)
|
||||
.enableCors({ origin: 'http://localhost:3000' })
|
||||
.addRouter('/search', router);
|
||||
.addRouter('/api/search', router);
|
||||
|
||||
return await service.start().catch(err => {
|
||||
logger.error(err);
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
"@backstage/core": "^0.7.2",
|
||||
"@backstage/catalog-model": "^0.7.3",
|
||||
"@backstage/plugin-catalog-react": "^0.1.2",
|
||||
"@backstage/plugin-search-backend": "^0.1.1",
|
||||
"@backstage/theme": "^0.2.4",
|
||||
"@material-ui/core": "^4.11.0",
|
||||
"@material-ui/icons": "^4.9.1",
|
||||
|
||||
@@ -15,7 +15,10 @@
|
||||
*/
|
||||
|
||||
import { Entity, ENTITY_DEFAULT_NAMESPACE } from '@backstage/catalog-model';
|
||||
import { DiscoveryApi } from '@backstage/core';
|
||||
import { CatalogApi } from '@backstage/plugin-catalog-react';
|
||||
import { SearchQuery, SearchResultSet } from '@backstage/plugin-search-backend';
|
||||
import qs from 'qs';
|
||||
|
||||
export type Result = {
|
||||
name: string;
|
||||
@@ -30,9 +33,11 @@ export type SearchResults = Array<Result>;
|
||||
|
||||
class SearchApi {
|
||||
private catalogApi: CatalogApi;
|
||||
private discoveryApi: DiscoveryApi;
|
||||
|
||||
constructor(catalogApi: CatalogApi) {
|
||||
constructor(catalogApi: CatalogApi, discoveryApi: DiscoveryApi) {
|
||||
this.catalogApi = catalogApi;
|
||||
this.discoveryApi = discoveryApi;
|
||||
}
|
||||
|
||||
private async entities() {
|
||||
@@ -56,6 +61,18 @@ class SearchApi {
|
||||
public getSearchResult(): Promise<SearchResults> {
|
||||
return this.entities();
|
||||
}
|
||||
|
||||
// @todo Productionalize as we implement search milestones.
|
||||
public async _alphaPerformSearch(
|
||||
query: SearchQuery,
|
||||
): Promise<SearchResultSet> {
|
||||
const queryString = qs.stringify(query);
|
||||
const url = `${await this.discoveryApi.getBaseUrl(
|
||||
'search/query',
|
||||
)}?${queryString}`;
|
||||
const response = await fetch(url);
|
||||
return response.json();
|
||||
}
|
||||
}
|
||||
|
||||
export default SearchApi;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {
|
||||
discoveryApiRef,
|
||||
EmptyState,
|
||||
Link,
|
||||
Progress,
|
||||
@@ -117,6 +118,7 @@ const TableHeader = ({
|
||||
|
||||
export const SearchResult = ({ searchQuery }: SearchResultProps) => {
|
||||
const catalogApi = useApi(catalogApiRef);
|
||||
const discoveryApi = useApi(discoveryApiRef);
|
||||
|
||||
const [showFilters, toggleFilters] = useState(false);
|
||||
const [selectedFilters, setSelectedFilters] = useState<FiltersState>({
|
||||
@@ -126,7 +128,7 @@ export const SearchResult = ({ searchQuery }: SearchResultProps) => {
|
||||
|
||||
const [filteredResults, setFilteredResults] = useState<SearchResults>([]);
|
||||
|
||||
const searchApi = new SearchApi(catalogApi);
|
||||
const searchApi = new SearchApi(catalogApi, discoveryApi);
|
||||
|
||||
const { loading, error, value: results } = useAsync(() => {
|
||||
return searchApi.getSearchResult();
|
||||
|
||||
Reference in New Issue
Block a user