Skip to content

Commit 2a6de07

Browse files
committed
feature: mark table as "ghost" to exclude from schema output #410
1 parent ad02a2f commit 2a6de07

17 files changed

Lines changed: 164 additions & 15 deletions

File tree

packages/erd-editor-schema/src/v3/parser/table.entity.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { isArray, isNill, isNumber, isObject, isString } from '@dineug/shared';
1+
import {
2+
isArray,
3+
isBoolean,
4+
isNill,
5+
isNumber,
6+
isObject,
7+
isString,
8+
} from '@dineug/shared';
29

310
import { assign, assignMeta, getDefaultEntityMeta } from '@/helper';
411
import { DeepPartial } from '@/internal-types';
@@ -19,6 +26,7 @@ export const createTable = (): Table => ({
1926
color: '',
2027
},
2128
meta: getDefaultEntityMeta(),
29+
ghost: false,
2230
});
2331

2432
export function createAndMergeTableEntities(
@@ -32,6 +40,7 @@ export function createAndMergeTableEntities(
3240
const target = createTable();
3341
const assignString = assign(isString, target, value);
3442
const assignArray = assign(isArray, target, value);
43+
const assignBoolean = assign(isBoolean, target, value);
3544
const uiAssignNumber = assign(isNumber, target.ui, value.ui);
3645
const uiAssignString = assign(isString, target.ui, value.ui);
3746

@@ -40,6 +49,7 @@ export function createAndMergeTableEntities(
4049
assignString('comment');
4150
assignArray('columnIds');
4251
assignArray('seqColumnIds');
52+
assignBoolean('ghost');
4353

4454
uiAssignString('color');
4555
uiAssignNumber('x');

packages/erd-editor-schema/src/v3/schema/table.entity.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type Table = EntityType<{
77
columnIds: string[];
88
seqColumnIds: string[];
99
ui: TableUI;
10+
ghost: boolean;
1011
}>;
1112

1213
export type TableUI = {

packages/erd-editor/src/components/erd/canvas/table/Table.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ const Table: FC<TableProps> = (props, ctx) => {
248248
'z-index': `${table.ui.zIndex}`,
249249
width: `${tableWidths.width}px`,
250250
height: `${height}px`,
251+
opacity: `${table.ghost ? 0.33 : 1}`,
251252
}}
252253
${ref(root)}
253254
?data-selected=${selected}

packages/erd-editor/src/components/erd/erd-context-menu/ErdContextMenu.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Open } from '@/constants/open';
99
import { changeOpenMapAction } from '@/engine/modules/editor/atom.actions';
1010
import { addMemoAction$ } from '@/engine/modules/memo/generator.actions';
1111
import { removeRelationshipAction } from '@/engine/modules/relationship/atom.actions';
12+
import { toggleGhostAction } from '@/engine/modules/table/atom.actions';
1213
import { addTableAction$ } from '@/engine/modules/table/generator.actions';
1314
import { changeColumnPrimaryKeyAction$ } from '@/engine/modules/table-column/generator.actions';
1415
import { useUnmounted } from '@/hooks/useUnmounted';
@@ -107,6 +108,15 @@ const ErdContextMenu: FC<ErdContextMenuProps> = (props, ctx) => {
107108
props.onClose();
108109
};
109110

111+
const handleToggleGhost = (event: MouseEvent) => {
112+
if (!props.tableId) return;
113+
114+
const { store } = app.value;
115+
store.dispatch(toggleGhostAction({ id: props.tableId }));
116+
117+
props.onClose();
118+
};
119+
110120
const handleOpenColorPicker = (event: MouseEvent) => {
111121
if (!props.tableId) return;
112122

@@ -183,6 +193,15 @@ const ErdContextMenu: FC<ErdContextMenuProps> = (props, ctx) => {
183193
/>
184194
`}
185195
/>
196+
<${ContextMenu.Item}
197+
.onClick=${handleToggleGhost}
198+
children=${html`
199+
<${ContextMenu.Menu}
200+
icon=${html`<${Icon} name="ghost" size=${14} />`}
201+
name="Toggle Ghost"
202+
/>
203+
`}
204+
/>
186205
`
187206
: props.type === ErdContextMenuType.relationship
188207
? html`

packages/erd-editor/src/components/primitives/icon/icons.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
faFileExport,
1313
faFileImage,
1414
faFileImport,
15+
faGhost,
1516
faKey,
1617
faLocationDot,
1718
faMagnifyingGlass,
@@ -128,6 +129,7 @@ const icons = [
128129
faBars,
129130
faLocationDot,
130131
faCircleHalfStroke,
132+
faGhost,
131133
createMDI('code-json', mdiCodeJson),
132134
createMDI('database', mdiDatabase),
133135
createMDI('database-import', mdiDatabaseImport),

packages/erd-editor/src/components/schema-sql/SchemaSQL.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const SchemaSQL: FC<SchemaSQLProps> = (props, ctx) => {
4343
.collection('tableEntities')
4444
.selectById(props.tableId);
4545

46-
if (table) {
46+
if (table && !table.ghost) {
4747
state.sql = createSchemaSQLTable(store.state, table);
4848
}
4949
} else {

packages/erd-editor/src/engine/actions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export const ChangeActionTypes: ReadonlyArray<ActionType> = [
8686
'table.changeComment',
8787
'table.changeColor',
8888
'table.sort',
89+
'table.toggleGhost',
8990
// column
9091
'column.add',
9192
'column.remove',

packages/erd-editor/src/engine/modules/table/actions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const ActionType = {
1414
changeTableColor: 'table.changeColor',
1515
changeZIndex: 'table.changeZIndex',
1616
sortTable: 'table.sort',
17+
toggleGhost: 'table.toggleGhost',
1718
} as const;
1819
export type ActionType = ValuesType<typeof ActionType>;
1920

@@ -51,6 +52,9 @@ export type ActionMap = {
5152
zIndex: number;
5253
};
5354
[ActionType.sortTable]: void;
55+
[ActionType.toggleGhost]: {
56+
id: string;
57+
};
5458
};
5559

5660
export type ReducerType<T extends keyof ActionMap> = Reducer<

packages/erd-editor/src/engine/modules/table/atom.actions.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { query } from '@dineug/erd-editor-schema';
2-
import { createAction } from '@dineug/r-html';
2+
import { createAction, Reducer } from '@dineug/r-html';
33
import { arrayHas } from '@dineug/shared';
44
import { round } from 'lodash-es';
55

@@ -147,6 +147,23 @@ const changeTableColor: ReducerType<typeof ActionType.changeTableColor> = (
147147
});
148148
};
149149

150+
export const toggleGhostAction = createAction<
151+
ActionMap[typeof ActionType.toggleGhost]
152+
>(ActionType.toggleGhost);
153+
154+
const toggleGhost: ReducerType<typeof ActionType.toggleGhost> = (
155+
{ collections, lww },
156+
{ payload: { id }, version },
157+
{ clock }
158+
) => {
159+
const collection = query(collections).collection('tableEntities');
160+
collection.getOrCreate(id, id => createTable({ id }));
161+
162+
collection.updateOne(id, table => {
163+
table.ghost = !table.ghost;
164+
});
165+
};
166+
150167
export const changeZIndexAction = createAction<
151168
ActionMap[typeof ActionType.changeZIndex]
152169
>(ActionType.changeZIndex);
@@ -211,6 +228,7 @@ export const tableReducers = {
211228
[ActionType.changeTableColor]: changeTableColor,
212229
[ActionType.changeZIndex]: changeZIndex,
213230
[ActionType.sortTable]: sortTable,
231+
[ActionType.toggleGhost]: toggleGhost,
214232
};
215233

216234
export const actions = {
@@ -223,4 +241,5 @@ export const actions = {
223241
changeTableColorAction,
224242
changeZIndexAction,
225243
sortTableAction,
244+
toggleGhostAction,
226245
};

packages/erd-editor/src/utils/collection/table.entity.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const createTable = (value?: DeepPartial<Table>): Table =>
2222
color: '',
2323
},
2424
meta: getDefaultEntityMeta(),
25+
ghost: false,
2526
},
2627
(value as Table) ?? {}
2728
);

0 commit comments

Comments
 (0)