-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing participant select and centralizes component (#3925)
* Fixing participant select and centralizes component * Add component * Removing spans * Fix linting * Fixes * Switch to auto-complete * Fixes autocomplete
- Loading branch information
1 parent
8dc45ef
commit 6a0a0b9
Showing
11 changed files
with
147 additions
and
262 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
127 changes: 0 additions & 127 deletions
127
src/dispatch/static/dispatch/src/case/ParticipantSelect.vue
This file was deleted.
Oops, something went wrong.
139 changes: 139 additions & 0 deletions
139
src/dispatch/static/dispatch/src/components/ParticipantSelect.vue
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,139 @@ | ||
<template> | ||
<v-autocomplete | ||
:items="items" | ||
:label="labelProp" | ||
:loading="loading" | ||
v-model:search="search" | ||
clearable | ||
hide-selected | ||
item-title="individual.name" | ||
item-value="individual.id" | ||
return-object | ||
chips | ||
:hide-no-data="false" | ||
v-model="participant" | ||
@update:modelValue="handleClear" | ||
> | ||
<template #no-data> | ||
<v-list-item v-if="!loading"> | ||
<v-list-item-title> | ||
No individuals matching <strong>"{{ search }}".</strong> | ||
</v-list-item-title> | ||
</v-list-item> | ||
</template> | ||
<template #item="{ props, item }"> | ||
<v-list-item v-bind="props" :subtitle="item.raw.individual.email" /> | ||
</template> | ||
<template #append-item v-if="items.length < total.value"> | ||
<v-list-item @click="loadMore()"> | ||
<v-list-item-subtitle> Load More </v-list-item-subtitle> | ||
</v-list-item> | ||
</template> | ||
<template #chip="data"> | ||
<v-chip v-bind="data.props" pill> | ||
<template #prepend> | ||
<v-avatar color="teal" start> {{ initials(data.item.title) }} </v-avatar> | ||
</template> | ||
{{ data.item.title }} | ||
</v-chip> | ||
</template> | ||
</v-autocomplete> | ||
</template> | ||
|
||
<script> | ||
import { ref, watch, toRefs, onMounted } from "vue" | ||
import { initials } from "@/filters" | ||
import { debounce } from "lodash" | ||
import IndividualApi from "@/individual/api" | ||
export default { | ||
name: "ParticipantSelect", | ||
props: { | ||
labelProp: { | ||
// Define the labelProp | ||
type: String, | ||
default: "Participant", | ||
}, | ||
initialValue: { | ||
type: Object, | ||
default: () => ({}), | ||
}, | ||
}, | ||
setup(props) { | ||
const { labelProp } = toRefs(props) // toRefs make props reactive | ||
let loading = ref(false) | ||
let items = ref([]) | ||
console.log(items) | ||
let numItems = ref(10) | ||
let participant = ref({ ...props.initialValue }) | ||
let currentPage = ref(1) | ||
let total = ref(0) | ||
const search = ref(props.initialValue.name) | ||
let debouncedGetIndividualData = null | ||
const getIndividualData = async (searchVal, page = currentPage.value) => { | ||
loading.value = true | ||
let filterOptions = { | ||
q: searchVal, | ||
sortBy: ["name"], | ||
descending: [false], | ||
itemsPerPage: numItems.value * page, | ||
} | ||
await IndividualApi.getAll(filterOptions).then((response) => { | ||
console.log(response.data.items) | ||
items.value = response.data.items.map(function (x) { | ||
return { individual: x } | ||
}) | ||
total.value = response.data.total | ||
}) | ||
loading.value = false | ||
} | ||
onMounted(() => { | ||
debouncedGetIndividualData = debounce(getIndividualData, 300) | ||
debouncedGetIndividualData(search.value) | ||
}) | ||
const loadMore = async () => { | ||
currentPage.value++ | ||
numItems.value += 10 | ||
await debouncedGetIndividualData(search.value) | ||
} | ||
const handleClear = (newValue) => { | ||
if (!newValue) { | ||
items.value = [] | ||
search.value = null | ||
participant.value = null | ||
numItems.value = 10 | ||
currentPage.value = 1 | ||
} | ||
} | ||
watch(search, async (newVal, oldVal) => { | ||
if (oldVal !== newVal) { | ||
numItems.value = 10 | ||
await debouncedGetIndividualData(newVal) | ||
} | ||
}) | ||
return { | ||
getIndividualData, | ||
handleClear, | ||
initials, | ||
items, | ||
labelProp, | ||
loading, | ||
loadMore, | ||
participant, | ||
search, | ||
total, | ||
} | ||
}, | ||
} | ||
</script> |
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
Oops, something went wrong.