mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 09:28:31 +00:00
cleanup
This commit is contained in:
parent
4eb9742d3e
commit
fe624d3abd
3 changed files with 6 additions and 66 deletions
|
|
@ -681,6 +681,7 @@ const EditorComponent = (props) => {
|
|||
appDefinition: appJson,
|
||||
});
|
||||
|
||||
//! need to handle
|
||||
for (const event of appJson.pages[homePageId]?.events ?? []) {
|
||||
await handleEvent(event.eventId, event);
|
||||
}
|
||||
|
|
@ -1427,6 +1428,7 @@ const EditorComponent = (props) => {
|
|||
});
|
||||
};
|
||||
|
||||
//!will remove this
|
||||
const updateOnPageLoadEvents = (pageId, events) => {
|
||||
const copyOfAppDefinition = JSON.parse(JSON.stringify(appDefinition));
|
||||
|
||||
|
|
|
|||
|
|
@ -1647,17 +1647,15 @@ export const computeQueryState = (queries) => {
|
|||
}
|
||||
};
|
||||
|
||||
export const buildComponentMetaDefinition = (components = {}, events = []) => {
|
||||
export const buildComponentMetaDefinition = (components = {}) => {
|
||||
for (const componentId in components) {
|
||||
const currentComponentData = components[componentId];
|
||||
const componentEvents = events
|
||||
.filter((event) => event.sourceId === componentId)
|
||||
?.map((event) => ({ ...event.event, id: event.id }));
|
||||
|
||||
const componentMeta = componentTypes.find((comp) => currentComponentData.component.component === comp.component);
|
||||
|
||||
const mergedDefinition = {
|
||||
...componentMeta.definition,
|
||||
events: componentEvents,
|
||||
|
||||
properties: {
|
||||
...componentMeta.definition.properties,
|
||||
...currentComponentData?.component.definition.properties,
|
||||
|
|
@ -1698,10 +1696,8 @@ export const buildAppDefinition = (data) => {
|
|||
editingVersion['currentVersionId'] = editingVersion.id;
|
||||
_.unset(editingVersion, 'id');
|
||||
|
||||
const eventsData = data?.events;
|
||||
|
||||
const pages = data.pages.reduce((acc, page) => {
|
||||
const currentComponents = buildComponentMetaDefinition(_.cloneDeep(page?.components), eventsData);
|
||||
const currentComponents = buildComponentMetaDefinition(_.cloneDeep(page?.components));
|
||||
|
||||
page.components = currentComponents;
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ const defaultComponent = {
|
|||
properties: {},
|
||||
styles: {},
|
||||
validation: {},
|
||||
events: [],
|
||||
type: '',
|
||||
};
|
||||
|
||||
|
|
@ -41,73 +40,16 @@ const updateType = Object.freeze({
|
|||
componentAdded: 'components',
|
||||
componentDefinitionChanged: 'components',
|
||||
componentDeleted: 'components',
|
||||
componentsEventsChanged: 'events',
|
||||
pageEventsChanged: 'events',
|
||||
});
|
||||
|
||||
const eventHandlerType = Object.freeze({
|
||||
componentsEventsChanged: 'components',
|
||||
pageEventsChanged: 'pages',
|
||||
});
|
||||
|
||||
export const computeAppDiff = (appDiff, currentPageId, opts) => {
|
||||
const { updateDiff, type, operation } = updateFor(appDiff, currentPageId, opts);
|
||||
|
||||
// console.log('----arpit [updateFor]', { updateDiff, type, operation });
|
||||
return { updateDiff, type, operation };
|
||||
};
|
||||
|
||||
function verifyIsEventUpdates(data, eventsObj) {
|
||||
if (!data.pages || Object.keys(data.pages).length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const pageId in data.pages) {
|
||||
const components = data.pages[pageId].components;
|
||||
for (const componentId in components) {
|
||||
if (components[componentId].component.definition.events) {
|
||||
eventsObj.components = Object.values(components[componentId].component.definition.events).map((e) => ({
|
||||
event: e,
|
||||
eventType: 'component',
|
||||
attachedTo: componentId,
|
||||
}));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function computeEventDiff(appDiff, currentPageId, opts = []) {
|
||||
let type = 'events';
|
||||
let updateDiff;
|
||||
let operation = 'update';
|
||||
|
||||
const events = {
|
||||
components: [],
|
||||
pages: [],
|
||||
};
|
||||
verifyIsEventUpdates(appDiff, events);
|
||||
|
||||
updateDiff = events[eventHandlerType[opts[0]]];
|
||||
console.log('----arpit [computeEventDiff]', { events, opts });
|
||||
|
||||
if (opts.includes('newEvent')) {
|
||||
operation = 'create';
|
||||
updateDiff = updateDiff[0];
|
||||
}
|
||||
|
||||
return { updateDiff, type, operation };
|
||||
}
|
||||
|
||||
const updateFor = (appDiff, currentPageId, opts) => {
|
||||
const updateTypeMappings = [
|
||||
{
|
||||
updateTypes: ['componentsEventsChanged', 'pageEventsChanged', 'eventsReOrdered', 'newEvent'],
|
||||
processingFunction: computeEventDiff,
|
||||
},
|
||||
{
|
||||
updateTypes: ['componentAdded', 'componentDefinitionChanged', 'componentDeleted', 'containerChanges'],
|
||||
processingFunction: computeComponentDiff,
|
||||
|
|
|
|||
Loading…
Reference in a new issue