debian-mirror-gitlab/app/assets/javascripts/sidebar/components/assignees/assignees_realtime.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

93 lines
2 KiB
Vue
Raw Normal View History

2020-05-24 23:13:21 +05:30
<script>
2022-06-21 17:19:12 +05:30
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
2022-01-26 12:08:38 +05:30
import { IssuableType } from '~/issues/constants';
2021-04-29 21:17:54 +05:30
import { assigneesQueries } from '~/sidebar/constants';
2020-05-24 23:13:21 +05:30
export default {
subscription: null,
name: 'AssigneesRealtime',
props: {
mediator: {
type: Object,
2021-04-29 21:17:54 +05:30
required: false,
default: null,
2020-05-24 23:13:21 +05:30
},
2021-06-08 01:23:25 +05:30
issuableType: {
2020-05-24 23:13:21 +05:30
type: String,
required: true,
},
2021-06-08 01:23:25 +05:30
queryVariables: {
type: Object,
2021-04-29 21:17:54 +05:30
required: true,
},
2020-05-24 23:13:21 +05:30
},
2021-06-08 01:23:25 +05:30
computed: {
issuableClass() {
return Object.keys(IssuableType).find((key) => IssuableType[key] === this.issuableType);
},
2022-06-21 17:19:12 +05:30
issuableId() {
return this.issuable?.id;
},
2021-06-08 01:23:25 +05:30
},
2020-05-24 23:13:21 +05:30
apollo: {
2021-06-08 01:23:25 +05:30
issuable: {
2021-04-29 21:17:54 +05:30
query() {
return assigneesQueries[this.issuableType].query;
},
2020-05-24 23:13:21 +05:30
variables() {
2021-06-08 01:23:25 +05:30
return this.queryVariables;
},
update(data) {
return data.workspace?.issuable;
2020-05-24 23:13:21 +05:30
},
2021-06-08 01:23:25 +05:30
subscribeToMore: {
document() {
return assigneesQueries[this.issuableType].subscription;
},
variables() {
return {
2022-06-21 17:19:12 +05:30
issuableId: this.issuableId,
2021-06-08 01:23:25 +05:30
};
},
2022-06-21 17:19:12 +05:30
skip() {
return !this.issuableId;
},
updateQuery(
_,
{
subscriptionData: {
data: { issuableAssigneesUpdated },
},
},
) {
if (issuableAssigneesUpdated) {
const {
id,
assignees: { nodes },
} = issuableAssigneesUpdated;
2021-06-08 01:23:25 +05:30
if (this.mediator) {
2022-06-21 17:19:12 +05:30
this.handleFetchResult(nodes);
2021-06-08 01:23:25 +05:30
}
2022-06-21 17:19:12 +05:30
this.$emit('assigneesUpdated', { id, assignees: nodes });
2021-06-08 01:23:25 +05:30
}
},
2020-05-24 23:13:21 +05:30
},
},
},
methods: {
2022-06-21 17:19:12 +05:30
handleFetchResult(nodes) {
2021-03-08 18:12:59 +05:30
const assignees = nodes.map((n) => ({
2020-05-24 23:13:21 +05:30
...n,
avatar_url: n.avatarUrl,
id: getIdFromGraphQLId(n.id),
}));
this.mediator.store.setAssigneesFromRealtime(assignees);
},
},
render() {
2021-04-29 21:17:54 +05:30
return null;
2020-05-24 23:13:21 +05:30
},
};
</script>