-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #829 from rainlanguage/2024-09-03-order-filtering-…
…by-watchlist Order filtering by watchlist
- Loading branch information
Showing
15 changed files
with
306 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
tauri-app/src/lib/components/dropdown/DropdownCheckbox.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<script lang="ts"> | ||
import { createEventDispatcher } from 'svelte'; | ||
import { Button, Dropdown, Label, Checkbox } from 'flowbite-svelte'; | ||
import { ChevronDownSolid } from 'flowbite-svelte-icons'; | ||
import { isEmpty } from 'lodash'; | ||
const dispatch = createEventDispatcher(); | ||
export let options: Record<string, string> = {}; | ||
export let value: Record<string, string> = {}; | ||
export let label: string = 'Select items'; | ||
export let allLabel: string = 'All items'; | ||
export let emptyMessage: string = 'No items available'; | ||
$: selectedCount = Object.keys(value).length; | ||
$: allSelected = selectedCount === Object.keys(options).length; | ||
$: buttonText = | ||
selectedCount === 0 | ||
? 'Select items' | ||
: allSelected | ||
? allLabel | ||
: `${selectedCount} item${selectedCount > 1 ? 's' : ''}`; | ||
function updateValue(newValue: Record<string, string>) { | ||
value = newValue; | ||
dispatch('change', value); | ||
} | ||
function toggleAll() { | ||
updateValue(allSelected ? {} : { ...options }); | ||
} | ||
function toggleItem(key: string) { | ||
const newValue = { ...value }; | ||
if (key in newValue) { | ||
delete newValue[key]; | ||
} else { | ||
newValue[key] = options[key]; | ||
} | ||
updateValue(newValue); | ||
} | ||
</script> | ||
|
||
<Label>{label}</Label> | ||
<div> | ||
<Button | ||
color="alternative" | ||
class="flex w-full justify-between overflow-hidden pl-2 pr-0 text-left" | ||
data-testid="dropdown-checkbox-button" | ||
> | ||
<div class="w-[90px] overflow-hidden text-ellipsis whitespace-nowrap"> | ||
{buttonText} | ||
</div> | ||
<ChevronDownSolid class="mx-2 h-3 w-3 text-black dark:text-white" /> | ||
</Button> | ||
|
||
<Dropdown class="w-full min-w-72 py-0" data-testid="dropdown-checkbox"> | ||
{#if isEmpty(options)} | ||
<div class="ml-2 w-full rounded-lg p-3">{emptyMessage}</div> | ||
{:else if Object.keys(options).length > 1} | ||
<Checkbox | ||
data-testid="dropdown-checkbox-option" | ||
class="w-full rounded-lg p-3 hover:bg-gray-100 dark:hover:bg-gray-600" | ||
on:click={toggleAll} | ||
checked={allSelected} | ||
> | ||
<div class="ml-2">{allLabel}</div> | ||
</Checkbox> | ||
{/if} | ||
|
||
{#each Object.entries(options) as [key, optionValue]} | ||
<Checkbox | ||
data-testid="dropdown-checkbox-option" | ||
class="w-full rounded-lg p-3 hover:bg-gray-100 dark:hover:bg-gray-600" | ||
on:click={() => toggleItem(key)} | ||
checked={key in value} | ||
> | ||
<div class="ml-2"> | ||
<div class="text-sm font-medium">{key}</div> | ||
<div class="text-xs text-gray-500">{optionValue}</div> | ||
</div> | ||
</Checkbox> | ||
{/each} | ||
</Dropdown> | ||
</div> |
14 changes: 14 additions & 0 deletions
14
tauri-app/src/lib/components/dropdown/DropdownOrderListWatchlist.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script lang="ts"> | ||
import { watchlist, activeWatchlistItems } from '$lib/stores/settings'; | ||
import DropdownCheckbox from './DropdownCheckbox.svelte'; | ||
$: options = $watchlist; | ||
</script> | ||
|
||
<DropdownCheckbox | ||
{options} | ||
bind:value={$activeWatchlistItems} | ||
label="Watchlist" | ||
allLabel="All addresses" | ||
emptyMessage="No watchlist added" | ||
/> |
Oops, something went wrong.