Skip to content

Commit

Permalink
feat: replace fulltext with search service
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreiffers committed Apr 23, 2024
1 parent bcd3eb2 commit cbc2e9a
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 115 deletions.
4 changes: 2 additions & 2 deletions config.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ window.env = {
ORGANIZATION_API: '$ORGANIZATION_API',
SSO_HOST: '$SSO_HOST',
CONCEPT_API: '$CONCEPT_API',
SEARCH_FULLTEXT_HOST: '$SEARCH_FULLTEXT_HOST',
SEARCH_SERVICE_HOST: '$SEARCH_SERVICE_HOST',
SEARCH_HOST: '$SEARCH_HOST',
ADMIN_GUI_HOST: '$ADMIN_GUI_HOST',
CATALOG_COMMENTS_SERVICE_HOST: '$CATALOG_COMMENTS_SERVICE_HOST',
CONCEPT_CATALOG_FRONTEND_BASE_URI: '$CONCEPT_CATALOG_FRONTEND_BASE_URI',
CATALOG_ADMIN_SERVICE_BASE_URI: '$CATALOG_ADMIN_SERVICE_BASE_URI',
CATALOG_ADMIN_BASE_URI: '$CATALOG_ADMIN_BASE_URI',
FDK_PORTAL_BASE_URI: '$FDK_PORTAL_BASE_URI',
USE_DEMO_LOGO: '$USE_DEMO_LOGO',
USE_DEMO_LOGO: '$USE_DEMO_LOGO'
};
28 changes: 28 additions & 0 deletions src/api/search-api/concepts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { searchApiPost } from './host';
import { Concept, SearchObject } from '../../types';

export const searchConcepts = (body: any) =>
searchApiPost('/search/concepts', body);

const mapFilters = ({ uri }: any) => {
if (uri) {
return { uri: { value: uri } };
}

return undefined;
};

export const paramsToSearchBody = ({ q, ...params }: any) => {
const body = {
query: q,
filters: mapFilters(params)
};
return body;
};

export const extractConcepts = (searchResponse: any): Promise<SearchObject[]> =>
searchResponse?.hits ?? [];

export const extractInternalConcepts = (
searchResponse: any
): Promise<Concept[]> => searchResponse?.hits ?? [];
26 changes: 26 additions & 0 deletions src/api/search-api/host.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import axios from 'axios';
import cleanDeep from 'clean-deep';
import { getConfig } from '../../config';

interface Props {
path: string;
method: any;
params?: any;
data?: any;
}

export const searchApi = ({ path, method, params, data }: Props) =>
axios({
url: `${getConfig().searchApi.host}${path}`,
method,
params,
data
})
.then(response => cleanDeep(response.data))
.catch(() => null);

export const searchApiPost = (path: string, body: any) =>
searchApi({ path, method: 'POST', data: body });

export const searchApiGet = (path: string, params: any) =>
searchApi({ path, method: 'GET', params });
9 changes: 9 additions & 0 deletions src/api/search-api/suggestions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { searchApiGet } from './host';
import { SearchObject } from '../../types';

export const extractSuggestions = (
searchResponse: any
): Promise<SearchObject[]> => searchResponse.suggestions ?? [];

export const getConceptSuggestions = (params: any) =>
searchApiGet('/suggestions/concepts', params);
34 changes: 0 additions & 34 deletions src/api/search-fulltext-api/concepts.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/api/search-fulltext-api/host.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/api/search-fulltext-api/suggestions.ts

This file was deleted.

14 changes: 7 additions & 7 deletions src/components/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import React, { FC, HTMLAttributes } from 'react';

import HeaderBase from '@fellesdatakatalog/internal-header';

interface Props extends HTMLAttributes<HTMLInputElement> {}

import Link from '@fellesdatakatalog/link';
import { useLocation } from 'react-router-dom';
import authService from '../../services/auth-service';
import { getConfig } from '../../config';
import { useLocation } from 'react-router-dom';

interface Props extends HTMLAttributes<HTMLInputElement> {}

