debian-mirror-gitlab/app/assets/javascripts/sidebar/components/assignees/assignees_realtime.vue
2023-03-04 22:38:38 +05:30

92 lines
2 KiB
Vue

<script>
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import { IssuableType } from '~/issues/constants';
import { assigneesQueries } from '../../constants';
export default {
subscription: null,
name: 'AssigneesRealtime',
props: {
mediator: {
type: Object,
required: false,
default: null,
},
issuableType: {
type: String,
required: true,
},
queryVariables: {
type: Object,
required: true,
},
},
computed: {
issuableClass() {
return Object.keys(IssuableType).find((key) => IssuableType[key] === this.issuableType);
},
issuableId() {
return this.issuable?.id;
},
},
apollo: {
issuable: {
query() {
return assigneesQueries[this.issuableType].query;
},
variables() {
return this.queryVariables;
},
update(data) {
return data.workspace?.issuable;
},
subscribeToMore: {
document() {
return assigneesQueries[this.issuableType].subscription;
},
variables() {
return {
issuableId: this.issuableId,
};
},
skip() {
return !this.issuableId;
},
updateQuery(
_,
{
subscriptionData: {
data: { issuableAssigneesUpdated },
},
},
) {
if (issuableAssigneesUpdated) {
const {
id,
assignees: { nodes },
} = issuableAssigneesUpdated;
if (this.mediator) {
this.handleFetchResult(nodes);
}
this.$emit('assigneesUpdated', { id, assignees: nodes });
}
},
},
},
},
methods: {
handleFetchResult(nodes) {
const assignees = nodes.map((n) => ({
...n,
avatar_url: n.avatarUrl,
id: getIdFromGraphQLId(n.id),
}));
this.mediator.store.setAssigneesFromRealtime(assignees);
},
},
render() {
return null;
},
};
</script>