Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify behavior of study page filters #955

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions web/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ function setConditions(conditions: Condition[], push = false) {
}
}

/**
* For each condition, remove all others with a similar table & field.
*/
function setUniqueCondition(
field: string[],
table: string[],
conditions: Condition[],
) {
const others = state.conditions.filter((c) => (
!field.includes(c.field)) || (!table.includes(c.table)
));
setConditions([
...conditions,
...others,
]);
}

/**
* Restore state from localStorage and clear
*/
Expand Down Expand Up @@ -119,23 +136,6 @@ async function getTreeData() {
}
}

/**
* For each condition, remove all others with a similar table & field.
*/
function setUniqueCondition(
field: string[],
table: string[],
conditions: Condition[],
) {
const others = state.conditions.filter((c) => (
!field.includes(c.field)) || (!table.includes(c.table)
));
setConditions([
...conditions,
...others,
]);
}

/**
* For each condition, if it already exists, remove it,
* otherwise, add it
Expand Down
8 changes: 4 additions & 4 deletions web/src/views/IndividualResults/StudyPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ export default defineComponent({

const router = useRouter();

function setChecked(omicsType = '') {
function seeOmicsForStudy(omicsType = '') {
setUniqueCondition(
['study_id', 'omics_type'],
['study', 'omics_processing'],
[{
value: props.id,
table: 'study',
op: '==',
field: 'study_id',
field: 'id',
}, {
value: omicsType,
table: 'omics_processing',
Expand Down Expand Up @@ -154,7 +154,7 @@ export default defineComponent({
item,
displayFields,
/* Methods */
setChecked,
seeOmicsForStudy,
relatedTypeDescription,
openLink,
formatAPA,
Expand Down Expand Up @@ -188,7 +188,7 @@ export default defineComponent({
:key="val.type"
small
class="mr-2 my-1"
@click="setChecked(val.type)"
@click="seeOmicsForStudy(val.type)"
>
{{ fieldDisplayName(val.type) }}: {{ val.count }}
</v-chip>
Expand Down
Loading