-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add explorer tags, searchbar, and search results table.
- Loading branch information
Showing
17 changed files
with
463 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<script lang="ts"> | ||
import type { Indexable } from '$lib/types'; | ||
import { TagCheckbox } from '$lib/models/Search'; | ||
import SearchStore from '$lib/stores/Search'; | ||
const { updateTag } = SearchStore; | ||
const icons: Indexable = { | ||
[TagCheckbox.Include]: { | ||
inactive: 'fa-regular fa-lg fa-square-plus text-primary-700', | ||
active: 'fa-solid fa-lg fa-square-plus text-sky-600', | ||
}, | ||
[TagCheckbox.Exclude]: { | ||
inactive: 'fa-regular fa-lg fa-square-minus text-primary-700', | ||
active: 'fa-solid fa-lg fa-square-minus text-red-600', | ||
}, | ||
}; | ||
export let type = ''; | ||
export let tag = ''; | ||
export let state: TagCheckbox = TagCheckbox.Default; | ||
const normalize = (n: string) => n.replaceAll(' ', '_').toLowerCase(); | ||
const elementId = `${normalize(type)}-${normalize(tag)}`; | ||
function newTagState(stateToggle: TagCheckbox) { | ||
const newState = state == stateToggle ? TagCheckbox.Default : stateToggle; | ||
updateTag(type, tag, newState); | ||
} | ||
</script> | ||
|
||
<div class="flex"> | ||
<div class="flex-auto pl-2"> | ||
{tag} | ||
</div> | ||
<div class="filter-group flex-none"> | ||
{#each [TagCheckbox.Include, TagCheckbox.Exclude] as boxType} | ||
<span | ||
role="checkbox" | ||
tabindex="0" | ||
id={`tag-${elementId}-${boxType}`} | ||
title={`${boxType} ${tag} tag in search`} | ||
aria-checked={state == boxType} | ||
on:click={() => newTagState(boxType)} | ||
on:keydown={(e) => e.key === ' ' && newTagState(boxType)} | ||
><i class={icons[boxType][state == boxType ? 'active' : 'inactive']}></i></span | ||
> | ||
<label for={`tag-${elementId}-${boxType}`} class="sr-only"> | ||
<span>{boxType}</span> | ||
</label> | ||
{/each} | ||
</div> | ||
</div> |
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,28 @@ | ||
<script lang="ts"> | ||
// export let data = { cell: '', row: { archived: false } }; | ||
</script> | ||
|
||
<button | ||
type="button" | ||
title="Information" | ||
class="bg-initial text-secondary-600 hover:text-primary-600" | ||
> | ||
<i class="fa-solid fa-circle-info fa-xl"></i> | ||
</button> | ||
<button type="button" title="Filter" class="bg-initial text-secondary-600 hover:text-primary-600"> | ||
<i class="fa-solid fa-filter fa-xl"></i> | ||
</button> | ||
<button | ||
type="button" | ||
title="Data Hierarchy" | ||
class="bg-initial text-secondary-600 hover:text-primary-600" | ||
> | ||
<i class="fa-solid fa-sitemap fa-xl"></i> | ||
</button> | ||
<button | ||
type="button" | ||
title="Data Export" | ||
class="bg-initial text-secondary-600 hover:text-primary-600" | ||
> | ||
<i class="fa-solid fa-right-from-bracket fa-xl"></i> | ||
</button> |
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,45 @@ | ||
import type { Indexable } from '$lib/types'; | ||
|
||
export enum TagCheckbox { | ||
Include = 'include', | ||
Exclude = 'exclude', | ||
Default = 'default', | ||
} | ||
|
||
export type SearchTag = Indexable & { | ||
name: string; | ||
type: string; | ||
state: TagCheckbox; | ||
}; | ||
|
||
export type SearchTagType = Indexable & { | ||
title: string; | ||
tags: SearchTag[]; | ||
}; | ||
|
||
export type SearchResult = Indexable & { | ||
id: string; | ||
name: string; | ||
description: string; | ||
}; | ||
|
||
export function mapTags(typeData: { title: string; tags: string[] }): SearchTagType { | ||
return { | ||
title: typeData.title, | ||
tags: typeData.tags.map((tag) => ({ | ||
name: tag, | ||
type: typeData.title, | ||
state: TagCheckbox.Default, | ||
})), | ||
}; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export function mapSearchResults(data: any): SearchResult { | ||
const segments = data.name.split('\\').filter((x: string) => x); | ||
return { | ||
id: data.name, | ||
name: segments[segments.length - 1], | ||
description: `categorical: ${data.categorical}, patients: ${data.patientCount}`, | ||
}; | ||
} |
File renamed without changes.
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,58 @@ | ||
import { get, writable, type Writable } from 'svelte/store'; | ||
|
||
import { | ||
mapTags, | ||
type SearchTagType, | ||
mapSearchResults, | ||
type SearchResult, | ||
TagCheckbox, | ||
} from '$lib/models/Search'; | ||
import * as api from '$lib/api'; | ||
|
||
const searchUrl = 'picsure/search/bf638674-053b-46c4-96a1-4cd6c8395248'; | ||
|
||
const tags: Writable<SearchTagType[]> = writable([]); | ||
const searchTerm: Writable<string> = writable(''); | ||
const searchResults: Writable<SearchResult[]> = writable([]); | ||
|
||
const tagsMock = [ | ||
{ | ||
title: 'Dataset', | ||
tags: ['NHANES', '1000 Genomes'], | ||
}, | ||
{ | ||
title: 'Category', | ||
tags: ['laboratory', 'questionaire'], | ||
}, | ||
{ | ||
title: 'Data Type', | ||
tags: ['type 1', 'type 2'], | ||
}, | ||
]; | ||
|
||
async function search(search: string) { | ||
if (!search) return; | ||
const response = await api.post(searchUrl, { query: search }); | ||
tags.set(tagsMock.map(mapTags)); | ||
searchResults.set(Object.values(response.results.phenotypes).map(mapSearchResults)); | ||
searchTerm.set(search); | ||
} | ||
|
||
// TODO: Update include/exclude method to send api update to the server, maybe with a debounce? | ||
function updateTag(type: string, tag: string, newState: TagCheckbox) { | ||
const newTags = get(tags); | ||
const typeIndex = newTags.findIndex((t) => t.title == type); | ||
const tagIndex = newTags[typeIndex].tags.findIndex((t) => t.name == tag); | ||
|
||
newTags[typeIndex].tags[tagIndex].state = newState; | ||
tags.set(newTags); | ||
} | ||
|
||
export default { | ||
subscribe: tags.subscribe, | ||
tags, | ||
searchTerm, | ||
searchResults, | ||
search, | ||
updateTag, | ||
}; |
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.