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

Fixes 1.4 #516

Merged
merged 11 commits into from
Aug 28, 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
2,263 changes: 1,189 additions & 1,074 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"ai": "^2.1.15",
"analytics": "^0.8.1",
"dayjs": "^1.11.9",
"deep-equal": "^2.2.2",
"dotenv": "^16.0.3",
"echarts": "^5.4.1",
"logrocket": "^3.0.1",
Expand All @@ -48,6 +49,7 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/svelte": "^3.2.2",
"@testing-library/user-event": "^14.4.3",
"@types/deep-equal": "^1.0.1",
"@types/prismjs": "^1.26.0",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
Expand Down
3 changes: 2 additions & 1 deletion src/lib/commandCenter/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const groups = [
'security',
'buckets',
'files',
'misc'
'misc',
'settings'
] as const;

export type CommandGroup = (typeof groups)[number];
Expand Down
13 changes: 7 additions & 6 deletions src/lib/commandCenter/panels/template.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -411,20 +411,21 @@

// Elements
.card {
position: absolute;
--top: clamp(64px, 10vh, 400px);
top: var(--top);
left: 50%;
translate: -50%;

display: flex;
flex-direction: column;
width: var(--width, 42.5rem);
max-width: 100%;
min-height: var(--min-height);
max-height: var(--max-height, 32rem);
max-height: min(calc(100vh - var(--top) - 4rem), var(--max-height, 32rem));
overflow: hidden;
padding: 0;

position: absolute;
top: clamp(128px, 15vh, 400px);
left: 50%;
translate: -50%;

border-radius: 0.5rem;
border: 1px solid var(--cmd-center-border);
background: var(--cmd-center-bg);
Expand Down
5 changes: 3 additions & 2 deletions src/lib/components/cardGrid.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import { Card } from './';

export let danger = false;
export let hideOverflow = false;
</script>

<Card {danger}>
<div class="common-section grid-1-2">
<div class="common-section grid-1-2" class:hideOverflow>
<div class="grid-1-2-col-1 u-flex u-flex-vertical u-gap-16">
<slot />
</div>
Expand All @@ -21,7 +22,7 @@
</Card>

<style lang="scss">
.grid-1-2 > * {
.hideOverflow > * {
width: 100%;
overflow: hidden;
}
Expand Down
29 changes: 2 additions & 27 deletions src/lib/helpers/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,8 @@ export function objectEntries<T extends object>(obj: T) {
return Object.entries(obj) as Array<[keyof T, T[keyof T]]>;
}

/**
* Recursively compares two objects to see if they are equal. Returns true if they are equal, false otherwise.
* @param obj1 the first object
* @param obj2 the second object
* @returns true if the objects are equal, false otherwise
*/
export function deepEqual<T>(obj1: T, obj2: T): boolean {
if (obj1 === obj2) return true;

if (typeof obj1 !== 'object' || typeof obj2 !== 'object' || obj1 === null || obj2 === null)
return false;

const keys1 = Object.keys(obj1);
const keys2 = Object.keys(obj2);

if (keys1.length !== keys2.length) return false;

for (const key of keys1) {
if (
!keys2.includes(key) ||
!Object.prototype.hasOwnProperty.call(obj2, key) ||
!deepEqual(obj1[key], obj2[key])
)
return false;
}

return true;
export function isRegExp(value: unknown): value is RegExp {
return value instanceof RegExp;
}

/**
Expand Down
38 changes: 38 additions & 0 deletions src/lib/helpers/stores.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { writable, type Writable } from 'svelte/store';
import { deepClone, objectEntries } from './object';

/**
* Given an object `obj`, returns an object of writable stores for each key in that object.
*
* Also returns a listen method that accepts an object of the same shape as `obj` and updates
* the stores with the values from that object if they are different.
*
* @export
*/
export function createConservative<Obj extends Record<string, any>>(obj: Obj) {
const stores = Object.fromEntries(
objectEntries(obj).map(([key, value]) => [key, writable(value)])
) as {
[K in keyof Obj]: Writable<Obj[K]>;
};

const history = deepClone(obj);

function listen(input: Obj) {
objectEntries(input).forEach(([key, value]) => {
if (!(key in stores) || !(key in history)) {
return;
}
const curr = history[key];
if (curr !== value) {
stores[key].set(value);
history[key] = value;
}
});
}

return {
stores,
listen
};
}
3 changes: 3 additions & 0 deletions src/lib/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ export function isHTMLElement(el: unknown): el is HTMLElement {
export function isHTMLInputElement(el: unknown): el is HTMLInputElement {
return el instanceof HTMLInputElement;
}

// eslint-disable-next-line @typescript-eslint/ban-types
export type Prettify<T> = T & {};
2 changes: 1 addition & 1 deletion src/routes/console/(migration-wizard)/resource-form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,10 @@
grid-template-columns: auto 1fr;
gap: 0.25rem 1rem;
align-items: center;
padding-block-end: 1rem;

ul {
grid-column-start: 2;
padding-block-end: 2rem;

li {
margin-block-start: 1rem;
Expand Down
10 changes: 5 additions & 5 deletions src/routes/console/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
goto(`/console/project-${$project.$id}/settings`);
},
disabled: isOnSettingsLayout && $page.url.pathname.endsWith('settings'),
group: 'navigation',
group: isOnSettingsLayout ? 'navigation' : 'settings',
rank: isOnSettingsLayout ? 40 : -1
},
{
Expand All @@ -170,7 +170,7 @@
goto(`/console/project-${$project.$id}/settings/domains`);
},
disabled: isOnSettingsLayout && $page.url.pathname.includes('domains'),
group: 'navigation',
group: isOnSettingsLayout ? 'navigation' : 'settings',
rank: isOnSettingsLayout ? 30 : -1
},
{
Expand All @@ -180,7 +180,7 @@
goto(`/console/project-${$project.$id}/settings/webhooks`);
},
disabled: isOnSettingsLayout && $page.url.pathname.includes('webhooks'),
group: 'navigation',
group: isOnSettingsLayout ? 'navigation' : 'settings',

rank: isOnSettingsLayout ? 20 : -1
},
Expand All @@ -191,7 +191,7 @@
goto(`/console/project-${$project.$id}/settings/migrations`);
},
disabled: isOnSettingsLayout && $page.url.pathname.includes('migrations'),
group: 'navigation',
group: isOnSettingsLayout ? 'navigation' : 'settings',

rank: isOnSettingsLayout ? 10 : -1
},
Expand All @@ -202,7 +202,7 @@
goto(`/console/project-${$project.$id}/settings/smtp`);
},
disabled: isOnSettingsLayout && $page.url.pathname.includes('smtp'),
group: 'navigation',
group: isOnSettingsLayout ? 'navigation' : 'settings',
rank: -1
}
]);
Expand Down
13 changes: 0 additions & 13 deletions src/routes/console/+page.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import { project } from '../../store';
import ResetEmail from './resetEmail.svelte';
import { baseEmailTemplate, emailTemplate } from './store';
import { deepEqual } from '$lib/helpers/object';
import deepEqual from 'deep-equal';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { Box } from '$lib/components';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { baseSmsTemplate, smsTemplate } from './store';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import { deepEqual } from '$lib/helpers/object';
import deepEqual from 'deep-equal';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { Box } from '$lib/components';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
}

