Skip to content

Commit 932ac64

Browse files
authored
Merge pull request #2812 from appwrite/fix-project-stores
2 parents 612cd0f + ad909fd commit 932ac64

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+591
-431
lines changed

src/lib/helpers/faker.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import type { DatabaseType, Field } from '$database/(entity)';
66
import { coerceToNumber, isWithinSafeRange } from '$lib/helpers/numbers';
77

88
export async function generateFields(
9-
project: Models.Project,
9+
project: {
10+
id: string;
11+
region: string;
12+
},
1013
databaseId: string,
1114
tableId: string,
1215
databaseType: DatabaseType
1316
): Promise<Field[]> {
14-
const client = sdk.forProject(project.region, project.$id);
17+
const client = sdk.forProject(project.region, project.id);
1518

1619
switch (databaseType) {
1720
case 'legacy':
Lines changed: 94 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,122 @@
11
<script lang="ts">
22
import { goto } from '$app/navigation';
3-
import { base } from '$app/paths';
43
import { page } from '$app/state';
54
import { addSubPanel, registerCommands, updateCommandGroupRanks } from '$lib/commandCenter';
65
import { TeamsPanel, UsersPanel } from '$lib/commandCenter/panels';
76
import { readOnly } from '$lib/stores/billing';
87
import { canWriteTeams, canWriteUsers } from '$lib/stores/roles';
98
import { GRACE_PERIOD_OVERRIDE } from '$lib/system';
10-
import { project } from '../store';
119
import { showCreateUser } from './+page.svelte';
1210
import { showCreateTeam } from './teams/+page.svelte';
1311
import { IconPlus } from '@appwrite.io/pink-icons-svelte';
12+
import { resolveRoute, withPath } from '$lib/stores/navigation';
1413
15-
$: $registerCommands([
16-
{
17-
label: 'Create user',
18-
callback: async () => {
19-
if (!page.url.pathname.endsWith('auth')) {
20-
await goto(`${base}/project-${$project.region}-${$project.$id}/auth`);
21-
}
22-
showCreateUser.set(true);
23-
},
24-
keys: page.url.pathname.endsWith('auth') ? ['c'] : ['c', 'u'],
25-
group: 'users',
26-
icon: IconPlus,
27-
rank: page.url.pathname.endsWith('auth') ? 10 : 0,
28-
disabled: ($readOnly && !GRACE_PERIOD_OVERRIDE) || !$canWriteUsers
29-
},
30-
{
31-
label: 'Create team',
32-
callback: async () => {
33-
if (!page.url.pathname.endsWith('teams')) {
34-
await goto(`${base}/project-${$project.region}-${$project.$id}/auth/teams`);
35-
}
36-
showCreateTeam.set(true);
14+
let { children } = $props();
15+
16+
const authProjectRoute = $derived.by(() => {
17+
return resolveRoute('/(console)/project-[region]-[project]/auth', {
18+
...page.params
19+
});
20+
});
21+
22+
$effect(() => {
23+
$registerCommands([
24+
{
25+
label: 'Create user',
26+
callback: async () => {
27+
if (!page.url.pathname.endsWith('auth')) {
28+
await goto(authProjectRoute);
29+
}
30+
showCreateUser.set(true);
31+
},
32+
keys: page.url.pathname.endsWith('auth') ? ['c'] : ['c', 'u'],
33+
group: 'users',
34+
icon: IconPlus,
35+
rank: page.url.pathname.endsWith('auth') ? 10 : 0,
36+
disabled: ($readOnly && !GRACE_PERIOD_OVERRIDE) || !$canWriteUsers
3737
},
38-
keys: page.url.pathname.endsWith('teams') ? ['c'] : ['c', 't'],
38+
{
39+
label: 'Create team',
40+
callback: async () => {
41+
if (!page.url.pathname.endsWith('teams')) {
42+
await goto(withPath(authProjectRoute, '/teams'));
43+
}
44+
showCreateTeam.set(true);
45+
},
46+
keys: page.url.pathname.endsWith('teams') ? ['c'] : ['c', 't'],
3947
40-
group: 'teams',
41-
icon: IconPlus,
42-
rank: page.url.pathname.endsWith('teams') ? 10 : 0,
43-
disabled: ($readOnly && !GRACE_PERIOD_OVERRIDE) || !$canWriteTeams
44-
},
45-
{
46-
label: 'Go to teams',
47-
keys: ['g', 't'],
48-
callback() {
49-
goto(`${base}/project-${$project.region}-${$project.$id}/auth/teams`);
48+
group: 'teams',
49+
icon: IconPlus,
50+
rank: page.url.pathname.endsWith('teams') ? 10 : 0,
51+
disabled: ($readOnly && !GRACE_PERIOD_OVERRIDE) || !$canWriteTeams
5052
},
51-
group: 'navigation',
52-
rank: 1,
53-
disabled: page.url.pathname.endsWith('teams')
54-
},
55-
{
56-
label: 'Go to usage',
57-
keys: ['g', 'u'],
58-
callback() {
59-
goto(`${base}/project-${$project.region}-${$project.$id}/auth/usage`);
53+
{
54+
label: 'Go to teams',
55+
keys: ['g', 't'],
56+
callback: async () => {
57+
await goto(withPath(authProjectRoute, '/teams'));
58+
},
59+
group: 'navigation',
60+
rank: 1,
61+
disabled: page.url.pathname.endsWith('teams')
6062
},
61-
group: 'navigation',
62-
rank: 1,
63-
disabled: page.url.pathname.endsWith('usage')
64-
},
65-
{
66-
label: 'Go to security',
67-
keys: ['g', 'e'],
68-
callback() {
69-
goto(`${base}/project-${$project.region}-${$project.$id}/auth/security`);
63+
{
64+
label: 'Go to usage',
65+
keys: ['g', 'u'],
66+
callback: async () => {
67+
await goto(withPath(authProjectRoute, '/usage'));
68+
},
69+
group: 'navigation',
70+
rank: 1,
71+
disabled: page.url.pathname.endsWith('usage')
7072
},
71-
group: 'navigation',
72-
rank: 1,
73-
disabled: page.url.pathname.endsWith('security') || !$canWriteUsers
74-
},
75-
{
76-
label: 'Go to settings',
77-
keys: ['g', 's'],
78-
callback() {
79-
goto(`${base}/project-${$project.region}-${$project.$id}/auth/settings`);
73+
{
74+
label: 'Go to security',
75+
keys: ['g', 'e'],
76+
callback: async () => {
77+
await goto(withPath(authProjectRoute, '/security'));
78+
},
79+
group: 'navigation',
80+
rank: 1,
81+
disabled: page.url.pathname.endsWith('security') || !$canWriteUsers
8082
},
81-
group: 'navigation',
82-
rank: 1,
83-
disabled: page.url.pathname.endsWith('settings') || !$canWriteUsers
84-
},
85-
{
86-
label: 'Find users',
87-
callback: () => {
88-
addSubPanel(UsersPanel);
83+
{
84+
label: 'Go to settings',
85+
keys: ['g', 's'],
86+
callback: async () => {
87+
await goto(withPath(authProjectRoute, '/settings'));
88+
},
89+
group: 'navigation',
90+
rank: 1,
91+
disabled: page.url.pathname.endsWith('settings') || !$canWriteUsers
8992
},
90-
group: 'users',
91-
rank: -1
92-
},
93-
{
94-
label: 'Find teams',
95-
callback: () => {
96-
addSubPanel(TeamsPanel);
93+
{
94+
label: 'Find users',
95+
callback: () => {
96+
addSubPanel(UsersPanel);
97+
},
98+
group: 'users',
99+
rank: -1
97100
},
98-
group: 'teams',
99-
rank: -1
100-
}
101-
]);
101+
{
102+
label: 'Find teams',
103+
callback: () => {
104+
addSubPanel(TeamsPanel);
105+
},
106+
group: 'teams',
107+
rank: -1
108+
}
109+
]);
110+
});
102111
103112
// To prioritize the groups!
104-
$: $updateCommandGroupRanks({ users: 300, teams: 200, security: 100, navigation: 50 });
113+
$effect(() => {
114+
$updateCommandGroupRanks({ users: 300, teams: 200, security: 100, navigation: 50 });
115+
});
105116
</script>
106117

107118
<svelte:head>
108119
<title>Auth - Appwrite</title>
109120
</svelte:head>
110121

111-
<slot />
122+
{@render children?.()}

src/routes/(console)/project-[region]-[project]/auth/+page.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
3535
import { Dependencies } from '$lib/constants';
3636
import { invalidate } from '$app/navigation';
37-
3837
import type { PageProps } from './$types';
3938
4039
let { data }: PageProps = $props();

src/routes/(console)/project-[region]-[project]/auth/breadcrumbs.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
<script lang="ts">
2+
import { page } from '$app/state';
23
import { base } from '$app/paths';
34
import { Breadcrumbs } from '$lib/layout';
45
import { organization } from '$lib/stores/organization';
5-
import { project } from '../store';
66
77
$: breadcrumbs = [
88
{
99
href: `${base}/organization-${$organization?.$id}`,
1010
title: $organization?.name
1111
},
1212
{
13-
href: `${base}/project-${$project.region}-${$project?.$id}`,
14-
title: $project?.name
13+
href: `${base}/project-${page.params.region}-${page.params.project}`,
14+
title: page.data?.project?.name
1515
},
1616
{
17-
href: `${base}/project-${$project.region}-${$project?.$id}/auth`,
17+
href: `${base}/project-${page.params.region}-${page.params.project}/auth`,
1818
title: 'Auth'
1919
}
2020
];

src/routes/(console)/project-[region]-[project]/auth/security/+page.svelte

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
</script>
1414

1515
<Container>
16-
<UpdateUsersLimit />
17-
<UpdateSessionLength />
18-
<UpdateSessionsLimit />
16+
<UpdateUsersLimit project={data.project} />
17+
<UpdateSessionLength project={data.project} />
18+
<UpdateSessionsLimit project={data.project} />
1919
<PasswordPolicies project={data.project} />
2020
<SessionSecurity project={data.project} />
21-
<UpdateMockNumbers />
22-
<UpdateMembershipPrivacy />
21+
<UpdateMockNumbers project={data.project} />
22+
<UpdateMembershipPrivacy project={data.project} />
2323
</Container>

src/routes/(console)/project-[region]-[project]/auth/security/updateMembershipPrivacy.svelte

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@
77
import { addNotification } from '$lib/stores/notifications';
88
import { sdk } from '$lib/stores/sdk';
99
import { Selector } from '@appwrite.io/pink-svelte';
10-
import { project } from '../../store';
10+
import type { Models } from '@appwrite.io/console';
1111
12-
let authMembershipsUserName = $project?.authMembershipsUserName ?? true;
13-
let authMembershipsUserEmail = $project?.authMembershipsUserEmail ?? true;
14-
let authMembershipsMfa = $project?.authMembershipsMfa ?? true;
12+
const {
13+
project
14+
}: {
15+
project: Models.Project;
16+
} = $props();
17+
18+
let authMembershipsMfa = $state(project?.authMembershipsMfa ?? true);
19+
let authMembershipsUserName = $state(project?.authMembershipsUserName ?? true);
20+
let authMembershipsUserEmail = $state(project?.authMembershipsUserEmail ?? true);
1521
1622
async function updateMembershipsPrivacy() {
1723
try {
1824
await sdk.forConsole.projects.updateMembershipsPrivacy({
19-
projectId: $project.$id,
25+
projectId: project.$id,
2026
userName: authMembershipsUserName,
2127
userEmail: authMembershipsUserEmail,
2228
mfa: authMembershipsMfa
@@ -60,9 +66,9 @@
6066
</svelte:fragment>
6167
<svelte:fragment slot="actions">
6268
<Button
63-
disabled={authMembershipsUserName === ($project?.authMembershipsUserName ?? true) &&
64-
authMembershipsUserEmail === ($project?.authMembershipsUserEmail ?? true) &&
65-
authMembershipsMfa === ($project?.authMembershipsMfa ?? true)}
69+
disabled={authMembershipsUserName === (project?.authMembershipsUserName ?? true) &&
70+
authMembershipsUserEmail === (project?.authMembershipsUserEmail ?? true) &&
71+
authMembershipsMfa === (project?.authMembershipsMfa ?? true)}
6672
submit>Update</Button>
6773
</svelte:fragment>
6874
</CardGrid>

0 commit comments

Comments
 (0)