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
7 changes: 6 additions & 1 deletion ui/apps/platform/src/Containers/Collections/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
isByNameField,
isByLabelField,
selectorEntityTypes,
isSelectorField,
} from './types';

const fieldToEntityMap: Record<SelectorField, SelectorEntityType> = {
Expand Down Expand Up @@ -51,8 +52,12 @@ export function parseCollection(data: CollectionResponse): Collection | Aggregat
}

data.resourceSelectors[0]?.rules.forEach((rule) => {
const entity = fieldToEntityMap[rule.fieldName];
const field = rule.fieldName;
if (!isSelectorField(field)) {
errors.push(`An invalid field name was detected. Found field name [${field}].`);
return;
}
const entity = fieldToEntityMap[field];
const selectorScope = collection.resourceSelector[entity];
const existingEntityField = selectorScope.type === 'All' ? undefined : selectorScope.field;
const hasMultipleFieldsForEntity = existingEntityField && existingEntityField !== field;
Expand Down
4 changes: 4 additions & 0 deletions ui/apps/platform/src/Containers/Collections/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const byNameRegExp = new RegExp(`^(${selectorEntityTypes.join('|')})$`);
const byLabelRegExp = new RegExp(`^(${selectorEntityTypes.join('|')}) Label$`);
const byAnnotationRegExp = new RegExp(`^(${selectorEntityTypes.join('|')}) Annotation$`);

export function isSelectorField(field: string): field is SelectorField {
return byNameRegExp.test(field) || byLabelRegExp.test(field) || byAnnotationRegExp.test(field);
}

export function isByNameField(field: SelectorField): field is ByNameSelectorField {
return byNameRegExp.test(field);
}
Expand Down
9 changes: 2 additions & 7 deletions ui/apps/platform/src/services/CollectionsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import qs from 'qs';

import { ListDeployment } from 'types/deployment.proto';
import { SearchFilter, ApiSortOption } from 'types/search';
import { SelectorField } from 'Containers/Collections/types';
import { getListQueryParams, getRequestQueryStringForSearchFilter } from 'utils/searchUtils';
import { CancellableRequest, makeCancellableAxiosRequest } from './cancellationUtils';
import axios from './instance';
Expand All @@ -14,7 +13,7 @@ export const collectionsDryRunUrl = '/v1/collections/dryrun';
export const collectionsAutocompleteUrl = '/v1/collections/autocomplete';

export type SelectorRule = {
fieldName: SelectorField;
fieldName: string;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only other occurrence of SelectorField later in this file might be an orphan type?

export type GetCollectionSelectorsResponse = {
    selectors: SelectorField[];
};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes! Good catch, my brain is apparently still enjoying the weekend.

values: { value: string }[];
operator: 'AND' | 'OR';
};
Expand Down Expand Up @@ -96,10 +95,6 @@ export function getCollection(
);
}

export type GetCollectionSelectorsResponse = {
selectors: SelectorField[];
};

/**
* Create a new collection
*
Expand Down Expand Up @@ -213,7 +208,7 @@ export function dryRunCollection(
*/
export function getCollectionAutoComplete(
resourceSelectors: ResourceSelector[],
searchCategory: SelectorField,
searchCategory: string,
searchLabel: string
): CancellableRequest<string[]> {
const params = qs.stringify(
Expand Down