$: isDisabled = (function getDisabled() {
return !operator || (!operator?.hideInput && !value);
return !operator || (!operator?.hideInput && !value)
})();
</script>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
<script lang="ts">
import { beforeNavigate } from '$app/navigation';
import { Drop, Modal } from '$lib/components';
import Content from './content.svelte';
import { Button } from '$lib/elements/forms';
import { queries, tags } from './store';
import Content from './content.svelte';
import { queries, queriesAreDirty, tags } from './store';

// We need to separate them so we don't trigger Drop's handlers
let showFiltersDesktop = false;
let showFiltersMobile = false;

let applied = $tags.length;

function apply() {
queries.apply();
beforeNavigate(() => {
applied = $tags.length;
showFiltersDesktop = false;
showFiltersMobile = false;
}

function clearAll() {
queries.clearAll();
queries.apply();
applied = 0;
}
});
</script>

<div class="is-not-mobile">
Expand All @@ -43,8 +37,8 @@
on:clear={() => (applied = 0)} />
<hr />
<div class="u-flex u-margin-block-start-16 u-main-end u-gap-8">
<Button text on:click={clearAll}>Clear all</Button>
<Button on:click={apply}>Apply</Button>
<Button text on:click={queries.clearAll}>Clear all</Button>
<Button on:click={queries.apply} disabled={!$queriesAreDirty}>Apply</Button>
</div>
</div>
</svelte:fragment>
Expand All @@ -69,8 +63,9 @@
size="big">
<Content on:apply={(e) => (applied = e.detail.applied)} on:clear={() => (applied = 0)} />
<svelte:fragment slot="footer">
<Button text on:click={clearAll}>Clear all</Button>
<Button on:click={apply}>Apply</Button></svelte:fragment>
<Button text on:click={queries.clearAll}>Clear all</Button>
<Button on:click={queries.apply} disabled={!$queriesAreDirty}>Apply</Button
></svelte:fragment>
</Modal>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { goto } from '$app/navigation';

