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

First steps towards enabling TypeScript strict mode #826

Merged
merged 9 commits into from
Jan 18, 2022
1 change: 1 addition & 0 deletions mathesar_ui/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module.exports = {
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'object-curly-newline': 'off',
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion mathesar_ui/src/component-library/button/Button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
export { classes as class };

// Underlying DOM element for direct access
export let element: HTMLElement = null;
export let element: HTMLElement | undefined = undefined;

$: allClasses = ['btn', `btn-${appearance}`, `size-${size}`, classes].join(' ');
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class EventHandler {
if (!this.listeners.has(eventName)) {
this.listeners.set(eventName, new Set());
}
this.listeners.get(eventName).add(callback);
this.listeners.get(eventName)?.add(callback);
return () => {
this.listeners?.get(eventName)?.delete(callback);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type {
export class AccompanyingElements implements Readable<Set<HTMLElement>> {
elements = writable(new Set<HTMLElement>());

parent: AccompanyingElements;
parent: AccompanyingElements | undefined;

constructor(parent?: AccompanyingElements) {
this.parent = parent;
Expand Down
10 changes: 8 additions & 2 deletions mathesar_ui/src/component-library/dropdown/Dropdown.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
export let contentClass = '';
export let isOpen = false;
export let closeOnInnerClick = false;
export let ariaLabel:string = null;
export let ariaControls: string = null;
export let ariaLabel: string | undefined = undefined;
export let ariaControls: string | undefined = undefined;
export let placement: Placement = 'bottom-start';
export let showArrow = true;
export let size: Size = 'medium';
Expand All @@ -41,12 +41,18 @@
if (!contentElement) {
await tick();
}
if (!contentElement) {
return;
}
parentAccompanyingElements?.add(contentElement);
}
async function unsetThisContentToAccompanyParent() {
if (!contentElement) {
await tick();
}
if (!contentElement) {
return;
}
parentAccompanyingElements?.delete(contentElement);
}
onDestroy(unsetThisContentToAccompanyParent);
Expand Down
13 changes: 8 additions & 5 deletions mathesar_ui/src/component-library/file-upload/FileUpload.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
const dispatch = createEventDispatcher();
const componentId = `file-import-${getId()}`;

export let fileProgress: Record<string, FileUploadProgress> = null;
export let fileProgress: Record<string, FileUploadProgress> | undefined = undefined;
export let multiple = false;
export let fileUploads: FileUpload[] = null;
export let fileUploads: FileUpload[] | undefined = undefined;

let fileId = 0;
let state = 'idle';
Expand Down Expand Up @@ -71,7 +71,10 @@
}

function onFileDrop(event: DragEvent) {
const fileList = event.dataTransfer.files;
const fileList = event.dataTransfer?.files;
if (!fileList) {
return;
}
if (multiple) {
processFiles(event, fileList);
} else {
Expand All @@ -86,8 +89,8 @@
}
</script>

<div class="file-upload" class:inprogress={fileUploads?.length > 0}>
{#if fileUploads?.length > 0}
<div class="file-upload" class:inprogress={fileUploads && fileUploads.length > 0}>
pavish marked this conversation as resolved.
Show resolved Hide resolved
{#if fileUploads && fileUploads.length > 0}
<div class="files">
{#each fileUploads as upload (upload.fileId)}
<div class="file">
Expand Down
6 changes: 3 additions & 3 deletions mathesar_ui/src/component-library/icon/Icon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
export let pulse = false;

// Flips the icon. Allowed values are 'vertical', 'horizontal' or 'both'.
export let flip: IconFlip = null;
export let flip: IconFlip | undefined = undefined;

// Rotates the icon to a specified angle. Allowed values are '90', '180', '270'.
export let rotate: IconRotate = null;
export let rotate: IconRotate | undefined = undefined;

// Additional classes
let classes = '';
export { classes as class };

// The aria-label for the icon. Typically describes the icon.
export let label: string = null;
export let label: string | undefined = undefined;

function concatClasses(_classes?: string, _flip?: IconFlip, _rotate?: IconRotate): string {
const faClass = ['fa-icon'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
},
},
flip: {
control: { type: 'inline-radio', options: ['horizontal', 'vertical', 'both', null] },
control: { type: 'inline-radio', options: ['horizontal', 'vertical', 'both', undefined] },
table: {
type: { summary: 'enum' },
},
},
rotate: {
control: { type: 'inline-radio', options: [90, 180, 270, null] },
control: { type: 'inline-radio', options: [90, 180, 270, undefined] },
table: {
type: { summary: 'enum' },
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
export let total = 0;

// Can be used to specify a path.
export let getLink: (page: number, pageSize: number) => string = null;
export let getLink: ((page: number, pageSize: number) => string) | undefined = undefined;

// Total number of pages.
export let pageCount = 0;
Expand Down
10 changes: 5 additions & 5 deletions mathesar_ui/src/component-library/tabs/Tab.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
export let totalTabs: number;
export let isActive = false;
export let allowRemoval = false;
export let getTabURL: (tab: Tab) => string;
export let getTabURL: (tab: Tab) => string | undefined;
</script>

<li role="presentation" class="tab" class:active={isActive} tabindex="-1"
style={isActive ? null : `width: ${Math.floor(100 / totalTabs)}%;`}>
style={isActive ? undefined : `width: ${Math.floor(100 / totalTabs)}%;`}>

<a role="tab" href={getTabURL(tab) || '#'} tabindex="0"
<a role="tab" href={getTabURL(tab) ?? '#'} tabindex="0"
aria-selected={isActive} aria-disabled="{!!tab.disabled}"
id={isActive ? `mtsr-${componentId}-tab` : null} data-tinro-ignore
aria-controls={isActive ? `mtsr-${componentId}-tabpanel` : null}
id={isActive ? `mtsr-${componentId}-tab` : undefined} data-tinro-ignore
aria-controls={isActive ? `mtsr-${componentId}-tabpanel` : undefined}
on:focus on:blur on:mousedown
on:click>
<slot></slot>
Expand Down
2 changes: 1 addition & 1 deletion mathesar_ui/src/component-library/tree/TreeItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
{#if entry[childKey]}
<li aria-level={level + 1} role="treeitem" tabindex="-1">
<Button appearance="plain" class="item parent" on:click={toggle}>
<Icon data={faCaretRight} rotate={isOpen ? IconRotate.NINETY : null}/>
<Icon data={faCaretRight} rotate={isOpen ? IconRotate.NINETY : undefined}/>
<span>{entry[labelKey]}</span>
</Button>

Expand Down
3 changes: 3 additions & 0 deletions mathesar_ui/src/header/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
import ImportIndicator from './import-indicator/ImportIndicator.svelte';

async function handleCreateEmptyTable() {
if (!$currentSchemaId) {
return;
}
const table = await createTable($currentSchemaId);
await refetchTablesForSchema($currentSchemaId);
const tab = constructTabularTab(
Expand Down
32 changes: 18 additions & 14 deletions mathesar_ui/src/header/schema-selector/SchemaSelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,25 @@
<div class="schema-selector">
<div class="databases">
<div class="section-header">
Databases ({$databases.data.length})
Databases ({$databases?.data?.length ?? 0})
</div>
<ul>
{#each $databases.data as database (database.name)}
<li class="item" class:active={interalSelectedDB === database.name}>
<button type="button"
on:click={() => selectDB(database)}
on:mouseover={() => selectDB(database)}
on:focus={() => selectDB(database)}>
<TextAvatar text={database.name} />
{database.name}
</button>
</li>
{/each}
</ul>
{#if $databases.data && $databases.data.length}
<ul>
{#each $databases.data as database (database.name)}
<li class="item" class:active={interalSelectedDB === database.name}>
<button type="button"
on:click={() => selectDB(database)}
on:mouseover={() => selectDB(database)}
on:focus={() => selectDB(database)}>
<TextAvatar text={database.name} />
{database.name}
</button>
</li>
{/each}
</ul>
{:else}
<div>No databases</div>
{/if}
</div>

<div class="schemas">
Expand Down
13 changes: 5 additions & 8 deletions mathesar_ui/src/pages/schemas/AddEditSchema.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

export let isOpen = false;
export let isEditMode = false;
export let schema: SchemaEntry = null;
export let schema: SchemaEntry;
pavish marked this conversation as resolved.
Show resolved Hide resolved

let name = '';
let state: States = States.Idle;
let error: string;
let error: string | undefined;

onMount(() => {
if (isEditMode) {
Expand All @@ -27,7 +27,7 @@
});

function isDuplicateName(_isEditMode: boolean, _name: string): boolean {
if (_isEditMode && _name.toLowerCase().trim() === schema?.name.toLowerCase().trim()) {
if (_isEditMode && _name.toLowerCase().trim() === schema.name.toLowerCase().trim()) {
return false;
}
return Array.from($schemas?.data || []).some(
Expand All @@ -46,12 +46,9 @@
async function saveSchema() {
try {
state = States.Loading;
error = null;
error = undefined;
if (isEditMode) {
await updateSchema($currentDBName, {
...schema,
name,
});
await updateSchema($currentDBName, { ...schema, name });
} else {
await createSchema($currentDBName, name);
}
Expand Down
10 changes: 5 additions & 5 deletions mathesar_ui/src/pages/schemas/Schemas.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
if ($currentDBName !== _db) {
$currentDBName = _db;
}
$currentSchemaId = null;
$currentSchemaId = undefined;
}

$: changeCurrentDB(database);

let filterQuery = '';
let activeSchema: SchemaEntry = null;
let activeSchema: SchemaEntry | undefined;

function filterSchemas(schemaData: DBSchemaStoreData['data'], filter: string): SchemaEntry[] {
const filtered: SchemaEntry[] = [];
Expand All @@ -40,7 +40,7 @@
$: displayList = filterSchemas($schemas.data, filterQuery);

function addSchema() {
activeSchema = null;
activeSchema = undefined;
isAddModalOpen = true;
}

Expand Down Expand Up @@ -80,9 +80,9 @@
</div>
</main>

{#if isAddModalOpen}
{#if isAddModalOpen && activeSchema}
pavish marked this conversation as resolved.
Show resolved Hide resolved
<AddEditSchema bind:isOpen={isAddModalOpen}
isEditMode={activeSchema !== null} schema={activeSchema}/>
isEditMode={activeSchema !== undefined} schema={activeSchema}/>
{/if}

<style global lang="scss">
Expand Down
6 changes: 3 additions & 3 deletions mathesar_ui/src/sections/Base.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
// TODO: Move this entire logic to data layer without involving view layer
$: changeCurrentSchema(database, schemaId);

function getTabLink(entry: MathesarTab) {
if (entry.isNew) {
return null;
function getTabLink(entry: MathesarTab): string | undefined {
if (entry.isNew || !entry.tabularData) {
return undefined;
}
return constructTabularTabLink(
database,
Expand Down
2 changes: 1 addition & 1 deletion mathesar_ui/src/sections/import-data/ImportData.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import Upload from './upload/Upload.svelte';
import { clearErrors } from './importUtils';

export let id: string;
export let id: string | undefined = undefined;
export let database: Database['name'];
export let schemaId: SchemaEntry['id'];

Expand Down
17 changes: 10 additions & 7 deletions mathesar_ui/src/sections/import-data/preview/Preview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@

function handleChangeType(e: CustomEvent) {
const { previewColumns } = get(fileImportStore);
if (!previewColumns) {
return;
}
const changedColumn = previewColumns.find((column) => column.name === e.detail.name);
if (changedColumn) {
changedColumn.type = e.detail.type as string;

setInFileStore(fileImportStore, {
previewColumns: [...previewColumns],
});
if (!changedColumn) {
return;
}
changedColumn.type = e.detail.type as string;
setInFileStore(fileImportStore, {
previewColumns: [...previewColumns],
});
}

function handleChangeFirstRowAsHeader(e: CustomEvent) {
Expand Down Expand Up @@ -84,7 +87,7 @@
{#if isLoading}<Spinner />{/if}
</div>

{#if $fileImportStore.previewColumns?.length > 0}
{#if $fileImportStore.previewColumns?.length}
<div class="preview-table" class:disabled={$fileImportStore.previewStatus === States.Loading}>
<table>
<thead>
Expand Down
4 changes: 2 additions & 2 deletions mathesar_ui/src/sections/left-pane/LeftPane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

export let database: string;
export let schemaId: SchemaEntry['id'];
export let activeTab: MathesarTab;
export let activeTab: MathesarTab | undefined = undefined;
export let getLink: (entry: TableEntry) => string;

let tree: TreeItem[] = [];
Expand Down Expand Up @@ -61,7 +61,7 @@

$: tree = generateTree($tables);

function onActiveTabChange(_activeTab: MathesarTab) {
function onActiveTabChange(_activeTab: MathesarTab | undefined) {
if (_activeTab?.tabularData) {
activeOptionSet = new Set([
_activeTab.tabularData.id,
Expand Down
2 changes: 1 addition & 1 deletion mathesar_ui/src/sections/table-view/header/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
function getColumnPosition(
_columnPositionMap: ColumnPositionMap,
_name: Column['name'],
): ColumnPosition {
): ColumnPosition | undefined {
return _columnPositionMap.get(_name);
}

Expand Down
Loading