woodpecker/web/src/views/RepoAdd.vue
Divya Jain e2ab8a46ed
Header and Tabs UI Improvements (#1290)
Some improvements to the Page Header and Tab UI.

Original |  New
:--------:|:-------:

![image](https://user-images.githubusercontent.com/62170586/197360886-046f1016-ca39-4b69-8134-99ba88e3a0c2.png)
|
![image](https://user-images.githubusercontent.com/62170586/197360819-7efd0d82-1412-465d-aefa-039164f97465.png)

![image](https://user-images.githubusercontent.com/62170586/197360872-f2ece5fd-7c0b-4e2c-8629-31524a412af5.png)
|
![image](https://user-images.githubusercontent.com/62170586/197360830-49f09e0d-619e-4fa9-8e38-8d05d9404185.png)

![image](https://user-images.githubusercontent.com/62170586/197281776-e3de6441-9417-4614-8b25-1aaef0b8da61.png)
|
![image](https://user-images.githubusercontent.com/62170586/197281698-40c66d34-76f3-4fd5-97e3-1c422b74844c.png)

![image](https://user-images.githubusercontent.com/62170586/196609248-ff150c6e-2995-4bcc-8573-49ffaf388446.png)
|
![image](https://user-images.githubusercontent.com/62170586/197323734-7c1a1b79-0f41-4bf2-96a3-dd38df9e1415.png)

![image](https://user-images.githubusercontent.com/62170586/196609329-b7a6f37e-e8c2-4004-a98b-73f837122ff8.png)
|
![image](https://user-images.githubusercontent.com/62170586/197323882-10141ffd-7411-4493-8291-b8000adc3cc5.png)


What?
- Create a new Scaffold component, which includes the header and tabs
required for a page.
- Use this component to wrap all the views that have a header.
- Ensures consistency in headers between different pages.
- [x] Add support to use custom html/component in place of title (for
repo page, pipeline page, etc)
- [x] Add support of right icon buttons (for repo page, pipeline page,
etc)
- [x] Refactor tabs handling using compositions (useTabsProvider, useTabsClient)
- [x] Make new header ui resposive
2022-10-28 00:55:07 +02:00

101 lines
3.2 KiB
Vue

<template>
<Scaffold v-model:search="search" :go-back="goBack">
<template #title>
{{ $t('repo.add') }}
</template>
<template #titleActions>
<Button start-icon="sync" :text="$t('repo.enable.reload')" :is-loading="isReloadingRepos" @click="reloadRepos" />
</template>
<div class="space-y-4">
<ListItem
v-for="repo in searchedRepos"
:key="repo.id"
class="items-center"
:clickable="repo.active"
@click="repo.active && $router.push({ name: 'repo', params: { repoOwner: repo.owner, repoName: repo.name } })"
>
<span class="text-color">{{ repo.full_name }}</span>
<span v-if="repo.active" class="ml-auto text-color-alt">{{ $t('repo.enable.enabled') }}</span>
<Button
v-if="!repo.active"
class="ml-auto"
:text="$t('repo.enable.enable')"
:is-loading="isActivatingRepo && repoToActivate?.id === repo.id"
@click="activateRepo(repo)"
/>
</ListItem>
</div>
</Scaffold>
</template>
<script lang="ts">
import { defineComponent, onMounted, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import Button from '~/components/atomic/Button.vue';
import ListItem from '~/components/atomic/ListItem.vue';
import Scaffold from '~/components/layout/scaffold/Scaffold.vue';
import useApiClient from '~/compositions/useApiClient';
import { useAsyncAction } from '~/compositions/useAsyncAction';
import useNotifications from '~/compositions/useNotifications';
import { useRepoSearch } from '~/compositions/useRepoSearch';
import { useRouteBackOrDefault } from '~/compositions/useRouteBackOrDefault';
import { Repo } from '~/lib/api/types';
export default defineComponent({
name: 'RepoAdd',
components: {
Button,
ListItem,
Scaffold,
},
setup() {
const router = useRouter();
const apiClient = useApiClient();
const notifications = useNotifications();
const repos = ref<Repo[]>();
const repoToActivate = ref<Repo>();
const search = ref('');
const i18n = useI18n();
const { searchedRepos } = useRepoSearch(repos, search);
onMounted(async () => {
repos.value = await apiClient.getRepoList({ all: true });
});
const { doSubmit: reloadRepos, isLoading: isReloadingRepos } = useAsyncAction(async () => {
repos.value = undefined;
repos.value = await apiClient.getRepoList({ all: true, flush: true });
notifications.notify({ title: i18n.t('repo.enable.list_reloaded'), type: 'success' });
});
const { doSubmit: activateRepo, isLoading: isActivatingRepo } = useAsyncAction(async (repo: Repo) => {
repoToActivate.value = repo;
await apiClient.activateRepo(repo.owner, repo.name);
notifications.notify({ title: i18n.t('repo.enabled.success'), type: 'success' });
repoToActivate.value = undefined;
await router.push({ name: 'repo', params: { repoName: repo.name, repoOwner: repo.owner } });
});
const goBack = useRouteBackOrDefault({ name: 'repos' });
return {
isReloadingRepos,
isActivatingRepo,
repoToActivate,
goBack,
reloadRepos,
activateRepo,
searchedRepos,
search,
};
},
});
</script>