Skip to content

Commit b6d68fd

Browse files
committed
New subjects have nested paths by default #319
1 parent ffa4c6b commit b6d68fd

File tree

6 files changed

+16
-4
lines changed

6 files changed

+16
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ This changelog covers all three packages, as they are (for now) updated as a who
77
### Atomic Browser
88

99
- Improve performance collapsed sidebar items.
10+
- Add article view #319
11+
- New subjects have nested paths by default
1012

1113
### @tomic/lib
1214

1315
- Add `store.getResourceAncestry` method, which returns the ancestry of a resource, including the resource itself.
1416
- Add `resource.title` property, which returns the name of a resource, or the first property that is can be used to name the resource.
17+
- `store.createSubject` now accepts a `parent` argument, which allows creating nested subjects.
1518

1619
#### Breaking changes
1720

data-browser/src/components/NewInstanceButton/useCreateAndNavigate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function useCreateAndNavigate(klass: string, parent?: string) {
3434
/** Do not set a parent for the new resource. Useful for top-level resources */
3535
noParent?: boolean,
3636
): Promise<Resource> => {
37-
const subject = store.createSubject(className);
37+
const subject = store.createSubject(className, parent);
3838
const resource = new Resource(subject, true);
3939

4040
await Promise.all([

data-browser/src/views/Article/ArticlePage.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import styled from 'styled-components';
1010
import { CommitDetail } from '../../components/CommitDetail';
1111
import { ContainerWide } from '../../components/Containers';
1212
import { EditableTitle } from '../../components/EditableTitle';
13+
import UploadForm from '../../components/forms/UploadForm';
1314
import { NewCard } from '../../components/NewCard';
1415
import { useCreateAndNavigate } from '../../components/NewInstanceButton';
1516
import { Column } from '../../components/Row';
@@ -49,6 +50,7 @@ export function ArticlePage({ resource }: ResourcePageProps): JSX.Element {
4950
<CommitDetail commitSubject={lastCommit} />
5051
</HeadingWrapper>
5152
<ArticleDescription resource={resource} canEdit={canEdit} />
53+
<UploadForm parentResource={resource} />
5254
</Column>
5355
</Content>
5456
</ArticleContainer>

data-browser/src/views/ChatRoomPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export function ChatRoomPage({ resource }: ResourcePageProps) {
7474
e && e.preventDefault();
7575

7676
if (!disableSend) {
77-
const subject = store.createSubject('messages');
77+
const subject = store.createSubject('messages', resource.getSubject());
7878
const msgResource = new Resource(subject, true);
7979
await msgResource.set(
8080
properties.parent,

data-browser/src/views/DocumentPage.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ function DocumentPageEdit({
187187
async function addElement(position: number) {
188188
// When an element is created, it should be a Resource that has this document as its parent.
189189
// or maybe a nested resource?
190-
const elementSubject = store.createSubject('element');
190+
const elementSubject = store.createSubject(
191+
'element',
192+
resource.getSubject(),
193+
);
191194
elements.splice(position, 0, elementSubject);
192195

193196
try {

lib/src/store.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,14 @@ export class Store {
176176
}
177177

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

183+
if (parentSubject) {
184+
return `${parentSubject}/${className}/${random}`;
185+
}
186+
183187
return `${this.getServerUrl()}/${className}/${random}`;
184188
}
185189

0 commit comments

Comments
 (0)