Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
112 changes: 56 additions & 56 deletions dist/ccdb5.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ccdb5.js.map

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/api/params/params.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { clamp, removeNullProperties } from '../../utils';
import {
clamp,
escapeElasticsearchCharacters,
removeNullProperties,
} from '../../utils';
import { enforceValues } from '../../utils/reducers';
// ----------------------------------------------------------------------------
// return parameter objects
Expand Down Expand Up @@ -113,7 +117,7 @@ export function extractQueryParams(queryState) {

/* istanbul ignore else */
if (query.searchText) {
params.search_term = query.searchText;
params.search_term = escapeElasticsearchCharacters(query.searchText);
}

if (query.searchAfter) {
Expand Down
4 changes: 2 additions & 2 deletions src/api/params/params.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('api.v2.params', () => {
});

it('handles search text', () => {
fixtureStore.query.searchText = 'foo';
fixtureStore.query.searchText = 'savings / loan';
actual = sut.extractAggregationParams(
fixtureStore.filters,
fixtureStore.query,
Expand All @@ -35,7 +35,7 @@ describe('api.v2.params', () => {
date_received_max: '2018-01-01',
date_received_min: '2011-07-21',
field: 'all',
search_term: 'foo',
search_term: 'savings \\/ loan',
size: 0,
});
});
Expand Down
21 changes: 6 additions & 15 deletions src/components/Search/SearchPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,13 @@ import { formatDisplayDate } from '../../utils/formatDate';
import { useGetAggregations } from '../../api/hooks/useGetAggregations';

export const SearchPanel = () => {
const { data, isLoading, isFetching } = useGetAggregations();

if (isLoading || isFetching) {
return null;
}

const { data } = useGetAggregations();
const lastIndexed = data?.lastIndexed;
let lastIndexedMessage = null;

if (lastIndexed) {
lastIndexedMessage = (
<span className="date-subscript">
(last updated: {formatDisplayDate(lastIndexed)})
</span>
);
}
const lastIndexedMessage = lastIndexed ? (
<span className="date-subscript">
(last updated: {formatDisplayDate(lastIndexed)})
</span>
) : null;

return (
<div className="search-panel">
Expand Down
8 changes: 5 additions & 3 deletions src/components/Tour/Tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useGetAggregations } from '../../api/hooks/useGetAggregations';
import { useGetMap } from '../../api/hooks/useGetMap';
import { useGetList } from '../../api/hooks/useGetList';
import { useGetTrends } from '../../api/hooks/useGetTrends';
import { isTrue } from '../../utils';

export const Tour = () => {
const dispatch = useDispatch();
Expand All @@ -33,16 +34,17 @@ export const Tour = () => {
const viewWidth = useSelector(selectViewWidth);
const stepRef = useRef();
// ORing all of these to prevent complexity warning
const isLoading = [
const isLoading = isTrue([
aggsLoading,
aggsFetching,
isPrintMode,
mapLoading,
mapFetching,
resultsLoading,
resultsFetching,
trendsLoading,
trendsFetching,
].some((val) => val);
]);

const mobileStepOpen = {
disableInteraction: false,
Expand Down Expand Up @@ -167,7 +169,7 @@ export const Tour = () => {
}
}

return isPrintMode || isLoading ? null : (
return isLoading ? null : (
<>
<TourButton />
<Steps
Expand Down
20 changes: 16 additions & 4 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,23 @@ export function formatUri(path, params) {
}

/**
* Helper function to check if any element in the array is true
* Helper function to check if any element in the array is truthy
*
* @param {Array} args - array of parameters to check against
* @param {Array} argArray - array of parameters to check against
* @returns {boolean} whether or not any value in the array is true
*/
export function isTrue(args) {
return args.includes(true);
export const isTrue = (argArray) => argArray.some((element) => !!element);

/**
* Escapes special characters in a string for use in Elasticsearch queries
*
* The reserved characters are: + - = && || > < ! ( ) { } [ ] ^ " ~ * ? : \ /
* Failing to escape these special characters correctly could lead to a syntax error which prevents your query from running.
* https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-query-string-query.html#_reserved_characters
*
* @param {string} str - The string with dirty input
* @returns {string} Sanitized escaped string
*/
export function escapeElasticsearchCharacters(str) {
return str ? str.replace(/([+\-=><!(){}[\]^"~*?:\\/]|&&|\|\|)/g, '\\$1') : '';
}