Skip to content

Commit

Permalink
fix(global): 🐛 make class for entitydata
Browse files Browse the repository at this point in the history
make class for entitydata and changes dynnamicattribute with entity data

Ref #54
  • Loading branch information
PritamBag committed Jan 6, 2025
1 parent 4621282 commit 75f23ce
Show file tree
Hide file tree
Showing 22 changed files with 270 additions and 49 deletions.
5 changes: 3 additions & 2 deletions app/actions/builder.actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AppBuilderData } from "../components/data/app-builder/AppBuilder.data";
import { DynamicEntity } from "../components/data/model/DynamicEntity.interface";
import { EntityData } from "../components/data/entity/Entity.data";
import { BuilderState } from "../reducers/builder.reducer";
import { SET_BUILDER_DATA } from "../types/builder.types";

Expand All @@ -22,6 +22,7 @@ import { SET_BUILDER_DATA } from "../types/builder.types";
// (data) => data.builderId === builderData.builderId
// );

// eslint-disable-next-line etc/no-commented-out-code
// let updatedAppBuilderData;

// if (existingBuilderIndex > -1) {
Expand All @@ -40,7 +41,7 @@ import { SET_BUILDER_DATA } from "../types/builder.types";
// };
// };

export const setBuilderData = (builderData: AppBuilderData, entityData: DynamicEntity, currentState: BuilderState) => {
export const setBuilderData = (builderData: AppBuilderData, entityData: EntityData, currentState: BuilderState) => {
const existingBuilderIndex = currentState.appBuilderData.findIndex(
(data) => data.builderId === builderData.builderId
);
Expand Down
11 changes: 7 additions & 4 deletions app/components/AppBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { useDispatch, useSelector } from "react-redux";

import { AppBuilderData } from "./data/app-builder/AppBuilder.data";
import { DynamicEntity } from "./data/model/DynamicEntity.interface";
import { EntityData } from "./data/entity/Entity.data";
import ToolbarGroup from "./toolbar/ToolbarGroup";
import ToolBoxGroup from "./toolbox/ToolBoxGroup";
import ViewerGroup from "./viewer/ViewerGroup";
Expand All @@ -19,7 +19,7 @@ import { GetDataFromReducer, getBuilderData, getBuilderType } from "../utils/Uti

interface BuilderState {
builderType?: string;
data?: DynamicEntity;
data?: EntityData;
}

/* Function for get builder state */
Expand All @@ -34,7 +34,7 @@ export default function AppBuilder<T extends AppBuilderData>() {
const builderType = getBuilderType();
const entityData = getBuilderData();

const [selectedBuilderId, setSelectedBuilderId] = useState<string>(GetDataFromReducer(entityData?.id)?.builderId);
const [selectedBuilderId, setSelectedBuilderId] = useState<string>(GetDataFromReducer(entityData?.getId())?.builderId);
const appBuilderDataFromStore = useSelector((state: any) => state.BuilderOptions?.appBuilderData);
const selectedBuilder = appBuilderDataFromStore?.find(
(builderData: AppBuilderData) => builderData.builderId === selectedBuilderId
Expand All @@ -51,7 +51,10 @@ export default function AppBuilder<T extends AppBuilderData>() {
const builderData = appBuilderDataFromStore?.find(
(_builderData: AppBuilderData) => {
Object.setPrototypeOf(_builderData, AppBuilderData.prototype);
return _builderData.getBuilderType() === builderType && _builderData.getEntityData().id === entityData?.id;
const _entityData = _builderData.getEntityData();

Object.setPrototypeOf(_entityData, EntityData.prototype);
return _builderData.getBuilderType() === builderType && _entityData.getId() === entityData?.getId();
});

if(builderData) {
Expand Down
8 changes: 4 additions & 4 deletions app/components/data/app-builder/AppBuilder.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import AppBuilderFactory from "../../../factory/AppBuilder.factory";
import ToolbarFactory from "../../../factory/Toolbar.factory";
import ToolBoxFactory from "../../../factory/ToolBox.factory";
import ViewerFactory from "../../../factory/Viewer.factory";
import { DynamicEntity } from "../model/DynamicEntity.interface";
import { EntityData } from "../entity/Entity.data";
import { ToolbarData } from "../toolbar/Toolbar.data";
import { ToolBoxData } from "../toolbox/ToolBox.data";
import { ViewerData } from "../viewer/Viewer.data";
Expand All @@ -23,7 +23,7 @@ export abstract class AppBuilderData {
private builderType: typeof AppBuilderFactory.BUILDER_TYPES[keyof typeof AppBuilderFactory.BUILDER_TYPES];

/** Private property to store entity data. */
private entityData: DynamicEntity;
private entityData: EntityData;

/** Private property to store toolbox-related data. */
private toolboxes: ToolBoxData[] = [];
Expand All @@ -48,7 +48,7 @@ export abstract class AppBuilderData {
* @param toolbarMeta - Icons for initializing the toolbar.
*/
constructor(
entityData: DynamicEntity,
entityData: EntityData,
builderType: typeof AppBuilderFactory.BUILDER_TYPES[keyof typeof AppBuilderFactory.BUILDER_TYPES],
builderIcon = STAR_ICON,
defaultToolboxeMeta: { [key: string]: any },
Expand Down Expand Up @@ -162,7 +162,7 @@ export abstract class AppBuilderData {
* @param defaultViewerMeta - The metadata for initializing viewers.
* @throws Error if entityData is invalid or empty.
*/
private prepareViewers(entityData: DynamicEntity, defaultViewerMeta: string[]): void {
private prepareViewers(entityData: EntityData, defaultViewerMeta: string[]): void {
// @todo need to update when we handle enpty entityData
if (!entityData || Object.keys(entityData).length === 0) {
throw new Error("Entity data is not set. Unable to prepare viewers.");
Expand Down
4 changes: 2 additions & 2 deletions app/components/data/app-builder/BusinessBuilder.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AppBuilderData } from "./AppBuilder.data";
import { BUSINESS_ICON } from "../../../constants/AppBuilder.constant";
import AppBuilderFactory from "../../../factory/AppBuilder.factory";
import ToolbarFactory from "../../../factory/Toolbar.factory";
import { DynamicEntity } from "../model/DynamicEntity.interface";
import { EntityData } from "../entity/Entity.data";

/**
* A concrete implementation of the `AppBuilderData` abstract class.
Expand All @@ -25,7 +25,7 @@ export class BusinessBuilderData extends AppBuilderData {
*
* @param entityData The dynamic entity data that is passed to the base class constructor.
*/
constructor(entityData: DynamicEntity) {
constructor(entityData: EntityData) {
super(
entityData,
AppBuilderFactory.BUILDER_TYPES.BUSINESS,
Expand Down
4 changes: 2 additions & 2 deletions app/components/data/app-builder/DefaultBuilder.data.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AppBuilderData } from "./AppBuilder.data";
import { DEFAULT_ICON } from "../../../constants/AppBuilder.constant";
import AppBuilderFactory from "../../../factory/AppBuilder.factory";
import { DynamicEntity } from "../model/DynamicEntity.interface";
import { EntityData } from "../entity/Entity.data";

/**
* A concrete implementation of the `AppBuilderData` abstract class.
Expand All @@ -23,7 +23,7 @@ export class DefaultBuilderData extends AppBuilderData {
*
* @param entityData The dynamic entity data that is passed to the base class constructor.
* */
constructor(entityData: DynamicEntity) {
constructor(entityData: EntityData) {
super(
entityData,
AppBuilderFactory.BUILDER_TYPES.DEFAULT,
Expand Down
4 changes: 2 additions & 2 deletions app/components/data/app-builder/FormBuilder.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FORM_ICON } from "../../../constants/AppBuilder.constant";
import AppBuilderFactory from "../../../factory/AppBuilder.factory";
import ToolbarFactory from "../../../factory/Toolbar.factory";
import ToolBoxFactory from "../../../factory/ToolBox.factory";
import { DynamicEntity } from "../model/DynamicEntity.interface";
import { EntityData } from "../entity/Entity.data";

/**
* A concrete implementation of the `AppBuilderData` abstract class.
Expand All @@ -26,7 +26,7 @@ export class FormBuilderData extends AppBuilderData {
*
* @param entityData The dynamic entity data that is passed to the base class constructor.
* */
constructor(entityData: DynamicEntity) {
constructor(entityData: EntityData) {
super(
entityData,
AppBuilderFactory.BUILDER_TYPES.FORM,
Expand Down
4 changes: 2 additions & 2 deletions app/components/data/app-builder/ModelBuilder.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import AppBuilderFactory from "../../../factory/AppBuilder.factory";
import ToolbarFactory from "../../../factory/Toolbar.factory";
import ToolBoxFactory from "../../../factory/ToolBox.factory";
import ViewerFactory from "../../../factory/Viewer.factory";
import { DynamicEntity } from "../model/DynamicEntity.interface";
import { EntityData } from "../entity/Entity.data";

/**
* A concrete implementation of the `AppBuilderData` abstract class.
Expand All @@ -28,7 +28,7 @@ export class ModelBuilderData extends AppBuilderData {
*
* @param entityData The dynamic entity data that is passed to the base class constructor.
*/
constructor(entityData: DynamicEntity) {
constructor(entityData: EntityData) {
super(
entityData,
AppBuilderFactory.BUILDER_TYPES.MODEL,
Expand Down
4 changes: 2 additions & 2 deletions app/components/data/app-builder/PageBuilder.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AppBuilderData } from "./AppBuilder.data";
import { PAGE_ICON } from "../../../constants/AppBuilder.constant";
import AppBuilderFactory from "../../../factory/AppBuilder.factory";
import ToolbarFactory from "../../../factory/Toolbar.factory";
import { DynamicEntity } from "../model/DynamicEntity.interface";
import { EntityData } from "../entity/Entity.data";

/**
* A concrete implementation of the `AppBuilderData` abstract class.
Expand All @@ -24,7 +24,7 @@ export class PageBuilderData extends AppBuilderData {
*
* @param entityData The dynamic entity data that is passed to the base class constructor.
* */
constructor(entityData: DynamicEntity) {
constructor(entityData: EntityData) {
super(
entityData,
AppBuilderFactory.BUILDER_TYPES.PAGE,
Expand Down
4 changes: 2 additions & 2 deletions app/components/data/app-builder/RouteBuilder.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AppBuilderData } from "./AppBuilder.data";
import { ROUTE_ICON } from "../../../constants/AppBuilder.constant";
import AppBuilderFactory from "../../../factory/AppBuilder.factory";
import ToolbarFactory from "../../../factory/Toolbar.factory";
import { DynamicEntity } from "../model/DynamicEntity.interface";
import { EntityData } from "../entity/Entity.data";

/**
* A concrete implementation of the `AppBuilderData` abstract class.
Expand All @@ -24,7 +24,7 @@ export class RouteBuilderData extends AppBuilderData {
*
* @param entityData The dynamic entity data that is passed to the base class constructor.
* */
constructor(entityData: DynamicEntity) {
constructor(entityData: EntityData) {
super(
entityData,
AppBuilderFactory.BUILDER_TYPES.ROUTE,
Expand Down
4 changes: 2 additions & 2 deletions app/components/data/app-builder/ThemeBuilder.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AppBuilderData } from "./AppBuilder.data";
import { THEME_ICON } from "../../../constants/AppBuilder.constant";
import AppBuilderFactory from "../../../factory/AppBuilder.factory";
import ToolbarFactory from "../../../factory/Toolbar.factory";
import { DynamicEntity } from "../model/DynamicEntity.interface";
import { EntityData } from "../entity/Entity.data";

/**
* A concrete implementation of the `AppBuilderData` abstract class.
Expand All @@ -24,7 +24,7 @@ export class ThemeBuilderData extends AppBuilderData {
*
* @param entityData The dynamic entity data that is passed to the base class constructor.
* */
constructor(entityData: DynamicEntity) {
constructor(entityData: EntityData) {
super(
entityData,
AppBuilderFactory.BUILDER_TYPES.THEME,
Expand Down
137 changes: 137 additions & 0 deletions app/components/data/entity/Entity.data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
export class EntityData<TSchema = any> {
private id: number;
private name: string;
private desc: string | null;
private system: string | null;
private schema: TSchema;
private extraInfo: any | null;
private _status: string;
private entityRef: string | null;
private deletedAt: Date | null;
private createdAt: Date;
private updatedAt: Date;
private commitId: string | null;
private comments: string | null;

constructor(data: any) {
this.id = data.id;
this.name = data.name;
this.desc = data.desc || null;
this.system = data.system || null;
this.schema = data.schema || {};
this.extraInfo = data.extraInfo || null;
this._status = data._status;
this.entityRef = data.entityRef || null;
this.deletedAt = data.deletedAt ? new Date(data.deletedAt) : null;
this.createdAt = new Date(data.createdAt);
this.updatedAt = new Date(data.updatedAt);
this.commitId = data.commitId || null;
this.comments = data.comments || null;
}

// Getters
public getId(): number {
return this.id;
}

public getName(): string {
return this.name;
}

public getDesc(): string | null {
return this.desc;
}

public getSystem(): string | null {
return this.system;
}

public getSchema(): TSchema {
return this.schema;
}

public getExtraInfo(): any | null {
return this.extraInfo;
}

public getStatus(): string {
return this._status;
}

public getEntityRef(): string | null {
return this.entityRef;
}

public getDeletedAt(): Date | null {
return this.deletedAt;
}

public getCreatedAt(): Date {
return this.createdAt;
}

public getUpdatedAt(): Date {
return this.updatedAt;
}

public getCommitId(): string | null {
return this.commitId;
}

public getComments(): string | null {
return this.comments;
}

// Setters
// public setId(id: number): void {
// this.id = id;
// }

// public setName(name: string): void {
// this.name = name;
// }

// public setDesc(desc: string | null): void {
// this.desc = desc;
// }

// public setSystem(system: string | null): void {
// this.system = system;
// }

public setSchema(schema: TSchema): void {
this.schema = schema;
}

// public setExtraInfo(extraInfo: any | null): void {
// this.extraInfo = extraInfo;
// }

// public setStatus(status: string): void {
// this._status = status;
// }

// public setEntityRef(entityRef: string | null): void {
// this.entityRef = entityRef;
// }

// public setDeletedAt(deletedAt: Date | null): void {
// this.deletedAt = deletedAt;
// }

// public setCreatedAt(createdAt: Date): void {
// this.createdAt = createdAt;
// }

// public setUpdatedAt(updatedAt: Date): void {
// this.updatedAt = updatedAt;
// }

// public setCommitId(commitId: string | null): void {
// this.commitId = commitId;
// }

// public setComments(comments: string | null): void {
// this.comments = comments;
// }
}
Loading

0 comments on commit 75f23ce

Please sign in to comment.