Skip to content

Commit

Permalink
chore: minor refactors from QA
Browse files Browse the repository at this point in the history
  • Loading branch information
christjt committed Aug 14, 2023
1 parent 9b09131 commit c3f30df
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 43 deletions.
2 changes: 1 addition & 1 deletion react-components/src/hooks/useCalculateModelsStyling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ function getModelMappings(
(mapping) => mapping.modelId === model.modelId && mapping.revisionId === model.revisionId
)
.reduce(
// reduce is added to avoid duplication of a models that span several pages.
(acc, mapping) => {
// reduce is added to avoid duplicate models from several pages.
mergeMaps(acc.mappings, mapping.mappings);
return acc;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ function groupToModelRevision(
const edgesForModel = map.get(modelRevisionIdKey);
if (edgesForModel === undefined) {
map.set(modelRevisionIdKey, [edge]);
return map;
} else {
edgesForModel.push(edge);
}
edgesForModel.push(edge);

return map;
}, new Map<ModelRevisionId, Array<EdgeItem<InModel3dEdgeProperties>>>());
Expand Down
17 changes: 11 additions & 6 deletions react-components/src/utilities/FdmSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,24 @@ export class FdmSDK {

const edgeResult = result.data.items as Array<EdgeItem<Record<string, any>>>;

if (source !== undefined) {
hoistEdgeProperties();

return {
edges: result.data.items as Array<EdgeItem<PropertiesType>>,
nextCursor: result.data.nextCursor
};

function hoistEdgeProperties(): void {
if (source === undefined) {
return;
}
const propertyKey = `${source.externalId}/${source.version}`;
edgeResult.forEach((edge) => {
if (edge.properties[source.space][propertyKey] !== undefined) {
edge.properties = edge.properties[source.space][propertyKey];
}
});
}

return {
edges: result.data.items as Array<EdgeItem<PropertiesType>>,
nextCursor: result.data.nextCursor
};
}

public async filterAllInstances<PropertiesType = Record<string, any>>(
Expand Down
51 changes: 17 additions & 34 deletions react-components/stories/Reveal3DResources.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
*/
import type { Meta, StoryObj } from '@storybook/react';
import { Reveal3DResources, RevealContainer } from '../src';
import { Color } from 'three';
import { Color, Matrix4 } from 'three';
import { CameraController } from '../src/';
import { createSdkByUrlToken } from './utilities/createSdkByUrlToken';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';

const meta = {
title: 'Example/Reveal3DResources',
Expand All @@ -23,16 +22,21 @@ export const Main: Story = {
args: {
resources: [
{
modelId: 2231774635735416,
revisionId: 912809199849811,
styling: {
default: {
color: new Color('#efefef')
},
mapped: {
color: new Color('#c5cbff')
}
}
modelId: 1791160622840317,
revisionId: 498427137020189,
transform: new Matrix4().makeTranslation(40, 0, 0)
},
{
modelId: 1791160622840317,
revisionId: 498427137020189,
transform: new Matrix4().makeTranslation(40, 10, 0)
},
{
siteId: 'c_RC_2'
},
{
modelId: 3865289545346058,
revisionId: 4160448151596909
}
]
},
Expand All @@ -47,28 +51,7 @@ export const Main: Story = {
placement: 'topRight'
}
}}>
<ReactQueryDevtools />
<Reveal3DResources
resources={resources}
instanceStyling={[
{
fdmAssetExternalIds: [
{ space: 'pdms-mapping', externalId: 'EQ-l-2231774635735416-2232218418169407' },
{ space: 'pdms-mapping', externalId: 'EQ-l-2231774635735416-5658577936769408' },
{ space: 'pdms-mapping', externalId: 'EQ-l-2231774635735416-850382017588429' },
{ space: 'pdms-mapping', externalId: 'EQ-l-2231774635735416-3070761313703702' },
{ space: 'pdms-mapping', externalId: 'EQ-l-2231774635735416-3951638513367021' },
{ space: 'pdms-mapping', externalId: 'EQ-l-2231774635735416-7062796113231733' },
{ space: 'pdms-mapping', externalId: 'EQ-l-2231774635735416-2890847372912846' },
{ space: 'pdms-mapping', externalId: 'EQ-l-2231774635735416-329414570333157' },
{ space: 'pdms-mapping', externalId: 'EQ-l-2231774635735416-3629108135100276' },
{ space: 'pdms-mapping', externalId: 'EQ-l-2231774635735416-6317623811412748' },
{ space: 'pdms-mapping', externalId: 'EQ-l-2231774635735416-3132072649556228' }
],
style: { cad: { color: new Color('#ff0000') } }
}
]}
/>
<Reveal3DResources resources={resources} />
<CameraController
initialFitCamera={{
to: 'allModels'
Expand Down

0 comments on commit c3f30df

Please sign in to comment.