Skip to content

Commit

Permalink
Merge pull request #1925 from sanger/develop
Browse files Browse the repository at this point in the history
Develop to master
  • Loading branch information
dasunpubudumal authored Sep 9, 2024
2 parents 0f85f1b + e420741 commit dfbaa98
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v20.16.0
v20.17.0
2 changes: 1 addition & 1 deletion .release-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.7.1
10.7.2
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"dependencies": {
"@sanger/ui-styling": "^4.1.0",
"@vitejs/plugin-vue": "^5.1.2",
"@vitejs/plugin-vue": "^5.1.3",
"autoprefixer": "^10.4.20",
"axios": "^1.7.5",
"csv-parse": "^5.5.6",
Expand All @@ -47,7 +47,7 @@
"@vue/test-utils": "^2.4.6",
"better-docs": "^2.7.3",
"clean-jsdoc-theme": "^4.3.0",
"cypress": "^13.14.0",
"cypress": "^13.14.1",
"cypress-file-upload": "^5.0.8",
"dotenv": "^16.4.5",
"eslint": "^9.9.1",
Expand All @@ -56,7 +56,7 @@
"eslint-plugin-vue": "^9.27.0",
"globals": "^15.9.0",
"jsdoc": "^4.0.3",
"jsdom": "^24.1.1",
"jsdom": "^25.0.0",
"npm-run-all": "^4.1.5",
"postcss-cli": "^11.0.0",
"prettier": "3.3.3",
Expand Down
61 changes: 44 additions & 17 deletions src/components/shared/DataTypeSelect.vue
Original file line number Diff line number Diff line change
@@ -1,56 +1,83 @@
<template>
<traction-select
id="data-type"
:model-value="value"
data-attribute="data-type-list"
:options="dataTypes"
@update:model-value="handleInput"
></traction-select>
<traction-field-group label="Data Type" label-for="data-type" layout="spacious">
<traction-select
id="data-type"
:model-value="dataType"
data-attribute="data-type-list"
:options="dataTypes"
@update:model-value="handleInput"
></traction-select
></traction-field-group>
</template>

<script>
import useSWRV from 'swrv'
import { filterByAttribute, mapAttribute } from '@/api/JsonApi'
const encode = (value) => (value === undefined ? 'basecalls and raw data' : value)
const decode = (value) => (value === '' ? null : value)
export default {
name: 'DataTypeSelect',
props: {
pipeline: {
// Filter to only list data_types for a given pipeline, leave null
// to apply no filters
type: String,
required: false,
default: null,
},
value: {
// The data type, we use value to allow us to simply bind it with v-model
modelValue: {
type: String,
default: undefined,
},
},
emits: ['input'],
emits: ['update:modelValue'],
setup() {
const baseURL = import.meta.env.VITE_TRACTION_BASE_URL
const { data: remoteDataTypes } = useSWRV(
`${baseURL}/v1/data_types?fields[data_types]=name,pipeline`,
)
return { remoteDataTypes }
},
data() {
return {
dataType: encode(this.modelValue),
}
},
computed: {
filters: ({ pipeline }) => (pipeline ? { pipeline } : {}),
// Same approach as src/components/shared/LibraryTypeSelect.vue
filters: ({ pipeline }) => (pipeline ? { pipeline, name: 'basecalls and raw data' } : {}),
filteredDataTypes() {
return filterByAttribute(this.remoteDataTypes?.data || [], this.filters)
},
emptyOption: ({ allowNone }) => (allowNone ? [{ value: '', text: 'None' }] : []),
dataTypes() {
return mapAttribute(this.filteredDataTypes, 'name')
const dataTypesOptions = mapAttribute(this.filteredDataTypes, 'name').map((val) => {
return {
text: val,
value: val,
}
})
return [...dataTypesOptions, ...this.emptyOption]
},
},
watch: {
remoteDataTypes: {
handler() {
this.setDataType()
},
immediate: true,
},
},
methods: {
handleInput(input) {
this.$emit('input', input)
this.$emit('update:modelValue', decode(input))
},
setDataType() {
if (this.dataTypes.length === 1) {
this.dataType = encode(this.dataTypes[0].value)
this.$emit('update:modelValue', this.dataTypes[0].value)
}
},
},
}
</script>
<style></style>
9 changes: 1 addition & 8 deletions src/views/GeneralReception.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,7 @@
</traction-field-group>
</div>
<div v-if="pipeline == 'ONT'">
<traction-field-group
label="Data Type"
attribute="data_type"
for="data_type"
layout="spacious"
>
<DataTypeSelect v-model="requestOptions.data_type" pipeline="ont" />
</traction-field-group>
<DataTypeSelect v-model="requestOptions.data_type" pipeline="ont" />
<traction-field-group
label="Number of Flowcells"
attribute="number_of_flowcells"
Expand Down
14 changes: 8 additions & 6 deletions tests/unit/components/shared/DataTypeSelect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,31 @@ describe('DataTypeSelect.vue', () => {
it('lists the expected options', () => {
const wrapper = buildWrapper()
const select = wrapper.find('select')
expect(findOption('basecalls', { from: select })).toBeTruthy()
expect(findOption('basecalls and raw data', { from: select })).toBeTruthy()
})

it('will not list data types from other pipelines', () => {
const wrapper = buildWrapper({ pipeline: 'ont' })
const select = wrapper.find('select')
expect(findOption('basecalls', { from: select })).toBeTruthy()
expect(findOption('basecalls and raw data', { from: select })).toBeTruthy()
expect(findOption('dummy type', { from: select })).toBeFalsy()
})

it('will list data types from all pipelines unless specified', () => {
const wrapper = buildWrapper({})
const select = wrapper.find('select')
expect(findOption('basecalls', { from: select })).toBeTruthy()
expect(findOption('basecalls and raw data', { from: select })).toBeTruthy()
expect(findOption('dummy type', { from: select })).toBeTruthy()
})

// 'basecalls and raw data' is the default type.
// This test checks whether if the default type is changed to 'dummy type',
// the component will emit 'dummy type' when the user selects it.
it('can emit a data type', async () => {
const wrapper = buildWrapper()
const wrapper = buildWrapper({})
const select = wrapper.find('select')
await findOption('basecalls', { from: select }).setSelected()
expect(wrapper.emitted('input')).toEqual([['basecalls']])
await findOption('dummy type', { from: select }).setSelected()
expect(wrapper.emitted('update:modelValue')).toEqual([['dummy type']])
})
})
})

0 comments on commit dfbaa98

Please sign in to comment.