debian-mirror-gitlab/app/assets/javascripts/runner/components/runner_projects.vue

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

145 lines
3.8 KiB
Vue
Raw Normal View History

2022-04-04 11:22:00 +05:30
<script>
2022-10-11 01:57:18 +05:30
import { GlSearchBoxByType, GlSkeletonLoader } from '@gitlab/ui';
2022-04-04 11:22:00 +05:30
import { sprintf, formatNumber } from '~/locale';
import { createAlert } from '~/flash';
2022-07-16 23:28:13 +05:30
import runnerProjectsQuery from '../graphql/show/runner_projects.query.graphql';
2022-04-04 11:22:00 +05:30
import {
I18N_ASSIGNED_PROJECTS,
2022-10-11 01:57:18 +05:30
I18N_CLEAR_FILTER_PROJECTS,
I18N_FILTER_PROJECTS,
I18N_NO_PROJECTS_FOUND,
2022-04-04 11:22:00 +05:30
I18N_FETCH_ERROR,
RUNNER_DETAILS_PROJECTS_PAGE_SIZE,
} from '../constants';
import { getPaginationVariables } from '../utils';
import { captureException } from '../sentry_utils';
import RunnerAssignedItem from './runner_assigned_item.vue';
import RunnerPagination from './runner_pagination.vue';
2022-10-11 01:57:18 +05:30
const SHORT_SEARCH_LENGTH = 3;
2022-04-04 11:22:00 +05:30
export default {
name: 'RunnerProjects',
components: {
2022-10-11 01:57:18 +05:30
GlSearchBoxByType,
2022-07-23 23:45:48 +05:30
GlSkeletonLoader,
2022-04-04 11:22:00 +05:30
RunnerAssignedItem,
RunnerPagination,
},
props: {
runner: {
type: Object,
required: true,
},
},
data() {
return {
projects: {
2022-08-27 11:52:29 +05:30
ownerProjectId: null,
2022-04-04 11:22:00 +05:30
items: [],
pageInfo: {},
count: 0,
},
2022-10-11 01:57:18 +05:30
search: '',
2022-08-27 11:52:29 +05:30
pagination: {},
2022-04-04 11:22:00 +05:30
};
},
apollo: {
projects: {
2022-05-07 20:08:51 +05:30
query: runnerProjectsQuery,
2022-04-04 11:22:00 +05:30
variables() {
return this.variables;
},
update(data) {
const { runner } = data;
return {
2022-08-27 11:52:29 +05:30
ownerProjectId: runner?.ownerProject?.id,
2022-04-04 11:22:00 +05:30
count: runner?.projectCount || 0,
items: runner?.projects?.nodes || [],
pageInfo: runner?.projects?.pageInfo || {},
};
},
error(error) {
createAlert({ message: I18N_FETCH_ERROR });
2022-05-07 20:08:51 +05:30
captureException({ error, component: this.$options.name });
2022-04-04 11:22:00 +05:30
},
},
},
computed: {
variables() {
2022-10-11 01:57:18 +05:30
const { search, runner } = this;
2022-04-04 11:22:00 +05:30
return {
2022-10-11 01:57:18 +05:30
id: runner.id,
search: search.length >= SHORT_SEARCH_LENGTH ? search : '',
2022-04-04 11:22:00 +05:30
...getPaginationVariables(this.pagination, RUNNER_DETAILS_PROJECTS_PAGE_SIZE),
};
},
loading() {
return this.$apollo.queries.projects.loading;
},
heading() {
return sprintf(I18N_ASSIGNED_PROJECTS, {
projectCount: formatNumber(this.projects.count),
});
},
},
2022-08-27 11:52:29 +05:30
methods: {
isOwner(projectId) {
return projectId === this.projects.ownerProjectId;
},
2022-10-11 01:57:18 +05:30
onSearchInput(search) {
this.search = search;
this.pagination = {};
},
2022-08-27 11:52:29 +05:30
onPaginationInput(value) {
this.pagination = value;
},
},
2022-10-11 01:57:18 +05:30
RUNNER_DETAILS_PROJECTS_PAGE_SIZE,
I18N_CLEAR_FILTER_PROJECTS,
I18N_FILTER_PROJECTS,
I18N_NO_PROJECTS_FOUND,
2022-04-04 11:22:00 +05:30
};
</script>
<template>
<div class="gl-border-t-gray-100 gl-border-t-1 gl-border-t-solid">
2022-10-11 01:57:18 +05:30
<h3 class="gl-font-lg gl-mt-5">
2022-04-04 11:22:00 +05:30
{{ heading }}
</h3>
2022-10-11 01:57:18 +05:30
<gl-search-box-by-type
:is-loading="loading"
:clear-button-title="$options.I18N_CLEAR_FILTER_PROJECTS"
:placeholder="$options.I18N_FILTER_PROJECTS"
debounce="500"
class="gl-w-28"
:value="search"
@input="onSearchInput"
/>
2022-04-04 11:22:00 +05:30
2022-10-11 01:57:18 +05:30
<div v-if="!projects.items.length && loading" class="gl-py-5">
<gl-skeleton-loader v-for="i in $options.RUNNER_DETAILS_PROJECTS_PAGE_SIZE" :key="i" />
2022-07-23 23:45:48 +05:30
</div>
2022-04-04 11:22:00 +05:30
<template v-else-if="projects.items.length">
<runner-assigned-item
v-for="(project, i) in projects.items"
:key="project.id"
:class="{ 'gl-border-t-gray-100 gl-border-t-1 gl-border-t-solid': i !== 0 }"
:href="project.webUrl"
:name="project.name"
:full-name="project.nameWithNamespace"
:avatar-url="project.avatarUrl"
2022-08-27 11:52:29 +05:30
:description="project.description"
:is-owner="isOwner(project.id)"
2022-04-04 11:22:00 +05:30
/>
</template>
2022-10-11 01:57:18 +05:30
<div v-else class="gl-py-5 gl-text-gray-500">{{ $options.I18N_NO_PROJECTS_FOUND }}</div>
2022-04-04 11:22:00 +05:30
2022-08-27 11:52:29 +05:30
<runner-pagination
:disabled="loading"
:page-info="projects.pageInfo"
@input="onPaginationInput"
/>
2022-04-04 11:22:00 +05:30
</div>
</template>