import { derived, get, writable, type Writable } from 'svelte/store';
import type { columns } from '../store';
import { page } from '$app/stores';
import deepEqual from 'deep-equal';

const columnTypes = ['string', 'integer', 'double', 'boolean', 'datetime', 'relationship'] as const;
type ColumnType = (typeof columnTypes)[number];
Expand Down Expand Up @@ -71,4 +73,18 @@ function initQueries(initialValue = new Map<string, string>()) {
}

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);
});

export const hasPageQueries = derived(page, ($page) => {
const paramQueries = $page.url.searchParams.get('query');
const parsedQueries = queryParamToMap(paramQueries || '[]');
return parsedQueries.size > 0;
});

export const tags = derived(queries, ($queries) => Array.from($queries.keys()));
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<script lang="ts">
import { page } from '$app/stores';
import { Empty, Heading, PaginationWithLimit } from '$lib/components';
import { Empty, EmptySearch, Heading, PaginationWithLimit } from '$lib/components';
import ViewSelector from '$lib/components/viewSelector.svelte';
import { Button } from '$lib/elements/forms';
import { Container } from '$lib/layout';
import { preferences } from '$lib/stores/preferences';
import { wizard } from '$lib/stores/wizard';
import type { PageData } from './$types';
import Filters from './(filters)/filters.svelte';
import { hasPageQueries, queries } from './(filters)/store';
import CreateAttributeDropdown from './attributes/createAttributeDropdown.svelte';
import type { Option } from './attributes/store';
import CreateAttribute from './createAttribute.svelte';
import Create from './createDocument.svelte';
import Filters from './(filters)/filters.svelte';
import { collection, columns } from './store';
import Table from './table.svelte';

Expand Down Expand Up @@ -84,6 +85,25 @@
limit={data.limit}
offset={data.offset}
total={data.documents.total} />
{:else if $hasPageQueries}
<EmptySearch hidePages>
<div class="common-section">
<div class="u-text-center common-section">
<b class="body-text-2 u-bold">Sorry, we couldn't find any documents.</b>
<p>There are no documents that match your filters.</p>
</div>
<div class="u-flex common-section u-main-center">
<Button
secondary
on:click={() => {
queries.clearAll();
queries.apply();
}}>
Clear filters
</Button>
</div>
</div>
</EmptySearch>
{:else}
<Empty
single
Expand Down
Loading