Skip to content

Commit

Permalink
store.createSubject allows creating nested paths
Browse files Browse the repository at this point in the history
  • Loading branch information
joepio committed Feb 5, 2023
1 parent 6bbfbf3 commit 9c4584d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ This changelog covers all three packages, as they are (for now) updated as a who

## UNRELEASED

- Let users register using e-mail address, improve sign-up UX.
- Add `Store.parseMetaTags` to load JSON-AD objects stored in the DOM. Speeds up initial page load by allowing server to set JSON-AD objects in the initial HTML response.
- Move static assets around, align build with server and fix PWA #292
- Let users register using e-mail address, improve sign-up UX.
- `store.createSubject` allows creating nested paths

## v0.35.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function useCreateAndNavigate(klass: string, parent?: string) {
/** Do not set a parent for the new resource. Useful for top-level resources */
noParent?: boolean,
): Promise<Resource> => {
const subject = store.createSubject(className);
const subject = store.createSubject(className, parent);
const resource = new Resource(subject, true);

await Promise.all([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { useCallback } from 'react';
import { useNavigate } from 'react-router-dom';
import { useSettings } from '../../helpers/AppSettings';
import { handleError } from '../../helpers/loggingHandlers';
import { newURL } from '../../helpers/navigation';
import { useCreateAndNavigate } from './useCreateAndNavigate';

Expand Down Expand Up @@ -99,7 +100,7 @@ export function useDefaultNewInstanceHandler(klass: string, parent?: string) {
}
}
} catch (e) {
store.handleError(e);
store.notifyError(e);
}
}, [klass, store, parent, createResourceAndNavigate]);

Expand Down
2 changes: 1 addition & 1 deletion data-browser/src/views/ChatRoomPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function ChatRoomPage({ resource }: ResourcePageProps) {
e && e.preventDefault();

if (!disableSend) {
const subject = store.createSubject('messages');
const subject = store.createSubject('messages', resource.getSubject());
const msgResource = new Resource(subject, true);
await msgResource.set(
properties.parent,
Expand Down
5 changes: 4 additions & 1 deletion data-browser/src/views/DocumentPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ function DocumentPageEdit({
async function addElement(position: number) {
// When an element is created, it should be a Resource that has this document as its parent.
// or maybe a nested resource?
const elementSubject = store.createSubject('element');
const elementSubject = store.createSubject(
'element',
resource.getSubject(),
);
elements.splice(position, 0, elementSubject);

try {
Expand Down
6 changes: 5 additions & 1 deletion lib/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,14 @@ export class Store {
}

/** Creates a random URL. Add a classnme (e.g. 'persons') to make a nicer name */
public createSubject(className?: string): string {
public createSubject(className?: string, parentSubject?: string): string {
const random = this.randomPart();
className = className ? className : 'things';

if (parentSubject) {
return `${parentSubject}/${className}/${random}`;
}

return `${this.getServerUrl()}/${className}/${random}`;
}

Expand Down

0 comments on commit 9c4584d

Please sign in to comment.