Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/erd-editor-schema/src/v3/parser/table.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { isArray, isNill, isNumber, isObject, isString } from '@dineug/shared';
import {
isArray,
isBoolean,
isNill,
isNumber,
isObject,
isString,
} from '@dineug/shared';

import { assign, assignMeta, getDefaultEntityMeta } from '@/helper';
import { DeepPartial } from '@/internal-types';
Expand All @@ -19,6 +26,7 @@ export const createTable = (): Table => ({
color: '',
},
meta: getDefaultEntityMeta(),
ghost: false,
});

export function createAndMergeTableEntities(
Expand All @@ -32,6 +40,7 @@ export function createAndMergeTableEntities(
const target = createTable();
const assignString = assign(isString, target, value);
const assignArray = assign(isArray, target, value);
const assignBoolean = assign(isBoolean, target, value);
const uiAssignNumber = assign(isNumber, target.ui, value.ui);
const uiAssignString = assign(isString, target.ui, value.ui);

Expand All @@ -40,6 +49,7 @@ export function createAndMergeTableEntities(
assignString('comment');
assignArray('columnIds');
assignArray('seqColumnIds');
assignBoolean('ghost');

uiAssignString('color');
uiAssignNumber('x');
Expand Down
1 change: 1 addition & 0 deletions packages/erd-editor-schema/src/v3/schema/table.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type Table = EntityType<{
columnIds: string[];
seqColumnIds: string[];
ui: TableUI;
ghost: boolean;
}>;

export type TableUI = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ const Table: FC<TableProps> = (props, ctx) => {
'z-index': `${table.ui.zIndex}`,
width: `${tableWidths.width}px`,
height: `${height}px`,
opacity: `${table.ghost ? 0.33 : 1}`,
}}
${ref(root)}
?data-selected=${selected}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Open } from '@/constants/open';
import { changeOpenMapAction } from '@/engine/modules/editor/atom.actions';
import { addMemoAction$ } from '@/engine/modules/memo/generator.actions';
import { removeRelationshipAction } from '@/engine/modules/relationship/atom.actions';
import { toggleGhostAction } from '@/engine/modules/table/atom.actions';
import { addTableAction$ } from '@/engine/modules/table/generator.actions';
import { changeColumnPrimaryKeyAction$ } from '@/engine/modules/table-column/generator.actions';
import { useUnmounted } from '@/hooks/useUnmounted';
Expand Down Expand Up @@ -107,6 +108,15 @@ const ErdContextMenu: FC<ErdContextMenuProps> = (props, ctx) => {
props.onClose();
};

const handleToggleGhost = (event: MouseEvent) => {
if (!props.tableId) return;

const { store } = app.value;
store.dispatch(toggleGhostAction({ id: props.tableId }));

props.onClose();
};

const handleOpenColorPicker = (event: MouseEvent) => {
if (!props.tableId) return;

Expand Down Expand Up @@ -183,6 +193,15 @@ const ErdContextMenu: FC<ErdContextMenuProps> = (props, ctx) => {
/>
`}
/>
<${ContextMenu.Item}
.onClick=${handleToggleGhost}
children=${html`
<${ContextMenu.Menu}
icon=${html`<${Icon} name="ghost" size=${14} />`}
name="Toggle Ghost"
/>
`}
/>
`
: props.type === ErdContextMenuType.relationship
? html`
Expand Down
2 changes: 2 additions & 0 deletions packages/erd-editor/src/components/primitives/icon/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
faFileExport,
faFileImage,
faFileImport,
faGhost,
faKey,
faLocationDot,
faMagnifyingGlass,
Expand Down Expand Up @@ -128,6 +129,7 @@ const icons = [
faBars,
faLocationDot,
faCircleHalfStroke,
faGhost,
createMDI('code-json', mdiCodeJson),
createMDI('database', mdiDatabase),
createMDI('database-import', mdiDatabaseImport),
Expand Down
2 changes: 1 addition & 1 deletion packages/erd-editor/src/components/schema-sql/SchemaSQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const SchemaSQL: FC<SchemaSQLProps> = (props, ctx) => {
.collection('tableEntities')
.selectById(props.tableId);

if (table) {
if (table && !table.ghost) {
state.sql = createSchemaSQLTable(store.state, table);
}
} else {
Expand Down
1 change: 1 addition & 0 deletions packages/erd-editor/src/engine/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const ChangeActionTypes: ReadonlyArray<ActionType> = [
'table.changeComment',
'table.changeColor',
'table.sort',
'table.toggleGhost',
// column
'column.add',
'column.remove',
Expand Down
4 changes: 4 additions & 0 deletions packages/erd-editor/src/engine/modules/table/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const ActionType = {
changeTableColor: 'table.changeColor',
changeZIndex: 'table.changeZIndex',
sortTable: 'table.sort',
toggleGhost: 'table.toggleGhost',
} as const;
export type ActionType = ValuesType<typeof ActionType>;

Expand Down Expand Up @@ -51,6 +52,9 @@ export type ActionMap = {
zIndex: number;
};
[ActionType.sortTable]: void;
[ActionType.toggleGhost]: {
id: string;
};
};

export type ReducerType<T extends keyof ActionMap> = Reducer<
Expand Down
21 changes: 20 additions & 1 deletion packages/erd-editor/src/engine/modules/table/atom.actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { query } from '@dineug/erd-editor-schema';
import { createAction } from '@dineug/r-html';
import { createAction, Reducer } from '@dineug/r-html';
import { arrayHas } from '@dineug/shared';
import { round } from 'lodash-es';

Expand Down Expand Up @@ -147,6 +147,23 @@ const changeTableColor: ReducerType<typeof ActionType.changeTableColor> = (
});
};

export const toggleGhostAction = createAction<
ActionMap[typeof ActionType.toggleGhost]
>(ActionType.toggleGhost);

const toggleGhost: ReducerType<typeof ActionType.toggleGhost> = (
{ collections, lww },
{ payload: { id }, version },
{ clock }
) => {
const collection = query(collections).collection('tableEntities');
collection.getOrCreate(id, id => createTable({ id }));

collection.updateOne(id, table => {
table.ghost = !table.ghost;
});
};

export const changeZIndexAction = createAction<
ActionMap[typeof ActionType.changeZIndex]
>(ActionType.changeZIndex);
Expand Down Expand Up @@ -211,6 +228,7 @@ export const tableReducers = {
[ActionType.changeTableColor]: changeTableColor,
[ActionType.changeZIndex]: changeZIndex,
[ActionType.sortTable]: sortTable,
[ActionType.toggleGhost]: toggleGhost,
};

export const actions = {
Expand All @@ -223,4 +241,5 @@ export const actions = {
changeTableColorAction,
changeZIndexAction,
sortTableAction,
toggleGhostAction,
};
1 change: 1 addition & 0 deletions packages/erd-editor/src/utils/collection/table.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const createTable = (value?: DeepPartial<Table>): Table =>
color: '',
},
meta: getDefaultEntityMeta(),
ghost: false,
},
(value as Table) ?? {}
);
21 changes: 19 additions & 2 deletions packages/erd-editor/src/utils/schema-sql/MSSQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,30 @@ export function createSchema(state: RootState): string {
const tables = query(collections)
.collection('tableEntities')
.selectByIds(tableIds)
.filter(table => !table.ghost)
.sort(orderByNameASC);
const relationships = query(collections)
.collection('relationshipEntities')
.selectByIds(relationshipIds);
.selectByIds(relationshipIds)
.filter(
rel =>
!(
query(collections)
.collection('tableEntities')
.selectById(rel.end.tableId)!.ghost &&
query(collections)
.collection('tableEntities')
.selectById(rel.start.tableId)!.ghost
)
);
const indexes = query(collections)
.collection('indexEntities')
.selectByIds(indexIds);
.selectByIds(indexIds)
.filter(index => {
return !query(collections)
.collection('tableEntities')
.selectById(index.tableId)!.ghost;
});

tables.forEach(table => {
formatTable(state, { table, buffer: stringBuffer });
Expand Down
21 changes: 19 additions & 2 deletions packages/erd-editor/src/utils/schema-sql/MariaDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,30 @@ export function createSchema(state: RootState): string {
const tables = query(collections)
.collection('tableEntities')
.selectByIds(tableIds)
.filter(table => !table.ghost)
.sort(orderByNameASC);
const relationships = query(collections)
.collection('relationshipEntities')
.selectByIds(relationshipIds);
.selectByIds(relationshipIds)
.filter(
rel =>
!(
query(collections)
.collection('tableEntities')
.selectById(rel.end.tableId)!.ghost &&
query(collections)
.collection('tableEntities')
.selectById(rel.start.tableId)!.ghost
)
);
const indexes = query(collections)
.collection('indexEntities')
.selectByIds(indexIds);
.selectByIds(indexIds)
.filter(index => {
return !query(collections)
.collection('tableEntities')
.selectById(index.tableId)!.ghost;
});

tables.forEach(table => {
formatTable(state, { table, buffer: stringBuffer });
Expand Down
21 changes: 19 additions & 2 deletions packages/erd-editor/src/utils/schema-sql/MySQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,30 @@ export function createSchema(state: RootState): string {
const tables = query(collections)
.collection('tableEntities')
.selectByIds(tableIds)
.filter(table => !table.ghost)
.sort(orderByNameASC);
const relationships = query(collections)
.collection('relationshipEntities')
.selectByIds(relationshipIds);
.selectByIds(relationshipIds)
.filter(
rel =>
!(
query(collections)
.collection('tableEntities')
.selectById(rel.end.tableId)!.ghost &&
query(collections)
.collection('tableEntities')
.selectById(rel.start.tableId)!.ghost
)
);
const indexes = query(collections)
.collection('indexEntities')
.selectByIds(indexIds);
.selectByIds(indexIds)
.filter(index => {
return !query(collections)
.collection('tableEntities')
.selectById(index.tableId)!.ghost;
});

tables.forEach(table => {
formatTable(state, { table, buffer: stringBuffer });
Expand Down
21 changes: 19 additions & 2 deletions packages/erd-editor/src/utils/schema-sql/Oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,30 @@ export function createSchema(state: RootState): string {
const tables = query(collections)
.collection('tableEntities')
.selectByIds(tableIds)
.filter(table => !table.ghost)
.sort(orderByNameASC);
const relationships = query(collections)
.collection('relationshipEntities')
.selectByIds(relationshipIds);
.selectByIds(relationshipIds)
.filter(
rel =>
!(
query(collections)
.collection('tableEntities')
.selectById(rel.end.tableId)!.ghost &&
query(collections)
.collection('tableEntities')
.selectById(rel.start.tableId)!.ghost
)
);
const indexes = query(collections)
.collection('indexEntities')
.selectByIds(indexIds);
.selectByIds(indexIds)
.filter(index => {
return !query(collections)
.collection('tableEntities')
.selectById(index.tableId)!.ghost;
});

tables.forEach(table => {
formatTable(state, { table, buffer: stringBuffer });
Expand Down
21 changes: 19 additions & 2 deletions packages/erd-editor/src/utils/schema-sql/PostgreSQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,30 @@ export function createSchema(state: RootState): string {
const tables = query(collections)
.collection('tableEntities')
.selectByIds(tableIds)
.filter(table => !table.ghost)
.sort(orderByNameASC);
const relationships = query(collections)
.collection('relationshipEntities')
.selectByIds(relationshipIds);
.selectByIds(relationshipIds)
.filter(
rel =>
!(
query(collections)
.collection('tableEntities')
.selectById(rel.end.tableId)!.ghost &&
query(collections)
.collection('tableEntities')
.selectById(rel.start.tableId)!.ghost
)
);
const indexes = query(collections)
.collection('indexEntities')
.selectByIds(indexIds);
.selectByIds(indexIds)
.filter(index => {
return !query(collections)
.collection('tableEntities')
.selectById(index.tableId)!.ghost;
});

tables.forEach(table => {
formatTable(state, { table, buffer: stringBuffer });
Expand Down
8 changes: 7 additions & 1 deletion packages/erd-editor/src/utils/schema-sql/SQLite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ export function createSchema(state: RootState): string {
const tables = query(collections)
.collection('tableEntities')
.selectByIds(tableIds)
.filter(table => !table.ghost)
.sort(orderByNameASC);
const indexes = query(collections)
.collection('indexEntities')
.selectByIds(indexIds);
.selectByIds(indexIds)
.filter(index => {
return !query(collections)
.collection('tableEntities')
.selectById(index.tableId)!.ghost;
});

tables.forEach(table => {
formatTable(state, { table, buffer: stringBuffer });
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vuerd-vscode",
"version": "2.1.0",
"version": "2.2.0",
"private": true,
"description": "Entity-Relationship Diagram Editor VSCode Extension",
"icon": "./assets/erd-editor.png",
Expand Down