Skip to content

Commit

Permalink
Merge pull request #1579 from cardstack/cs-7173-add-sorting-by-create…
Browse files Browse the repository at this point in the history
…d_at-to-cards-grid

Add sorting by "created at" to workspace cards
  • Loading branch information
jurgenwerk committed Sep 18, 2024
2 parents 575d1d1 + b33f46d commit 68e5b3e
Show file tree
Hide file tree
Showing 20 changed files with 302 additions and 5 deletions.
9 changes: 9 additions & 0 deletions packages/base/cards-grid.gts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ let availableSortOptions: SortOption[] = [
},
],
},
{
displayName: 'Created at',
sort: [
{
by: 'createdAt',
direction: 'desc',
},
],
},
];

class Isolated extends Component<typeof CardsGrid> {
Expand Down
8 changes: 7 additions & 1 deletion packages/host/app/lib/current-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export class CurrentRun {
error.deps = [url.href];
throw error;
}
let { content, lastModified } = fileRef;
let { content, lastModified, created } = fileRef;
if (hasExecutableExtension(url.href)) {
await this.indexModule(url, fileRef);
} else {
Expand Down Expand Up @@ -327,6 +327,7 @@ export class CurrentRun {
path: localPath,
source: content,
lastModified,
resourceCreatedAt: created,
resource,
identityContext,
});
Expand Down Expand Up @@ -377,6 +378,7 @@ export class CurrentRun {
type: 'module',
source: ref.content,
lastModified: ref.lastModified,
resourceCreatedAt: ref.created,
deps: new Set(deps),
});
this.stats.modulesIndexed++;
Expand All @@ -386,12 +388,14 @@ export class CurrentRun {
path,
source,
lastModified,
resourceCreatedAt,
resource,
identityContext,
}: {
path: LocalPath;
source: string;
lastModified: number;
resourceCreatedAt: number;
resource: LooseCardResource;
identityContext: IdentityContextType;
}): Promise<void> {
Expand Down Expand Up @@ -485,6 +489,7 @@ export class CurrentRun {
id: instanceURL.href,
meta: {
lastModified,
resourceCreatedAt,
realmInfo: this.#realmInfo,
realmURL: this.realmURL.href,
},
Expand Down Expand Up @@ -538,6 +543,7 @@ export class CurrentRun {
embeddedHtml,
fittedHtml,
lastModified,
resourceCreatedAt,
types: typesMaybeError.types.map(({ refURL }) => refURL),
displayNames: typesMaybeError.types.map(
({ displayName }) => displayName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
atom_html TEXT,
fitted_html BLOB,
display_names BLOB,
resource_created_at,
PRIMARY KEY ( url, realm_version, realm_url, type )
);

Expand Down
1 change: 1 addition & 0 deletions packages/host/tests/acceptance/code-submode/editor-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ module('Acceptance | code submode | editor tests', function (hooks) {
delete json.data.meta.realmInfo;
delete json.data.meta.realmURL;
delete json.data.meta.lastModified;
delete json.data.meta.resourceCreatedAt;
assert.strictEqual(
stringify(json),
stringify(expected),
Expand Down
10 changes: 10 additions & 0 deletions packages/host/tests/helpers/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ let shimmedModuleIndicator = '// this file is shimmed';
export class TestRealmAdapter implements RealmAdapter {
#files: Dir = { kind: 'directory', contents: {} };
#lastModified: Map<string, number> = new Map();
#resourceCreatedAt: Map<string, number> = new Map();
#paths: RealmPaths;
#subscriber: ((message: UpdateEventData) => void) | undefined;
#loader: Loader | undefined; // Will be set in the realm's constructor - needed for openFile for shimming purposes
Expand All @@ -65,6 +66,7 @@ export class TestRealmAdapter implements RealmAdapter {
}
let url = this.#paths.fileURL(path);
this.#lastModified.set(url.href, now);
this.#resourceCreatedAt.set(url.href, now);
dir.contents[last] = { kind: 'file', content };
if (typeof content === 'object') {
this.#potentialModulesAndInstances.push({ content, url });
Expand Down Expand Up @@ -142,6 +144,10 @@ export class TestRealmAdapter implements RealmAdapter {
return this.#lastModified;
}

get resourceCreatedAtMap() {
return this.#resourceCreatedAt;
}

async lastModified(path: string): Promise<number | undefined> {
return this.#lastModified.get(this.#paths.fileURL(path).href);
}
Expand Down Expand Up @@ -243,6 +249,7 @@ export class TestRealmAdapter implements RealmAdapter {
path,
content: fileRefContent,
lastModified: this.#lastModified.get(this.#paths.fileURL(path).href)!,
created: this.#resourceCreatedAt.get(this.#paths.fileURL(path).href)!,
};

if (fileRefContent === shimmedModuleIndicator) {
Expand Down Expand Up @@ -278,6 +285,9 @@ export class TestRealmAdapter implements RealmAdapter {
};
let lastModified = unixTime(Date.now());
this.#lastModified.set(this.#paths.fileURL(path).href, lastModified);
if (type === 'added') {
this.#resourceCreatedAt.set(this.#paths.fileURL(path).href, lastModified);
}

this.postUpdateEvent({ [type]: path } as
| { added: string }
Expand Down
Loading

0 comments on commit 68e5b3e

Please sign in to comment.