mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-23 17:08:34 +00:00
fixes: cloning components to a new version should also create associated events
This commit is contained in:
parent
91ff545d4e
commit
0117c90f5f
3 changed files with 52 additions and 21 deletions
|
|
@ -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) => {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Reference in a new issue