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

chore: cleanup some code #520

Merged
merged 5 commits into from
Aug 29, 2023
Merged
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
15 changes: 7 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@analytics/google-analytics": "^1.0.5",
"@analytics/google-tag-manager": "^0.5.3",
"@appwrite.io/console": "npm:[email protected]",
"@appwrite.io/console": "^0.3.0",
"@appwrite.io/pink": "0.1.0-next.8",
"@appwrite.io/pink-icons": "^0.1.0-next.8",
"@popperjs/core": "^2.11.6",
Expand Down
4 changes: 3 additions & 1 deletion src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export enum Dependencies {
WEBHOOK = 'dependency:webhook',
WEBHOOKS = 'dependency:webhooks',
MIGRATIONS = 'dependency:migrations',
COLLECTIONS = 'dependency:collections'
COLLECTIONS = 'dependency:collections',
RUNTIMES = 'dependency:runtimes',
CONSOLE_VARIABLES = 'dependency:console_variables'
}

export const scopes: {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/helpers/debounce.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function debounce<F extends (...params: any[]) => void>(fn: F, delay: number) {
export function debounce<F extends (...params: unknown[]) => void>(fn: F, delay: number) {
let timeoutID: ReturnType<typeof setTimeout> = null;
const debounceFn = function (this: any, ...args: any[]) {
const debounceFn = function (this: unknown, ...args: unknown[]) {
clearTimeout(timeoutID);
timeoutID = window.setTimeout(() => fn.apply(this, args), delay) as unknown as ReturnType<
typeof setTimeout
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function deepMap<T, U>(
return result;
}

export function parseIfString(value: unknown): any {
export function parseIfString(value: unknown): unknown {
if (typeof value === 'string') {
try {
return JSON.parse(value);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/project.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function getProjectId() {
const pathname = window.location.pathname;
const pathname = window.location.pathname + '/';
const projectMatch = pathname.match(/\/project-(.*?)\//);
return projectMatch?.[1] || null;
}
2 changes: 1 addition & 1 deletion src/lib/helpers/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { deepClone, objectEntries } from './object';
*
* @export
*/
export function createConservative<Obj extends Record<string, any>>(obj: Obj) {
export function createConservative<Obj extends Record<string, unknown>>(obj: Obj) {
const stores = Object.fromEntries(
objectEntries(obj).map(([key, value]) => [key, writable(value)])
) as {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/pages/domains/wizard/step1.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { onMount } from 'svelte';
import { ProxyTypes } from '../index.svelte';
import { domain, typeStore } from './store';
import { consoleVariables } from '$routes/console/store';

let error = null;
let isDomainsEnabled = false;
Expand All @@ -17,9 +18,8 @@
if (!isSelfHosted) {
return;
}
const vars = await sdk.forConsole.console.variables();
//@ts-expect-error needs an sdk release
isDomainsEnabled = vars?._APP_DOMAIN_ENABLED === true;

isDomainsEnabled = (await $consoleVariables)?._APP_DOMAIN_ENABLED === true;
});

async function createDomain() {
Expand Down
33 changes: 28 additions & 5 deletions src/lib/wizards/functions/cover.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import CreateTemplate from './createTemplate.svelte';

export function connectTemplate(template: MarketplaceTemplate, runtime: string | null = null) {
const variables: any = {};
const variables: Record<string, string> = {};
template.variables.forEach((variable) => {
variables[variable.name] = variable.value ?? '';
});
Expand All @@ -29,17 +29,19 @@
<script lang="ts">
import { base } from '$app/paths';
import { AvatarGroup, Box, Heading } from '$lib/components';
import WizardCover from '$lib/layout/wizardCover.svelte';
import { app } from '$lib/stores/app';
import { wizard } from '$lib/stores/wizard';
import { repository, runtimes, templateConfig, template as templateStore } from './store';
import { repository, templateConfig, template as templateStore } from './store';
import { marketplace, type MarketplaceTemplate } from '$lib/stores/marketplace';
import { Button } from '$lib/elements/forms';
import { page } from '$app/stores';
import { runtimes } from '$routes/console/project-[project]/functions/store';
import { trackEvent } from '$lib/actions/analytics';
import type { Models } from '@appwrite.io/console';
import WizardCover from '$lib/layout/wizardCover.svelte';
import Repositories from './components/repositories.svelte';
import CreateManual from './createManual.svelte';
import CreateGit from './createGit.svelte';
import { Button } from '$lib/elements/forms';
import { page } from '$app/stores';

let hasInstallations: boolean;
let selectedRepository: string;
Expand All @@ -48,6 +50,9 @@
const templates = marketplace.filter((template) => template.id !== 'starter').slice(0, 2);

function connect(event: CustomEvent<Models.ProviderRepository>) {
trackEvent('click_connect_repository', {
from: 'cover'
});
repository.set(event.detail);
wizard.start(CreateGit);
}
Expand Down Expand Up @@ -109,6 +114,13 @@
)}
<li>
<button
on:click={() => {
trackEvent('click_connect_template', {
from: 'cover',
template: quickStart.id,
runtime: runtime.name
});
}}
on:click={() => connectTemplate(quickStart, runtime.name)}
class="box u-width-full-line u-flex u-cross-center u-gap-8"
style:--box-padding="1rem"
Expand Down Expand Up @@ -157,6 +169,12 @@
<li class="clickable-list-item">
<button
type="button"
on:click={() => {
trackEvent('click_connect_template', {
from: 'cover',
template: template.id
});
}}
on:click={() => connectTemplate(template)}
class="clickable-list-button u-width-full-line u-flex u-gap-12">
<div class="avatar is-size-small" style:--p-text-size="1.25rem">
Expand Down Expand Up @@ -185,6 +203,11 @@
<p class="u-margin-block-start-16">
You can also create a function <button
class="link"
on:click={() => {
trackEvent('click_create_function_manual', {
from: 'cover'
});
}}
on:click={() => wizard.start(CreateManual)}>manually</button>
or using the CLI.
<a
Expand Down
3 changes: 2 additions & 1 deletion src/lib/wizards/functions/steps/details.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import { InputText, InputSelect, FormList } from '$lib/elements/forms';
import { WizardStep } from '$lib/layout';
import { onMount } from 'svelte';
import { createFunction, runtimes } from '../store';
import { createFunction } from '../store';
import { runtimes } from '$routes/console/project-[project]/functions/store';

let showCustomId = false;

Expand Down
3 changes: 2 additions & 1 deletion src/lib/wizards/functions/steps/functionConfiguration.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import { WizardStep } from '$lib/layout';
import { onMount } from 'svelte';
import { sdk } from '$lib/stores/sdk';
import { choices, createFunction, installation, repository, runtimes } from '../store';
import { choices, createFunction, installation, repository } from '../store';
import { runtimes } from '$routes/console/project-[project]/functions/store';

let showCustomId = false;

Expand Down
3 changes: 2 additions & 1 deletion src/lib/wizards/functions/steps/templateConfiguration.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import { Pill } from '$lib/elements';
import { FormList, InputSelect, InputText } from '$lib/elements/forms';
import { WizardStep } from '$lib/layout';
import { runtimes, template, templateConfig } from '../store';
import { runtimes } from '$routes/console/project-[project]/functions/store';
import { template, templateConfig } from '../store';

let showCustomId = false;

Expand Down
5 changes: 0 additions & 5 deletions src/lib/wizards/functions/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ export const installations = derived(
($page) => $page.data.installations as Models.InstallationList
);

export const runtimes = derived(
page,
($page) => $page.data.runtimes as Promise<Models.RuntimeList>
);

const initialCreateFunction: Partial<Models.Function> = {
$id: null,
name: null,
Expand Down
2 changes: 1 addition & 1 deletion src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
onMount(async () => {
if ($page.url.searchParams.has('migrate')) {
const migrateData = $page.url.searchParams.get('migrate');
requestedMigration.set(parseIfString(migrateData));
requestedMigration.set(parseIfString(migrateData) as Record<string, string>);
}
/**
* Reporting Web Vitals.
Expand Down
31 changes: 11 additions & 20 deletions src/routes/console/(migration-wizard)/resource-form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
resourcesToMigrationForm
} from '$lib/stores/migration';
import { wizard } from '$lib/stores/wizard';
import type { Models } from '@appwrite.io/console';

export let formData: ReturnType<typeof createMigrationFormStore>;
export let provider: ReturnType<typeof createMigrationProviderStore>;
Expand Down Expand Up @@ -76,7 +77,7 @@
$formData = resourcesToMigrationForm(resources, version);
}

let report: any;
let report: Models.MigrationReport;
$: version = report?.version || '0.0.0';

let isOpen = false;
Expand All @@ -86,18 +87,16 @@
isOpen = true;
try {
switch ($provider.provider) {
case 'appwrite': {
const res = await projectSdk.migrations.getAppwriteReport(
case 'appwrite':
report = await projectSdk.migrations.getAppwriteReport(
providerResources.appwrite,
$provider.endpoint,
$provider.projectID,
$provider.apiKey
);
report = res;
break;
}
case 'supabase': {
const res = await projectSdk.migrations.getSupabaseReport(
case 'supabase':
report = await projectSdk.migrations.getSupabaseReport(
providerResources.supabase,
$provider.endpoint,
$provider.apiKey,
Expand All @@ -106,31 +105,25 @@
$provider.password,
$provider.port
);
report = res;
break;
}
case 'firebase': {
case 'firebase':
if ($provider.projectId) {
// OAuth
const res = await sdk.forProject.migrations.getFirebaseReportOAuth(
report = await sdk.forProject.migrations.getFirebaseReportOAuth(
providerResources.firebase,
$provider.projectId
);

report = res;
} else if ($provider.serviceAccount) {
// Manual auth
const res = await projectSdk.migrations.getFirebaseReport(
report = await projectSdk.migrations.getFirebaseReport(
providerResources.firebase,
$provider.serviceAccount
);
report = res;
}

break;
}
case 'nhost': {
const res = await projectSdk.migrations.getNHostReport(
case 'nhost':
report = await projectSdk.migrations.getNHostReport(
providerResources.nhost,
$provider.subdomain,
$provider.region,
Expand All @@ -139,8 +132,6 @@
$provider.username,
$provider.password
);
report = res;
}
}
} catch (e) {
if (!isOpen) return;
Expand Down
5 changes: 2 additions & 3 deletions src/routes/console/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import { addNotification } from '$lib/stores/notifications';
import { openMigrationWizard } from './(migration-wizard)';
import { project } from './project-[project]/store';
import { sdk } from '$lib/stores/sdk';
import { feedback } from '$lib/stores/feedback';
import { consoleVariables } from './store';

function kebabToSentenceCase(str: string) {
return str
Expand All @@ -35,8 +35,7 @@

let isAssistantEnabled = false;
onMount(async () => {
const vars = await sdk.forConsole.console.variables();
isAssistantEnabled = vars._APP_ASSISTANT_ENABLED === true;
isAssistantEnabled = (await $consoleVariables)?._APP_ASSISTANT_ENABLED === true;
});

$: isOnSettingsLayout = $project?.$id
Expand Down
7 changes: 6 additions & 1 deletion src/routes/console/+layout.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Dependencies } from '$lib/constants';
import { sdk } from '$lib/stores/sdk';

import type { LayoutLoad } from './$types';

export const load: LayoutLoad = async ({ fetch }) => {
export const load: LayoutLoad = async ({ fetch, depends }) => {
depends(Dependencies.RUNTIMES);
depends(Dependencies.CONSOLE_VARIABLES);

const { endpoint, project } = sdk.forConsole.client.config;
const response = await fetch(`${endpoint}/health/version`, {
headers: {
Expand All @@ -12,6 +16,7 @@ export const load: LayoutLoad = async ({ fetch }) => {
const data = await response.json();

return {
consoleVariables: sdk.forConsole.console.variables(),
version: data?.version ?? null
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
};

$: operatorsForColumn = Object.entries(operators)
.filter(([_, v]) => v.types.includes(column?.type))
.filter(([, v]) => v.types.includes(column?.type))
.map(([k]) => ({
label: k,
value: k
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export const queries = initQueries();
export const queriesAreDirty = derived([queries, page], ([$queries, $page]) => {
const paramQueries = $page.url.searchParams.get('query');
const parsedQueries = queryParamToMap(paramQueries || '[]');
console.log({ $queries, parsedQueries, notDirty: deepEqual($queries, parsedQueries) });

return !deepEqual($queries, parsedQueries);
});
Expand Down
Loading