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

Refactor: enable strict null checks #225

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2fd3a6d
feat: empty arrays UI
TGlide Dec 12, 2022
7c784f7
chore: remove date on array jsdoc
TGlide Dec 12, 2022
f1b4205
feat: add attribute types to input labels
TGlide Dec 12, 2022
d8aaf06
refactor(WIP): refactor event modal
TGlide Dec 13, 2022
afd1f8b
refactor: refactor event modal & fix copy
TGlide Dec 13, 2022
0e5e113
fix: eventModal wrong event string
TGlide Dec 14, 2022
27923ca
refactor: code documentation
TGlide Dec 14, 2022
b83526f
feat: show eventString on custom inputs
TGlide Dec 14, 2022
107a3e3
refactor: code organization
TGlide Dec 14, 2022
df29f3e
feat: custom input helper
TGlide Dec 14, 2022
cdcd79c
feat: eventModal customInput cursor helper
TGlide Dec 14, 2022
6718168
refactor: eventModal code organization
TGlide Dec 14, 2022
a8c69f2
chore: remove console log
TGlide Dec 14, 2022
20297da
feat: allow event editing
TGlide Dec 14, 2022
6e87480
refactor: move eventModal constants
TGlide Dec 15, 2022
26690c7
refactor: document table improvements
TGlide Dec 15, 2022
df3544e
refactor: separate updateEvents & use droplist for event options
TGlide Dec 15, 2022
bb2f10e
fix: event action naming convetions
TGlide Dec 15, 2022
2991a80
refactor(WIP): enable strict null checks
TGlide Dec 16, 2022
a13e838
chore: more ts fixes
TGlide Dec 22, 2022
e79712e
chore: ts strict null checks fixes
TGlide Dec 23, 2022
bf14907
refactor: pr reviews
TGlide Jan 23, 2023
c8c502d
Merge pull request #217 from appwrite/feat-display-attribute-types
TorstenDittmann Jan 27, 2023
c3e5389
fix: label alignment
TGlide Jan 30, 2023
020a08d
fix: event modal input styles
TGlide Jan 30, 2023
2222c56
Merge branch 'feat-empty-arrays-ui' into refactor-enable-strict-null-…
TGlide Jan 30, 2023
7f92472
Merge branch 'refactor-event-modal' into refactor-enable-strict-null-…
TGlide Jan 30, 2023
483f7ef
Merge branch 'main' into refactor-enable-strict-null-checks
TGlide Jan 30, 2023
100fc7a
fix: type-checking in multiple files
TGlide Jan 30, 2023
fd3be64
fix: type-checking in multiple files
TGlide Jan 31, 2023
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
18 changes: 16 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,31 @@ module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
plugins: ['svelte3', '@typescript-eslint'],
ignorePatterns: ['*.cjs'],
overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }],
overrides: [
{
files: ['*.svelte'],
processor: 'svelte3/svelte3',
rules: {
'no-redeclare': 'off'
}
}
],
settings: {
'svelte3/typescript': () => require('typescript')
},
parserOptions: {
sourceType: 'module',
ecmaVersion: 2020
ecmaVersion: 2020,
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
extraFileExtensions: ['.svelte']
},
env: {
browser: true,
es2017: true,
node: true
},
rules: {
'@typescript-eslint/no-explicit-any': 'warn'
}
};
13 changes: 13 additions & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,16 @@ interface Window {
VERCEL_ANALYTICS_ID: string | false;
SENTRY_DSN: string | false;
}

declare module 'prismjs/plugins/line-numbers/prism-line-numbers' {}
declare module 'prismjs/components/prism-dart' {}
declare module 'prismjs/components/prism-kotlin' {}
declare module 'prismjs/components/prism-json' {}
declare module 'prismjs/components/prism-bash' {}
declare module 'prismjs/components/prism-yaml' {}
declare module 'prismjs/components/prism-swift' {}
declare module 'prismjs/plugins/autoloader/prism-autoloader' {}
declare module 'prismjs/plugins/custom-class/prism-custom-class' {}
declare module '@analytics/google-analytics' {
export default function googleAnalytics(options: any): any;
}
21 changes: 11 additions & 10 deletions src/lib/actions/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { get } from 'svelte/store';
import { page } from '$app/stores';
import { user } from '$lib/stores/user';
import { growthEndpoint, Mode } from '$lib/constants';
import { isNonNullable, isNonNullableObject, type Nullable } from '$lib/helpers/type';

