Skip to content

Commit

Permalink
Merge pull request #5056 from systeminit/jobelenus/unify-component-up…
Browse files Browse the repository at this point in the history
…dated-view-operation

Unify view logic in one place
  • Loading branch information
jobelenus authored Dec 3, 2024
2 parents 704eb9c + e8844d3 commit ba8abd0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 54 deletions.
33 changes: 0 additions & 33 deletions app/web/src/store/components.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import { useAssetStore } from "./asset.store";
import { useRealtimeStore } from "./realtime/realtime.store";
import { useWorkspacesStore } from "./workspaces.store";
import { useFeatureFlagsStore } from "./feature_flags.store";
import { useViewsStore } from "./views.store";

export type ComponentNodeId = string;

Expand Down Expand Up @@ -1253,38 +1252,6 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => {
this.processAndStoreRawComponent(componentId);
if (oldParent && !data.component.parentId)
this.processAndStoreRawComponent(oldParent);

// Updates without geometry may still change component type
// So we need to coerce the geometry to the correct array in the views store
if (!data.component.viewData) {
const viewsStore = useViewsStore();

for (const view of _.values(viewsStore.viewsById)) {
const groupGeo = view.groups[componentId];
const componentGeo = view.components[componentId];

const geo = groupGeo ?? componentGeo;
if (!geo) continue;

delete view.groups[componentId];
delete view.components[componentId];

if (
data.component.componentType === ComponentType.Component
) {
const node = processRawComponent(
data.component,
this.rawComponentsById,
) as DiagramNodeData;
geo.height = node.height;
geo.width = node.width;

view.components[componentId] = geo;
} else {
view.groups[componentId] = geo;
}
}
}
},
},
{
Expand Down
52 changes: 31 additions & 21 deletions app/web/src/store/views.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1622,28 +1622,38 @@ export const useViewsStore = (forceChangeSetId?: ChangeSetId) => {
// don't update
if (metadata.change_set_id !== changeSetId) return;
const { viewId, geometry } = { ...data.component.viewData };
if (!viewId || !geometry)
// this is expected in many situations
return; // but will be populated on changing componentType

const view = this.viewsById[viewId];
if (!view) return; // FIXME later when we have full WsEvents

delete view.components[data.component.id];
delete view.groups[data.component.id];
if (data.component.componentType === ComponentType.Component) {
const node = processRawComponent(
data.component,
componentsStore.rawComponentsById,
) as DiagramNodeData;
geometry.height = node.height;
geometry.width = node.width;
view.components[data.component.id] = geometry as IRect;
} else {
if (!geometry.width) geometry.width = 500;
if (!geometry.height) geometry.height = 500;
view.groups[data.component.id] = geometry as IRect;
}
// changed component type means book-keeping for all views
// PSA: currently SDF does not change any geometry when you change component types
// if it starts to change geometry, it must return new geometry for every view
// the structure doesn't currently support that
Object.values(this.viewsById).forEach((view) => {
const groupGeo = view.groups[data.component.id];
const componentGeo = view.components[data.component.id];
const _geo = groupGeo ?? componentGeo;
// i don't exist in this view, and i am not being added to this view
if (!_geo && !viewId) return;
const finalGeo = geometry ?? _geo;
if (!finalGeo) return;

delete view.components[data.component.id];
delete view.groups[data.component.id];
if (
data.component.componentType === ComponentType.Component
) {
const node = processRawComponent(
data.component,
componentsStore.rawComponentsById,
) as DiagramNodeData;
finalGeo.height = node.height;
finalGeo.width = node.width;
view.components[data.component.id] = geometry as IRect;
} else {
if (!finalGeo.width) finalGeo.width = 500;
if (!finalGeo.height) finalGeo.height = 500;
view.groups[data.component.id] = finalGeo as IRect;
}
});

if (this.selectedComponentId === data.component.id) {
if (data.component.changeStatus !== "deleted")
Expand Down
2 changes: 2 additions & 0 deletions lib/sdf-server/src/service/component/set_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ pub async fn set_type(

let component = Component::get_by_id(&ctx, component_id).await?;
let mut socket_map = HashMap::new();
// PSA: when we call `set_type_by_id` we are not altering any geometries (e.g. turning a small component into a default 500x500 sized frame)
// if we do alter those geometries, we need to send multiple geometries back over the wire (currently, we only support sending one)
let payload = component
.into_frontend_type(
&ctx,
Expand Down

0 comments on commit ba8abd0

Please sign in to comment.