diff --git a/package-lock.json b/package-lock.json index 835beaecb..d4245c929 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,8 +7,8 @@ "name": "@appwrite/console", "dependencies": { "@analytics/google-analytics": "^1.0.5", - "@appwrite.io/console": "npm:matej-appwrite-console@7.1.65", - "@appwrite.io/pink": "^0.0.6-rc.10", + "@appwrite.io/console": "npm:matej-appwrite-console@7.1.68", + "@appwrite.io/pink": "0.0.6-rc.10", "@popperjs/core": "^2.11.6", "@sentry/svelte": "^7.44.2", "@sentry/tracing": "^7.44.2", @@ -148,9 +148,9 @@ }, "node_modules/@appwrite.io/console": { "name": "matej-appwrite-console", - "version": "7.1.65", - "resolved": "https://registry.npmjs.org/matej-appwrite-console/-/matej-appwrite-console-7.1.65.tgz", - "integrity": "sha512-410zM0jX+ndZP/g6biKc7M96mV9Bir/86v9rlkrI+C4CaPzU1FPNOWNfmQNUgFvYriKaw9f2p79/3LlfCheIjg==", + "version": "7.1.68", + "resolved": "https://registry.npmjs.org/matej-appwrite-console/-/matej-appwrite-console-7.1.68.tgz", + "integrity": "sha512-as9TjhuBpIXoUtVNTvvVV7umdrNp2cpnKuMC2HusQLlAtrZOdVjZfaoaEyCxpAdkbUIrIuvmEwW8fvb39UNsFA==", "dependencies": { "cross-fetch": "3.1.5", "isomorphic-form-data": "2.0.0" @@ -167,9 +167,9 @@ } }, "node_modules/@appwrite.io/pink-icons": { - "version": "0.0.6-rc.5", - "resolved": "https://registry.npmjs.org/@appwrite.io/pink-icons/-/pink-icons-0.0.6-rc.5.tgz", - "integrity": "sha512-Jv6ecAPhOp50SMiwBiWjK1yl+E/ZK0GzqVxo3nSoo2hIGO8GhfUhgK+yNJc0J9ccV0QjrU+3xxcmzuBWNXJfkA==" + "version": "0.0.6-rc.14", + "resolved": "https://registry.npmjs.org/@appwrite.io/pink-icons/-/pink-icons-0.0.6-rc.14.tgz", + "integrity": "sha512-OHkW3nOc7aTNlf+kdcSojlimWR+NKUJoYNCcC6ysQs7GnD/ny+en6bpT6u1X5EYEszO/IUQuQYDZhURFeGGO1A==" }, "node_modules/@babel/code-frame": { "version": "7.18.6", diff --git a/package.json b/package.json index abf2930dc..071d39429 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ }, "dependencies": { "@analytics/google-analytics": "^1.0.5", - "@appwrite.io/console": "npm:matej-appwrite-console@7.1.65", - "@appwrite.io/pink": "^0.0.6-rc.10", + "@appwrite.io/console": "npm:matej-appwrite-console@7.1.68", + "@appwrite.io/pink": "0.0.6-rc.10", "@popperjs/core": "^2.11.6", "@sentry/svelte": "^7.44.2", "@sentry/tracing": "^7.44.2", diff --git a/src/lib/actions/analytics.ts b/src/lib/actions/analytics.ts index 8c84b714a..ed9c55e99 100644 --- a/src/lib/actions/analytics.ts +++ b/src/lib/actions/analytics.ts @@ -211,5 +211,7 @@ export enum Submit { BucketUpdateExtensions = 'submit_bucket_update_extensions', FileCreate = 'submit_file_create', FileDelete = 'submit_file_delete', - FileUpdatePermissions = 'submit_file_update_permissions' + FileUpdatePermissions = 'submit_file_update_permissions', + InstallationCreate = 'submit_installation_create', + InstallationDelete = 'submit_installation_delete' } diff --git a/src/lib/constants.ts b/src/lib/constants.ts index d7e16823c..6169c7005 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -5,7 +5,8 @@ export const INTERVAL = 5 * 60000; // default interval to check for feedback export enum Dependencies { ORGANIZATION = 'dependency:organization', PROJECT = 'dependency:project', - PROJECT_SETTINGS = 'dependency:project_settings', + PROJECT_VARIABLES = 'dependency:project_variables', + PROJECT_INSTALLATIONS = 'dependency:project_installations', PROJECTS = 'dependency:projects', ACCOUNT = 'dependency:account', ACCOUNT_SESSIONS = 'dependency:account_sessions', diff --git a/src/lib/stores/sdk.ts b/src/lib/stores/sdk.ts index f0ae42a37..543622dbe 100644 --- a/src/lib/stores/sdk.ts +++ b/src/lib/stores/sdk.ts @@ -13,7 +13,8 @@ import { Storage, Teams, Users, - Project as ProjectApi + Project as ProjectApi, + Vcs } from '@appwrite.io/console'; const endpoint = VARS.APPWRITE_ENDPOINT ?? `${globalThis?.location?.origin}/v1`; @@ -35,7 +36,8 @@ const sdkForProject = { projectApi: new ProjectApi(clientProject), storage: new Storage(clientProject), teams: new Teams(clientProject), - users: new Users(clientProject) + users: new Users(clientProject), + vcs: new Vcs(clientProject) }; export const sdk = { diff --git a/src/routes/console/project-[project]/rawVariableEditor.svelte b/src/routes/console/project-[project]/rawVariableEditor.svelte index de5634fea..841210c38 100644 --- a/src/routes/console/project-[project]/rawVariableEditor.svelte +++ b/src/routes/console/project-[project]/rawVariableEditor.svelte @@ -8,6 +8,7 @@ import { parse } from 'dotenv'; export let redeployMessage: string; + export let isGlobal: boolean; export let showEditor = false; export let variableList: Models.VariableList; @@ -111,9 +112,10 @@ - Raw editor + Editor

- Edit environment variables below or download as a .{tab} file. + Edit {isGlobal ? 'global' : 'environment'} variables below or download as a + .{tab} file.

diff --git a/src/routes/console/project-[project]/settings/+page.svelte b/src/routes/console/project-[project]/settings/+page.svelte index 0978ff4f0..3b8f50db3 100644 --- a/src/routes/console/project-[project]/settings/+page.svelte +++ b/src/routes/console/project-[project]/settings/+page.svelte @@ -16,31 +16,98 @@ import { Submit, trackEvent, trackError } from '$lib/actions/analytics'; import type { PageData } from './$types'; import UpdateVariables from '../updateVariables.svelte'; + import GitInstallationModal from './GitInstallationModal.svelte'; + import { browser } from '$app/environment'; + import PaginationInline from '$lib/components/paginationInline.svelte'; + import { + TableBody, + TableCell, + TableCellHead, + TableHeader, + TableRow + } from '$lib/elements/table'; + import Table from '$lib/elements/table/table.svelte'; + import { Query, type Models } from '@appwrite.io/console'; + import DropList from '$lib/components/dropList.svelte'; + import DropListItem from '$lib/components/dropListItem.svelte'; + import GitDisconnectModal from './GitDisconnectModal.svelte'; export let data: PageData; const sdkCreateVariable = async (key: string, value: string) => { await sdk.forProject.projectApi.createVariable(key, value); - await invalidate(Dependencies.PROJECT_SETTINGS); + await invalidate(Dependencies.PROJECT_VARIABLES); }; const sdkUpdateVariable = async (variableId: string, key: string, value: string) => { await sdk.forProject.projectApi.updateVariable(variableId, key, value); - await invalidate(Dependencies.PROJECT_SETTINGS); + await invalidate(Dependencies.PROJECT_VARIABLES); }; const sdkDeleteVariable = async (variableId: string) => { await sdk.forProject.projectApi.deleteVariable(variableId); - await invalidate(Dependencies.PROJECT_SETTINGS); + await invalidate(Dependencies.PROJECT_VARIABLES); }; let name: string = null; let showDelete = false; + let showGitIstall = false; + let showGitDisconnect = false; + let selectedInstallation: Models.Installation; + const endpoint = sdk.forConsole.client.config.endpoint; const projectId = $page.params.project; + let showInstallationDropdown: boolean[] = []; + let installationsSum = data.installations.total; + let installationsLimit = 10; + let installationsOffset = 0; + + // TODO: Fix. Should not run on initial load. We get data from page.ts + $: if (installationsOffset !== null) { + (async () => { + data.installations = await sdk.forProject.vcs.listInstallations([ + Query.offset(installationsOffset), + Query.limit(installationsLimit) + ]); + })(); + } + onMount(async () => { name ??= $project.name; + + if (browser) { + const queryString = window.location.search; + const urlParams = new URLSearchParams(queryString); + + const alert = urlParams.get('alert') ?? ''; + + let notified = false; + + if (alert === 'installation-created') { + addNotification({ + type: 'success', + message: `Git installation has been successfully added` + }); + trackEvent(Submit.InstallationCreate); + notified = true; + } else if (alert === 'installation-updated') { + addNotification({ + type: 'success', + message: `Git installation has been successfully updated` + }); + trackEvent(Submit.InstallationCreate); + notified = true; + } + + if (notified) { + window.history.replaceState( + {}, + document.title, + window.location.origin + window.location.pathname + ); + } + } }); async function updateName() { @@ -88,7 +155,29 @@ } } + function configureGitHub() { + sdk.forProject.vcs.createGitHubInstallation( + window.location.href + '?alert=installation-updated' + ); + } + $: services.load($project); + + function getInstallationLink(installation: Models.Installation) { + if (installation.provider === 'GitHub') { + return `https://github.com/${installation.organization}`; + } + + return ''; + } + + function getInstallationIcon(installation: Models.Installation) { + if (installation.provider === 'GitHub') { + return `icon-github`; + } + + return ''; + } @@ -157,6 +246,151 @@ + + Git configuration +

+ Add a Git installation to your project. You can connect a repository in your + function settings. +

+ + {#if data.installations.total > 0} +
+
+
    +
  • + +
  • +
+
+ + + + Installations + + + {#each data.installations.installations as installation, i} + + +
+
+
+ +
+
+
+
{installation.organization}
+ +
+

+ Last configure: {toLocaleDateTime( + installation.$updatedAt + )} +

+
+
+ +
+ + + + { + showInstallationDropdown[ + i + ] = false; + configureGitHub(); + }}> + Configure {installation.provider} + + { + showInstallationDropdown[ + i + ] = false; + showGitDisconnect = true; + selectedInstallation = + installation; + }}> + Disconnect + + + +
+
+
+
+ {/each} +
+
+
+
+

Total installations: {installationsSum}

+ +
+ {:else} +
+
+
+
    +
  • +
    +
  • +
  • +
    +
  • +
  • +
    +
  • +
+ + + +
+
+ +
+
+ {/if} +
+
+ + +{#if showGitIstall} + +{/if} + +{#if showGitDisconnect} + +{/if} + + diff --git a/src/routes/console/project-[project]/settings/+page.ts b/src/routes/console/project-[project]/settings/+page.ts index 40056591b..a0168ccf9 100644 --- a/src/routes/console/project-[project]/settings/+page.ts +++ b/src/routes/console/project-[project]/settings/+page.ts @@ -1,11 +1,14 @@ import { Dependencies } from '$lib/constants'; import { sdk } from '$lib/stores/sdk'; import type { PageLoad } from './$types'; +import { Query } from '@appwrite.io/console'; export const load: PageLoad = async ({ depends }) => { - depends(Dependencies.PROJECT_SETTINGS); + depends(Dependencies.PROJECT_VARIABLES); + depends(Dependencies.PROJECT_INSTALLATIONS); return { - variables: await sdk.forProject.projectApi.listVariables() + variables: await sdk.forProject.projectApi.listVariables(), + installations: await sdk.forProject.vcs.listInstallations([Query.limit(10)]) }; }; diff --git a/src/routes/console/project-[project]/settings/GitDisconnectModal.svelte b/src/routes/console/project-[project]/settings/GitDisconnectModal.svelte new file mode 100644 index 000000000..a413c6716 --- /dev/null +++ b/src/routes/console/project-[project]/settings/GitDisconnectModal.svelte @@ -0,0 +1,86 @@ + + + + Disconnect installation + + {#if selectedInstallation.functions.length > 0} +

+ Are you sure you want to disconnect this git installation? This will affect future + deployments to the following functions: +

+ +
+
+ {#each selectedInstallation.functions as func} +
+
+
+ technology +
+
{func.name}
+
+ +

+ Last deployed: 12m ago +

+
+ {/each} +
+
+ {:else} +

Are you sure you want to disconnect this git installation?

+ {/if} + + + + + +
diff --git a/src/routes/console/project-[project]/settings/GitInstallationModal.svelte b/src/routes/console/project-[project]/settings/GitInstallationModal.svelte new file mode 100644 index 000000000..2416cb5ee --- /dev/null +++ b/src/routes/console/project-[project]/settings/GitInstallationModal.svelte @@ -0,0 +1,39 @@ + + + + Connect to Git +

Select a provider to import an existing git repositories.

+ +
+ + + +
+ + + + +
diff --git a/src/routes/console/project-[project]/updateVariables.svelte b/src/routes/console/project-[project]/updateVariables.svelte index 4f1ac9dc9..b5847a979 100644 --- a/src/routes/console/project-[project]/updateVariables.svelte +++ b/src/routes/console/project-[project]/updateVariables.svelte @@ -145,7 +145,7 @@ showPromoteModal = false; await invalidate(Dependencies.VARIABLES); - await invalidate(Dependencies.PROJECT_SETTINGS); + await invalidate(Dependencies.PROJECT_VARIABLES); addNotification({ type: 'success', @@ -188,7 +188,7 @@
  • @@ -334,6 +334,7 @@ {#if showEditorModal} import { Modal } from '$lib/components'; + import Alert from '$lib/components/alert.svelte'; import { Button, InputFile } from '$lib/elements/forms'; import { addNotification } from '$lib/stores/notifications'; import type { Models } from '@appwrite.io/console'; import { parse } from 'dotenv'; export let redeployMessage: string; + export let isGlobal: boolean; export let show = false; export let variableList: Models.VariableList; export let sdkCreateVariable: (key: string, value: string) => Promise; @@ -60,10 +62,21 @@ - Upload Variables -

    - Upload multiple environment variables via a .env file that will be passed to your function. -

    + Import {isGlobal ? 'global' : 'environment'} variables +
    +

    + Upload multiple {isGlobal ? 'global' : 'environment'} variables via a .env file that will + be passed to {isGlobal ? 'all functions within your project' : 'your function'}. +

    + + {#if variableList.total > 0} + + Existing {isGlobal ? 'global' : 'environment'} variables will be updated. They will not + be deleted if they are not present in your .env file. + + {/if} +