Skip to content

Commit

Permalink
remove dead code and make filtering generic for id/identifier.
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasStordeur committed May 30, 2024
1 parent c69d9f5 commit 5a1139b
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 225 deletions.
4 changes: 1 addition & 3 deletions src/Core/Domain/ServiceInstanceParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ export interface Filter {
attributeSetEmpty?: AttributeSet[];
attributeSetNotEmpty?: AttributeSet[];
deleted?: DeletedRule;
id?: string[];
identity?: { key: string; value: string };
state?: string[];
id_or_service_identity?: string;
id_or_service_identity?: string[];
}

export type DeletedRule = "Include" | "Only" | undefined;
Expand All @@ -32,7 +31,6 @@ export enum Kind {
Id = "Id",
AttributeSet = "AttributeSet",
Deleted = "Deleted",
IdentityAttribute = "IdentityAttribute",
}

export const List: Kind[] = [
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Managers/ServiceInstances/getUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ test("getUrl returns correct url for empty filter", () => {
name,
filter: {
state: [],
id: [],
id_or_service_identity: [],
attributeSetEmpty: [],
attributeSetNotEmpty: [],
},
Expand Down
2 changes: 0 additions & 2 deletions src/Data/Managers/ServiceInstances/getUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type Filter = NonNullable<Query.SubQuery<"GetServiceInstances">["filter"]>;
const filterToRaw = (filter: Filter) => {
if (typeof filter === "undefined") return {};
const {
id,
state,
deleted,
attributeSetEmpty: attribute_set_empty,
Expand All @@ -43,7 +42,6 @@ const filterToRaw = (filter: Filter) => {
} = filter;

return {
id,
state,
deleted: deleted === "Only" ? true : undefined,
attribute_set_empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { words } from "@/UI/words";
import { AttributeSets, AttributesFilter } from "./AttributesFilter";
import { DeletedFilter } from "./DeletedFilter";
import { IdFilter } from "./IdFilter";
import { IdentityFilter } from "./IdentityFilter";

interface Props {
filter: ServiceInstanceParams.Filter;
Expand All @@ -20,7 +19,6 @@ export const FilterWidget: React.FC<Props> = ({
filter,
setFilter,
states,
identityAttribute,
}) => {
const [filterKind, setFilterKind] = useState<ServiceInstanceParams.Kind>(
ServiceInstanceParams.Kind.State,
Expand All @@ -31,8 +29,8 @@ export const FilterWidget: React.FC<Props> = ({

const updateId = (id?: string) =>
id
? setFilter({ ...filter, id: [id] })
: setFilter({ ...filter, id: undefined });
? setFilter({ ...filter, id_or_service_identity: [id] })
: setFilter({ ...filter, id_or_service_identity: undefined });

const updateAttributes = ({ empty, notEmpty }: AttributeSets) =>
setFilter({
Expand All @@ -44,26 +42,12 @@ export const FilterWidget: React.FC<Props> = ({
const updateDeleted = (deleted: ServiceInstanceParams.DeletedRule) =>
setFilter({ ...filter, deleted });

const updateIdentity = (value?: string) => {
setFilter({
...filter,
identity:
value && identityAttribute
? { value, key: identityAttribute.key }
: undefined,
});
};

return (
<ToolbarGroup variant="filter-group" aria-label="FilterBar" role="toolbar">
<FilterPicker
setFilterKind={setFilterKind}
filterKind={filterKind}
items={
identityAttribute?.pretty
? [...ServiceInstanceParams.List, identityAttribute.pretty]
: ServiceInstanceParams.List
}
items={ServiceInstanceParams.List}
/>
<SelectOptionFilter
isVisible={filterKind === ServiceInstanceParams.Kind.State}
Expand All @@ -75,7 +59,11 @@ export const FilterWidget: React.FC<Props> = ({
/>
<IdFilter
isVisible={filterKind === ServiceInstanceParams.Kind.Id}
id={filter.id ? filter.id[0] : undefined}
id={
filter.id_or_service_identity
? filter.id_or_service_identity[0]
: undefined
}
update={updateId}
/>
<AttributesFilter
Expand All @@ -91,16 +79,6 @@ export const FilterWidget: React.FC<Props> = ({
update={updateDeleted}
deleted={filter.deleted}
/>
{identityAttribute ? (
<IdentityFilter
identity={{
pretty: identityAttribute.pretty,
value: filter.identity?.value,
}}
isVisible={filterKind === identityAttribute.pretty}
update={updateIdentity}
/>
) : null}
</ToolbarGroup>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const IdFilter: React.FC<Props> = ({ id, isVisible, update }) => {
aria-label="IdFilter"
onChange={(_event, val) => setIdInput(val)}
value={idInput}
placeholder="Filter by id..."
placeholder="Filter by id or identifier..."
onKeyDown={onIdInput}
/>
</InputGroupItem>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ export const TableControls: React.FC<Props> = ({
const composerEnabled =
service.owner === null && featureManager.isComposerEnabled();

const { service_identity, service_identity_display_name } = service;
const identityAttribute =
service_identity && service_identity_display_name
? { key: service_identity, pretty: service_identity_display_name }
: undefined;
const states = service.lifecycle.states.map((state) => state.name).sort();

const onToggleClick = () => {
Expand Down Expand Up @@ -84,12 +79,7 @@ export const TableControls: React.FC<Props> = ({
return (
<Toolbar clearAllFilters={() => setFilter({})}>
<ToolbarContent>
<FilterWidget
filter={filter}
setFilter={setFilter}
states={states}
identityAttribute={identityAttribute}
/>
<FilterWidget filter={filter} setFilter={setFilter} states={states} />
<ToolbarGroup align={{ default: "alignRight" }}>
{composerEnabled ? (
<ToolbarItem>
Expand Down
2 changes: 1 addition & 1 deletion src/Slices/ServiceInventory/UI/Spec/IdFilter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ test("GIVEN The Service Inventory WHEN the user filters on id ('a') THEN only 1
});

expect(apiHelper.pendingRequests[0].url).toEqual(
`/lsm/v1/service_inventory/${Service.a.name}?include_deployment_progress=True&limit=20&filter.id=${ServiceInstance.a.id}&sort=created_at.desc`,
`/lsm/v1/service_inventory/${Service.a.name}?include_deployment_progress=True&limit=20&filter.id_or_service_identity=${ServiceInstance.a.id}&sort=created_at.desc`,
);

await act(async () => {
Expand Down
66 changes: 0 additions & 66 deletions src/Slices/ServiceInventory/UI/Spec/IdentityFilter.spec.ts

This file was deleted.

7 changes: 4 additions & 3 deletions src/Slices/ServiceInventory/UI/Tabs/AttributesTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ export const AttributesTab: React.FC<Props> = ({
return (
<TreeTableCellContext.Provider
value={{
onClick: (value, serviceName) =>
onClick: (value, serviceName) => {
navigate(
"Inventory",
{ service: serviceName as string },
`?env=${service?.environment}&state.Inventory.filter.id[0]=${value}`,
),
`?env=${service?.environment}&state.Inventory.filter.id_or_service_identity[0]=${value}`,
);
},
}}
>
<TreeTable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { AutoCompleteInput } from "./AutoCompleteInput";

interface Props {
serviceName: string;
serviceIdentity?: string;
attributeName: string;
attributeValue: string | string[];
description?: string;
Expand All @@ -19,7 +18,6 @@ interface Props {

export const AutoCompleteInputProvider: React.FC<Props> = ({
serviceName,
serviceIdentity,
attributeName,
attributeValue,
description,
Expand All @@ -41,21 +39,16 @@ export const AutoCompleteInputProvider: React.FC<Props> = ({
});

const onSearchTextChanged = (searchText: string) => {
setFilter({ id_or_service_identity: searchText });
setFilter({ id_or_service_identity: [searchText] });
};

const selectedValue = getCurrentValue(
attributeValue,
filter,
!!serviceIdentity,
);
return RemoteData.fold(
{
notAsked: () => null,
loading: () => (
<AutoCompleteInput
options={[]}
selected={selectedValue}
selected={attributeValue}
serviceEntity={serviceName}
attributeName={attributeName}
isOptional={isOptional}
Expand Down Expand Up @@ -85,7 +78,7 @@ export const AutoCompleteInputProvider: React.FC<Props> = ({
options={options}
attributeName={attributeName}
serviceEntity={serviceName}
selected={selectedValue}
selected={attributeValue}
isOptional={isOptional}
shouldBeDisabled={isDisabled}
description={description}
Expand All @@ -100,17 +93,3 @@ export const AutoCompleteInputProvider: React.FC<Props> = ({
data,
);
};

const getCurrentValue = (
attributeValue: string | string[],
filter: ServiceInstanceParams.Filter,
serviceIdentity?: boolean,
): string | string[] => {
if (attributeValue) {
return attributeValue;
}
if (serviceIdentity) {
return filter?.identity ? filter?.identity.value : "";
}
return filter?.id ? filter?.id[0] : "";
};
Loading

0 comments on commit 5a1139b

Please sign in to comment.