Skip to content

Commit 36653b3

Browse files
authored
publish entity updates (values only) (#286)
1 parent 57bc847 commit 36653b3

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

apps/connect/src/hooks/use-private-spaces.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export const usePrivateSpaces = (): UseQueryResult<PrivateSpaceData[], Error> =>
4545
...space,
4646
apps: Array.from(spaceAppIds).map((appId) => {
4747
return {
48-
// @ts-expect-error - need to improve appInfo typing
4948
name: appInfo[appId]?.name ?? 'Unknown',
5049
id: appId,
5150
};

packages/hypergraph-react/src/prepare-publish.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ query entityToPublish($entityId: String!, $spaceId: String!) {
2121
entity(id: $entityId, spaceId: $spaceId) {
2222
values {
2323
propertyId
24+
value
2425
}
2526
relations {
2627
id
@@ -33,6 +34,7 @@ type EntityToPublishQueryResult = {
3334
entity: {
3435
values: {
3536
propertyId: string;
37+
value: string;
3638
}[];
3739
relations: {
3840
id: string;
@@ -97,7 +99,34 @@ export const preparePublish = async <S extends Entity.AnyNoContext>({
9799
return { ops };
98100
}
99101

100-
// TODO: implement updating an existing entity
102+
if (data?.entity) {
103+
for (const [key, propertyId] of Object.entries(mappingEntry.properties || {})) {
104+
let serializedValue: string = entity[key];
105+
if (fields[key] === Type.Checkbox) {
106+
serializedValue = Graph.serializeCheckbox(entity[key]);
107+
} else if (fields[key] === Type.Date) {
108+
serializedValue = Graph.serializeDate(entity[key]);
109+
} else if (fields[key] === Type.Point) {
110+
serializedValue = Graph.serializePoint(entity[key]);
111+
} else if (fields[key] === Type.Number) {
112+
serializedValue = Graph.serializeNumber(entity[key]);
113+
}
114+
115+
const existingValue = data.entity.values.find((value) => value.propertyId === propertyId);
116+
117+
if (serializedValue !== existingValue?.value) {
118+
values.push({ property: propertyId, value: serializedValue });
119+
}
120+
}
121+
122+
// TODO: handle added or removed relations
123+
// TODO: handle updated relations
124+
// TODO: handle added or removed types
125+
if (values.length > 0) {
126+
const { ops: updateEntityOps } = Graph.updateEntity({ id: entity.id, values });
127+
ops.push(...updateEntityOps);
128+
}
129+
}
101130

102131
return { ops };
103132
};

0 commit comments

Comments
 (0)