Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UHF-8081: Add sentry to react apps #765

Merged
merged 19 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8f8d077
UHF-8081: UHF-8081: add sentry react package.
Jussiles Sep 5, 2023
34f2a47
UHF-8081: UHF-8081: add sentry init.
Jussiles Sep 6, 2023
0889ff5
UHF-8081: UHF-8081: remove react_app envs. Cleaning.
Jussiles Sep 6, 2023
51c0636
UHF-8081: UHF-8081: cleaning.
Jussiles Sep 6, 2023
b5241fb
UHF-8081: UHF-8081: move sentry init to common helpers. Add it to dis…
Jussiles Sep 6, 2023
8c46a05
UHF-8081: UHF-8081: refactoring.
Jussiles Sep 6, 2023
0edfed7
UHF-8081: UHF-8081: add package-lock and dist.
Jussiles Sep 6, 2023
e36b579
UHF-8081: UHF-8081: add sentry to school search.
Jussiles Sep 7, 2023
19224a2
UHF-8081: UHF-8081: add sentry to news search. Modify no results and …
Jussiles Sep 7, 2023
3309ef4
UHF-8081: UHF-8081: clean news search.
Jussiles Sep 7, 2023
8cc0506
UHF-8081: UHF-8081: clean and add sentry exception to job search.
Jussiles Sep 7, 2023
baca2a1
UHF-8081: Add package-lock and dist.
Jussiles Sep 7, 2023
d55733b
UHF-8081: UHF-8081: catch errors when initializing search. Cleaning.
Jussiles Sep 7, 2023
6734a19
UHF-8081: UHF-8081: add better error handling to project and district…
Jussiles Sep 7, 2023
92609b9
UHF-8081: UHF-8081: Add ResultsError common component.
Jussiles Sep 8, 2023
bc15233
UHF-8081: UHF-8081: Cleaning.
Jussiles Sep 8, 2023
aadfe7d
UHF-8081: UHF-8081: add initialization error.
Jussiles Sep 8, 2023
b7294dc
UHF-8081: MErge main into UHF-8081-add-sentry-to-react-apps. Fix conf…
Jussiles Sep 8, 2023
eb70302
UHF-8081: UHF-8081: fix conflicted district and project search file. …
Jussiles Sep 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/js/district-and-project-search.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/job-search.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/news-archive.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/school-search.min.js

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions hdbt.theme
Original file line number Diff line number Diff line change
Expand Up @@ -1632,11 +1632,6 @@ function hdbt_preprocess_paragraph__job_search(array &$variables) {
}
}

$config = \Drupal::config('elastic_proxy.settings');
if ($config->get('elastic_proxy_url')) {
$variables['#attached']['drupalSettings']['helfi_rekry_job_search']['elastic_proxy_url'] = $config->get('elastic_proxy_url');
}

$variables['#attached']['library'][] = 'hdbt/job-search';
}

