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

basic search functionality from probe search service #594

Closed
wants to merge 1 commit into from
Closed
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: 3 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"d3-time-format": "2.2.3",
"flexsearch": "0.6.30",
"page": "1.11.6",
"throttle-debounce": "^2.2.1",
"udgl": "file:src/udgl/"
},
"scripts": {
Expand Down
5 changes: 5 additions & 0 deletions public/static/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@

--content-border-radius: var(--space-2x);
--main-content-width: 1200px;

--alert-notice-item-padding: var(--space-2x);
--alert-notice-background: var(--bright-yellow-100);
--alert-notice-border: 1px solid var(--bright-yellow-500);
--alert-notice-text-color: var(--bright-yellow-700);
}

html,
Expand Down
8 changes: 4 additions & 4 deletions src/components/controls/AlertNotice.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
position: fixed;
left: var(--space-6x);
bottom: var(--space-6x);
border: 1px solid var(--bright-yellow-500);
background-color: var(--bright-yellow-100);
color: var(--bright-yellow-700);
border: var(--alert-notice-border);
background-color: var(--alert-notice-background);
color: var(--alert-notice-text-color);
border-radius: var(--border-radius-base);
padding: var(--space-2x);
padding: var(--alert-notice-item-padding);
box-shadow: var(--depth-small);
z-index: 10;
}
Expand Down
136 changes: 96 additions & 40 deletions src/components/search/Search.svelte
Original file line number Diff line number Diff line change
@@ -1,41 +1,73 @@
<script>
import { tick } from 'svelte';
import { tick } from 'svelte';
import { fly } from 'svelte/transition';
import { cubicOut } from 'svelte/easing';
import SearchIcon from 'udgl/icons/Search.svelte';
import LineSegSpinner from 'udgl/LineSegSpinner.svelte';

import {
store,
} from '../../state/store';


import telemetrySearch from '../../state/telemetry-search';
import { throttle } from 'throttle-debounce';

import TelemetrySearchResults from './SearchResults.svelte';


let inputElement;
let searchContainer;
let results = [];
let searchIsActive = false;
let searchQuery = '';
const SEARCH_THROTTLE_TIME = 500; // how often to send the PSS fetch (in ms)

function turnOnSearch() {
store.setField('searchIsActive', true);
searchIsActive = true;
}

function unfocus() {
inputElement.blur();
store.setField('searchIsActive', false);
inputElement.blur();
searchIsActive = false;
}

async function onKeypress(event) {
if ($store.searchIsActive) {
const { key } = event;
if (key === 'Escape') {
await tick();
unfocus();
}
if (searchIsActive) {
const { key } = event;
if (key === 'Escape') {
await tick();
unfocus();
}
}
}

const domain = (str, product = 'desktop') => {
Copy link
Contributor

Choose a reason for hiding this comment

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

just to note what we discussed over zoom:

  1. let's move this + the probeSearchService function over to api.js
  2. let's decompose the domain function into its constituent parts so it is easier to reason about it

const formattedStr = str.replace(' ', '%20');
return `https://dev.probe-search.nonprod.dataops.mozgcp.net/probes?limit=15&select=name,definition,type&product=eq.${product}&or=(name.eq.${formattedStr},index.phfts(english).${formattedStr},description.phfts(english).${formattedStr},name.ilike.${formattedStr}%)`;
Copy link
Contributor

Choose a reason for hiding this comment

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

more follow-up from chatting:

(1) the ilike is technically not doing anything. Moving it to name.ilike.*${formattedStr}* will fix it
(2) adding &type=neq.event after the product-eq statement will filter out events, which I think we need here (we should not be returning events)

Copy link
Member

Choose a reason for hiding this comment

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

I would suggest making the base URL for the probe-search service to be configurable in some way. At some point we may have multiple instances for dev & prod.

};

function probeSearchServiceRequest(str) {
return results = fetch(domain(str)).then((r) => {
if (r.ok) return r.json();
return r;
});
}

let searchResults = Promise.resolve([]);
let query = '';

const handleSearchInput = throttle(SEARCH_THROTTLE_TIME, ({target: {value}}) => {
query = value;
searchResults = probeSearchServiceRequest(query).then((r) => {
// sort these?
if (r.constructor === Array) {
results = r.sort((a, b) => {
const aHas = a.name.toLowerCase().includes(query);
const bHas = b.name.toLowerCase().includes(query);
if (aHas && !bHas) return -1;
if (bHas && !aHas) return 1;
return 0;
});
} else {
results = r;
}
});
searchIsActive = true;
}, false);
</script>

<style>
Expand All @@ -62,15 +94,14 @@ async function onKeypress(event) {
align-items: stretch;
background-color: var(--input-background-color);
border-radius: var(--space-1h);

position: relative;
}

.icon-container {
position: relative;
display: grid;
align-items: center;
justify-items: center;

}

.icon {
Expand Down Expand Up @@ -101,47 +132,72 @@ async function onKeypress(event) {
border: 2px solid var(--input-focus-border-color);
transition: border 200ms;
}

.search-error-notice {
position: absolute;
padding: var(--alert-notice-item-padding);
background-color: var(--alert-notice-background);
border: var(--alert-notice-border);
border-radius: var(--border-radius-base);
color: var(--alert-notice-text-color);
font-size: var(--text-015);
top: 0;
left: 102%;
white-space: nowrap;
z-index: 10;
box-shadow: var(--depth-small);
}
</style>

<svelte:window on:keydown={onKeypress} />
<svelte:body on:click={(evt) => {
if ($store.searchIsActive) {
if (searchIsActive) {
if (evt.target !== inputElement) {
inputElement.blur();
store.setField('searchIsActive', false);
searchIsActive = false;
}
}
}}></svelte:body>

<div class=search-container>
<div class=inner-container bind:this={searchContainer}
aria-expanded={!!($store.searchIsActive && $store.searchQuery.length)}
<div class="search-container">
<div class="inner-container" bind:this={searchContainer}
aria-expanded={searchIsActive && searchQuery.length}
aria-haspopup="listbox"
aria-owns="telemetry-search-results"
>
<div class=icon-container>
{#if $telemetrySearch.loaded}
<div class=icon in:fly={{ y: -10, duration: 100 }}>
<div class="icon-container">
<div class="icon" in:fly={{ y: -10, duration: 100 }}>
<SearchIcon />
</div>
{:else}
<div class=icon transition:fly={{ y: -10, duration: 100 }}>
<LineSegSpinner />
</div>
{/if}
</div>
<input
<input
type="search"
aria-autocomplete="list"
aria-controls="telemetry-search-results"
aria-controls="telemetry-search-results"
on:focus={turnOnSearch}
bind:this={inputElement}
placeholder="search for a telemetry probe"
value={$store.searchQuery} on:input={(evt) => {
store.setField('searchQuery', evt.target.value);
store.setField('searchIsActive', true);
}} />
</div>
value={searchQuery}
on:input={handleSearchInput}
/>
{#if results.status}
<div
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I would expect the error message in the search results area, not off to the side specifically. I would also expect it to be probably not yellow but kind of more in-line with our other error message.

class="search-error-notice"
transition:fly={{ y: 10, duration: 200, easing: cubicOut }}
>
Probe search failed with status {results.status}
</div>
{/if}
</div>
</div>

<TelemetrySearchResults parentElement={searchContainer} />
{#if results.constructor === Array}
<TelemetrySearchResults
{query}
{results}
bind:searchIsActive
parentElement={searchContainer}
/>
{/if}


Loading