Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into shard-server-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
habdelra committed Jan 8, 2025
2 parents 94e1037 + 8dde0cd commit 83e0cc5
Show file tree
Hide file tree
Showing 26 changed files with 564 additions and 594 deletions.
10 changes: 7 additions & 3 deletions packages/base/cards-grid.gts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class Isolated extends Component<typeof CardsGrid> {
</style>
</template>

filters: { displayName: string; icon: IconComponent; query: any }[] =
filters: { displayName: string; icon: IconComponent | string; query: any }[] =
new TrackedArray([
{
displayName: 'All Cards',
Expand Down Expand Up @@ -424,7 +424,11 @@ class Isolated extends Component<typeof CardsGrid> {
}
let cardTypeSummaries = (await response.json()).data as {
id: string;
attributes: { displayName: string; total: number };
attributes: {
displayName: string;
total: number;
iconHTML: string | null;
};
}[];
let excludedCardTypeIds = [
`${baseRealm.url}card-api/CardDef`,
Expand All @@ -441,7 +445,7 @@ class Isolated extends Component<typeof CardsGrid> {
const lastIndex = summary.id.lastIndexOf('/');
this.filters.push({
displayName: summary.attributes.displayName,
icon: Captions,
icon: summary.attributes.iconHTML ?? Captions,
query: {
filter: {
type: {
Expand Down
32 changes: 27 additions & 5 deletions packages/boxel-ui/addon/src/components/filter-list/index.gts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ export interface FilterListIconSignature {

export type FilterListIcon = ComponentLike<FilterListIconSignature>;

import { htmlSafe } from '@ember/template';

import { cn, eq } from '../../helpers.ts';

export type Filter = {
displayName: string;
icon: FilterListIcon;
icon: FilterListIcon | string;
};

interface Signature {
Expand All @@ -39,9 +41,16 @@ export default class FilterList extends Component<Signature> {
class={{cn 'filter-list__button' selected=(eq @activeFilter filter)}}
{{on 'click' (fn this.onChanged filter)}}
data-test-boxel-filter-list-button={{filter.displayName}}
><filter.icon
class='filter-list__icon'
/>{{filter.displayName}}</button>
>
{{#if (isIconString filter.icon)}}
{{htmlSafe
(addClassToSVG filter.icon 'filter-list__icon')
}}{{filter.displayName}}
{{else}}
<filter.icon
class='filter-list__icon'
/>{{filter.displayName}}{{/if}}</button>

{{/each}}
</div>
<style scoped>
Expand All @@ -58,6 +67,9 @@ export default class FilterList extends Component<Signature> {
font: 500 var(--boxel-font-sm);
padding: var(--boxel-sp-xxs);
margin-bottom: var(--boxel-sp-4xs);
display: flex;
gap: var(--boxel-sp-4xs);
}
.filter-list__button.selected {
color: var(--boxel-light);
Expand All @@ -68,11 +80,21 @@ export default class FilterList extends Component<Signature> {
background: var(--boxel-300);
border-radius: 6px;
}
.filter-list__icon {
:global(.filter-list__icon) {
width: var(--boxel-icon-xs);
height: var(--boxel-icon-xs);
vertical-align: top;
}
</style>
</template>
}

function addClassToSVG(svgString: string, className: string) {
return svgString
.replace(/<svg\b([^>]*)\sclass="([^"]*)"/, `<svg$1 class="$2 ${className}"`)
.replace(/<svg\b([^>]*)>/, `<svg$1 class="${className}">`);
}

function isIconString(icon: FilterListIcon | string): icon is string {
return typeof icon === 'string';
}
6 changes: 4 additions & 2 deletions packages/host/app/components/card-prerender.gts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ export default class CardPrerender extends Component {
realmURL,
reader,
indexWriter,
renderCard: this.renderService.renderCard.bind(this.renderService),
renderCard: this.renderService.renderCard,
render: this.renderService.render,
});
setOwner(currentRun, getOwner(this)!);

Expand All @@ -127,7 +128,8 @@ export default class CardPrerender extends Component {
reader,
indexWriter,
ignoreData: { ...ignoreData },
renderCard: this.renderService.renderCard.bind(this.renderService),
renderCard: this.renderService.renderCard,
render: this.renderService.render,
});
setOwner(currentRun, getOwner(this)!);
let current = await CurrentRun.incremental(currentRun, {
Expand Down
9 changes: 9 additions & 0 deletions packages/host/app/lib/current-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
serializableError,
type SerializedError,
} from '@cardstack/runtime-common/error';
import { cardTypeIcon } from '@cardstack/runtime-common/helpers';
import { RealmPaths, LocalPath } from '@cardstack/runtime-common/paths';
import { isIgnored } from '@cardstack/runtime-common/realm-index-updater';
import { type Reader, type Stats } from '@cardstack/runtime-common/worker';
Expand All @@ -50,6 +51,7 @@ import type * as CardAPI from 'https://cardstack.com/base/card-api';

import {
type RenderCard,
type Render,
IdentityContextWithErrors,
} from '../services/render-service';

Expand Down Expand Up @@ -82,6 +84,7 @@ export class CurrentRun {
#realmPaths: RealmPaths;
#ignoreData: Record<string, string>;
#renderCard: RenderCard;
#render: Render;
#realmURL: URL;
#realmInfo?: RealmInfo;
readonly stats: Stats = {
Expand All @@ -100,19 +103,22 @@ export class CurrentRun {
indexWriter,
ignoreData = {},
renderCard,
render,
}: {
realmURL: URL;
reader: Reader;
indexWriter: IndexWriter;
ignoreData?: Record<string, string>;
renderCard: RenderCard;
render: Render;
}) {
this.#indexWriter = indexWriter;
this.#realmPaths = new RealmPaths(realmURL);
this.#reader = reader;
this.#realmURL = realmURL;
this.#ignoreData = ignoreData;
this.#renderCard = renderCard;
this.#render = render;
}

static async fromScratch(current: CurrentRun): Promise<IndexResults> {
Expand Down Expand Up @@ -413,6 +419,7 @@ export class CurrentRun {
let cardType: typeof CardDef | undefined;
let isolatedHtml: string | undefined;
let atomHtml: string | undefined;
let iconHTML: string | undefined;
let card: CardDef | undefined;
let embeddedHtml: Record<string, string> | undefined;
let fittedHtml: Record<string, string> | undefined;
Expand Down Expand Up @@ -473,6 +480,7 @@ export class CurrentRun {
}),
),
);
iconHTML = unwrap(sanitizeHTML(this.#render(cardTypeIcon(card))));
cardType = Reflect.getPrototypeOf(card)?.constructor as typeof CardDef;
let data = api.serializeCard(card, { includeComputeds: true });
// prepare the document for index serialization
Expand Down Expand Up @@ -552,6 +560,7 @@ export class CurrentRun {
atomHtml,
embeddedHtml,
fittedHtml,
iconHTML,
lastModified,
resourceCreatedAt,
types: typesMaybeError.types.map(({ refURL }) => refURL),
Expand Down
4 changes: 2 additions & 2 deletions packages/host/app/lib/isolated-render.gts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import type { SimpleElement } from '@simple-dom/interface';

interface Signature {
Args: {
format: Format;
format?: Format;
};
}

export function render(
C: ComponentLike<Signature>,
element: SimpleElement,
owner: Owner,
format: Format,
format?: Format,
): void {
// this needs to be a template-only component because the way we're invoking it
// just grabs the template and would drop any associated class.
Expand Down
1 change: 1 addition & 0 deletions packages/host/app/lib/sqlite-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '@cardstack/runtime-common';

export default class SQLiteAdapter implements DBAdapter {
readonly kind = 'sqlite';
private _sqlite: typeof SQLiteWorker | undefined;
private _dbId: string | undefined;
private primaryKeys = new Map<string, string>();
Expand Down
15 changes: 13 additions & 2 deletions packages/host/app/services/render-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getOwner } from '@ember/application';
import type Owner from '@ember/owner';
import Service, { service } from '@ember/service';

import { ComponentLike } from '@glint/template';
import Serializer from '@simple-dom/serializer';

import voidMap from '@simple-dom/void-map';
Expand Down Expand Up @@ -58,6 +59,7 @@ interface RenderCardParams {
componentCodeRef?: CodeRef;
}
export type RenderCard = (params: RenderCardParams) => Promise<string>;
export type Render = (component: ComponentLike) => string;

const maxRenderThreshold = 10000;
export default class RenderService extends Service {
Expand All @@ -69,7 +71,7 @@ export default class RenderService extends Service {
renderError: Error | undefined;
owner: Owner = getOwner(this)!;

async renderCard(params: RenderCardParams): Promise<string> {
renderCard = async (params: RenderCardParams): Promise<string> => {
let {
card,
visit,
Expand Down Expand Up @@ -127,7 +129,16 @@ export default class RenderService extends Service {
let serializer = new Serializer(voidMap);
let html = serializer.serialize(element);
return parseCardHtml(html);
}
};

render = (component: ComponentLike): string => {
let element = getIsolatedRenderElement(this.document);
render(component, element, this.owner);

let serializer = new Serializer(voidMap);
let html = serializer.serialize(element);
return parseCardHtml(html);
};

// TODO delete me
private async resolveField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,34 @@
fitted_html BLOB,
display_names BLOB,
resource_created_at,
PRIMARY KEY ( url, realm_version, realm_url )
icon_html TEXT,
PRIMARY KEY ( url, realm_url )
);

CREATE TABLE IF NOT EXISTS boxel_index_working (
url TEXT NOT NULL,
file_alias TEXT NOT NULL,
type TEXT NOT NULL,
realm_version INTEGER NOT NULL,
realm_url TEXT NOT NULL,
pristine_doc BLOB,
search_doc BLOB,
error_doc BLOB,
deps BLOB,
types BLOB,
icon_html TEXT,
isolated_html TEXT,
indexed_at,
is_deleted BOOLEAN,
source TEXT,
transpiled_code TEXT,
last_modified,
embedded_html BLOB,
atom_html TEXT,
fitted_html BLOB,
display_names BLOB,
resource_created_at,
PRIMARY KEY ( url, realm_url )
);

CREATE TABLE IF NOT EXISTS realm_meta (
Expand Down
9 changes: 0 additions & 9 deletions packages/host/tests/unit/index-query-engine-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,15 +484,6 @@ module('Unit | query', function (hooks) {
});
});

test('can get paginated results that are stable during index mutations', async function (assert) {
await runSharedTest(indexQueryEngineTests, assert, {
indexQueryEngine,
dbAdapter,
loader,
testCards,
});
});

test(`can filter using 'gt'`, async function (assert) {
await runSharedTest(indexQueryEngineTests, assert, {
indexQueryEngine,
Expand Down
8 changes: 0 additions & 8 deletions packages/host/tests/unit/index-writer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ module('Unit | index-writer', function (hooks) {
});
});

test('only invalidates latest version of content', async function (assert) {
await runSharedTest(indexWriterTests, assert, {
indexWriter,
indexQueryEngine,
adapter,
});
});

test('can update an index entry', async function (assert) {
await runSharedTest(indexWriterTests, assert, {
indexWriter,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable camelcase */

exports.shorthands = undefined;

exports.up = (pgm) => {
pgm.addColumns('boxel_index', {
icon_html: 'varchar',
});
};

exports.down = (pgm) => {
pgm.dropColumns('boxel_index', ['icon_html']);
};
Loading

0 comments on commit 83e0cc5

Please sign in to comment.