Skip to content

Commit e714a46

Browse files
authored
Merge pull request #2698 from appwrite/fix-disabled-states
2 parents e26e9bb + 55ad9a6 commit e714a46

File tree

4 files changed

+52
-23
lines changed

4 files changed

+52
-23
lines changed

src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/+layout.svelte

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@
8282
let editRelatedRow: EditRelatedRow;
8383
let editRowPermissions: EditRowPermissions;
8484
85+
let editRowDisabled = true;
86+
let editRelatedRowDisabled = true;
87+
let editRowPermissionsDisabled = true;
88+
8589
let createIndex: CreateIndex;
8690
let createColumn: CreateColumn;
8791
let selectedOption: Option['name'] = 'String';
@@ -436,7 +440,7 @@
436440
bind:show={$databaseRowSheetOptions.show}
437441
submit={{
438442
text: 'Update',
439-
disabled: editRow?.isDisabled(),
443+
disabled: editRowDisabled,
440444
onClick: async () => await editRow?.update()
441445
}}
442446
topAction={{
@@ -501,6 +505,7 @@
501505
bind:this={editRow}
502506
bind:row={$databaseRowSheetOptions.row}
503507
bind:rowId={$databaseRowSheetOptions.rowId}
508+
bind:disabled={editRowDisabled}
504509
autoFocus={$databaseRowSheetOptions.autoFocus} />
505510
{/key}
506511
</SideSheet>
@@ -511,13 +516,14 @@
511516
bind:show={$databaseRelatedRowSheetOptions.show}
512517
submit={{
513518
text: 'Update',
514-
disabled: editRelatedRow?.isDisabled(),
519+
disabled: editRelatedRowDisabled,
515520
onClick: async () => await editRelatedRow?.update()
516521
}}>
517522
<EditRelatedRow
518523
bind:this={editRelatedRow}
519524
rows={$databaseRelatedRowSheetOptions.rows}
520-
tableId={$databaseRelatedRowSheetOptions.tableId} />
525+
tableId={$databaseRelatedRowSheetOptions.tableId}
526+
bind:disabledState={editRelatedRowDisabled} />
521527
</SideSheet>
522528

523529
<SideSheet
@@ -542,10 +548,13 @@
542548
bind:show={$rowPermissionSheet.show}
543549
submit={{
544550
text: 'Update',
545-
disabled: editRowPermissions?.disableSubmit(),
551+
disabled: editRowPermissionsDisabled,
546552
onClick: async () => editRowPermissions?.updatePermissions()
547553
}}>
548-
<EditRowPermissions bind:this={editRowPermissions} bind:row={$rowPermissionSheet.row} />
554+
<EditRowPermissions
555+
bind:this={editRowPermissions}
556+
bind:row={$rowPermissionSheet.row}
557+
bind:arePermsDisabled={editRowPermissionsDisabled} />
549558
</SideSheet>
550559

551560
<SideSheet title="Row activity" bind:show={$rowActivitySheet.show} closeOnBlur>

src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/rows/edit.svelte

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,33 @@
1919
import { Layout, Skeleton } from '@appwrite.io/pink-svelte';
2020
import { deepClone } from '$lib/helpers/object';
2121
import deepEqual from 'deep-equal';
22+
import { onMount } from 'svelte';
2223
2324
const tableId = page.params.table;
2425
const databaseId = page.params.database;
2526
2627
let {
2728
row = $bindable(),
2829
rowId = $bindable(null),
29-
autoFocus = true
30+
autoFocus = true,
31+
disabled = $bindable(true)
3032
}: {
3133
row?: Models.Row | null;
3234
rowId?: string | null;
3335
autoFocus?: boolean;
36+
disabled?: boolean;
3437
} = $props();
3538
3639
let loading = $state(false);
3740
3841
let work = $state<Writable<Models.Row> | null>(null);
3942
let columnFormWrapper = $state<HTMLElement | null>(null);
4043
44+
onMount(() => {
45+
/* silences the not read error warning */
46+
disabled;
47+
});
48+
4149
function initWork() {
4250
const filteredKeys = Object.keys(row).filter((key) => {
4351
return !PROHIBITED_ROW_KEYS.includes(key);
@@ -157,11 +165,14 @@
157165
}
158166
}
159167
160-
export function isDisabled(): boolean {
161-
if (!work || !row || !$table?.columns?.length) return true;
168+
$effect(() => {
169+
if (!work || !row || !$table?.columns?.length) {
170+
disabled = true;
171+
return;
172+
}
162173
163-
return $table.columns.every((column) => compareColumns(column, $work, row));
164-
}
174+
disabled = $table.columns.every((column) => compareColumns(column, $work, row));
175+
});
165176
166177
function focusFirstInput() {
167178
const firstInput = columnFormWrapper?.querySelector<HTMLInputElement | HTMLTextAreaElement>(

src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/rows/editPermissions.svelte

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,23 @@
1010
import { addNotification } from '$lib/stores/notifications';
1111
import { symmetricDifference } from '$lib/helpers/array';
1212
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
13+
import { onMount } from 'svelte';
1314
1415
let {
15-
row = $bindable(null)
16+
row = $bindable(null),
17+
arePermsDisabled = $bindable(true)
1618
}: {
1719
row: Models.DefaultRow | Models.Row;
20+
arePermsDisabled?: boolean;
1821
} = $props();
1922
20-
let permissions = $state(row.$permissions);
21-
let arePermsDisabled = $state(true);
2223
let showPermissionAlert = $state(true);
24+
let permissions = $state(row.$permissions);
2325
24-
export function disableSubmit() {
25-
return arePermsDisabled;
26-
}
26+
onMount(() => {
27+
/* silences the not read error warning */
28+
arePermsDisabled;
29+
});
2730
2831
export async function updatePermissions() {
2932
try {

src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/rows/editRelated.svelte

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,32 @@
1414
import { Accordion, Layout, Skeleton } from '@appwrite.io/pink-svelte';
1515
import { deepClone } from '$lib/helpers/object';
1616
import { preferences } from '$lib/stores/preferences';
17+
import { onMount } from 'svelte';
1718
1819
const databaseId = page.params.database;
1920
2021
let {
2122
rows,
22-
tableId
23+
tableId,
24+
disabledState = $bindable(true)
2325
}: {
2426
rows: string | Models.Row[];
2527
tableId: string;
28+
disabledState?: boolean;
2629
} = $props();
2730
2831
let loading = $state(false);
2932
let fetchedRows = $state<Models.Row[]>([]);
3033
let relatedTable = $state<Models.Table | null>(null);
3134
32-
let disabledState = $state(calculateAndCompareDisabledState());
33-
3435
let workData = $state<Map<string, Writable<Models.Row>>>(new Map());
3536
let columnFormWrapper = $state<HTMLElement | null>(null);
3637
38+
onMount(() => {
39+
/* silences the not read error warning */
40+
disabledState;
41+
});
42+
3743
function isSingleStore() {
3844
return typeof rows === 'string';
3945
}
@@ -287,10 +293,6 @@
287293
}
288294
}
289295
290-
export function isDisabled(): boolean {
291-
return disabledState;
292-
}
293-
294296
function focusFirstInput() {
295297
const firstInput = columnFormWrapper?.querySelector<HTMLInputElement | HTMLTextAreaElement>(
296298
'input:not([disabled]):not([readonly]), textarea:not([disabled]):not([readonly])'
@@ -335,6 +337,10 @@
335337
});
336338
}
337339
});
340+
341+
$effect(() => {
342+
disabledState = calculateAndCompareDisabledState();
343+
});
338344
</script>
339345

340346
{#if loading}

0 commit comments

Comments
 (0)