mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 17:37:37 -02:30
refactor JobOutput to use replaceNamespacedParams util
This commit is contained in:
@@ -39,12 +39,11 @@ import getRowRangePageSize from './shared/jobOutputUtils';
|
|||||||
import { getJobModel, isJobRunning } from '../../../util/jobs';
|
import { getJobModel, isJobRunning } from '../../../util/jobs';
|
||||||
import useRequest, { useDismissableError } from '../../../util/useRequest';
|
import useRequest, { useDismissableError } from '../../../util/useRequest';
|
||||||
import {
|
import {
|
||||||
encodeNonDefaultQueryString,
|
|
||||||
parseQueryString,
|
parseQueryString,
|
||||||
mergeParams,
|
mergeParams,
|
||||||
replaceParams,
|
|
||||||
removeParams,
|
removeParams,
|
||||||
getQSConfig,
|
getQSConfig,
|
||||||
|
replaceNamespacedParams,
|
||||||
} from '../../../util/qs';
|
} from '../../../util/qs';
|
||||||
import useIsMounted from '../../../util/useIsMounted';
|
import useIsMounted from '../../../util/useIsMounted';
|
||||||
|
|
||||||
@@ -589,35 +588,47 @@ function JobOutput({ job, eventRelatedSearchableKeys, eventSearchableKeys }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSearch = (key, value) => {
|
const handleSearch = (key, value) => {
|
||||||
let params = parseQueryString(QS_CONFIG, location.search);
|
const params = parseQueryString(QS_CONFIG, location.search);
|
||||||
params = mergeParams(params, { [key]: value });
|
const qs = replaceNamespacedParams(
|
||||||
pushHistoryState(params);
|
QS_CONFIG,
|
||||||
|
location.search,
|
||||||
|
mergeParams(params, { [key]: value })
|
||||||
|
);
|
||||||
|
pushHistoryState(qs);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleReplaceSearch = (key, value) => {
|
const handleReplaceSearch = (key, value) => {
|
||||||
const oldParams = parseQueryString(QS_CONFIG, location.search);
|
const qs = replaceNamespacedParams(QS_CONFIG, location.search, {
|
||||||
pushHistoryState(replaceParams(oldParams, { [key]: value }));
|
[key]: value,
|
||||||
|
});
|
||||||
|
pushHistoryState(qs);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRemoveSearchTerm = (key, value) => {
|
const handleRemoveSearchTerm = (key, value) => {
|
||||||
let oldParams = parseQueryString(QS_CONFIG, location.search);
|
const oldParams = parseQueryString(QS_CONFIG, location.search);
|
||||||
if (parseInt(value, 10)) {
|
const updatedParams = removeParams(QS_CONFIG, oldParams, {
|
||||||
oldParams = removeParams(QS_CONFIG, oldParams, {
|
[key]: value,
|
||||||
[key]: parseInt(value, 10),
|
});
|
||||||
});
|
const qs = replaceNamespacedParams(
|
||||||
}
|
QS_CONFIG,
|
||||||
pushHistoryState(removeParams(QS_CONFIG, oldParams, { [key]: value }));
|
location.search,
|
||||||
|
updatedParams
|
||||||
|
);
|
||||||
|
pushHistoryState(qs);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRemoveAllSearchTerms = () => {
|
const handleRemoveAllSearchTerms = () => {
|
||||||
const oldParams = parseQueryString(QS_CONFIG, location.search);
|
const oldParams = parseQueryString(QS_CONFIG, location.search);
|
||||||
pushHistoryState(removeParams(QS_CONFIG, oldParams, { ...oldParams }));
|
Object.keys(oldParams).forEach(key => {
|
||||||
|
oldParams[key] = null;
|
||||||
|
});
|
||||||
|
const qs = replaceNamespacedParams(QS_CONFIG, location.search, oldParams);
|
||||||
|
pushHistoryState(qs);
|
||||||
};
|
};
|
||||||
|
|
||||||
const pushHistoryState = params => {
|
const pushHistoryState = qs => {
|
||||||
const { pathname } = history.location;
|
const { pathname } = history.location;
|
||||||
const encodedParams = encodeNonDefaultQueryString(QS_CONFIG, params);
|
history.push(qs ? `${pathname}?${qs}` : pathname);
|
||||||
history.push(encodedParams ? `${pathname}?${encodedParams}` : pathname);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderSearchComponent = () => (
|
const renderSearchComponent = () => (
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
import { useEffect, useState, useCallback } from 'react';
|
import { useEffect, useState, useCallback } from 'react';
|
||||||
import { useLocation, useHistory } from 'react-router-dom';
|
import { useLocation, useHistory } from 'react-router-dom';
|
||||||
import {
|
import { parseQueryString, replaceNamespacedParams } from './qs';
|
||||||
parseQueryString,
|
|
||||||
replaceParams,
|
|
||||||
encodeNonDefaultQueryString,
|
|
||||||
replaceNamespacedParams,
|
|
||||||
} from './qs';
|
|
||||||
import useIsMounted from './useIsMounted';
|
import useIsMounted from './useIsMounted';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user