fixes: cloning components to a new version should also create associated events

This commit is contained in:
arpitnath 2023-10-17 16:37:45 +05:30
parent 91ff545d4e
commit 0117c90f5f
3 changed files with 52 additions and 21 deletions

View file

@ -871,33 +871,28 @@ const EditorComponent = (props) => {
const newComponentIds = Object.keys(componentUpdateDiff);
const mappedEvents = [];
newComponentIds.forEach((componentId) => {
const sourceComponentId = getKeyFromComponentMap(componentMap, componentId);
if (!sourceComponentId) return;
const componentEvents = events.filter((event) => event.sourceId === sourceComponentId);
appVersionService
.findAllEventsWithSourceId(appId, currentVersionId, sourceComponentId)
.then((componentEvents) => {
if (!componentEvents) return;
componentEvents.forEach((event) => {
const newEvent = {
event: {
...event?.event,
},
eventType: event?.target,
attachedTo: componentMap[event?.sourceId],
index: event?.index,
};
mappedEvents.push(...componentEvents);
createAppVersionEventHandlers(newEvent);
});
});
});
if (mappedEvents.length === 0) return;
return Promise.all(
mappedEvents.map((event) => {
const newEvent = {
event: {
...event?.event,
},
eventType: event?.target,
attachedTo: componentMap[event?.sourceId],
index: event?.index,
};
createAppVersionEventHandlers(newEvent);
})
);
};
const saveEditingVersion = (isUserSwitchedVersion = false) => {

View file

@ -13,6 +13,7 @@ export const appVersionService = {
createAppVersionEventHandler,
deleteAppVersionEventHandler,
clonePage,
findAllEventsWithSourceId,
};
function getAll(appId) {
@ -155,3 +156,17 @@ function clonePage(appId, versionId, pageId) {
handleResponse
);
}
function findAllEventsWithSourceId(appId, versionId, sourceId) {
const requestOptions = {
method: 'GET',
headers: authHeader(),
credentials: 'include',
};
return fetch(
`${config.apiUrl}/v2/apps/${appId}/versions/${versionId}/events${sourceId ? `?sourceId=${sourceId}` : ''}
`,
requestOptions
).then(handleResponse);
}

View file

@ -406,6 +406,27 @@ export class AppsControllerV2 {
}
// events api
@UseGuards(JwtAuthGuard)
@UseInterceptors(ValidAppInterceptor)
@Get(':id/versions/:versionId/events')
async getEvents(@User() user, @Param('id') id, @Param('versionId') versionId, @Query('sourceId') sourceId) {
const version = await this.appsService.findVersion(versionId);
const app = version.app;
if (app.id !== id) {
throw new BadRequestException();
}
const ability = await this.appsAbilityFactory.appsActions(user, id);
if (!ability.can('viewApp', app)) {
throw new ForbiddenException('You do not have permissions to perform this action');
}
return this.eventService.findAllEventsWithSourceId(sourceId);
}
@UseGuards(JwtAuthGuard)
@UseInterceptors(ValidAppInterceptor)
@Post(':id/versions/:versionId/events')