Skip to content

Commit

Permalink
fix: lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
xmlking committed Jul 10, 2024
1 parent 19231be commit 340e987
Show file tree
Hide file tree
Showing 15 changed files with 446 additions and 74 deletions.
4 changes: 0 additions & 4 deletions .secrets.example
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,3 @@ OPENAI_ORG_ID = ''
OPENAI_PROJECT_ID = ''
OPENAI_API_KEY = ''
GRAPHITE_WEBHOOK_SECRET = ''

## FEATURE FLAGS
# you could generate new secret with: `node -e "console.log(crypto.randomBytes(32).toString('base64url'))"`
FLAGS_SECRET = 'FIXME'
30 changes: 21 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,17 @@
"files.defaultLanguage": "go",
"files.trimTrailingWhitespace": true,
////////// GoLang //////////
"go.testFlags": ["-v", "-count=1"],
"go.testFlags": [
"-v",
"-count=1"
],
"go.testTimeout": "5s",
"go.useLanguageServer": true,
"go.lintTool": "golangci-lint",
"go.lintFlags": ["--fast", "--config=.github/linters/.golangci.yml"],

"go.lintFlags": [
"--fast",
"--config=.github/linters/.golangci.yml"
],
////////// Spell checker //////////
// Map spelling errors to Hints so that they don't show up in the Problems pane.
"cSpell.diagnosticLevel": "Hint",
Expand All @@ -133,9 +138,10 @@
// "css-unused-selector": "ignore",
// "a11y-label-has-associated-control": "ignore"
},

////////// vitest //////////
"vitest.include": ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx,svelte}"],
"vitest.include": [
"**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx,svelte}"
],
"vitest.exclude": [
"**/node_modules/**",
"$houdini/**",
Expand All @@ -145,21 +151,28 @@
"**/ignored.test.ts",
"tests/**"
],

////////// tailwindCSS //////////
"tailwindCSS.emmetCompletions": true,
"tailwindCSS.includeLanguages": {
"plaintext": "html"
},
// for tailwind-variants
"tailwindCSS.experimental.classRegex": [["([\"'`][^\"'`]*.*?[\"'`])", "[\"'`]([^\"'`]*).*?[\"'`]"]],
"tailwindCSS.experimental.classRegex": [
[
"([\"'`][^\"'`]*.*?[\"'`])",
"[\"'`]([^\"'`]*).*?[\"'`]"
]
],
////////// TypeScript //////////
// astro requires this
"typescript.inlayHints.parameterNames.enabled": "all",
////////// Proto //////////
"clang-format.style": "google",
"protoc": {
"options": ["--proto_path=${workspaceRoot}/proto", "--proto_path=${env.GOPATH}/src"]
"options": [
"--proto_path=${workspaceRoot}/proto",
"--proto_path=${env.GOPATH}/src"
]
},
////////// Skeleton UI //////////
"tailwindCSS.classAttributes": [
Expand Down Expand Up @@ -275,7 +288,6 @@
"width",
"zIndex"
],

// ##################################################
// ### Language customisations ###
// ##################################################
Expand Down
4 changes: 4 additions & 0 deletions apps/console/.secrets.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ RATE_LIMIT_SECRET='fill-me-in'
OPENAI_ORG_ID = ''
OPENAI_PROJECT_ID = ''
OPENAI_API_KEY = ''

## FEATURE FLAGS
# you could generate new secret with: `node -e "console.log(crypto.randomBytes(32).toString('base64url'))"`
FLAGS_SECRET = 'FIXME'
10 changes: 10 additions & 0 deletions apps/console/src/lib/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,13 @@ export const showSocialLogin = flag<boolean>({
return true;
},
});

export const simulateLoadingState = flag<boolean>({
key: 'simulateLoadingState',
description: 'Enable simulating loading states for testing',
origin: 'https://example.com/#simulateLoadingState',
options: [{ value: true }, { value: false }],
decide(event) {
return false;
},
});
83 changes: 83 additions & 0 deletions apps/console/src/lib/graphql/loading.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { dev } from '$app/environment';
import { PendingValue } from '$houdini';

/**
* To develop a loading state, set this to true
* WARNING: NEVER LEAVE THIS TRUE WHEN COMITTING
* TODO: Add a CI check that makes sure this is false
*/
const SIMULATE_LOADING_STATE = false;

function simulatingLoadingState(): boolean {
// Safeguard to prevent simulating loading states on production
return dev && SIMULATE_LOADING_STATE;
}

export type MaybeLoading<T> = T | typeof PendingValue;

