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

Implement Solid stores #195

Merged
merged 32 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
10fb9f5
feat: created solid stores
lem-onade May 11, 2021
e7e9bf8
chore: added basic test data to pod
lem-onade May 11, 2021
0b385b9
chore: moved solid stores to manage
lem-onade May 11, 2021
f78d537
chore: fixed test data prefix
lem-onade May 11, 2021
6a02568
feat: basic implementation of solid sdk stores
lem-onade May 11, 2021
7a05829
chore: renamed test data files
lem-onade May 11, 2021
48f76d9
feat: implemented retrieval of collections and objects WIP
lem-onade May 11, 2021
c834fe6
feat: implemented deleting collections WIP
lem-onade May 12, 2021
0922a0a
fix: fixed broken delete WIP
lem-onade May 12, 2021
82d6394
feat: implemented saving WIP
lem-onade May 12, 2021
9203eef
feat: finished basic implementation of the solid collection store WIP
lem-onade May 12, 2021
89aeefd
test: added tests for collection solid store WIP
lem-onade May 14, 2021
b0aac7f
test: added tests for (object) solid store
lem-onade May 14, 2021
b9a8430
chore: fixed build errors
lem-onade May 14, 2021
7387db6
test: updated tests for object memory store
lem-onade May 14, 2021
b041d09
fix: saving/deleting collections now creates/deletes the object dump
lem-onade May 14, 2021
4117d7e
chore: fixed build errors
lem-onade May 14, 2021
d89cfa4
test: fixed test issues
lem-onade May 14, 2021
d073798
chore: apply suggestions from code review
lem-onade May 14, 2021
2ce142a
chore: merge branch 'develop' into feat/implement-solid-store
wouteraj May 17, 2021
8d81edd
Merge remote-tracking branch 'origin/develop' into feat/implement-sol…
lem-onade May 17, 2021
c23e1fe
fix: check if a collection is selected before highlighting
wouteraj May 17, 2021
72fc648
Merge branch 'feat/implement-solid-store' of github.com:digita-ai/nde…
wouteraj May 17, 2021
20ea9ae
fix: sidebar selection not updated correctly
lem-onade May 17, 2021
bbe1ce2
test: enabled skipped tests
lem-onade May 17, 2021
81da39a
chore: updated coverage
wouteraj May 17, 2021
16ad313
feat: create initial type registration when not set
lem-onade May 17, 2021
7dae207
Merge branch 'develop' into feat/implement-solid-store
lem-onade May 17, 2021
bbb65ae
chore: merge develop
wouteraj May 17, 2021
0e0c24f
chore: merge develop
wouteraj May 17, 2021
60f3e96
fix: fix profile test data
wouteraj May 17, 2021
df5e7e1
fix: fixed save name updates
lem-onade May 17, 2021
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
4 changes: 2 additions & 2 deletions packages/nde-erfgoed-client/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { login, handleIncomingRedirect, logout } from '@inrupt/solid-client-authn-browser';
export { getSolidDataset, getThing, getStringNoLocale, getUrl } from '@inrupt/solid-client';
export { login, handleIncomingRedirect, logout, fetch, getDefaultSession } from '@inrupt/solid-client-authn-browser';
export { getSolidDataset, getThing, getStringNoLocale, getStringNoLocaleAll, getUrl, getStringByLocaleAll, getStringWithLocale, getStringWithLocaleAll, getThingAll, getUrlAll, removeAll, removeThing, saveSolidDatasetAt, setThing, removeUrl, Thing, addStringWithLocale, addStringNoLocale, addUrl, addDatetime, getDatetime, createThing, asUrl, overwriteFile, deleteFile, ThingPersisted } from '@inrupt/solid-client';
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ export class ObjectCardComponent extends LitElement {
<nde-card>
${this.object.image && this.object.image !== 'undefined' ? html`<img slot="image" src="${this.object.image}" alt="card image"/>` : html`<div slot="image">${unsafeSVG(Picture)}</div>`}
<span slot='title'>
${this.object.name ?? this.translator.translate('nde.features.collections.card.name-unavailable')}
${this.object.name ?? this.translator?.translate('nde.features.collections.card.name-unavailable')}
</span>
<span slot='subtitle'>
<span class='subject'>
${this.object.subject ?? this.translator.translate('nde.features.collections.card.subject-unavailable')}
${this.object.subject ?? this.translator?.translate('nde.features.collections.card.subject-unavailable')}
</span>
<span class='time-ago'>
${this.object.updated ? ` - ${timeAgo}` : ''}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class DemoFormComponent extends RxLitElement {
* The actor controlling this component.
*/
@property({ type: Object })
public actor: Interpreter<FormContext<Collection>>;
public actor: Interpreter<FormContext<Partial<Collection>>>;

/**
* Enables or disables the submit button.
Expand All @@ -79,7 +79,7 @@ export class DemoFormComponent extends RxLitElement {
super();

this.actor = interpret(
formMachine<Collection>(validator, submitter).withContext({
formMachine<Partial<Collection>>(validator, submitter).withContext({
data: { uri: '', name: 'Test', description: 'Test desc' },
original: { uri: '', name: 'Test', description: 'Test desc' },
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export class SidebarListItemComponent extends RxLitElement {
}

.actions {
margin-right: var(--gap-small);
display: flex;
flex-direction: row;
gap: var(--gap-normal);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ArgumentError } from '../errors/argument-error';
import { Collection } from './collection';
import { CollectionObject } from './collection-object';
import { CollectionObjectMemoryStore } from './collection-object-memory-store';

Expand All @@ -8,7 +9,8 @@ describe('CollectionObjectMemoryStore', () => {
uri: 'collection-uri-1',
name: 'Collection 1',
description: 'This is collection 1',
};
objectsUri: 'objects-uri',
} as Collection;

const resources: CollectionObject[] = [
{
Expand Down Expand Up @@ -109,4 +111,20 @@ describe('CollectionObjectMemoryStore', () => {

});

describe('getObject()', () => {

it('should throw error when collection is undefined', async () => {

await expect(service.getObject(undefined)).rejects.toThrow(ArgumentError);

});

it('should return object with matching uri', async () => {

await expect(service.getObject(resources[0].uri)).resolves.toEqual(resources[0]);

});

});

});
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ export class CollectionObjectMemoryStore extends MemoryStore<CollectionObject> i

}

/**
* Retrieves a single CollectionObject
*
* @param uri The URI of the CollectionObject
*/
async getObject(uri: string): Promise<CollectionObject> {

if (!uri) {

throw new ArgumentError('Argument uri should be set.', uri);

}

return this.resources.find((resource) => resource.uri === uri);

}

/**
* Retrieves all objects for a specific collection.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ export interface CollectionObjectStore extends Store<CollectionObject> {
* @param collection The collection for which to retrieve objects.
*/
getObjectsForCollection(collection: Collection): Promise<CollectionObject[]>;

/**
* Retrieves a single CollectionObject
*
* @param uri The URI of the CollectionObject
*/
getObject(uri: string): Promise<CollectionObject>;
}
15 changes: 15 additions & 0 deletions packages/nde-erfgoed-core/lib/collections/collection-store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Store } from '../stores/store';
import { Collection } from './collection';

