misc: fixes.

This commit is contained in:
Darshan committed 2025-05-14 09:51:56 +05:30
1 parent 4c2475879d
commit ffa59104ea
7 files changed
+174 -132

No files matched your search

+25 -9
View File
@@ -1,3 +1,10 @@
<script context="module" lang="ts">
export type ExpirationOptions = {
label: string;
value: string;
};
</script>
<script lang="ts">
import { InputDateTime, InputSelect } from '$lib/elements/forms';
import { isSameDay, isValidDate, toLocaleDate } from '$lib/helpers/date';
@@ -19,7 +26,7 @@
return date.toISOString();
}
const defaultOptions = [
const defaultOptions: ExpirationOptions[] = [
{
label: 'Never',
value: null
@@ -46,7 +53,7 @@
}
];
const limitedOptions = [
const limitedOptions: ExpirationOptions[] = [
{
label: '1 Day',
value: incrementToday(1, 'day')
@@ -62,9 +69,16 @@
];
export let value: string | null = null;
export let keyType: 'api' | 'dev' = 'api';
export let dateSelectorLabel: string | undefined = undefined;
export let selectorLabel: string | undefined = 'Expiration date';
export let resourceType: string | 'key' | 'token' | undefined = 'key';
export let expiryOptions: 'default' | 'limited' | ExpirationOptions[] = 'default';
const options = keyType === 'api' ? defaultOptions : limitedOptions;
const options = Array.isArray(expiryOptions)
? expiryOptions
: expiryOptions === 'default'
? defaultOptions
: limitedOptions;
function initExpirationSelect() {
if (value === null || !isValidDate(value)) {
@@ -84,7 +98,9 @@
return result;
}
// dd/mm/yy format for selecting dates only!
/**
* Custom picker only supports `dd/mm/yy` format.
*/
function splitDateValue(value: string): string {
return value.slice(0, 10);
}
@@ -100,8 +116,8 @@
$: helper =
expirationSelect !== 'custom' && expirationSelect !== null
? `Your key will expire in ${toLocaleDate(value)}`
: undefined;
? `Your ${resourceType} will expire in ${toLocaleDate(value)}`
: null;
</script>
<InputSelect
@@ -109,9 +125,9 @@
{helper}
{options}
id="preset"
label="Expiration date"
label={selectorLabel}
bind:value={expirationSelect} />
{#if expirationSelect === 'custom'}
<InputDateTime required id="expire" label="" bind:value={expirationCustom} />
<InputDateTime required id="expire" label={dateSelectorLabel} bind:value={expirationCustom} />
{/if}
+124 -120
View File
@@ -22,6 +22,7 @@
import { connectGitHub } from '$lib/stores/git';
import { page } from '$app/state';
import Card from '../card.svelte';
import SkeletonRepoList from './skeletonRepoList.svelte';
let {
action = $bindable('select'),
@@ -43,6 +44,7 @@
let search = $state('');
let selectedInstallation = null;
let isLoadingRepositories = $state(null);
async function loadInstallations() {
if (installationList) {
@@ -153,6 +155,11 @@
installation.set(
installations.find((entry) => entry.$id === selectedInstallation)
);
isLoadingRepositories = true;
loadRepositories(selectedInstallation, search).then(() => {
isLoadingRepositories = false;
});
}}
bind:value={selectedInstallation} />
<InputSearch
@@ -163,133 +170,130 @@
{/await}
</Layout.Stack>
{#if selectedInstallation}
{#await loadRepositories(selectedInstallation, search)}
<Table.Root columns={1} let:root>
{#each Array(4) as _}
<Table.Row.Base {root}>
<Table.Cell {root}>
<Layout.Stack direction="row" alignItems="center">
<Skeleton variant="circle" width={24} />
<Layout.Stack gap="s" direction="row" alignItems="center">
<Skeleton variant="line" width={200} height={20} />
</Layout.Stack>
<Skeleton variant="line" width={76} height={32} />
</Layout.Stack>
</Table.Cell>
</Table.Row.Base>
{/each}
</Table.Root>
{:then response}
{#if response?.length}
<Paginator items={response} hideFooter={response?.length <= 6} limit={6}>
{#snippet children(
paginatedItems: Models.ProviderRepositoryRuntime[] &
Models.ProviderRepositoryFramework[]
)}
<Table.Root columns={1} let:root>
{#each paginatedItems as repo}
<Table.Row.Base {root}>
<Table.Cell {root}>
<Layout.Stack
direction="row"
alignItems="center"
gap="s">
{#if action === 'select'}
<input
class="is-small u-margin-inline-end-8"
type="radio"
name="repositories"
bind:group={selectedRepository}
onchange={() => repository.set(repo)}
value={repo.id} />
{/if}
{#if product === 'sites'}
{#if repo?.framework && repo.framework !== 'other'}
<Avatar size="xs" alt={repo.name}>
<!-- manual installation change -->
{#if isLoadingRepositories}
<SkeletonRepoList />
{:else}
{#await loadRepositories(selectedInstallation, search)}
<SkeletonRepoList />
{:then response}
{#if response?.length}
<Paginator items={response} hideFooter={response?.length <= 6} limit={6}>
{#snippet children(
paginatedItems: Models.ProviderRepositoryRuntime[] &
Models.ProviderRepositoryFramework[]
)}
<Table.Root columns={1} let:root>
{#each paginatedItems as repo}
<Table.Row.Base {root}>
<Table.Cell {root}>
<Layout.Stack
direction="row"
alignItems="center"
gap="s">
{#if action === 'select'}
<input
class="is-small u-margin-inline-end-8"
type="radio"
name="repositories"
bind:group={selectedRepository}
onchange={() => repository.set(repo)}
value={repo.id} />
{/if}
{#if product === 'sites'}
{#if repo?.framework && repo.framework !== 'other'}
<Avatar size="xs" alt={repo.name}>
<SvgIcon
name={getFrameworkIcon(
repo.framework
)}
iconSize="small" />
</Avatar>
{:else}
<Avatar
size="xs"
alt={repo.name}
empty />
{/if}
{:else}
{@const iconName = repo?.runtime
? repo.runtime.split('-')[0]
: undefined}
<Avatar
size="xs"
alt={repo.name}
empty={!iconName}>
<SvgIcon
name={getFrameworkIcon(
repo.framework
)}
name={iconName}
iconSize="small" />
</Avatar>
{:else}
<Avatar size="xs" alt={repo.name} empty />
{/if}
{:else}
{@const iconName = repo?.runtime
? repo.runtime.split('-')[0]
: undefined}
<Avatar
size="xs"
alt={repo.name}
empty={!iconName}>
<SvgIcon name={iconName} iconSize="small" />
</Avatar>
{/if}
<Layout.Stack
gap="s"
direction="row"
alignItems="center">
<Typography.Text
truncate
color="--fgcolor-neutral-secondary">
{repo.name}
</Typography.Text>
{#if repo.private}
<Icon
size="s"
icon={IconLockClosed}
color="--fgcolor-neutral-tertiary" />
{/if}
<time datetime={repo.pushedAt}>
<Typography.Caption
variant="400"
truncate
color="--fgcolor-neutral-tertiary">
{timeFromNow(repo.pushedAt)}
</Typography.Caption>
</time>
</Layout.Stack>
{#if action === 'button'}
<Layout.Stack
gap="s"
direction="row"
justifyContent="flex-end">
<PinkButton.Button
size="xs"
variant="secondary"
on:click={() => connect(repo)}>
Connect
</PinkButton.Button>
alignItems="center">
<Typography.Text
truncate
color="--fgcolor-neutral-secondary">
{repo.name}
</Typography.Text>
{#if repo.private}
<Icon
size="s"
icon={IconLockClosed}
color="--fgcolor-neutral-tertiary" />
{/if}
<time datetime={repo.pushedAt}>
<Typography.Caption
variant="400"
truncate
color="--fgcolor-neutral-tertiary">
{timeFromNow(repo.pushedAt)}
</Typography.Caption>
</time>
</Layout.Stack>
{/if}
</Layout.Stack>
</Table.Cell>
</Table.Row.Base>
{/each}
</Table.Root>
{/snippet}
</Paginator>
{:else if search}
<EmptySearch hidePages hidePagination bind:search target="repositories">
<svelte:fragment slot="actions">
{#if search}
<Button secondary on:click={() => (search = '')}>
Clear search
</Button>
{/if}
</svelte:fragment>
</EmptySearch>
{:else}
<Card>
<Layout.Stack alignItems="center" justifyContent="center">
<Typography.Text variation="m-500" color="--fgcolor-neutral-tertiary">
No repositories available
</Typography.Text>
</Layout.Stack>
</Card>
{/if}
{/await}
{#if action === 'button'}
<Layout.Stack
direction="row"
justifyContent="flex-end">
<PinkButton.Button
size="xs"
variant="secondary"
on:click={() => connect(repo)}>
Connect
</PinkButton.Button>
</Layout.Stack>
{/if}
</Layout.Stack>
</Table.Cell>
</Table.Row.Base>
{/each}
</Table.Root>
{/snippet}
</Paginator>
{:else if search}
<EmptySearch hidePages hidePagination bind:search target="repositories">
<svelte:fragment slot="actions">
{#if search}
<Button secondary on:click={() => (search = '')}>
Clear search
</Button>
{/if}
</svelte:fragment>
</EmptySearch>
{:else}
<Card>
<Layout.Stack alignItems="center" justifyContent="center">
<Typography.Text
variation="m-500"
color="--fgcolor-neutral-tertiary">
No repositories available
</Typography.Text>
</Layout.Stack>
</Card>
{/if}
{/await}
{/if}
{/if}
</Layout.Stack>
{:else}
@@ -0,0 +1,20 @@
<script lang="ts">
import { Layout, Table, Skeleton } from '@appwrite.io/pink-svelte';
</script>
<Table.Root columns={1} let:root>
{#each Array(4) as _}
<Table.Row.Base {root}>
<Table.Cell {root}>
<Layout.Stack direction="row" alignItems="center">
<Skeleton variant="circle" width={24} />
<Layout.Stack gap="s" direction="row" alignItems="center">
<Skeleton variant="line" width={200} height={20} />
</Layout.Stack>
<Skeleton variant="line" width={76} height={32} />
</Layout.Stack>
</Table.Cell>
</Table.Row.Base>
{/each}
</Table.Root>
@@ -75,7 +75,7 @@
required
bind:value={name} />
<ExpirationInput bind:value={expire} keyType="api" />
<ExpirationInput bind:value={expire} />
</Layout.Stack>
</Fieldset>
@@ -19,6 +19,7 @@
const isApiKey = keyType === 'api';
const label = isApiKey ? 'API' : 'Dev';
const expiryOptions = isApiKey ? 'default' : 'limited';
const dependency = isApiKey ? Dependencies.KEY : Dependencies.DEV_KEY;
const event = isApiKey ? Submit.KeyUpdateExpire : Submit.DevKeyUpdateExpire;
@@ -90,7 +91,7 @@
Update the expiration date to keep the key active
</Alert.Inline>
{/if}
<ExpirationInput bind:value={expiration} {keyType} />
<ExpirationInput bind:value={expiration} {expiryOptions} />
</svelte:fragment>
<svelte:fragment slot="actions">
@@ -69,7 +69,7 @@
required
bind:value={name} />
<ExpirationInput bind:value={expire} keyType="dev" />
<ExpirationInput bind:value={expire} expiryOptions="limited" />
</Layout.Stack>
<Layout.Stack direction="row" justifyContent="flex-end" slot="footer">
@@ -30,6 +30,7 @@
expire = null;
isDelete = false;
fileToken = null;
isUpdatePermissions = false;
}
function handleFileToken() {