Skip to content

Commit ebab5d2

Browse files
authored
Merge pull request #4658 from 3drepo/ISSUE_4642
ISSUE #4642 - Tickets supports transformations
2 parents bddf217 + cb396c7 commit ebab5d2

File tree

17 files changed

+139
-133
lines changed

17 files changed

+139
-133
lines changed

frontend/.storybook/preview.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { theme as V5Theme } from '@/v5/ui/themes/theme';
22
import { theme as V5ViewerTheme } from '@/v5/ui/routes/viewer/theme';
33
import { IntlProvider } from 'react-intl';
4-
import { getIntlProviderProps } from '@/v5/services/intl';
4+
import { getIntl } from '@/v5/services/intl';
55
import { GlobalStyle } from '@/v5/ui/themes/global';
66
import { ThemeProvider as MuiThemeProvider } from '@mui/material';
77
import { ThemeProvider, createGlobalStyle } from 'styled-components';
@@ -73,7 +73,7 @@ const withThemeProvider = (Story, context)=>{
7373
export const decorators = [
7474
withThemeProvider,
7575
(Story) => (
76-
<IntlProvider {...getIntlProviderProps()}>
76+
<IntlProvider {...getIntl()}>
7777
<Story />
7878
</IntlProvider>
7979
),

frontend/src/main.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { Root as V5Root } from '@/v5/ui/routes';
3030

3131
import { UnityUtil } from '@/globals/unity-util';
3232
import { clientConfigService } from '@/v4/services/clientConfig';
33-
import { formatMessage, getIntlProviderProps, initializeIntl } from '@/v5/services/intl';
33+
import { formatMessage, getIntl, initializeIntl } from '@/v5/services/intl';
3434
import { initializeActionsDispatchers } from '@/v5/helpers/actionsDistpatchers.helper';
3535
import { IntlProvider } from 'react-intl';
3636
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
@@ -68,7 +68,7 @@ const render = () => {
6868
ReactDOM.render(
6969
<Provider store={store as any}>
7070
<ConnectedRouter history={history as History}>
71-
<IntlProvider {...getIntlProviderProps()}>
71+
<IntlProvider {...getIntl()}>
7272
<LocalizationProvider dateAdapter={AdapterDayjs}>
7373
<Switch>
7474
<Route exact path="/">

frontend/src/v4/routes/viewerGui/viewerGui.component.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { Tickets } from '@/v5/ui/routes/viewer/tickets/tickets.component';
19-
import { isEmpty } from 'lodash';
19+
import { isEmpty, isEqual } from 'lodash';
2020
import { PureComponent } from 'react';
2121
import { Toolbar } from '@/v5/ui/routes/viewer/toolbar/toolbar.component';
2222
import { VIEWER_EVENTS } from '../../constants/viewer';
@@ -181,6 +181,7 @@ export class ViewerGui extends PureComponent<IProps, IState> {
181181
this.props.setPanelVisibility(VIEWER_PANELS.COMPARE, false);
182182
this.props.resetCompareComponent();
183183
}
184+
184185
}
185186

186187
public componentWillUnmount() {

frontend/src/v4/routes/viewerGui/viewerGui.container.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { TeamspacesActions } from '@/v4/modules/teamspaces';
1919
import { connect } from 'react-redux';
2020
import { bindActionCreators } from 'redux';
2121
import { createStructuredSelector } from 'reselect';
22+
import { selectSelectedTicket } from '@/v5/store/tickets/card/ticketsCard.selectors';
2223
import { CompareActions } from '../../modules/compare';
2324

2425
import { selectCurrentTeamspace, selectCurrentUser } from '../../modules/currentUser';

frontend/src/v5/helpers/viewpoint.helpers.ts

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ import { generateViewpoint as generateViewpointV4, getNodesIdsFromSharedIds, toS
2020
import { formatMessage } from '@/v5/services/intl';
2121
import { dispatch, getState } from '@/v4/modules/store';
2222
import { isEmpty, isString } from 'lodash';
23-
import { Viewer as ViewerService } from '@/v4/services/viewer/viewer';
24-
import { TreeActions } from '@/v4/modules/tree';
25-
import { ViewerGuiActions } from '@/v4/modules/viewerGui';
2623
import { selectCurrentTeamspace } from '../store/teamspaces/teamspaces.selectors';
27-
import { TicketsCardActionsDispatchers } from '../services/actionsDispatchers';
24+
import { ViewpointsActions } from '@/v4/modules/viewpoints';
2825

2926
export const convertToV5GroupNodes = (objects) => objects.map((object) => ({
3027
container: object.model as string,
@@ -73,6 +70,12 @@ const convertToV5GroupOverride = (group: any, type: ViewpointGroupOverrideType):
7370
override.opacity = opacity;
7471
}
7572

73+
if (group.transformation) {
74+
const { transformation } = group;
75+
override.transformation = transformation;
76+
}
77+
78+
7679
return override;
7780
};
7881

@@ -100,10 +103,8 @@ export const getViewerState = async () => {
100103
return state;
101104
};
102105

103-
const mergeGroups = (groups: any[]) => ({ objects: groups.flatMap((group) => group.objects) });
104-
105106
const convertToV4Group = (groupOverride: GroupOverride) => {
106-
const { color, opacity, group: v5Group } = groupOverride;
107+
const { color, opacity, transformation, group: v5Group } = groupOverride;
107108

108109
if (isString(v5Group)) {
109110
return { color: [0, 0, 0, 0], objects: [] }; // theres no info yet so I say us an empty group
@@ -121,9 +122,15 @@ const convertToV4Group = (groupOverride: GroupOverride) => {
121122
group.opacity = opacity;
122123
}
123124

125+
if (transformation) {
126+
group.transformation = transformation;
127+
}
128+
124129
return group;
125130
};
126131

132+
const mergeGroups = (groups: any[]) => ({ objects: groups.flatMap((group) => group.objects) });
133+
127134
export const viewpointV5ToV4 = (viewpoint: Viewpoint) => {
128135
let v4Viewpoint:any = {};
129136
if (viewpoint.camera) {
@@ -140,14 +147,15 @@ export const viewpointV5ToV4 = (viewpoint: Viewpoint) => {
140147
v4Viewpoint.clippingPlanes = viewpoint.clippingPlanes;
141148
}
142149

143-
if (!isEmpty(viewpoint.state?.colored)) {
144-
v4Viewpoint.override_groups = viewpoint.state.colored.map(convertToV4Group);
145-
}
146-
147150
if (!isEmpty(viewpoint.state?.transformed)) {
148151
v4Viewpoint.transformation_groups = viewpoint.state.transformed.map(convertToV4Group);
149152
}
150153

154+
155+
if (!isEmpty(viewpoint.state?.colored)) {
156+
v4Viewpoint.override_groups = viewpoint.state.colored.map(convertToV4Group);
157+
}
158+
151159
if (!isEmpty(viewpoint.state?.hidden)) {
152160
v4Viewpoint.hidden_group = mergeGroups(viewpoint.state.hidden.map(convertToV4Group));
153161
}
@@ -160,19 +168,21 @@ export const meshObjectsToV5GroupNode = (objects) => objects.map((obj) => ({
160168
_ids: obj.mesh_ids,
161169
}));
162170

163-
export const toColorAndTransparencyDicts = (overrides: GroupOverride[]): OverridesDicts => {
164-
const toMeshDictionary = (objects: V4GroupObjects, color: string, opacity: number): OverridesDicts => objects.shared_ids.reduce((dict, id) => {
165-
if (color !== undefined) {
171+
export const toGroupPropertiesDicts = (overrides: GroupOverride[]): OverridesDicts => {
172+
const toMeshDictionary = (objects: V4GroupObjects, color: string, opacity: number): OverridesDicts =>
173+
objects.shared_ids.reduce((dict, id) => {
174+
if (color !== undefined) {
166175
// eslint-disable-next-line no-param-reassign
167-
dict.overrides[id] = color;
168-
}
176+
dict.overrides[id] = color;
177+
}
169178

170-
if (opacity !== undefined) {
179+
if (opacity !== undefined) {
171180
// eslint-disable-next-line no-param-reassign
172-
dict.transparencies[id] = opacity;
173-
}
174-
return dict;
175-
}, { overrides: {}, transparencies: {} } as OverridesDicts);
181+
dict.transparencies[id] = opacity;
182+
}
183+
184+
return dict;
185+
}, { overrides: {}, transparencies: {} } as OverridesDicts);
176186

177187
return overrides.reduce((acum, current) => {
178188
const color = current.color ? getGroupHexColor(current.color) : undefined;
@@ -186,32 +196,21 @@ export const toColorAndTransparencyDicts = (overrides: GroupOverride[]): Overrid
186196
dict.overrides = { ...dict.overrides, ...overrideDict.overrides };
187197
// eslint-disable-next-line no-param-reassign
188198
dict.transparencies = { ...dict.transparencies, ...overrideDict.transparencies };
199+
189200
return dict;
190201
}, acum);
191202
}, { overrides: {}, transparencies: {} } as OverridesDicts);
192203
};
193204

194205
export const goToView = async (view: Viewpoint) => {
195-
if (isEmpty(view?.state?.colored) && isEmpty(view?.state?.hidden) && isEmpty(view?.camera) && isEmpty(view?.clippingPlanes)) {
206+
if (
207+
isEmpty(view?.state?.colored) &&
208+
isEmpty(view?.state?.hidden) &&
209+
isEmpty(view?.state?.transformed) &&
210+
isEmpty(view?.camera) &&
211+
isEmpty(view?.clippingPlanes)) {
196212
return;
197213
}
198-
199214

200-
dispatch(ViewerGuiActions.clearColorOverrides());
201-
await ViewerService.setViewpoint(view);
202-
const overrides = toColorAndTransparencyDicts(view?.state?.colored || []);
203-
TicketsCardActionsDispatchers.setOverrides(overrides);
204-
205-
await ViewerService.clearHighlights();
206-
207-
if (view?.state) {
208-
dispatch(TreeActions.setHiddenGeometryVisible(!!view.state.showHidden));
209-
}
210-
211-
const v4HiddenObjects = convertToV4GroupNodes(view.state?.hidden?.flatMap((hiddenOverride) => (hiddenOverride.group as Group)?.objects || []));
212-
if (v4HiddenObjects.length) {
213-
dispatch(TreeActions.hideNodesBySharedIds(v4HiddenObjects, true));
214-
} else {
215-
dispatch(TreeActions.showAllNodes());
216-
}
215+
dispatch(ViewpointsActions.showViewpoint(null, null, viewpointV5ToV4(view)));
217216
};

frontend/src/v5/services/intl.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,19 @@ export const initializeIntl = (locale: string) => {
4343
// Locale of the fallback defaultMessage
4444
defaultLocale: DEFAULT_LOCALE,
4545
messages,
46+
onError: (error) => {
47+
if (error.code === 'MISSING_TRANSLATION') {
48+
return;
49+
}
50+
51+
console.error(error);
52+
},
4653
},
4754
cache,
4855
);
4956
};
5057

51-
const getIntl = () => {
58+
export const getIntl = () => {
5259
if (!intlInternal) {
5360
initializeIntl(DEFAULT_LOCALE);
5461
}
@@ -70,16 +77,3 @@ export const formatRelativeTime: typeof intlInternal.formatRelativeTime = (value
7077

7178
// eslint-disable-next-line max-len
7279
export const formatPlural: typeof intlInternal.formatPlural = (value, opts?): Intl.LDMLPluralRule => getIntl().formatPlural(value, opts);
73-
74-
export const getIntlProviderProps = () => ({
75-
messages: getIntl().messages,
76-
defaultLocal: getIntl().defaultLocale,
77-
locale: getIntl().locale,
78-
onError: (error) => {
79-
if (error.code === 'MISSING_TRANSLATION' && getIntl().locale === DEFAULT_LOCALE) {
80-
return;
81-
}
82-
83-
console.error(error);
84-
},
85-
});

frontend/src/v5/store/tickets/card/ticketsCard.redux.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const { Types: TicketsCardTypes, Creators: TicketsCardActions } = createA
3636
resetState: [],
3737
setOverrides: ['overrides'],
3838
setUnsavedTicket: ['ticket'],
39+
setTransformations: ['transformations'],
3940
}, { prefix: 'TICKETS_CARD/' }) as { Types: Constants<ITicketsCardActionCreators>; Creators: ITicketsCardActionCreators };
4041

4142
export interface ITicketsCardState {
@@ -47,6 +48,7 @@ export interface ITicketsCardState {
4748
readOnly: boolean,
4849
overrides: OverridesDicts | null,
4950
unsavedTicket: EditableTicket | null,
51+
transformations: any,
5052
}
5153

5254
export const INITIAL_STATE: ITicketsCardState = {
@@ -60,6 +62,7 @@ export const INITIAL_STATE: ITicketsCardState = {
6062
},
6163
view: TicketsCardViews.List,
6264
overrides: null,
65+
transformations: null,
6366
readOnly: false,
6467
unsavedTicket: null,
6568
};
@@ -156,5 +159,5 @@ export interface ITicketsCardActionCreators {
156159
setReadOnly: (readOnly: boolean) => SetReadOnlyAction,
157160
resetState: () => ResetStateAction,
158161
setOverrides: (overrides: OverridesDicts) => SetOverridesAction,
159-
setUnsavedTicket: (ticket: EditableTicket) => SetUnsavedTicketAction,
162+
setUnsavedTicket: (ticket: EditableTicket) => SetUnsavedTicketAction
160163
}

frontend/src/v5/store/tickets/card/ticketsCard.selectors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const selectSelectedTicketPinId = createSelector(
6767

6868
export const selectTicketOverridesDict = createSelector(
6969
selectTicketsCardDomain,
70-
(ticketCardState) => ticketCardState.overrides || { overrides: {}, transparencies: {} },
70+
(ticketCardState) => ticketCardState.overrides || { overrides: {}, transparencies: {}, transformations: {} },
7171
);
7272

7373
export const selectTicketOverrides = createSelector(

frontend/src/v5/store/tickets/tickets.helpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ const fillEmptyOverrides = (values: Partial<ITicket>) => {
273273
viewValue.state ||= {} as any;
274274
viewValue.state.colored ||= [];
275275
viewValue.state.hidden ||= [];
276+
viewValue.state.transformed ||= [];
276277
}
277278
});
278279
};

frontend/src/v5/store/tickets/tickets.selectors.ts

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import { createSelector } from 'reselect';
1919
import { orderBy } from 'lodash';
2020
import { BaseProperties } from '@/v5/ui/routes/viewer/tickets/tickets.constants';
2121
import { ITicketsState } from './tickets.redux';
22-
import { createPropertiesWithGroups } from './ticketsGroups.helpers';
23-
import { ITicket, Properties, TicketWithModelIdAndName } from './tickets.types';
22+
import { createPropertiesWithGroups, ticketWithGroups } from './ticketsGroups.helpers';
23+
import { ITicket, TicketWithModelIdAndName } from './tickets.types';
2424
import { selectContainers } from '../containers/containers.selectors';
2525
import { selectFederations } from '../federations/federations.selectors';
2626

@@ -70,27 +70,27 @@ export const selectTicketsGroups = createSelector(
7070
(state) => state.groupsByGroupId,
7171
);
7272

73-
export const selectTickets = createSelector(
73+
const selectTicketsRaw = createSelector(
7474
selectTicketsDomain,
7575
(state, modelId) => modelId,
76+
(state, modelId) => state.ticketsByModelId[modelId] || [],
77+
);
78+
79+
export const selectTickets = createSelector(
80+
selectTicketsRaw,
7681
selectTicketsGroups,
77-
(state, modelId, groups): ITicket[] => {
82+
(ticketsList, groups): ITicket[] => {
7883
const tickets = [];
79-
(state.ticketsByModelId[modelId] || []).forEach((ticket) => {
80-
let { properties } = ticket;
81-
properties = createPropertiesWithGroups(properties, groups);
82-
tickets.push({
83-
...ticket,
84-
properties,
85-
});
84+
ticketsList.forEach((ticket) => {
85+
tickets.push({ ...ticket, properties: createPropertiesWithGroups(ticket.properties, groups) });
8686
});
8787

8888
return orderBy(tickets, `properties.${BaseProperties.CREATED_AT}`, 'desc');
8989
},
9090
);
9191

9292
export const selectTicketByIdRaw = createSelector(
93-
selectTickets,
93+
selectTicketsRaw,
9494
(_, modelId, ticketId) => ticketId,
9595
(tickets, ticketId) => tickets.find(({ _id }) => _id === ticketId) || null,
9696
);
@@ -102,25 +102,7 @@ export const selectTicketById = createSelector(
102102
if (!ticket) {
103103
return ticket;
104104
}
105-
106-
let { properties } = ticket;
107-
properties = createPropertiesWithGroups(properties, groups);
108-
const finalTicket = {
109-
...ticket,
110-
properties,
111-
};
112-
113-
if (ticket.modules) {
114-
let { modules } = ticket;
115-
modules = Object.keys(modules).reduce((partialModules, key) => {
116-
// eslint-disable-next-line no-param-reassign
117-
partialModules[key] = createPropertiesWithGroups(modules[key], groups);
118-
return partialModules;
119-
}, {} as Record<string, Properties>);
120-
121-
finalTicket.modules = modules;
122-
}
123-
return finalTicket;
105+
return ticketWithGroups(ticket, groups);
124106
},
125107
);
126108

0 commit comments

Comments
 (0)