Expand Down
375 changes: 241 additions & 134 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"dependencies": {
"@nuxt/friendly-errors-webpack-plugin": "^2.5.1",
"@sentry/react": "^7.66.0",
"@sideway/address": "^5.0.0",
"@sideway/formula": "^3.0.0",
"@sideway/pinpoint": "^2.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { LoadingSpinner } from 'hds-react';
import { useAtomValue, useSetAtom } from 'jotai';
import useSWR from 'swr';
import { SyntheticEvent, createRef } from 'react';

import Pagination from '@/react/common/Pagination';
import useScrollToResults from '@/react/common/hooks/useScrollToResults';
import LoadingOverlay from '@/react/common/LoadingOverlay';
import ResultsError from '@/react/common/ResultsError';
import ResultCard from '../components/results/ResultCard';
import ResultsSort from '../components/results/ResultsSort';
import { configurationsAtom, pageAtom, setPageAtom, urlAtom } from '../store';
Expand All @@ -12,7 +14,6 @@ import Global from '../enum/Global';
import Settings from '../enum/Settings';
import type URLParams from '../types/URLParams';
import Result from '../types/Result';
import useScrollToResults from '@/react/common/hooks/useScrollToResults';

const ResultsContainer = (): JSX.Element => {
const { size } = Global;
Expand All @@ -27,8 +28,8 @@ const ResultsContainer = (): JSX.Element => {
useScrollToResults(scrollTarget, choices);

const fetcher = () => {
const proxyUrl = drupalSettings?.helfi_kymp_district_project_search?.elastic_proxy_url;
const url: string | undefined = proxyUrl || process.env.REACT_APP_ELASTIC_URL;
const proxyUrl = drupalSettings?.helfi_react_search?.elastic_proxy_url;
const url: string | undefined = proxyUrl;

return fetch(`${url}/${Settings.INDEX}/_search`, {
method: 'POST',
Expand All @@ -43,9 +44,22 @@ const ResultsContainer = (): JSX.Element => {
revalidateOnFocus: false,
});


if (!data && !error) {
return <LoadingSpinner loadingText="" loadingFinishedText="" />;
return (
<div className='hdbt__loading-wrapper'>
<LoadingOverlay />
</div>
);
}

if (error || initializationError) {
return (
<ResultsError
error={error || initializationError}
className='district-project-search__results'
ref={scrollTarget}
/>
);
}

if (!data?.hits?.hits.length) {
Expand All @@ -64,15 +78,6 @@ const ResultsContainer = (): JSX.Element => {
const pages = Math.floor(total / size);
const addLastPage = total > size && total % size;

if (error || initializationError) {
console.warn(`Error loading data. ${ error || initializationError}`);
return (
<div className='district-project-search__results' ref={scrollTarget}>
{Drupal.t('The website encountered an unexpected error. Please try again later.')}
</div>
);
}

const updatePage = (e: SyntheticEvent<HTMLButtonElement>, index: number) => {
e.preventDefault();
setPage(index.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@

import { LoadingSpinner } from 'hds-react';
import { Suspense } from 'react';

import LoadingOverlay from '@/react/common/LoadingOverlay';
import FormContainer from './FormContainer';
import ResultsContainer from './ResultsContainer';

const SearchContainer = ():JSX.Element => (
<>
{/* For async atoms that need to load option values from elastic */}
<Suspense fallback={<LoadingSpinner loadingText="" loadingFinishedText="" />}>
<Suspense fallback={
<div className='hdbt__loading-wrapper'>
<LoadingOverlay />
</div>
}>
<FormContainer />
<ResultsContainer />
</Suspense>
Expand Down
3 changes: 3 additions & 0 deletions src/js/react/apps/district-and-project-search/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom';

import initSentry from '@/react/common/helpers/Sentry';
import SearchContainer from './containers/SearchContainer';

initSentry();

const rootSelector: string = 'helfi-kymp-district-project-search';
const rootElement: HTMLElement | null = document.getElementById(rootSelector);

Expand Down
12 changes: 8 additions & 4 deletions src/js/react/apps/district-and-project-search/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export const setPageAtom = atom(null, (get, set, page: string) => {
export const pageAtom = atom((get) => Number(get(urlAtom)?.page) || 1);

export const configurationsAtom = atom(async(): Promise<configurations> => {
const proxyUrl = drupalSettings?.helfi_kymp_district_project_search.elastic_proxy_url;
const url: string | undefined = proxyUrl || process.env.REACT_APP_ELASTIC_URL;
const proxyUrl = drupalSettings?.helfi_react_search.elastic_proxy_url;
const url: string | undefined = proxyUrl;

const body = JSON.stringify(AGGREGATIONS);

Expand All @@ -96,15 +96,19 @@ export const configurationsAtom = atom(async(): Promise<configurations> => {
error: new Error(
'Initialization failed.'
),
aggs:{}
aggs: {}
};
}

return {
error: null,
aggs: aggregations
};
});
})
.catch(error => ({
error,
aggs: {}
}));
});

export const titleAtom = atom('');
Expand Down
22 changes: 11 additions & 11 deletions src/js/react/apps/job-search/components/results/ResultsList.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import Job from '../../types/Job';
import Result from '@/types/Result';
import Job from '../../types/Job';
import ResultCard from './ResultCard';

type ResultsListProps = {
hits: Result<Job>[]
};

const ResultsList = ({ hits }: ResultsListProps) => (
<>
{hits.map(hit => (
<ResultCard
key={hit._id}
innerHits={hit?.inner_hits.translations.hits.hits || null}
job={hit._source}
/>
))}
</>
);
<>
{hits.map(hit => (
<ResultCard
key={hit._id}
innerHits={hit?.inner_hits.translations.hits.hits || null}
job={hit._source}
/>
))}
</>
);

export default ResultsList;
2 changes: 1 addition & 1 deletion src/js/react/apps/job-search/containers/FormContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Button, Checkbox, Select, TextInput } from 'hds-react';
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
import React, { useEffect } from 'react';

import bucketToMap from '@/react/common/helpers/Aggregations';
import CustomIds from '../enum/CustomTermIds';
import SearchComponents from '../enum/SearchComponents';
import bucketToMap from '@/react/common/helpers/Aggregations';
import { getInitialLanguage } from '../helpers/Language';
import transformDropdownsValues from '../helpers/Params';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { useAtomValue, useSetAtom } from 'jotai';
import { SyntheticEvent, createRef } from 'react';

import Pagination from '@/react/common/Pagination';
import ResultWrapper from '@/react/common/ResultWrapper';
import useScrollToResults from '@/react/common/hooks/useScrollToResults';
import ResultsError from '@/react/common/ResultsError';
import Global from '../enum/Global';
import URLParams from '../types/URLParams';
import { configurationsAtom, pageAtom, setPageAtom, urlAtom } from '../store';
import usePromotedQuery from '../hooks/usePromotedQuery';
import useIndexQuery from '../hooks/useIndexQuery';
import NoResults from '../components/results/NoResults';
import ResultsError from '../components/results/ResultsError';
import IndexFields from '../enum/IndexFields';
import ResultsSort from '../components/results/ResultsSort';
import ResultsCount from '../components/results/ResultsCount';
import ResultsList from '../components/results/ResultsList';
import Pagination from '@/react/common/Pagination';
import ResultWrapper from '@/react/common/ResultWrapper';
import useScrollToResults from '@/react/common/hooks/useScrollToResults';

const PromotedResultsContainer = () => {
const { size } = Global;
Expand Down Expand Up @@ -44,10 +45,11 @@ const PromotedResultsContainer = () => {
return;
}

if (error || initializationError|| data.error) {
if (error || initializationError || data.error) {
return (
<ResultsError
error={error||initializationError||data.error}
error={error || initializationError || data.error}
className='job-search__results'
ref={scrollTarget}
/>
);
Expand Down
16 changes: 8 additions & 8 deletions src/js/react/apps/job-search/containers/SearchContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import FormContainer from './FormContainer';
import ResultsContainer from './ResultsContainer';

const SearchContainer = () => (
<div className='recruitment-search'>
{/* For async atoms that need to load option values from elastic */}
<Suspense fallback={<LoadingSpinner loadingText="" loadingFinishedText="" />}>
<FormContainer />
{!drupalSettings?.helfi_rekry_job_search?.results_page_path && <ResultsContainer />}
</Suspense>
</div>
);
<div className='recruitment-search'>
{/* For async atoms that need to load option values from elastic */}
<Suspense fallback={<LoadingSpinner loadingText="" loadingFinishedText="" />}>
<FormContainer />
{!drupalSettings?.helfi_rekry_job_search?.results_page_path && <ResultsContainer />}
</Suspense>
</div>
);

export default SearchContainer;
23 changes: 15 additions & 8 deletions src/js/react/apps/job-search/containers/SimpleResultsContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { useAtomValue, useSetAtom } from 'jotai';
import { SyntheticEvent, createRef } from 'react';

import Pagination from '@/react/common/Pagination';
import ResultWrapper from '@/react/common/ResultWrapper';
import useScrollToResults from '@/react/common/hooks/useScrollToResults';
import ResultsError from '@/react/common/ResultsError';
import URLParams from '../types/URLParams';
import { urlAtom , configurationsAtom, pageAtom, setPageAtom } from '../store';
import useQueryString from '../hooks/useQueryString';
import useIndexQuery from '../hooks/useIndexQuery';
import ResultsCount from '../components/results/ResultsCount';
import NoResults from '../components/results/NoResults';
import ResultsError from '../components/results/ResultsError';
import ResultsSort from '../components/results/ResultsSort';
import Pagination from '@/react/common/Pagination';
import ResultsList from '../components/results/ResultsList';
import Global from '../enum/Global';
import IndexFields from '../enum/IndexFields';
import ResultWrapper from '@/react/common/ResultWrapper';
import useScrollToResults from '@/react/common/hooks/useScrollToResults';

const SimpleResultsContainer = () => {
const { size } = Global;
Expand All @@ -38,12 +39,18 @@ const SimpleResultsContainer = () => {
return;
}

if (!data?.hits?.hits.length) {
return <NoResults ref={scrollTarget} />;
if (error || initializationError) {
return (
<ResultsError
error={error || initializationError}
className='job-search__results'
ref={scrollTarget}
/>
);
}

if (error || initializationError) {
return <ResultsError error={error||initializationError} ref={scrollTarget}/>;
if (!data?.hits?.hits.length) {
return <NoResults ref={scrollTarget} />;
}

const results = data.hits.hits;
Expand Down
4 changes: 2 additions & 2 deletions src/js/react/apps/job-search/hooks/useIndexQuery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ type UseIndexQueryProps = {

const useIndexQuery = ({ query, multi, ...rest }: UseIndexQueryProps) => {
const fetcher = () => {
const proxyUrl = drupalSettings?.helfi_rekry_job_search?.elastic_proxy_url;
const url: string|undefined = proxyUrl || process.env.REACT_APP_ELASTIC_URL;
const proxyUrl = drupalSettings?.helfi_react_search?.elastic_proxy_url;
const url: string|undefined = proxyUrl;
const endpoint = multi ? '_msearch' : '_search';
const contentType = `application/${multi ? 'x-ndjson' : 'json'}`;

Expand Down
3 changes: 3 additions & 0 deletions src/js/react/apps/job-search/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom';

import initSentry from '@/react/common/helpers/Sentry';
import SearchContainer from './containers/SearchContainer';

initSentry();

const rootSelector: string = 'helfi-rekry-job-search';
const rootElement: HTMLElement | null = document.getElementById(rootSelector);

Expand Down
Loading