|
| 1 | +<svelte:options immutable={true} /> |
| 2 | + |
| 3 | +<script lang="ts"> |
| 4 | + import { Button, Input as InputStellar, Label } from '@nasa-jpl/stellar-svelte'; |
| 5 | + import { hasSearched, searchResults } from '../../stores/search'; |
| 6 | + import type { User } from '../../types/app'; |
| 7 | + import effects from '../../utilities/effects'; |
| 8 | + import Panel from '../ui/Panel.svelte'; |
| 9 | + import SectionTitle from '../ui/SectionTitle.svelte'; |
| 10 | +
|
| 11 | + export let user: User | null; |
| 12 | +
|
| 13 | + let filterActType: string = ''; |
| 14 | + let filterActName: string = ''; |
| 15 | + let filterArgName: string = ''; |
| 16 | + let filterArgValue: string = ''; |
| 17 | + let filterTagValue: string = ''; |
| 18 | +
|
| 19 | + async function onSearch() { |
| 20 | + hasSearched.set(true); |
| 21 | +
|
| 22 | + const filterArgs: [name: string, value: string | number | boolean][] = []; |
| 23 | + if (filterArgName || filterArgValue) { |
| 24 | + if (filterArgValue.toLowerCase() === 'true') { |
| 25 | + filterArgs.push([filterArgName, true]); |
| 26 | + } else if (filterArgValue.toLowerCase() === 'false') { |
| 27 | + filterArgs.push([filterArgName, false]); |
| 28 | + } else if (!isNaN(Number(filterArgValue))) { |
| 29 | + filterArgs.push([filterArgName, Number(filterArgValue)]); |
| 30 | + } else { |
| 31 | + filterArgs.push([filterArgName, filterArgValue]); |
| 32 | + } |
| 33 | + } |
| 34 | + const results = await effects.searchActivities(filterActType, filterActName, filterArgs, filterTagValue, user); |
| 35 | + if (results) { |
| 36 | + searchResults.set(results); |
| 37 | + } |
| 38 | + } |
| 39 | +</script> |
| 40 | + |
| 41 | +<Panel overflowYBody="hidden"> |
| 42 | + <svelte:fragment slot="header"> |
| 43 | + <SectionTitle>Search for activities across plans</SectionTitle> |
| 44 | + </svelte:fragment> |
| 45 | + |
| 46 | + <svelte:fragment slot="body"> |
| 47 | + <form on:submit|preventDefault={onSearch} class="flex flex-col"> |
| 48 | + <fieldset> |
| 49 | + <Label for="activity-type-input">Activity Type</Label> |
| 50 | + <InputStellar |
| 51 | + bind:value={filterActType} |
| 52 | + id="activity-type-input" |
| 53 | + placeholder="Activity Type" |
| 54 | + autocomplete="off" |
| 55 | + class="w-[300px]" |
| 56 | + sizeVariant="xs" |
| 57 | + aria-label="Activity Type" |
| 58 | + /> |
| 59 | + </fieldset> |
| 60 | + <fieldset> |
| 61 | + <Label for="activity-name-input">Activity Name</Label> |
| 62 | + <InputStellar |
| 63 | + bind:value={filterActName} |
| 64 | + id="activity-name-input" |
| 65 | + placeholder="Activity Name" |
| 66 | + autocomplete="off" |
| 67 | + class="w-[300px]" |
| 68 | + sizeVariant="xs" |
| 69 | + aria-label="Activity Name" |
| 70 | + /> |
| 71 | + </fieldset> |
| 72 | + <fieldset> |
| 73 | + <Label for="argument-name-input">Argument Name</Label> |
| 74 | + <InputStellar |
| 75 | + bind:value={filterArgName} |
| 76 | + id="argument-name-input" |
| 77 | + placeholder="Argument Name" |
| 78 | + autocomplete="off" |
| 79 | + class="w-[300px]" |
| 80 | + sizeVariant="xs" |
| 81 | + aria-label="Argument Name" |
| 82 | + /> |
| 83 | + <Label for="argument-value-input">Argument Value</Label> |
| 84 | + <InputStellar |
| 85 | + bind:value={filterArgValue} |
| 86 | + id="argument-value-input" |
| 87 | + placeholder="Argument Value" |
| 88 | + autocomplete="off" |
| 89 | + class="w-[300px]" |
| 90 | + sizeVariant="xs" |
| 91 | + aria-label="Argument Value" |
| 92 | + /> |
| 93 | + </fieldset> |
| 94 | + <fieldset> |
| 95 | + <Label for="tag-value-input">Tag Value</Label> |
| 96 | + <InputStellar |
| 97 | + bind:value={filterTagValue} |
| 98 | + id="tag-value-input" |
| 99 | + placeholder="Tag Value" |
| 100 | + autocomplete="off" |
| 101 | + class="w-[300px]" |
| 102 | + sizeVariant="xs" |
| 103 | + aria-label="Tag Value" |
| 104 | + /> |
| 105 | + </fieldset> |
| 106 | + <fieldset class="my-4"> |
| 107 | + <Button |
| 108 | + type="submit" |
| 109 | + class="w-full" |
| 110 | + disabled={filterActType === '' && |
| 111 | + filterActName === '' && |
| 112 | + filterArgName === '' && |
| 113 | + filterArgValue === '' && |
| 114 | + filterTagValue === ''}>Search</Button |
| 115 | + > |
| 116 | + </fieldset> |
| 117 | + </form> |
| 118 | + </svelte:fragment> |
| 119 | +</Panel> |
0 commit comments