/**
* Provide a fallback value if the value is PendingValue
* @param value the value
* @param fallback the fallback to use if value is PendingValue
* @returns the value or the fallback
*/
export function loading<T>(value: MaybeLoading<T>, fallback: T): T {
if (simulatingLoadingState()) return fallback;
return value === PendingValue ? fallback : value;
}

type AllLoaded<T> = T extends object
? { [K in keyof T]: AllLoaded<T[K]> }
: T extends unknown[]
? AllLoaded<T[number]>[]
: T extends typeof PendingValue
? never
: T;

export function loaded<T>(value: MaybeLoading<T>): value is T {
if (simulatingLoadingState()) return false;
return value !== PendingValue;
}

export function onceLoaded<I, O>(value: MaybeLoading<I>, compute: (loadedValue: I) => O, fallback: O): O {
return loaded(value) ? compute(value) : fallback;
}

export function onceAllLoaded<T extends unknown[], O, FO>(
values: { [K in keyof T]: MaybeLoading<T[K]> },
compute: (...loadedValues: T) => O,
fallback: FO,
): O | FO {
if (values.every(loaded)) return compute(...(values as T));
return fallback;
}

// @ts-expect-error don't know how to fix the 'T could be instanciated with a type that is unrelated to AllLoaded' error
export function allLoaded<T>(value: T): value is AllLoaded<T> {
if (simulatingLoadingState()) return false;
if (Array.isArray(value)) return value.every((item) => allLoaded(item));
if (typeof value === 'object' && value !== null) return Object.values(value).every((item) => allLoaded(item));

return loaded(value);
}

export function mapLoading<T, O>(value: MaybeLoading<T>, mapping: (value: T) => O): MaybeLoading<O> {
if (loaded(value)) return mapping(value);
return PendingValue;
}

export const LOREM_IPSUM = `Lorem ipsum dolor sit amet. A impedit beatae sed nostrum voluptatem
ut omnis aliquid et galisum quaerat. Est sunt voluptatem aut porro iste et tempora voluptatem
aut pariatur minima sed omnis cumque est iusto fugit vel rerum magni. 33 ducimus nesciunt ut
consequuntur esse nam necessitatibus tempore sit suscipit voluptatibus qui rerum earum non autem
doloribus. Rem itaque esse est nostrum optio id repellat recusandae et ipsa quis.
Aut odio ipsa sed autem esse ut autem error qui voluptates perspiciatis aut officiis consequuntur
sit amet nihil. Eos delectus consequatur sit natus iure qui omnis omnis ea illum distinctio et
quos quidem. Et nisi autem est rerum eius ut dolorum commodi et temporibus expedita ea dolorem
error ad asperiores facilis ad numquam libero. Aut suscipit maxime sit explicabo dolorem est
accusantium enim et repudiandae omnis cum dolorem nemo id quia facilis.
Et dolorem perferendis et rerum suscipit qui voluptatibus quia et nihil nostrum 33 omnis soluta.
Nam minus minima et perspiciatis velit et eveniet rerum et nihil voluptates aut eaque ipsa et
ratione facere!`;
10 changes: 5 additions & 5 deletions apps/console/src/lib/schema/organization.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { z } from 'zod';