const showManageConceptCatalogsUrl = () => {
const resourceRoles = authService.getResourceRoles();
const location = useLocation();
const pathParts = location.pathname.split('/');
const currentCatalogId = pathParts ? pathParts[1] : undefined;

return resourceRoles.some((role) => {
return resourceRoles.some(role => {
const roleOrgNumber = role?.resourceId;
return authService.hasOrganizationAdminPermission(
currentCatalogId ? currentCatalogId : roleOrgNumber
currentCatalogId || roleOrgNumber
);
});
};
Expand All @@ -32,9 +32,9 @@ export const Header: FC<Props> = () => (
showManageConceptCatalogsUrl={showManageConceptCatalogsUrl()}
manageConceptCatalogsUrl={getConfig().catalogAdminBaseUri}
>
<Link href={`${getConfig().searchHost}/guidance`}>Registrere data</Link>
<Link href={`${getConfig().fdkBaseUri}/guidance`}>Registrere data</Link>
<Link href={getConfig().adminGui.host}>Høste data</Link>
<Link href={getConfig().searchHost} external>
<Link href={getConfig().fdkBaseUri} external>
Søk i Felles datakatalog
</Link>
</HeaderBase>
Expand Down
9 changes: 5 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const env = (window as any).env || {
// env.ORGANIZATION_API =
// 'https://organization-catalog.staging.fellesdatakatalog.digdir.no';
// env.CONCEPT_API = 'https://www.staging.fellesdatakatalog.digdir.no';
// env.SEARCH_FULLTEXT_HOST = 'https://search.staging.fellesdatakatalog.digdir.no';
// env.SEARCH_SERVICE_HOST =
// 'https://search.api.staging.fellesdatakatalog.digdir.no';
// env.SEARCH_HOST = 'https://www.staging.fellesdatakatalog.digdir.no';
// env.FDK_PORTAL_BASE_URI = 'https://staging.fellesdatakatalog.digdir.no';
// env.ADMIN_GUI_HOST = 'https://admin.staging.fellesdatakatalog.digdir.no';
Expand Down Expand Up @@ -52,10 +53,10 @@ const config = {
referenceDataApi: {
host: env.FDK_PORTAL_BASE_URI
},
searchFullTextApi: {
host: env.SEARCH_FULLTEXT_HOST
searchApi: {
host: env.SEARCH_SERVICE_HOST
},
searchHost: env.SEARCH_HOST || 'https://fellesdatakatalog.digdir.no',
fdkBaseUri: env.SEARCH_HOST || 'https://fellesdatakatalog.digdir.no',
adminGui: {
host: env.ADMIN_GUI_HOST
},
Expand Down
16 changes: 8 additions & 8 deletions src/features/concept-suggestions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ import {
createEntityAdapter
} from '@reduxjs/toolkit';

import { Concept, SkosConcept } from '../../types';
import { Concept, SearchObject } from '../../types';
import type { RootState } from '../../app/redux/store';
import {
getConceptSuggestions,
extractSuggestions
} from '../../api/search-fulltext-api/suggestions';
} from '../../api/search-api/suggestions';
import { getInternalConceptSuggestions } from '../../api/concept-catalog-api';

interface SuggestionsAttributes {
q: string;
publisherId?: string;
org?: string;
}
interface InternalSuggestionsAttributes {
query: string;
publisherId: string;
}

export const fetchConceptSuggestions = createAsyncThunk<
SkosConcept[],
SearchObject[],
SuggestionsAttributes
>('conceptForm/fetchConceptSuggestions', async ({ q, publisherId }) =>
getConceptSuggestions({ q, publisherId }).then(extractSuggestions)
>('conceptForm/fetchConceptSuggestions', async ({ q, org }) =>
getConceptSuggestions({ q, org }).then(extractSuggestions)
);

export const fetchInternalConceptSuggestions = createAsyncThunk<
Expand All @@ -37,8 +37,8 @@ export const fetchInternalConceptSuggestions = createAsyncThunk<
getInternalConceptSuggestions(publisherId, query)
);

const conceptSuggestionsAdapter = createEntityAdapter<SkosConcept>({
selectId: concept => concept.identifier
const conceptSuggestionsAdapter = createEntityAdapter<SearchObject>({
selectId: concept => concept.uri
});

const internalConceptSuggestionsAdapter = createEntityAdapter<Concept>({
Expand Down
16 changes: 7 additions & 9 deletions src/features/concepts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,25 @@ import {
createEntityAdapter
} from '@reduxjs/toolkit';

import { Concept, SkosConcept } from '../../types';
import { Concept, SearchObject } from '../../types';
import type { RootState } from '../../app/redux/store';
import {
extractConcepts,
extractInternalConcepts,
paramsToSearchBody,
searchConcepts
} from '../../api/search-fulltext-api/concepts';
} from '../../api/search-api/concepts';
import { searchInternalConcepts } from '../../api/concept-catalog-api';

interface InternalConceptFetchRequest {
catalogId: string;
values: string[];
}

export const fetchConcepts = createAsyncThunk<SkosConcept[], string[]>(
export const fetchConcepts = createAsyncThunk<SearchObject[], string[]>(
'conceptForm/fetchConcepts',
async identifiers =>
searchConcepts(paramsToSearchBody({ identifier: identifiers })).then(
extractConcepts
)
async uris =>
searchConcepts(paramsToSearchBody({ uri: uris })).then(extractConcepts)
);

export const fetchInternalConcepts = createAsyncThunk<
Expand All @@ -34,8 +32,8 @@ export const fetchInternalConcepts = createAsyncThunk<
searchInternalConcepts(catalogId, values).then(extractInternalConcepts)
);

const conceptsAdapter = createEntityAdapter<SkosConcept>({
selectId: concept => concept.identifier
const conceptsAdapter = createEntityAdapter<SearchObject>({
selectId: concept => concept.uri
});

const internalConceptsAdapter = createEntityAdapter<Concept>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const RelationItem: FC<Props> = ({
const getLabel = () =>
fieldName === 'begrepsRelasjon'
? getTranslateText(
relatedConcepts[fieldValue.value[index].relatertBegrep]?.prefLabel
relatedConcepts[fieldValue.value[index].relatertBegrep]?.title
) || 'default'
: getTranslateText(
relatedInternalConcepts[fieldValue.value[index].relatertBegrep]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const RelatedConceptsPure: FC<Props> = ({
}, [internSeOgsaaField]);

const executeConceptSuggestionSearch = (q: string, publisherId?: string) => {
dispatch(fetchConceptSuggestions({ q, publisherId }));
dispatch(fetchConceptSuggestions({ q, org: publisherId }));
};

const executeInternalConceptSuggestionSearch = (
Expand Down Expand Up @@ -127,13 +127,13 @@ const RelatedConceptsPure: FC<Props> = ({
};

const conceptSuggestionsMap = conceptSuggestions.map(
({ identifier, prefLabel, definition, publisher }) =>
({ uri, title, description, organization }) =>
({
value: identifier,
label: getTranslateText(prefLabel),
description: getTranslateText(definition?.text),
value: uri,
label: getTranslateText(title),
description: getTranslateText(description),
publisher:
getTranslateText(publisher?.prefLabel) ?? publisher?.name ?? ''
getTranslateText(organization?.prefLabel) ?? organization?.name ?? ''
} as OptionProps)
);

Expand Down Expand Up @@ -192,8 +192,7 @@ const RelatedConceptsPure: FC<Props> = ({
defaultValue={form?.values?.seOgså?.map(item => ({
value: item,
label:
getTranslateText(relatedConcepts[item]?.prefLabel) ??
'default'
getTranslateText(relatedConcepts[item]?.title) ?? 'default'
}))}
isMulti
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ export const Validity: FC<Props> = ({ catalogId }) => {
}, [internErstattesAv.value]);

const conceptSuggestionsMap = conceptSuggestions.map(
({ identifier, prefLabel, definition, publisher }) =>
({ uri, title, description, organization }) =>
({
value: identifier,
label: getTranslateText(prefLabel),
description: getTranslateText(definition?.text),
value: uri,
label: getTranslateText(title),
description: getTranslateText(description),
publisher:
getTranslateText(publisher?.prefLabel) ?? publisher?.name ?? ''
getTranslateText(organization?.prefLabel) ?? organization?.name ?? ''
} as OptionProps)
);

Expand Down Expand Up @@ -171,8 +171,7 @@ export const Validity: FC<Props> = ({ catalogId }) => {
defaultValue={form?.values?.erstattesAv?.map(item => ({
value: item,
label:
getTranslateText(relatedConcepts[item]?.prefLabel) ??
'default'
getTranslateText(relatedConcepts[item]?.title) ?? 'default'
}))}
isMulti
/>
Expand Down
Loading

0 comments on commit cbc2e9a

Please sign in to comment.