const analytics = Analytics({
app: 'appwrite',
Expand All @@ -14,13 +15,14 @@ const analytics = Analytics({
]
});

export function trackEvent(name: string, data: object = null): void {
export function trackEvent(name: string, data: Nullable<object> = null): void {
if (!isTrackingAllowed()) {
return;
}
const path = get(page).routeId;
analytics.track(name, { ...data, path });
sendEventToGrowth(name, path, data);

isNonNullable(path) && sendEventToGrowth(name, path, data);
}

export function trackPageView(path: string) {
Expand All @@ -33,13 +35,12 @@ export function trackPageView(path: string) {
});
}

function sendEventToGrowth(event: string, path: string, data: object = null): void {
let email: string, name: string;
function sendEventToGrowth(event: string, path: string, data: Nullable<object> = null): void {
const userStore = get(user);
if (userStore) {
email = userStore.email;
name = userStore.name;
}
const args = { email: userStore?.email, name: userStore?.name };

if (!isNonNullableObject(args)) return;

fetch(`${growthEndpoint}/analytics`, {
method: 'POST',
headers: {
Expand All @@ -51,8 +52,8 @@ function sendEventToGrowth(event: string, path: string, data: object = null): vo
url: window.location.origin + path,
account: import.meta.env.VITE_CONSOLE_MODE?.toString() || Mode.SELF_HOSTED,
data: {
email,
name,
email: args.email,
name: args.name,
...data
}
})
Expand Down
32 changes: 32 additions & 0 deletions src/lib/actions/selectionStart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { isNonNullable } from '$lib/helpers/type';
import type { Action } from 'svelte/action';

type Props = {
onChange: (selectionStart: number) => void;
};

const init: Action<HTMLInputElement, Props> = (node, props) => {
const { onChange } = props ?? {};

const handler = () => {
if (!isNonNullable(node.selectionStart)) return;
onChange?.(node.selectionStart);
};

node.addEventListener('click', handler);
node.addEventListener('keydown', handler);
node.addEventListener('keyup', handler);
};

export const selectionStart: Action<HTMLInputElement, Props> = (node, props) => {
init(node, props);

return {
update(props) {
init(node, props);
},
destroy() {
props?.onChange(-1);
}
};
};
11 changes: 9 additions & 2 deletions src/lib/actions/tooltip.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import type { Action } from 'svelte/action';
import type { Props } from 'tippy.js';
import type { Props as TippyProps } from 'tippy.js';
import tippy from 'tippy.js';

type Props = TippyProps & {
disabled?: boolean;
};

export const tooltip: Action<HTMLElement, Partial<Props>> = (node, config) => {
const instance = tippy(node, config);
if (config?.disabled) instance.disable();

return {
update({ content }) {
update({ content, disabled }) {
if (content !== instance.props.content) {
instance.setProps({
content
});
}

disabled ? instance.disable() : instance.enable();
},
destroy() {
instance.destroy();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/charts/bar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import Base from './base.svelte';

export let series: BarSeriesOption[];
export let options: EChartsOption = null;
export let options: EChartsOption | null = null;
</script>

<Base
Expand Down
2 changes: 1 addition & 1 deletion src/lib/charts/base.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
registerTheme('light', { ...base, ...light });
registerTheme('dark', { ...base, ...dark });

export let options: EChartsOption;
export let options: EChartsOption | null;
export let series: (BarSeriesOption | LineSeriesOption)[];

let chart: ECharts;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/charts/line.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import Base from './base.svelte';

export let series: LineSeriesOption[];
export let options: EChartsOption = null;
export let options: EChartsOption | null = null;
</script>

<Base
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/card.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
export let isDashed = false;
export let isButton = false;
export let danger = false;
export let href: string = null;
export let href: string | null = null;

function getElement(): string {
switch (true) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/cardContainer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
export let offset = 0;
export let limit = $cardLimit;
export let total = 0;
export let event: string = null;
export let event: string | null = null;
</script>

<ul
Expand Down
6 changes: 3 additions & 3 deletions src/lib/components/code.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import { afterUpdate } from 'svelte';
import { Copy } from '.';

export let label: string = null;
export let labelIcon: 'code' | 'android' | 'flutter' | 'apple' = null;
export let code: string;
export let label: string | null = null;
export let labelIcon: 'code' | 'android' | 'flutter' | 'apple' | null = null;
export let code: string = '';
export let language: 'js' | 'html' | 'dart' | 'kotlin' | 'json' | 'sh' | 'yml' | 'swift';
export let withLineNumbers = false;
export let withCopy = false;
Expand Down
7 changes: 5 additions & 2 deletions src/lib/components/copy.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import { clickOnEnter } from '$lib/helpers/a11y';
import { copy } from '$lib/helpers/copy';
import { addNotification } from '$lib/stores/notifications';
import type { Props as TippyProps } from 'tippy.js';

export let value: string;
export let event: string = null;
export let event: string | null = null;
export let appendTo: TippyProps['appendTo'] | undefined = undefined;

let content = 'Click to copy';

Expand Down Expand Up @@ -36,7 +38,8 @@
on:mouseenter={() => setTimeout(() => (content = 'Click to copy'))}
use:tooltip={{
content,
hideOnClick: false
hideOnClick: false,
appendTo
}}>
<slot />
</span>
2 changes: 1 addition & 1 deletion src/lib/components/copyInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { addNotification } from '$lib/stores/notifications';

export let value: string;
export let label: string = null;
export let label: string | null = null;
export let showLabel = false;

let content = 'Click to copy';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/customId.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

export let show = false;
export let name: string;
export let id: string;
export let id: string | null | undefined;

$: if (!show) {
id = null;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/dropList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
export let scrollable = false;
export let childStart = false;
export let noArrow = false;
export let width: string = null;
export let width: string | null = null;
</script>

<Drop bind:show {placement} {childStart} {noArrow}>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/dropListItem.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
export let disabled = false;
export let icon: string = null;
export let icon: string | null = null;
</script>

<li class="drop-list-item">
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/dropListLink.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { clickOnEnter } from '$lib/helpers/a11y';

export let href: string;
export let icon: string = null;
export let icon: string | null = null;
export let disabled = false;
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/empty.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import { trackEvent } from '$lib/actions/analytics';

export let single = false;
export let target: string = null;
export let href: string = null;
export let target: string | null = null;
export let href: string | null = null;

function track() {
if (target) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/evaluation.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { clickOnEnter } from '$lib/helpers/a11y';

export let value: number = null;
export let value: number | null = null;
</script>

<fieldset class="u-margin-block-start-8">
Expand Down
Loading