Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Message on relationship deletion #1727

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lib/components/trim.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { throttle } from '$lib/helpers/functions';
import { onMount } from 'svelte';

export let alternativeTrim = false;
let showTooltip = false;
export let alternativeTrim = false;
let container: HTMLSpanElement | null;

onMount(onResize);
Expand All @@ -21,6 +21,7 @@
bind:this={container}
use:tooltip={{
disabled: !showTooltip,
appendTo: 'parent',
content: container?.innerText ?? undefined,
maxWidth: '30rem'
}}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { page } from '$app/stores';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import { Alert, Modal, Trim } from '$lib/components';
import { Button, InputChoice } from '$lib/elements/forms';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import {
TableBody,
TableCell,
Expand All @@ -17,7 +17,7 @@
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { attributes, collection } from '../store';
import { isRelationship } from './attributes/store';
import { isRelationship, isRelationshipToMany } from './attributes/store';
import type { Models } from '@appwrite.io/console';

export let showDelete = false;
Expand Down Expand Up @@ -52,11 +52,20 @@
enum Deletion {
'setNull' = 'Set document ID as NULL in all related documents',
'cascade' = 'All related documents will be deleted',
'restrict' = 'Document can not be deleted'
'restrict' = 'Document cannot be deleted'
}

$: relAttributes = $attributes?.filter((attribute) =>
isRelationship(attribute)
$: relAttributes = $attributes?.filter(
(attribute) =>
isRelationship(attribute) &&
// One-to-One are always included
(attribute.relationType === 'oneToOne' ||
// One-to-Many: Only if parent is deleted
(attribute.relationType === 'oneToMany' && attribute.side === 'parent') ||
// Many-to-One: Only include if child is deleted
(attribute.relationType === 'manyToOne' && attribute.side === 'child') ||
// Many-to-Many: Only include if the parent is being deleted
(isRelationshipToMany(attribute) && attribute.side === 'parent'))
) as Models.AttributeRelationship[];
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,17 @@
'restrict' = 'Document can not be deleted'
}

$: relAttributes = $attributes?.filter((attribute) =>
isRelationship(attribute)
$: relAttributes = $attributes?.filter(
(attribute) =>
isRelationship(attribute) &&
// One-to-One are always included
(attribute.relationType === 'oneToOne' ||
// One-to-Many: Only if parent is deleted
(attribute.relationType === 'oneToMany' && attribute.side === 'parent') ||
// Many-to-One: Only include if child is deleted
(attribute.relationType === 'manyToOne' && attribute.side === 'child') ||
// Many-to-Many: Only include if the parent is being deleted
(isRelationshipToMany(attribute) && attribute.side === 'parent'))
) as Models.AttributeRelationship[];

let checked = false;
Expand Down