-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into user-metadata
- Loading branch information
Showing
8 changed files
with
223 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<script lang="ts"> | ||
import { page } from '$app/stores'; | ||
import Combobox from '$lib/holocene/combobox/combobox.svelte'; | ||
import { translate } from '$lib/i18n/translate'; | ||
import { lastUsedNamespace } from '$lib/stores/namespaces'; | ||
import type { NamespaceListItem } from '$lib/types/global'; | ||
import { routeForNamespace } from '$lib/utilities/route-for'; | ||
export let namespaceList: NamespaceListItem[] = []; | ||
$: namespace = $page.params.namespace || $lastUsedNamespace; | ||
$: namespaceExists = namespaceList.some( | ||
(namespaceListItem) => namespaceListItem.namespace === namespace, | ||
); | ||
$: href = routeForNamespace({ namespace }); | ||
const handleNamespaceSelect = ( | ||
event: CustomEvent<{ value: NamespaceListItem }>, | ||
) => { | ||
const namespaceListItem = event.detail.value; | ||
$lastUsedNamespace = namespaceListItem.namespace; | ||
namespaceListItem?.onClick(namespaceListItem.namespace); | ||
}; | ||
</script> | ||
|
||
<Combobox | ||
label={translate('namespaces.namespace-label', { namespace })} | ||
noResultsText={translate('common.no-results')} | ||
labelHidden | ||
value={namespace} | ||
id="namespace-switcher" | ||
leadingIcon="namespace-switcher" | ||
options={namespaceList} | ||
optionValueKey="namespace" | ||
on:change={handleNamespaceSelect} | ||
minSize={32} | ||
actionTooltip={translate('namespaces.go-to-namespace')} | ||
{href} | ||
hrefDisabled={!namespaceExists} | ||
/> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<script lang="ts"> | ||
// The worst case smallest repro for interacting with combobox async | ||
import Combobox from './combobox.svelte'; | ||
let syncOptions = ['one', 'two', 'three']; | ||
let asyncOptions = ['asyncone', 'asynctwo', 'asyncthree']; | ||
let value = ''; | ||
let options = syncOptions; | ||
let loading = false; | ||
let abortController: AbortController | null = null; | ||
$: i = 0; | ||
export let id = ''; | ||
function keypress(stuff) { | ||
loading = true; | ||
value = stuff.target.value; | ||
options = syncOptions; | ||
// This makes sure the worst case always happens the newest value comes first | ||
// with old values coming after, so we know to discard old values. | ||
i -= 1; | ||
if (abortController) { | ||
abortController.abort(); | ||
} | ||
abortController = new AbortController(); | ||
const { signal } = abortController; | ||
setTimeout( | ||
(value) => { | ||
if (!signal.aborted) { | ||
console.log('newest options', { value }); | ||
options = asyncOptions; | ||
loading = false; | ||
} else { | ||
// console.log("it's old!", { value }); | ||
} | ||
}, | ||
2000 + i * 100, | ||
value, | ||
); | ||
} | ||
</script> | ||
|
||
<Combobox | ||
bind:value | ||
{options} | ||
{keypress} | ||
on:change={(newVal) => { | ||
console.log('change', newVal); | ||
}} | ||
{loading} | ||
{id} | ||
noResultsText="No Results" | ||
label="Async Test" | ||
placeholder="Type away!" | ||
></Combobox> |
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
Oops, something went wrong.