Skip to content

Commit

Permalink
Add search bar to pivot UI (#4108)
Browse files Browse the repository at this point in the history
* initial search progress

* sidebar recalc fix

* remove console log
  • Loading branch information
briangregoryholmes authored and nishantmonu51 committed Feb 22, 2024
1 parent 793783a commit 9bbef82
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
10 changes: 8 additions & 2 deletions web-common/src/features/dashboards/pivot/PivotDrag.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import CaretDownIcon from "@rilldata/web-common/components/icons/CaretDownIcon.svelte";
import DragList from "./DragList.svelte";
import type { PivotSidebarSection, PivotChipData } from "./types";
import { beforeUpdate } from "svelte";
import { afterUpdate } from "svelte";
</script>

<script lang="ts">
Expand All @@ -12,8 +12,9 @@
let container: HTMLDivElement;
beforeUpdate(() => {
afterUpdate(() => {
if (!container) return;
console.log("bottom");
calculateSize(container);
});
Expand Down Expand Up @@ -67,6 +68,11 @@
@apply pt-3 px-4;
@apply flex flex-col gap-1 items-start;
@apply w-full overflow-hidden flex-grow-0;
@apply border-b border-slate-200;
}
.container:last-child {
@apply border-b-0;
}
button {
Expand Down
39 changes: 33 additions & 6 deletions web-common/src/features/dashboards/pivot/PivotSidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import PivotDrag from "./PivotDrag.svelte";
import { getAllowedTimeGrains } from "@rilldata/web-common/lib/time/grains";
import { PivotChipType } from "./types";
// import { SearchIcon } from "lucide-svelte";
import type { PivotChipData } from "./types";
import Search from "@rilldata/web-common/components/icons/Search.svelte";
const stateManagers = getStateManagers();
const {
selectors: {
Expand All @@ -14,6 +16,9 @@
const timeControlsStore = useTimeControlStore(getStateManagers());
let inputEl: HTMLInputElement;
let searchText = "";
$: allTimeGrains = getAllowedTimeGrains(
new Date($timeControlsStore.timeStart!),
new Date($timeControlsStore.timeEnd!),
Expand All @@ -32,18 +37,40 @@
$: timeGrainOptions = allTimeGrains.filter(
(tgo) => !usedTimeGrains.some((utg) => utg.id === tgo.id),
);
$: filteredMeasures = filterBasedOnSearch($measures, searchText);
$: filteredDimensions = filterBasedOnSearch($dimensions, searchText);
function filterBasedOnSearch(fullList: PivotChipData[], search: string) {
return fullList.filter((d) =>
d.title.toLowerCase().includes(search.toLowerCase()),
);
}
</script>

<div class="sidebar">
<PivotDrag title="Time" items={timeGrainOptions} />
<div
class="flex w-full items-center p-2 h-[34px] gap-x-2 border-b border-slate-200"
>
<button on:click={() => inputEl.focus()}>
<Search size="16px" />
</button>

<span class="splitter" />
<input
bind:value={searchText}
bind:this={inputEl}
type="text"
placeholder="Search"
class="w-full h-full"
/>
</div>

<PivotDrag title="Measures" items={$measures} />
<PivotDrag title="Time" items={timeGrainOptions} />

<span class="splitter" />
<PivotDrag title="Measures" items={filteredMeasures} />

<PivotDrag title="Dimensions" items={$dimensions} />
<PivotDrag title="Dimensions" items={filteredDimensions} />
</div>

<style lang="postcss">
Expand Down

2 comments on commit 9bbef82

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉 Published on https://ui.rilldata.com as production
🚀 Deployed on https://65d6cfedec150551e23c14e1--rill-ui.netlify.app

Please sign in to comment.