Skip to content

Commit b06abb8

Browse files
committed
#711 #593 Default to ULID for subjects
1 parent 2223aba commit b06abb8

File tree

16 files changed

+59
-71
lines changed

16 files changed

+59
-71
lines changed

browser/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ This changelog covers all five packages, as they are (for now) updated as a whol
2626
- Added `collection.totalPages`.
2727
- BREAKING CHANGE: Renamed `resource.getCommitsCollection` to `resource.getCommitsCollectionSubject`.
2828
- BREAKING CHANGE: `resource.getChildrenCollection()` now returns a `Promise<Collection>` instead of a subject.
29+
- BREAKING CHANGE: `resource.createSubject()` no longer accepts a class name as an argument and defaults to a fully random subject.
2930
- BREAKING CHANGE: Resource now keeps a reference to store internally, therefore all methods that required you to pass a store have been changed to not require a store.
3031
These methods are:
3132
- `resource.canWrite()`

browser/data-browser/src/components/InviteForm.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interface InviteFormProps {
2626
*/
2727
export function InviteForm({ target }: InviteFormProps) {
2828
const store = useStore();
29-
const [subject] = useState(() => store.createSubject('invite'));
29+
const [subject] = useState(() => store.createSubject());
3030
const invite = useResource(subject, {
3131
newResource: true,
3232
});
@@ -59,7 +59,7 @@ export function InviteForm({ target }: InviteFormProps) {
5959
return (
6060
<Card>
6161
<ResourceField
62-
label={'Give edit rights'}
62+
label={'Allow edits'}
6363
propertyURL={server.properties.write}
6464
resource={invite}
6565
/>
@@ -69,11 +69,11 @@ export function InviteForm({ target }: InviteFormProps) {
6969
resource={invite}
7070
/>
7171
<ResourceField
72-
label={'How many times this link can be used. No value = no limit.'}
72+
label={'Limit Usages (optional)'}
7373
propertyURL={server.properties.usagesLeft}
7474
resource={invite}
7575
/>
76-
<Button onClick={createInvite}>Create Invite</Button>
76+
<Button onClick={createInvite}>Create</Button>
7777
{err && (
7878
<p>
7979
<ErrorLook>{err.message}</ErrorLook>
@@ -84,7 +84,7 @@ export function InviteForm({ target }: InviteFormProps) {
8484
} else
8585
return (
8686
<Card>
87-
<p>Invite created and copied to clipboard! Send it to your buddy:</p>
87+
<p>Invite created and copied to clipboard! 🚀</p>
8888
<CodeBlock content={invite.subject} data-test='invite-code' />
8989
</Card>
9090
);

browser/data-browser/src/components/forms/NewForm/CustomCreateActions/CustomForms/NewTableDialog.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export const NewTableDialog: FC<NewTableDialogProps> = ({
4949

5050
if (!useExistingClass) {
5151
const instanceResource = await store.newResource({
52-
subject: store.createSubject('class'),
5352
isA: core.classes.class,
5453
propVals: {
5554
[core.properties.shortname]: stringToSlug(name),

browser/data-browser/src/components/forms/NewForm/NewFormDialog.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Core, JSONValue, useResource, useStore, useTitle } from '@tomic/react';
1+
import { Core, JSONValue, useResource, useStore } from '@tomic/react';
22
import { useState, useCallback } from 'react';
33
import { useEffectOnce } from '../../../hooks/useEffectOnce';
44
import { Button } from '../../Button';
@@ -11,7 +11,6 @@ import { NewFormProps } from './NewFormPage';
1111
import { NewFormTitle, NewFormTitleVariant } from './NewFormTitle';
1212
import { SubjectField } from './SubjectField';
1313
import { useNewForm } from './useNewForm';
14-
import { getNamePartFromProps } from '../../../helpers/getNamePartFromProps';
1514

1615
export interface NewFormDialogProps extends NewFormProps {
1716
closeDialog: (success?: boolean) => void;
@@ -29,7 +28,6 @@ export const NewFormDialog = ({
2928
parent,
3029
}: NewFormDialogProps): JSX.Element => {
3130
const klass = useResource<Core.Class>(classSubject);
32-
const [className] = useTitle(klass);
3331
const store = useStore();
3432

3533
const [subject, setSubject] = useState<string>();
@@ -49,14 +47,7 @@ export const NewFormDialog = ({
4947
// Onmount we generate a new subject based on the classtype and the user input.
5048
useEffectOnce(() => {
5149
(async () => {
52-
const namePart = getNamePartFromProps(initialProps ?? {});
53-
54-
const uniqueSubject = await store.buildUniqueSubjectFromParts(
55-
[className, namePart],
56-
parent,
57-
);
58-
59-
await setSubjectValue(uniqueSubject);
50+
await setSubjectValue(store.createSubject());
6051

6152
for (const [prop, value] of Object.entries(initialProps ?? {})) {
6253
await resource.set(prop, value);

browser/data-browser/src/components/forms/NewForm/useNewForm.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const useNewForm = (args: UseNewForm) => {
2727

2828
const [subjectValue, setSubjectValueInternal] = useState<string>(() => {
2929
if (initialSubject === undefined) {
30-
return store.createSubject(klass.props.shortname);
30+
return store.createSubject();
3131
}
3232

3333
return initialSubject;
@@ -46,7 +46,7 @@ export const useNewForm = (args: UseNewForm) => {
4646
}
4747

4848
if (isAVal.length === 0) {
49-
await resource.addClasses(klass.getSubject());
49+
await resource.addClasses(klass.subject);
5050
}
5151

5252
setInitialized(true);

browser/data-browser/src/components/forms/NewForm/useNewResourceUI.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Core, Store, useStore } from '@tomic/react';
1+
import { Store, useStore } from '@tomic/react';
22
import {
33
FC,
44
PropsWithChildren,
@@ -107,10 +107,7 @@ export function NewResourceUIProvider({ children }: PropsWithChildren) {
107107
}
108108

109109
// Default behaviour. Navigate to a new resource form for the given class.
110-
const classResource = await store.getResource<Core.Class>(isA);
111-
navigate(
112-
newURL(isA, parent, store.createSubject(classResource.props.shortname)),
113-
);
110+
navigate(newURL(isA, parent, store.createSubject()));
114111
}, []);
115112

116113
const context = useMemo(

browser/data-browser/src/components/forms/ResourceField.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ function ResourceField({
4545
}
4646

4747
const label =
48-
labelProp || property.error
49-
? generateErrorPropName(property)
50-
: property.shortname;
48+
labelProp ??
49+
(property.error ? generateErrorPropName(property) : property.shortname);
5150

5251
if (property.isDynamic) {
5352
return (

browser/data-browser/src/helpers/getNamePartFromProps.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

browser/data-browser/src/hooks/useCreateAndNavigate.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { useCallback } from 'react';
33
import toast from 'react-hot-toast';
44
import { useNavigate } from 'react-router-dom';
55
import { constructOpenURL } from '../helpers/navigation';
6-
import { getNamePartFromProps } from '../helpers/getNamePartFromProps';
76

87
export type CreateAndNavigate = (
98
isA: string,
@@ -34,14 +33,7 @@ export function useCreateAndNavigate(): CreateAndNavigate {
3433
): Promise<Resource> => {
3534
const classResource = await store.getResource<Core.Class>(isA);
3635

37-
const namePart = getNamePartFromProps(propVals);
38-
const newSubject = await store.buildUniqueSubjectFromParts(
39-
[classResource.props.shortname, namePart],
40-
parent,
41-
);
42-
4336
const resource = await store.newResource({
44-
subject: newSubject,
4537
isA,
4638
parent,
4739
propVals,
@@ -54,7 +46,7 @@ export function useCreateAndNavigate(): CreateAndNavigate {
5446
await onCreated(resource);
5547
}
5648

57-
navigate(constructOpenURL(newSubject, extraParams));
49+
navigate(constructOpenURL(resource.subject, extraParams));
5850
toast.success(`${classResource.title} created`);
5951
store.notifyResourceManuallyCreated(resource);
6052
} catch (e) {

browser/data-browser/src/routes/ShareRoute.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { useNavigate } from 'react-router-dom';
1515
import { ErrorLook } from '../components/ErrorLook';
1616
import { Column } from '../components/Row';
1717
import { Main } from '../components/Main';
18+
import { FaShare } from 'react-icons/fa6';
1819

1920
/** Form for managing and viewing rights for this resource */
2021
export function ShareRoute(): JSX.Element {
@@ -138,13 +139,14 @@ export function ShareRoute(): JSX.Element {
138139
{canWrite && !showInviteForm && (
139140
<span>
140141
<Button onClick={() => setShowInviteForm(true)}>
141-
Send Invite...
142+
<FaShare />
143+
Create Invite
142144
</Button>
143145
</span>
144146
)}
145147
{showInviteForm && <InviteForm target={resource} />}
146148
<Card>
147-
<RightsHeader text='rights set here:' />
149+
<RightsHeader text='Rights set here:' />
148150
<CardInsideFull>
149151
{/* This key might be a bit too much, but the component wasn't properly re-rendering before */}
150152
{constructAgentProps().map(right => (
@@ -171,7 +173,7 @@ export function ShareRoute(): JSX.Element {
171173
{err && <ErrorLook>{err.message}</ErrorLook>}
172174
{inheritedRights.length > 0 && (
173175
<Card>
174-
<RightsHeader text='inherited rights:' />
176+
<RightsHeader text='Inherited rights:' />
175177
<CardInsideFull>
176178
{inheritedRights.map(right => (
177179
<AgentRights

0 commit comments

Comments
 (0)