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

[7.x] Add exact match filtering to in memory tables (#81539) #81570

Merged
merged 1 commit into from
Oct 23, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { useCapabilities, useLink } from '../../../../../hooks';
import { useAgentPolicyRefresh } from '../../hooks';

interface InMemoryPackagePolicy extends PackagePolicy {
inputTypes: string[];
packageName?: string;
packageTitle?: string;
packageVersion?: string;
Expand Down Expand Up @@ -56,11 +55,7 @@ export const PackagePoliciesTable: React.FunctionComponent<Props> = ({
// With the package policies provided on input, generate the list of package policies
// used in the InMemoryTable (flattens some values for search) as well as
// the list of options that will be used in the filters dropdowns
const [packagePolicies, namespaces, inputTypes] = useMemo((): [
InMemoryPackagePolicy[],
FilterOption[],
FilterOption[]
] => {
const [packagePolicies, namespaces] = useMemo((): [InMemoryPackagePolicy[], FilterOption[]] => {
const namespacesValues: string[] = [];
const inputTypesValues: string[] = [];
const mappedPackagePolicies = originalPackagePolicies.map<InMemoryPackagePolicy>(
Expand All @@ -69,13 +64,8 @@ export const PackagePoliciesTable: React.FunctionComponent<Props> = ({
namespacesValues.push(packagePolicy.namespace);
}

const dsInputTypes: string[] = [];

dsInputTypes.sort(stringSortAscending);

return {
...packagePolicy,
inputTypes: dsInputTypes,
packageName: packagePolicy.package?.name ?? '',
packageTitle: packagePolicy.package?.title ?? '',
packageVersion: packagePolicy.package?.version ?? '',
Expand All @@ -86,11 +76,7 @@ export const PackagePoliciesTable: React.FunctionComponent<Props> = ({
namespacesValues.sort(stringSortAscending);
inputTypesValues.sort(stringSortAscending);

return [
mappedPackagePolicies,
namespacesValues.map(toFilterOption),
inputTypesValues.map(toFilterOption),
];
return [mappedPackagePolicies, namespacesValues.map(toFilterOption)];
}, [originalPackagePolicies]);

const columns = useMemo(
Expand Down Expand Up @@ -273,13 +259,7 @@ export const PackagePoliciesTable: React.FunctionComponent<Props> = ({
name: 'Namespace',
options: namespaces,
multiSelect: 'or',
},
{
type: 'field_value_selection',
field: 'inputTypes',
name: 'Input types',
options: inputTypes,
multiSelect: 'or',
operator: 'exact',
},
],
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,29 +182,50 @@ export const DataStreamListPage: React.FunctionComponent<{}> = () => {
[]
);

const filterOptions: { [key: string]: string[] } = {
const filterOptions: {
[key: string]: Array<{
value: string;
name: string;
}>;
} = {
dataset: [],
type: [],
namespace: [],
package: [],
};

if (dataStreamsData && dataStreamsData.data_streams.length) {
const dataValues: {
[key: string]: string[];
} = {
dataset: [],
type: [],
namespace: [],
package: [],
};
dataStreamsData.data_streams.forEach((stream) => {
const { dataset, type, namespace, package: pkg } = stream;
if (!filterOptions.dataset.includes(dataset)) {
filterOptions.dataset.push(dataset);
if (!dataValues.dataset.includes(dataset)) {
dataValues.dataset.push(dataset);
}
if (!filterOptions.type.includes(type)) {
filterOptions.type.push(type);
if (!dataValues.type.includes(type)) {
dataValues.type.push(type);
}
if (!filterOptions.namespace.includes(namespace)) {
filterOptions.namespace.push(namespace);
if (!dataValues.namespace.includes(namespace)) {
dataValues.namespace.push(namespace);
}
if (!filterOptions.package.includes(pkg)) {
filterOptions.package.push(pkg);
if (!dataValues.package.includes(pkg)) {
dataValues.package.push(pkg);
}
});
for (const field in dataValues) {
if (filterOptions[field]) {
filterOptions[field] = dataValues[field].sort().map((option) => ({
value: option,
name: option,
}));
}
}
}

return (
Expand Down Expand Up @@ -266,10 +287,8 @@ export const DataStreamListPage: React.FunctionComponent<{}> = () => {
defaultMessage: 'Dataset',
}),
multiSelect: 'or',
options: filterOptions.dataset.map((option) => ({
value: option,
name: option,
})),
operator: 'exact',
options: filterOptions.dataset,
},
{
type: 'field_value_selection',
Expand All @@ -278,10 +297,8 @@ export const DataStreamListPage: React.FunctionComponent<{}> = () => {
defaultMessage: 'Type',
}),
multiSelect: 'or',
options: filterOptions.type.map((option) => ({
value: option,
name: option,
})),
operator: 'exact',
options: filterOptions.type,
},
{
type: 'field_value_selection',
Expand All @@ -290,10 +307,8 @@ export const DataStreamListPage: React.FunctionComponent<{}> = () => {
defaultMessage: 'Namespace',
}),
multiSelect: 'or',
options: filterOptions.namespace.map((option) => ({
value: option,
name: option,
})),
operator: 'exact',
options: filterOptions.namespace,
},
{
type: 'field_value_selection',
Expand All @@ -302,10 +317,8 @@ export const DataStreamListPage: React.FunctionComponent<{}> = () => {
defaultMessage: 'Integration',
}),
multiSelect: 'or',
options: filterOptions.package.map((option) => ({
value: option,
name: option,
})),
operator: 'exact',
options: filterOptions.package,
},
],
}}
Expand Down