Skip to content
Open
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 @@ -90,17 +90,17 @@ describe("DetectedListView tests", () => {

describe("filtering scenarios", () => {
function getFilterNameElement() {
return screen.getByRole("searchbox", { name: /Filter by name/i }) as HTMLTextAreaElement;
}

function getFilterNameTypeElement() {
return screen.getByRole("combobox", { name: /Filter name type/i }) as HTMLSelectElement;
return screen.getByRole("searchbox", { name: /Filter by name/i }) as HTMLInputElement;
}

function getFilterUnsetCheckboxElement() {
return screen.getByRole("checkbox", { name: /Show only not set Endpoint Types/i }) as HTMLInputElement;
}

function waitForDebounce(ms: number = 1000) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

test("by name", async () => {
await renderComponent({ source: DataSource.WellKnownEndpoint }, async (driver) => {
await driver.setUp(
Expand All @@ -114,28 +114,28 @@ describe("DetectedListView tests", () => {

const user = userEvent.setup();
const filterNameElement = getFilterNameElement();
await user.type(filterNameElement, "Alpha");
await user.type(filterNameElement, "Alpha*");
await waitForDebounce();

expect(screen.queryAllByText(/Alpha\d/i).length).toBe(10);
expect(screen.queryAllByText(/\dBeta/i).length).toBe(0);
expect(screen.queryAllByText(/\dDelta\d/i).length).toBe(0);

const filterNameTypeElement = getFilterNameTypeElement();
await user.selectOptions(filterNameTypeElement, "Ends with");
await user.clear(filterNameElement);
await user.type(filterNameElement, "Beta");
await user.type(filterNameElement, "*Beta");
await waitForDebounce();

expect(screen.queryAllByText(/\dBeta/i).length).toBe(10);
expect(screen.queryAllByText(/Alpha\d/i).length).toBe(0);
expect(screen.queryAllByText(/\dDelta\d/i).length).toBe(0);

await user.selectOptions(filterNameTypeElement, "Contains");
await user.clear(filterNameElement);
await user.type(filterNameElement, "Delta");
await user.type(filterNameElement, "*Delta*");
await waitForDebounce();

expect(screen.queryAllByText(/\dDelta\d/i).length).toBe(10);
expect(screen.queryAllByText(/\dBeta/i).length).toBe(0);
expect(screen.queryAllByText(/Alpha\d/i).length).toBe(0);
expect(screen.queryAllByText(/\dBeta/i).length).toBe(0);
expect(screen.queryAllByText(/Alpha\d/i).length).toBe(0);
});

test("by unset only", async () => {
Expand Down Expand Up @@ -176,9 +176,7 @@ describe("DetectedListView tests", () => {
const filterCheckboxElement = getFilterUnsetCheckboxElement();
await user.click(filterCheckboxElement);

const filterNameTypeElement = getFilterNameTypeElement();
const filterNameElement = getFilterNameElement();
await user.selectOptions(filterNameTypeElement, "Begins with");
await user.clear(filterNameElement);
await user.type(filterNameElement, "boo");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ import ResultsCount from "@/components/ResultsCount.vue";
import { useHiddenFeature } from "./useHiddenFeature";
import { license } from "@/composables/serviceLicense";
import FAIcon from "@/components/FAIcon.vue";
import { faInfoCircle } from "@fortawesome/free-solid-svg-icons";

enum NameFilterType {
beginsWith = "Begins with",
contains = "Contains",
endsWith = "Ends with",
}
import { faInfoCircle, faAsterisk } from "@fortawesome/free-solid-svg-icons";
import FilterInput from "@/components/FilterInput.vue";

interface SortData {
text: string;
Expand Down Expand Up @@ -51,17 +46,19 @@ const props = defineProps<DetectedListViewProps>();

const data = ref<EndpointThroughputSummary[]>([]);
const dataChanges = ref(new Map<string, { indicator: string }>());
const filterData = reactive({ name: "", nameFilterType: NameFilterType.beginsWith, sort: "name", showUnsetOnly: false });
const filterNameOptions = [
{ text: NameFilterType.beginsWith, filter: (a: EndpointThroughputSummary) => a.name.toLowerCase().startsWith(filterData.name.toLowerCase()) },
{ text: NameFilterType.contains, filter: (a: EndpointThroughputSummary) => a.name.toLowerCase().includes(filterData.name.toLowerCase()) },
{ text: NameFilterType.endsWith, filter: (a: EndpointThroughputSummary) => a.name.toLowerCase().endsWith(filterData.name.toLowerCase()) },
];
const filterData = reactive({ name: "", sort: "name", showUnsetOnly: false });

const filteredData = computed(() => {
const sortItem = sortData.find((value) => value.value === filterData.sort);

return data.value
.filter((row) => !row.name || filterNameOptions.find((v) => v.text === filterData.nameFilterType)?.filter(row))
.filter((row) => {
if (!filterData.name) return true;
// Escape regex special chars except *
const escaped = filterData.name.replace(/[-[\]/{}()+?.\\^$|]/g, "\\$&").replace(/\*/g, ".*");
const regex = new RegExp(`^${escaped}$`, "i");
return regex.test(row.name);
})
.filter((row) => {
if (filterData.showUnsetOnly) {
return dataChanges.value.get(row.name)?.indicator === "";
Expand Down Expand Up @@ -103,18 +100,10 @@ async function loadData() {
data.value = results.filter((row) => row.is_known_endpoint === (props.source === DataSource.WellKnownEndpoint));
}

function nameFilterChanged(event: Event) {
filterData.name = (event.target as HTMLInputElement).value;
}

function sortChanged(item: Item) {
filterData.sort = item.value;
}

function searchTypeChanged(event: Event) {
filterData.nameFilterType = (event.target as HTMLInputElement).value as NameFilterType;
}

function updateIndicator(event: Event, name: string) {
const value = (event.target as HTMLSelectElement).value;
updateDataChanged(name, (item) => (item.indicator = value));
Expand Down Expand Up @@ -173,19 +162,17 @@ async function save() {
<div class="row filters">
<div class="col">
<div class="text-search-container">
<div>
<select class="form-select text-search format-text" aria-label="Filter name type" @change="searchTypeChanged">
<option v-for="item in filterNameOptions" :value="item.text" :key="item.text">{{ item.text }}</option>
</select>
</div>
<div>
<!-- <FilterInput v-model="filterData.name" /> TODO: this is failing a test, should replace the line below -->
<input type="search" aria-label="Filter by name" class="form-control format-text" :value="filterData.name" @input="nameFilterChanged" placeholder="Filter by name..." />
<FilterInput v-model="filterData.name" placeholder="Filter by name..." aria-label="Filter by name" />
<div class="note">
Use <FAIcon :icon="faAsterisk" size="xs" /> as a wildcard. E.g.: PRD_<FAIcon :icon="faAsterisk" size="xs" /> or <FAIcon :icon="faAsterisk" size="xs" />_PRD or <FAIcon :icon="faAsterisk" size="xs" />_PRD_<FAIcon
:icon="faAsterisk"
size="xs"
/>
</div>
</div>
</div>
<div class="col" style="align-content: center">
<div>
<div class="col">
<div class="middle-column">
<input type="checkbox" aria-label="Show only not set Endpoint Types" class="check-label" id="showUnsetOnly" @input="showUnsetChanged" />
<label for="showUnsetOnly">Show only not set Endpoint Types</label>
</div>
Expand Down Expand Up @@ -259,17 +246,13 @@ async function save() {
.formatThroughputColumn {
padding-right: 20px;
}
.format-text {
font-weight: unset;
font-size: 14px;
min-width: 120px;
}
.text-search-container {
display: flex;
flex-direction: row;
width: 25rem;
}
.text-search {
width: 130px;
.middle-column {
align-content: center;
display: flex;
padding-top: 5px;
}
.endpointType {
width: 340px;
Expand Down
Loading