Skip to content

Commit

Permalink
Merge pull request #69 from ssciwr/fix_57_add_other_option_to_selects
Browse files Browse the repository at this point in the history
Add free text other option for source/tumor type/platform
  • Loading branch information
lkeegan authored Jan 2, 2025
2 parents 9d0901e + b3235e1 commit e8f38f2
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 26 deletions.
61 changes: 61 additions & 0 deletions frontend/src/components/SelectWithOther.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<script setup lang="ts">
import { ref, computed, watch } from "vue";
import { FwbSelect, FwbInput } from "flowbite-vue";
const model = defineModel();
const otherText = "Other (please specify)";
const textInput = ref("");
const selectInput = ref("");
const showTextInput = ref(true);
type OptionsType = {
name: string;
value: string;
};
watch([selectInput, textInput], ([newSelectInput, newTextInput]) => {
if (newSelectInput === otherText) {
showTextInput.value = true;
model.value = newTextInput;
} else {
showTextInput.value = false;
textInput.value = "";
model.value = newSelectInput;
}
});
function string_to_options(str: string): Array<OptionsType> {
const items = `${str};${otherText}`.split(";");
return items.map((x) => ({ value: x, name: x }));
}
const props = defineProps({
options: String,
id: String,
label: String,
});
const optionsArray = computed(() => {
if (!props.options) {
return [];
}
return string_to_options(props.options);
});
</script>

<template>
<div class="flex flex-row mb-2">
<fwb-select
v-model="selectInput"
:options="optionsArray"
:id="id"
:label="label"
class="grow"
/>
<fwb-input
v-if="showTextInput"
v-model="textInput"
label="Other"
class="ml-2 grow"
/>
</div>
</template>
34 changes: 8 additions & 26 deletions frontend/src/views/SamplesView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { ref, onUnmounted } from "vue";
import SamplesTable from "@/components/SamplesTable.vue";
import ListComponent from "@/components/ListComponent.vue";
import SelectWithOther from "@/components/SelectWithOther.vue";
import ListItem from "@/components/ListItem.vue";
import { apiClient, logout } from "@/utils/api-client";
import type { Sample } from "@/utils/types";
Expand All @@ -15,16 +16,8 @@ import {
FwbCheckbox,
} from "flowbite-vue";
import { useSettingsStore } from "@/stores/settings";
const settingsStore = useSettingsStore();
type OptionsType = {
name: string;
value: string;
};
const tumor_types = ref([] as Array<OptionsType>);
const sources = ref([] as Array<OptionsType>);
const platforms = ref([] as Array<OptionsType>);
const settingsStore = useSettingsStore();
const required_columns = ref([] as Array<string>);
function closeModalSubmit() {
Expand Down Expand Up @@ -103,14 +96,6 @@ async function on_csv_file_changed(event: Event) {
}
}
function string_to_options(str: string): Array<OptionsType> {
const items = str.split(";");
return items.map((x) => ({ value: x, name: x }));
}
tumor_types.value = string_to_options(settingsStore.settings.tumor_types);
sources.value = string_to_options(settingsStore.settings.sources);
platforms.value = string_to_options(settingsStore.settings.platforms);
required_columns.value = settingsStore.settings.csv_required_columns.split(";");
const samples = ref([] as Sample[]);
Expand Down Expand Up @@ -211,26 +196,23 @@ function add_sample() {
maxlength="128"
class="mb-2"
/>
<fwb-select
<SelectWithOther
v-model="tumor_type"
:options="tumor_types"
:options="settingsStore.settings.tumor_types"
id="tumor_type"
label="Tumor type"
class="mb-2"
/>
<fwb-select
<SelectWithOther
v-model="source"
:options="sources"
:options="settingsStore.settings.sources"
id="source"
label="Source"
class="mb-2"
/>
<fwb-select
<SelectWithOther
v-model="platform"
:options="platforms"
:options="settingsStore.settings.platforms"
id="platform"
label="Platform"
class="mb-2"
/>
<fwb-file-input
type="file"
Expand Down

0 comments on commit e8f38f2

Please sign in to comment.