export const organizationsSchema = z.object({
export const organization = z.object({
organization: z.string().trim().min(2),
description: z.string().trim().max(256).min(2),
allowedEmails: z.string().email().array().nullish(),
allowedEmailDomains: z.string().trim().min(2).array().nullish(),
});

export type organizationsSchema = typeof organizationsSchema;
export type organizations = z.infer<typeof organizationsSchema>;
export type organizationsSchema = typeof organization;
export type organizations = z.infer<typeof organization>;

export const updateOrganizationsSchema = organizationsSchema;
export const updateOrganizationsSchema = organization;

export type UpdateOrganizationsSchema = typeof updateOrganizationsSchema;
export type UpdateOrganizations = z.infer<typeof updateOrganizationsSchema>;
export const updateOrganizationsKeys = updateOrganizationsSchema.keyof().Enum;

export const organizationsCreateSchema = organizationsSchema.extend({
export const organizationsCreateSchema = organization.extend({
allowedEmails: z.string().email().array().default([]),
allowedEmailDomains: z.string().trim().min(2).array().nullish().default([]),
});
Expand Down
2 changes: 1 addition & 1 deletion apps/console/src/routes/(app)/organizations/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { invalidateAll } from '$app/navigation';
import { DeleteOrgStore } from '$houdini';
import { default as ChipButton } from '$lib/components/chip-button.svelte';
import { ChipButton } from '$lib/components';
import { handleMessage } from '$lib/components/layout/toast-manager';
import { getToastStore, popup } from '@skeletonlabs/skeleton';
import * as Table from '@spectacular/skeleton/components/table';
Expand Down
3 changes: 1 addition & 2 deletions apps/console/src/routes/(app)/profile/+page.gql
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ query GetUser($userId: uuid!) @role(name: "me") {
...UserOrgRolesFragment
...PersonalAccessTokensFragment
...AuthProvidersFragment
securityKeys(order_by: { nickname: asc }) @list(name: "Security_Keys") @loading {
__typename
securityKeys(order_by: { nickname: asc }) @list(name: "Security_Keys") {
...SecurityKeyFragment
}
}
Expand Down
35 changes: 16 additions & 19 deletions apps/console/src/routes/(app)/profile/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
import { page } from '$app/stores';
import { PendingValue } from '$houdini';
import { Meta } from '$lib/components';
import { allLoaded, loaded, loading } from '$lib/graphql/loading';
import { GraphQLErrors } from '@spectacular/skeleton/components';
import type { PageData } from './$houdini';
import ChangeEmailForm from './components/change-email.svelte';
import ChangePasswordForm from './components/change-password.svelte';
import ConnectSocials from './components/connect-socials.svelte';
import HasuraJwtClaims from './components/hasura-jwt-claims.svelte';
import MultiFactorAuth from './components/multi-factor-auth.svelte';
import PersonalAccessTokenForm from './components/personal-access-token-form.svelte';
import PersonalAccessTokens from './components/personal-access-tokens.svelte';
import SecurityKeyForm from './components/security-key-form.svelte';
import SecurityKeys from './components/security-keys.svelte';
Expand All @@ -28,13 +30,6 @@ export let data: PageData;
// Reactivity
let { GetUser } = data;
$: ({ GetUser } = data);
// biome-ignore lint/correctness/noUndeclaredVariables: <explanation>
// biome-ignore lint/style/noNonNullAssertion: <explanation>
$: user = $GetUser.data!.user!;
$: securityKeys = user.securityKeys;
// biome-ignore lint/correctness/noUndeclaredVariables: <explanation>
// biome-ignore lint/style/noNonNullAssertion: <explanation>
$: email = user.email!;
$: meta = {
title: 'Datablocks | Profile',
Expand All @@ -56,7 +51,10 @@ $: meta = {

{#if $GetUser.errors}
<GraphQLErrors errors={$GetUser.errors} />
{:else}
{:else if $GetUser.data?.user}
{@const user = $GetUser.data.user}
{@const { email, securityKeys } = user}

<section class="space-y-4">
<h2 class="h2">User Details</h2>
<p>Update user details</p>
Expand All @@ -66,33 +64,32 @@ $: meta = {
<section class="space-y-4">
<h2 class="h2">User Org Roles</h2>
<p>Orgs and roles you are granted</p>
<UserOrgRoles {user} />
<UserOrgRoles {user} />
</section>

<section class="space-y-4">
<h2 class="h2">Auth Providers</h2>
<p>Add or delete auth providers</p>
<ConnectSocials {user} />
<ConnectSocials {user} />
</section>

<section class="space-y-4">
<h2 class="h2">Personal Access Tokens</h2>
<p>Add are delete your personal access tokens(PAT)</p>
<PersonalAccessTokens {user} ></PersonalAccessTokens>
<PersonalAccessTokenForm />
<PersonalAccessTokens {user}></PersonalAccessTokens>
</section>


<section class="space-y-4">
<h2 class="h2">Change Email</h2>
<p>Change the password of the current user.</p>
{#if email === PendingValue}
<div class="placeholder animate-pulse" />
{#if loaded(email)}
<ChangeEmailForm initialData={{ email: email || "" }} />
{:else}
<ChangeEmailForm initialData={{ email }} />
<div class="placeholder animate-pulse" />
{/if}
</section>


<section class="space-y-4">
<h2 class="h2">Change Password</h2>
<p>
Expand All @@ -107,9 +104,9 @@ $: meta = {
Add are delete your security keys like TouchID, FaceID, YubiKeys etc
</p>
<SecurityKeyForm />
<!-- {#if securityKeys?.__typename !== 'SecurityKeys'} -->
{#if allLoaded(securityKeys) && securityKeys.length > 0}
<SecurityKeys {securityKeys} />
<!-- {/if} -->
{/if}
</section>

<section class="space-y-4">
Expand All @@ -126,5 +123,5 @@ $: meta = {
</p>
<HasuraJwtClaims />
</section>
{/if}
{/if}
</div>
Loading

0 comments on commit 340e987

Please sign in to comment.