Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
manudous committed Jan 17, 2024
2 parents 0d18509 + a7fa35f commit 7f9c3c1
Show file tree
Hide file tree
Showing 19 changed files with 184 additions and 28 deletions.
1 change: 1 addition & 0 deletions src/common/components/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './canvas-setting-icon.component';
export * from './relation-icon.component';
export * from './zoom-in-icon.component';
export * from './zoom-out-icon.component';
export * from './export-icon.component';
1 change: 1 addition & 0 deletions src/common/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './modal-dialog';
export * from './table-pk-picker';
export * from './dropdown';
export * from './icons';
1 change: 1 addition & 0 deletions src/common/components/modal-dialog/modal-dialog.const.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const CANVAS_SETTINGS_TITLE = 'Canvas Settings';
export const EDIT_TABLE_TITLE = 'Edit table';
export const EDIT_RELATION_TITLE = 'Edit relation';
export const EDIT_COLLECTION_TITLE = 'Edit Collection';
1 change: 1 addition & 0 deletions src/core/model/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type FieldType = 'number' | 'string' | 'object' | 'objectId';
export type ExportType = 'svg' | 'png' | 'mongo';

export interface Size {
width: number;
Expand Down
11 changes: 11 additions & 0 deletions src/core/providers/canvas-schema/canvas-schema.business.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('canvas-schema.business', () => {
const dbSchema: DatabaseSchemaVm = {
relations: [
{
id: '20',
fromFieldId: '10',
fromTableId: '9',
toFieldId: '1',
Expand Down Expand Up @@ -52,6 +53,7 @@ describe('canvas-schema.business', () => {
const expectedResult: DatabaseSchemaVm = {
relations: [
{
id: '20',
fromFieldId: '10',
fromTableId: '9',
toFieldId: '1',
Expand Down Expand Up @@ -109,6 +111,7 @@ describe('canvas-schema.business', () => {
const dbSchema: DatabaseSchemaVm = {
relations: [
{
id: '20',
fromFieldId: '10',
fromTableId: '9',
toFieldId: '1',
Expand Down Expand Up @@ -137,6 +140,7 @@ describe('canvas-schema.business', () => {
const expectedResult: DatabaseSchemaVm = {
relations: [
{
id: '20',
fromFieldId: '10',
fromTableId: '9',
toFieldId: '1',
Expand Down Expand Up @@ -187,6 +191,7 @@ describe('canvas-schema.business', () => {
const dbSchema: DatabaseSchemaVm = {
relations: [
{
id: '20',
fromFieldId: '10',
fromTableId: '9',
toFieldId: '1',
Expand Down Expand Up @@ -257,6 +262,7 @@ describe('canvas-schema.business', () => {
const dbSchema: DatabaseSchemaVm = {
relations: [
{
id: '20',
fromFieldId: '10',
fromTableId: '9',
toFieldId: '1',
Expand Down Expand Up @@ -297,6 +303,7 @@ describe('canvas-schema.business', () => {
const expectedResult: DatabaseSchemaVm = {
relations: [
{
id: '20',
fromFieldId: '10',
fromTableId: '9',
toFieldId: '1',
Expand Down Expand Up @@ -360,6 +367,7 @@ describe('canvas-schema.business', () => {
const dbSchema: DatabaseSchemaVm = {
relations: [
{
id: '20',
fromFieldId: '10',
fromTableId: '9',
toFieldId: '1',
Expand Down Expand Up @@ -426,6 +434,7 @@ describe('canvas-schema.business', () => {
const expectedResult: DatabaseSchemaVm = {
relations: [
{
id: '20',
fromFieldId: '10',
fromTableId: '9',
toFieldId: '1',
Expand Down Expand Up @@ -509,6 +518,7 @@ describe('canvas-schema.business', () => {
const dbSchema: DatabaseSchemaVm = {
relations: [
{
id: '20',
fromFieldId: '10',
fromTableId: '9',
toFieldId: '1',
Expand Down Expand Up @@ -537,6 +547,7 @@ describe('canvas-schema.business', () => {
const expectedResult: DatabaseSchemaVm = {
relations: [
{
id: '20',
fromFieldId: '10',
fromTableId: '9',
toFieldId: '1',
Expand Down
1 change: 1 addition & 0 deletions src/core/providers/canvas-schema/canvas-schema.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface FieldVm {
export type RelationType = '1:1' | '1:M' | 'M:1';

export interface RelationVm {
id: GUID;
fromTableId: string;
toTableId: string;
fromFieldId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('calculateTablePosition', () => {
];
const relations: RelationVm[] = [
{
id: '20',
fromTableId: '1',
toTableId: '2',
fromFieldId: '1',
Expand Down Expand Up @@ -177,6 +178,7 @@ describe('calculateTablePosition', () => {
];
const relations: RelationVm[] = [
{
id: '20',
fromTableId: '1',
toTableId: '2',
fromFieldId: '1',
Expand Down Expand Up @@ -301,6 +303,7 @@ describe('calculateTablePosition', () => {
];
const relations: RelationVm[] = [
{
id: '20',
fromTableId: '1',
toTableId: '2',
fromFieldId: '1',
Expand Down Expand Up @@ -425,6 +428,7 @@ describe('calculateTablePosition', () => {
];
const relations: RelationVm[] = [
{
id: '20',
fromTableId: '1',
toTableId: '2',
fromFieldId: '1',
Expand Down Expand Up @@ -549,6 +553,7 @@ describe('calculateTablePosition', () => {
];
const relations: RelationVm[] = [
{
id: '20',
fromTableId: '1',
toTableId: '2',
fromFieldId: '1',
Expand Down
1 change: 1 addition & 0 deletions src/core/providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './canvas-view-settings';
export * from './modal-dialog-provider';
export * from './theme-provider';
export * from './canvas-schema';
7 changes: 6 additions & 1 deletion src/pods/canvas/canvas-svg.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface Props {
) => void;
onToggleCollapse: (tableId: GUID, fieldId: GUID) => void;
onEditTable: (tableInfo: TableVm) => void;
onEditRelation: (relationId: GUID) => void;
}

export const CanvasSvgComponent: React.FC<Props> = props => {
Expand All @@ -26,6 +27,7 @@ export const CanvasSvgComponent: React.FC<Props> = props => {
onUpdateTablePosition,
onToggleCollapse,
onEditTable,
onEditRelation,
} = props;
return (
<svg
Expand All @@ -45,7 +47,10 @@ export const CanvasSvgComponent: React.FC<Props> = props => {
canvasSize={canvasSize}
/>
))}
<DatabaseRelationCollectionComponent schema={canvasSchema} />
<DatabaseRelationCollectionComponent
schema={canvasSchema}
onEditRelation={onEditRelation}
/>
</svg>
);
};
2 changes: 2 additions & 0 deletions src/pods/canvas/canvas.mock.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@/core/providers/canvas-schema';
import { TABLE_CONST } from '@/core/providers/canvas-schema/canvas.const';

const tagRelationId = '1';
const tagTableId = '1';
const restaurantTableId = '2';
const tagFieldId = GenerateGUID();
Expand All @@ -16,6 +17,7 @@ const restaurantIdField = GenerateGUID();

const mockRelations: RelationVm[] = [
{
id: tagRelationId,
fromTableId: tagTableId,
toTableId: restaurantTableId,
fromFieldId: tagFieldId,
Expand Down
5 changes: 5 additions & 0 deletions src/pods/canvas/canvas.pod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export const CanvasPod: React.FC = () => {
}
};

const handleEditRelation = (relationId: GUID) => {
console.log('TODO: handleEditRelation', relationId);
};

return (
<div
className={classes.container}
Expand All @@ -84,6 +88,7 @@ export const CanvasPod: React.FC = () => {
onUpdateTablePosition={updateTablePosition}
onToggleCollapse={handleToggleCollapse}
onEditTable={handleEditTable}
onEditRelation={handleEditRelation}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Coords } from '@/core/model';
import { Coords, GUID } from '@/core/model';
import { DatabaseSchemaVm, RelationVm } from '@/core/providers/canvas-schema';
import DatabaseRelationshipComponent from './database-relation.component';
import {
Expand All @@ -9,11 +9,12 @@ import {

interface DatabaseRelationCollectionProps {
schema: DatabaseSchemaVm;
onEditRelation: (relationId: GUID) => void;
}

export const DatabaseRelationCollectionComponent: React.FC<
DatabaseRelationCollectionProps
> = ({ schema }) => {
> = ({ schema, onEditRelation }) => {
const renderRelation = (relation: RelationVm) => {
const fromTable = schema.tables.find(
table => table.id === relation.fromTableId
Expand Down Expand Up @@ -47,6 +48,8 @@ export const DatabaseRelationCollectionComponent: React.FC<
return (
<DatabaseRelationshipComponent
key={`${relation.fromTableId}-${relation.fromFieldId}-${relation.toTableId}-${relation.toFieldId}`}
id={relation.id}
onClick={onEditRelation}
relationType={relation.type}
startCoords={startCoords}
endCoords={endCoords}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import React from 'react';
import { RelationType } from '@/core/providers/canvas-schema';
import { Coords } from '@/core/model';
import { Coords, GUID } from '@/core/model';

interface DatabaseRelationshipProps {
id: GUID;
relationType: RelationType;
startCoords: Coords;
endCoords: Coords;
onClick: (relationId: GUID) => void;
}

const FORK_WIDTH = 10;
const FORK_LINE_SPACING = 5;

const DatabaseRelationshipComponent: React.FC<DatabaseRelationshipProps> = ({
id,
relationType,
startCoords,
endCoords,
onClick,
}) => {
const drawFork = (forkCoords: Coords, drawLeftToRight: boolean) => {
const direction = drawLeftToRight ? 1 : -1;
Expand Down Expand Up @@ -48,6 +52,22 @@ const DatabaseRelationshipComponent: React.FC<DatabaseRelationshipProps> = ({
);
};

// Enhancemnt proposal: #127
// https://github.com/Lemoncode/mongo-modeler/pull/127
const drawClickableLine = () => {
return (
<line
x1={startCoords.x}
y1={startCoords.y}
x2={endCoords.x}
y2={endCoords.y}
strokeWidth={20}
stroke="transparent"
onClick={() => onClick(id)}
/>
);
};

// Determine the direction of the fork
const isDrawLeftToRight =
relationType === '1:M'
Expand Down Expand Up @@ -81,6 +101,8 @@ const DatabaseRelationshipComponent: React.FC<DatabaseRelationshipProps> = ({
)}
{relationType === 'M:1' &&
drawFork({ x: originXMinusFork, y: startCoords.y }, !isDrawLeftToRight)}

{drawClickableLine()}
</svg>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/pods/edit-realtion/edit-relation.pod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const EditRelationPod: React.FC<Props> = props => {

//TODO: Initialize 'relation' with existing values when the user clicks on 'relation' SVG
const [relation, setRelation] = React.useState<RelationVm>({
id: '20',
fromFieldId: '',
fromTableId: '',
toFieldId: '',
Expand Down
2 changes: 2 additions & 0 deletions src/pods/edit-table/edit-table.mapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,15 @@ describe('pods/edit-table/edit-table.mappers', () => {
};
const relation: canvasModel.RelationVm[] = [
{
id: '20',
fromTableId: '01',
toTableId: '02',
fromFieldId: '1',
toFieldId: '2',
type: '1:1',
},
{
id: '21',
fromTableId: '01',
toTableId: '02',
fromFieldId: '3',
Expand Down
7 changes: 7 additions & 0 deletions src/pods/export/export-table.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.input-content {
display: flex;
flex-direction: column;
align-items: start;
gap: 15px;
margin: 10px;
}
Loading

0 comments on commit 7f9c3c1

Please sign in to comment.