move bot versions to its own tab

This commit is contained in:
Ilion Beyst 2022-11-01 22:36:19 +01:00
parent 06a8ed945b
commit 0e65f04e1e
3 changed files with 90 additions and 43 deletions

View file

@ -16,6 +16,8 @@
</script> </script>
<script lang="ts"> <script lang="ts">
import { currentUser } from "$lib/stores/current_user";
export let bot; export let bot;
export let owner; export let owner;
</script> </script>
@ -36,6 +38,9 @@
<a class="bot-tab" href={`/bots/${bot.name}`}>index</a> <a class="bot-tab" href={`/bots/${bot.name}`}>index</a>
<a class="bot-tab" href={`/bots/${bot.name}/matches`}>matches</a> <a class="bot-tab" href={`/bots/${bot.name}/matches`}>matches</a>
<a class="bot-tab" href={`/bots/${bot.name}/stats`}>stats</a> <a class="bot-tab" href={`/bots/${bot.name}/stats`}>stats</a>
{#if $currentUser && $currentUser["user_id"] === bot["owner_id"]}
<a class="bot-tab" href={`/bots/${bot.name}/versions`}>versions</a>
{/if}
</div> </div>
</div> </div>
<slot /> <slot />

View file

@ -20,8 +20,6 @@
return { return {
props: { props: {
bot, bot,
owner,
versions,
botStats, botStats,
matches: matchesPage["matches"], matches: matchesPage["matches"],
errorMatches: errorMatchesPage["matches"], errorMatches: errorMatchesPage["matches"],
@ -43,8 +41,6 @@
import LinkButton from "$lib/components/LinkButton.svelte"; import LinkButton from "$lib/components/LinkButton.svelte";
export let bot: object; export let bot: object;
export let owner: object;
export let versions: object[];
export let matches: object[]; export let matches: object[];
export let errorMatches: object[]; export let errorMatches: object[];
</script> </script>
@ -58,31 +54,6 @@
<div class="container"> <div class="container">
{#if $currentUser && $currentUser["user_id"] === bot["owner_id"]} {#if $currentUser && $currentUser["user_id"] === bot["owner_id"]}
<div>
<!-- TODO: can we avoid hardcoding the url? -->
Publish a new version by pushing a docker container to
<code>registry.planetwars.dev/{bot["name"]}:latest</code>, or using the web editor.
</div>
<div class="versions">
<h3>Versions</h3>
<ul class="version-list">
{#each versions.slice(0, 10) as version}
<li class="bot-version">
{dayjs(version["created_at"]).format("YYYY-MM-DD HH:mm")}
{#if version["container_digest"]}
<span class="container-digest">{version["container_digest"]}</span>
{:else}
<a href={`/code/${version["id"]}`}>view code</a>
{/if}
</li>
{/each}
</ul>
{#if versions.length == 0}
This bot does not have any versions yet.
{/if}
</div>
<div class="matches"> <div class="matches">
<h3>Matches with errors</h3> <h3>Matches with errors</h3>
<MatchList matches={errorMatches} /> <MatchList matches={errorMatches} />
@ -126,18 +97,4 @@
padding: 12px; padding: 12px;
text-align: center; text-align: center;
} }
.versions {
margin: 30px 0;
}
.version-list {
padding: 0;
}
.bot-version {
display: flex;
justify-content: space-between;
padding: 4px 24px;
}
</style> </style>

View file

@ -0,0 +1,85 @@
<!-- TODO: should we prevent users who are not the bot owner
from seeing this page? -->
<script lang="ts" context="module">
import { ApiClient } from "$lib/api_client";
import dayjs from "dayjs";
export async function load({ params, fetch }) {
const apiClient = new ApiClient(fetch);
try {
const botName = params["bot_name"];
const { bot, versions } = await apiClient.get(`/api/bots/${botName}`);
versions.sort((a: string, b: string) =>
dayjs(a["created_at"]).isAfter(b["created_at"]) ? -1 : 1
);
return {
props: {
bot,
versions,
},
};
} catch (error) {
return {
status: error.status,
error: error,
};
}
}
</script>
<script lang="ts">
export let bot;
export let versions;
</script>
<div class="container">
<div>
<!-- TODO: can we avoid hardcoding the url? -->
Publish a new version by pushing a docker container to
<code>registry.planetwars.dev/{bot["name"]}:latest</code>, or using the web editor.
</div>
<div class="versions">
<h3>Versions</h3>
<ul class="version-list">
{#each versions as version}
<li class="bot-version">
{dayjs(version["created_at"]).format("YYYY-MM-DD HH:mm")}
{#if version["container_digest"]}
<span class="container-digest">{version["container_digest"]}</span>
{:else}
<a href={`/code/${version["id"]}`}>view code</a>
{/if}
</li>
{/each}
</ul>
{#if versions.length == 0}
This bot does not have any versions yet.
{/if}
</div>
</div>
<style lang="scss">
.container {
width: 800px;
max-width: 80%;
margin: 50px auto;
padding-bottom: 24px;
}
.versions {
margin: 30px 0;
}
.version-list {
padding: 0;
}
.bot-version {
display: flex;
justify-content: space-between;
padding: 4px 24px;
}
</style>