/**
* A store for collections.
*/
export interface CollectionStore extends Store<Collection> {

/**
* Retrieves a single collection
*
* @param uri The URI of the collection.
*/
getCollection(uri: string): Promise<Collection>;
}
10 changes: 10 additions & 0 deletions packages/nde-erfgoed-core/lib/collections/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,14 @@ export interface Collection extends Resource {
* The description of the collection.
*/
description: string;

/**
* The URI of this collection's objects
*/
objectsUri: string;

/**
* The distribution URI of this collection
*/
distribution: string;
}
1 change: 1 addition & 0 deletions packages/nde-erfgoed-core/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Exports the modules of the package.
*/
export * from './collections/collection';
export * from './collections/collection-store';
export * from './collections/collection-object';
export * from './collections/collection-object-memory-store';
export * from './collections/collection-object-store';
Expand Down
8 changes: 8 additions & 0 deletions packages/nde-erfgoed-core/lib/stores/memory-store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,32 @@ describe('MemoryStore', () => {
uri: 'collection-uri-1',
name: 'Collection 1',
description: 'This is collection 1',
objectsUri: 'objects-uri',
distribution: 'distribution-uri',
};

const collection2: Collection = {
uri: 'collection-uri-2',
name: 'Collection 2',
description: 'This is collection 2',
objectsUri: 'objects-uri',
distribution: 'distribution-uri',
};

const collection3: Collection = {
uri: 'collection-uri-3',
name: 'Collection 3',
description: 'This is collection 3',
objectsUri: 'objects-uri',
distribution: 'distribution-uri',
};

const collection2Updated: Collection = {
uri: 'collection-uri-2',
name: 'Collection 2',
description: 'This is collection 2 with update',
objectsUri: 'objects-uri',
distribution: 'distribution-uri',
};

const resources: Collection[] = [ collection1, collection2 ];
Expand Down
6 changes: 6 additions & 0 deletions packages/nde-erfgoed-manage/lib/app-root.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ describe('AppRootComponent', () => {
uri: 'collection-uri-3',
name: 'Collection 3',
description: 'This is collection 3',
objectsUri: 'test-uri',
distribution: 'test-uri',
};

beforeEach(() => {
Expand All @@ -27,11 +29,15 @@ describe('AppRootComponent', () => {
uri: 'collection-uri-1',
name: 'Collection 1',
description: 'This is collection 1',
objectsUri: 'test-uri',
distribution: 'test-uri',
},
{
uri: 'collection-uri-2',
name: 'Collection 2',
description: 'This is collection 2',
objectsUri: 'test-uri',
distribution: 'test-uri',
},
]),
new CollectionObjectMemoryStore([
Expand Down
66 changes: 9 additions & 57 deletions packages/nde-erfgoed-manage/lib/app-root.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { html, property, PropertyValues, internalProperty, unsafeCSS, css, CSSResult, TemplateResult } from 'lit-element';
import { interpret, State } from 'xstate';
import { from } from 'rxjs';
import { filter, map } from 'rxjs/operators';
import { ArgumentError, Collection, ConsoleLogger, Logger, LoggerLevel, MemoryTranslator, Translator, CollectionObjectMemoryStore, MemoryStore } from '@digita-ai/nde-erfgoed-core';
import { map } from 'rxjs/operators';
import { ArgumentError, Collection, ConsoleLogger, Logger, LoggerLevel, MemoryTranslator, Translator } from '@digita-ai/nde-erfgoed-core';
import { Alert } from '@digita-ai/nde-erfgoed-components';
import { RxLitElement } from 'rx-lit';
import { Theme, Logout, Logo, Plus } from '@digita-ai/nde-erfgoed-theme';
Expand All @@ -11,8 +11,10 @@ import { AppActors, AppAuthenticateStates, AppContext, AppFeatureStates, appMach
import nlNL from './i8n/nl-NL.json';
import { AppEvents } from './app.events';
import { SolidSDKService } from './common/solid/solid-sdk.service';
import { CollectionEvents, SelectedCollectionEvent } from './features/collection/collection.events';
import { CollectionEvents } from './features/collection/collection.events';
import { SolidProfile } from './common/solid/solid-profile';
import { CollectionSolidStore } from './common/solid/collection-solid-store';
import { CollectionObjectSolidStore } from './common/solid/collection-object-solid-store';

/**
* The root page of the application.
Expand Down Expand Up @@ -51,64 +53,14 @@ export class AppRootComponent extends RxLitElement {
actor = interpret(
(appMachine(
new SolidSDKService(this.logger),
new MemoryStore<Collection>([
{
uri: 'collection-uri-1',
name: 'Collection 1',
description: 'This is collection 1',
},
{
uri: 'collection-uri-2',
name: 'Collection 2',
description: 'This is collection 2',
},
]),
new CollectionObjectMemoryStore([
{
uri: 'object-uri-1',
name: 'Object 1',
description: 'This is object 1',
image: 'https://images.unsplash.com/photo-1615390164801-cf2e70f32b53?ixid=MnwxMjA3fDB8MHxwcm9maWxlLXBhZ2V8M3x8fGVufDB8fHx8&ixlib=rb-1.2.1&w=1000&q=80',
subject: null,
type: null,
updated: 0,
collection: 'collection-uri-1',
},
{
uri: 'object-uri-2',
name: 'Object 2',
description: 'This is object 2',
image: 'https://images.unsplash.com/photo-1615390164801-cf2e70f32b53?ixid=MnwxMjA3fDB8MHxwcm9maWxlLXBhZ2V8M3x8fGVufDB8fHx8&ixlib=rb-1.2.1&w=1000&q=80',
subject: null,
type: null,
updated: 0,
collection: 'collection-uri-1',
},
{
uri: 'object-uri-3',
name: 'Object 3',
description: 'This is object 3',
image: 'https://images.unsplash.com/photo-1615390164801-cf2e70f32b53?ixid=MnwxMjA3fDB8MHxwcm9maWxlLXBhZ2V8M3x8fGVufDB8fHx8&ixlib=rb-1.2.1&w=1000&q=80',
subject: null,
type: null,
updated: 0,
collection: 'collection-uri-1',
},
{
uri: 'object-uri-4',
name: 'Object 4',
description: 'This is object 4',
image: 'https://images.unsplash.com/photo-1615390164801-cf2e70f32b53?ixid=MnwxMjA3fDB8MHxwcm9maWxlLXBhZ2V8M3x8fGVufDB8fHx8&ixlib=rb-1.2.1&w=1000&q=80',
subject: null,
type: null,
updated: 0,
collection: 'collection-uri-1',
},
]),
new CollectionSolidStore(),
new CollectionObjectSolidStore(),
{
uri: null,
name: this.translator.translate('nde.features.collections.new-collection-name'),
description: this.translator.translate('nde.features.collections.new-collection-description'),
objectsUri: undefined,
distribution: undefined,
},
)).withContext({
alerts: [],
Expand Down
18 changes: 13 additions & 5 deletions packages/nde-erfgoed-manage/lib/app.machine.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Alert, State } from '@digita-ai/nde-erfgoed-components';
import { Collection, CollectionObjectStore, Store } from '@digita-ai/nde-erfgoed-core';
import { Collection, CollectionObjectStore, CollectionStore } from '@digita-ai/nde-erfgoed-core';
import { createMachine, forwardTo } from 'xstate';
import { assign, log, send } from 'xstate/lib/actions';
import { addAlert, addCollection, AppEvent, AppEvents, dismissAlert, removeSession, setCollections, setProfile, setSession } from './app.events';
Expand Down Expand Up @@ -94,7 +94,7 @@ export type AppStates = AppRootStates | AppFeatureStates | AppAuthenticateStates
*/
export const appMachine = (
solid: SolidService,
collectionStore: Store<Collection>,
collectionStore: CollectionStore,
objectStore: CollectionObjectStore,
template: Collection,
) =>
Expand All @@ -105,7 +105,7 @@ export const appMachine = (
[CollectionEvents.SELECTED_COLLECTION]: {
actions:
[
(context, event) => forwardTo(AppActors.COLLECTION_MACHINE),
forwardTo(AppActors.COLLECTION_MACHINE),
assign({ selected: (context, event) => event.collection }),
],
},
Expand Down Expand Up @@ -146,7 +146,6 @@ export const appMachine = (
{
id: AppActors.COLLECTION_MACHINE,
src: collectionMachine(collectionStore, objectStore),
autoForward: true,
onError: {
actions: send({ type: AppEvents.ERROR }),
},
Expand Down Expand Up @@ -263,7 +262,8 @@ export const appMachine = (
setCollections,
send((context, event) => ({
type: CollectionEvents.SELECTED_COLLECTION,
collection: context.selected ? context.selected : event.data[0],
collection: event.data.find((collection: Collection) =>
context.selected?.uri === collection.uri) ?? event.data[0],
})),
],
cond: (context, event) => event.data.length > 0,
Expand All @@ -272,6 +272,9 @@ export const appMachine = (
target: AppDataStates.CREATING,
},
],
onError: {
actions: send((context, event) => ({ type: AppEvents.ERROR, data: event.data })),
},
},
},
/**
Expand All @@ -290,6 +293,11 @@ export const appMachine = (
send((context, event) => ({ type: CollectionEvents.SELECTED_COLLECTION, collection: event.data })),
],
},
onError: {
actions: [
send((context, event) => ({ type: AppEvents.ERROR, data: event.data })),
],
},
},
},
},
Expand Down
Loading