mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
fix: various fixes to edit attributes
This commit is contained in:
1 parent
a8b614d7c6
commit
fa25ddef02
15 files changed
+68
-59
No files matched your search
@@ -9,7 +9,7 @@
|
||||
class="/*u-flex-basis-140*/ u-flex-shrink-0 u-text-start u-trim-start u-x-small u-color-text-gray">
|
||||
<slot />
|
||||
</span>
|
||||
{#if data.length}
|
||||
{#if data?.length}
|
||||
<span
|
||||
class="u-flex u-trim-1 u-gap-4"
|
||||
use:tooltip={{
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@
|
||||
collectionId,
|
||||
data.key,
|
||||
data.required,
|
||||
data.default ? data.default : undefined
|
||||
data.default ? data.default : null
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@
|
||||
collectionId,
|
||||
data.key,
|
||||
data.required,
|
||||
data.default ? data.default : undefined
|
||||
data.default ? data.default : null
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
+7
-2
@@ -10,6 +10,7 @@
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
|
||||
export let showDelete = false;
|
||||
export let selectedAttribute: Attributes;
|
||||
@@ -41,8 +42,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
function isRelationship(attr: Attributes): attr is Models.AttributeRelationship {
|
||||
return attr.type === 'relationship';
|
||||
}
|
||||
|
||||
$: isDeleteBtnDisabled =
|
||||
selectedAttribute?.type === 'relationship' && selectedAttribute?.twoWay && !checked;
|
||||
isRelationship(selectedAttribute) && selectedAttribute?.twoWay && !checked;
|
||||
</script>
|
||||
|
||||
<Modal
|
||||
@@ -56,7 +61,7 @@
|
||||
Are you sure you want to delete <b>"{selectedAttribute?.key}" from "{$collection?.name}"</b
|
||||
>?
|
||||
</p>
|
||||
{#if selectedAttribute?.type === 'relationship' && selectedAttribute?.twoWay}
|
||||
{#if isRelationship(selectedAttribute) && selectedAttribute?.twoWay}
|
||||
<div class="u-flex u-flex-vertical u-gap-24">
|
||||
<p class="text">
|
||||
Are you sure you want to delete <b
|
||||
|
||||
+3
-14
@@ -16,7 +16,6 @@
|
||||
const databaseId = $page.params.database;
|
||||
const collectionId = $page.params.collection;
|
||||
|
||||
let updateButtonDisabled = true;
|
||||
let error: string;
|
||||
let currentAttr: string;
|
||||
|
||||
@@ -33,7 +32,7 @@
|
||||
}
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: `Attribute ${selectedAttribute.key} has been created`
|
||||
message: `Attribute ${selectedAttribute.key} has been updated`
|
||||
});
|
||||
showEdit = false;
|
||||
trackEvent(Submit.AttributeUpdate);
|
||||
@@ -44,19 +43,9 @@
|
||||
}
|
||||
|
||||
$: if (showEdit) {
|
||||
currentAttr ??= JSON.stringify(selectedAttribute);
|
||||
currentAttr = JSON.parse(JSON.stringify(selectedAttribute));
|
||||
error = null;
|
||||
}
|
||||
|
||||
$: updateButtonDisabled = (() => {
|
||||
console.log(
|
||||
JSON.stringify(selectedAttribute),
|
||||
currentAttr,
|
||||
JSON.stringify(selectedAttribute) === currentAttr
|
||||
);
|
||||
return JSON.stringify(selectedAttribute) === currentAttr;
|
||||
})();
|
||||
// $: console.log(updateButtonDisabled, JSON.stringify(selectedAttribute), currentAttr);
|
||||
</script>
|
||||
|
||||
{#if selectedAttribute}
|
||||
@@ -101,7 +90,7 @@
|
||||
</FormList>
|
||||
<svelte:fragment slot="footer">
|
||||
<Button secondary on:click={() => (showEdit = false)}>Cancel</Button>
|
||||
<Button submit disabled={updateButtonDisabled}>Update</Button>
|
||||
<Button submit>Update</Button>
|
||||
</svelte:fragment>
|
||||
</Modal>
|
||||
{/if}
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
collectionId,
|
||||
data.key,
|
||||
data.required,
|
||||
data.default ? data.default : undefined
|
||||
data.default ? data.default : null
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@
|
||||
data.key,
|
||||
data.elements,
|
||||
data.required,
|
||||
data.default ? data.default : undefined
|
||||
data.default ? data.default : null
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@
|
||||
data.required,
|
||||
data.min,
|
||||
data.max,
|
||||
typeof data.default === 'number' ? data.default : undefined
|
||||
typeof data.default === 'number' ? data.default : null
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@
|
||||
data.required,
|
||||
data.min,
|
||||
data.max,
|
||||
typeof data.default === 'number' ? data.default : undefined
|
||||
typeof data.default === 'number' ? data.default : null
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
collectionId,
|
||||
data.key,
|
||||
data.required,
|
||||
data.default ? data.default : undefined
|
||||
data.default ? data.default : null
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
collectionId,
|
||||
data.key,
|
||||
data.required,
|
||||
data.default ? (data.default as string) : undefined
|
||||
data.default ? (data.default as string) : null
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@
|
||||
collectionId,
|
||||
data.key,
|
||||
data.required,
|
||||
data.default ? data.default : undefined
|
||||
data.default ? data.default : null
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
+3
-3
@@ -13,7 +13,7 @@
|
||||
export let showCreate = false;
|
||||
export let selectedOption: string = null;
|
||||
const databaseId = $page.params.database;
|
||||
const collectionId = $page.params.collection;
|
||||
$: collectionId = $page.params.collection;
|
||||
|
||||
let key: string = null;
|
||||
let data: Partial<Attributes> = {
|
||||
@@ -26,8 +26,8 @@
|
||||
async function submit() {
|
||||
try {
|
||||
await $option.create(databaseId, collectionId, key, data);
|
||||
// await invalidate(Dependencies.COLLECTION);
|
||||
await Promise.allSettled([invalidate(Dependencies.COLLECTION)]);
|
||||
await invalidate(Dependencies.COLLECTION);
|
||||
// await Promise.allSettled([invalidate(Dependencies.COLLECTION)]);
|
||||
if (!$page.url.pathname.includes('attributes')) {
|
||||
await goto(
|
||||
`${base}/console/project-${$page.params.project}/databases/database-${databaseId}/collection-${collectionId}/attributes`
|
||||
|
||||
+33
-22
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/stores';
|
||||
import { Paginator } from '$lib/components';
|
||||
import { PaginationInline } from '$lib/components';
|
||||
import { SelectSearchItem } from '$lib/elements';
|
||||
import { Button, InputSelectSearch, Label } from '$lib/elements/forms';
|
||||
import { organization } from '$lib/stores/organization';
|
||||
@@ -22,8 +22,10 @@
|
||||
let documentList: Models.DocumentList<Models.Document>;
|
||||
let search: string = null;
|
||||
let displayNames = ['$id'];
|
||||
let relatedList: string[] | { label: string; data: Record<string, unknown> }[] = [];
|
||||
let relatedList: string[] = [];
|
||||
let showInput = false;
|
||||
let limit = 10;
|
||||
let offset = 0;
|
||||
|
||||
onMount(async () => {
|
||||
teamPrefs.load($organization.$id);
|
||||
@@ -74,10 +76,13 @@
|
||||
$: getDocuments(search).then((res) => (documentList = res));
|
||||
|
||||
$: if (isArray) value = relatedList;
|
||||
|
||||
$: paginatedItems = relatedList.slice(offset, offset + limit);
|
||||
$: total = relatedList?.length;
|
||||
</script>
|
||||
|
||||
{#if editing && isArray && relatedList.length > 0}
|
||||
<Paginator items={relatedList} limit={5} let:paginatedItems>
|
||||
{#if editing && isArray && total > 0}
|
||||
<div>
|
||||
<div class="u-flex u-cross-center u-main-space-between">
|
||||
<div>
|
||||
<Label required={attribute.required} {optionalText} for={id}>
|
||||
@@ -107,17 +112,19 @@
|
||||
customOutput
|
||||
placeholder={`Select ${attribute.key}`}
|
||||
bind:search
|
||||
bind:value={relatedList[relatedList.length]}
|
||||
options={documentList?.documents?.map((n) => {
|
||||
const data = displayNames
|
||||
.filter((name) => name !== '$id')
|
||||
.map((name) => n?.[name]);
|
||||
return {
|
||||
value: n.$id,
|
||||
label: n.$id,
|
||||
data
|
||||
};
|
||||
}) ?? []}
|
||||
bind:value={relatedList[total]}
|
||||
options={documentList?.documents
|
||||
?.filter((n) => !relatedList.includes(n.$id))
|
||||
.map((n) => {
|
||||
const data = displayNames
|
||||
.filter((name) => name !== '$id')
|
||||
.map((name) => n?.[name]);
|
||||
return {
|
||||
value: n.$id,
|
||||
label: n.$id,
|
||||
data
|
||||
};
|
||||
}) ?? []}
|
||||
on:select={() => {
|
||||
showInput = false;
|
||||
}}
|
||||
@@ -135,8 +142,8 @@
|
||||
</Button>
|
||||
</li>
|
||||
{/if}
|
||||
{#if paginatedItems?.length}
|
||||
{#each paginatedItems as doc, i}
|
||||
{#if paginatedItems}
|
||||
{#each relatedList as item, i}
|
||||
<li class="u-flex u-gap-16">
|
||||
<InputSelectSearch
|
||||
{id}
|
||||
@@ -145,7 +152,7 @@
|
||||
required
|
||||
customOutput
|
||||
bind:search
|
||||
bind:value={doc}
|
||||
bind:value={item}
|
||||
options={documentList?.documents?.map((n) => {
|
||||
const data = displayNames
|
||||
.filter((name) => name !== '$id')
|
||||
@@ -175,7 +182,11 @@
|
||||
{/each}
|
||||
{/if}
|
||||
</ul>
|
||||
</Paginator>
|
||||
<div class="u-flex u-margin-block-start-32 u-main-space-between">
|
||||
<p class="text">Total results: {total}</p>
|
||||
<PaginationInline {limit} bind:offset sum={total} hidePages />
|
||||
</div>
|
||||
</div>
|
||||
{:else if isArray}
|
||||
<div class="u-width-full-line">
|
||||
<div class="u-flex u-cross-center u-main-space-between">
|
||||
@@ -184,7 +195,7 @@
|
||||
{label}
|
||||
</Label>
|
||||
</div>
|
||||
{#if relatedList.length === 0}
|
||||
{#if total === 0}
|
||||
<Button
|
||||
text
|
||||
noMargin
|
||||
@@ -246,7 +257,7 @@
|
||||
customOutput
|
||||
placeholder={`Select ${attribute.key}`}
|
||||
bind:search
|
||||
bind:value={relatedList[relatedList.length]}
|
||||
bind:value={relatedList[total]}
|
||||
options={documentList?.documents?.map((n) => {
|
||||
const data = displayNames
|
||||
.filter((name) => name !== '$id')
|
||||
@@ -276,7 +287,7 @@
|
||||
{/if}
|
||||
</ul>
|
||||
|
||||
{#if relatedList.length > 0}
|
||||
{#if total > 0}
|
||||
<Button
|
||||
text
|
||||
noMargin
|
||||
|
||||
+12
-8
@@ -14,6 +14,7 @@
|
||||
TableScroll
|
||||
} from '$lib/elements/table';
|
||||
import { organization } from '$lib/stores/organization';
|
||||
import { preferences } from '$lib/stores/preferences';
|
||||
import { teamPrefs } from '$lib/stores/team';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
import { onMount } from 'svelte';
|
||||
@@ -32,14 +33,6 @@
|
||||
|
||||
onMount(() => {
|
||||
teamPrefs.load($organization.$id);
|
||||
columns.set([
|
||||
...$collection.attributes.map((attribute) => ({
|
||||
id: attribute.key,
|
||||
title: attribute.key,
|
||||
type: attribute.type,
|
||||
show: true
|
||||
}))
|
||||
]);
|
||||
});
|
||||
|
||||
function formatArray(array: unknown[]) {
|
||||
@@ -83,6 +76,17 @@
|
||||
function isRelationship(attr: Partial<Attribute>): attr is Models.AttributeRelationship {
|
||||
return attr?.type === 'relationship';
|
||||
}
|
||||
|
||||
$: selected = preferences.getCustomCollectionColumns($page.params.collection);
|
||||
|
||||
$: columns.set(
|
||||
$collection.attributes.map((attribute) => ({
|
||||
id: attribute.key,
|
||||
title: attribute.key,
|
||||
type: attribute.type,
|
||||
show: selected?.includes(attribute.key) ?? true
|
||||
}))
|
||||
);
|
||||
</script>
|
||||
|
||||
<TableScroll isSticky>
|
||||
|
||||
Reference in new issue
Block a user