Skip to content

Commit

Permalink
Fix the rundr undersider effect by using the useEffect feature
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesVautier committed Jun 18, 2024
1 parent 2ff9395 commit 5955534
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { useRef, useState } from 'react';
import { useRef, useEffect, useState } from 'react';
import { SearchComponentProps } from '../../utils/SearchComponentProps';
import { TermAgg, HistogramAgg } from '../../utils/models';
import { Box } from '@mui/material';
Expand Down Expand Up @@ -107,13 +107,23 @@ export function AggregationKind(props: SearchComponentProps) {
const [aggregations, setAggregations] = useState<({term: TermAgg} | {histogram: HistogramAgg})[]>(
[defaultAgg]);

useEffect(() => {
// do the initial filling of parameters
const aggregationConfig = props.searchRequest.aggregationConfig;
if (aggregationConfig.histogram === null && aggregationConfig.term === null) {
const initialAggregation = Object.assign({}, ...aggregations);
const initialSearchRequest = {...props.searchRequest, aggregationConfig: initialAggregation};
props.onSearchRequestUpdate(initialSearchRequest);
}
}, []); // Empty dependency array means this runs once after mount

const updateAggregationProp = (newAggregations: ({term: TermAgg} | {histogram: HistogramAgg})[]) => {
const metric = props.searchRequest.aggregationConfig.metric;
const updatedAggregation = Object.assign({}, {metric: metric}, ...newAggregations);
const updatedSearchRequest = {...props.searchRequest, aggregationConfig: updatedAggregation};
props.onSearchRequestUpdate(updatedSearchRequest);
};

const handleAggregationChange = (pos: number, event: SelectChangeEvent) => {
const value = event.target.value;
setAggregations((agg) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ export default function SearchResult(props: SearchResultProps) {
if (props.searchResponse == null || props.index == null) {
return null;
} else if (props.searchResponse.aggregations === undefined) {
console.log("result table");
return (<ResultTable searchResponse={props.searchResponse} index={props.index} />);
} else {
console.log("aggregation result");
return (<AggregationResult searchResponse={props.searchResponse} />);
}
},
Expand Down

0 comments on commit 5955534

Please sign in to comment.