Skip to content

Commit

Permalink
feat: TableProperties layout
Browse files Browse the repository at this point in the history
  • Loading branch information
dineug committed Dec 4, 2023
1 parent bc3d4f7 commit dceb413
Show file tree
Hide file tree
Showing 26 changed files with 481 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ export const root = css`
}
`;

export const main = css`
export const scope = css`
${container};
`;
36 changes: 22 additions & 14 deletions packages/erd-editor/src/components/erd-editor/ErdEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,28 @@ const ErdEditor: FC<ErdEditorProps, ErdEditorElement> = (props, ctx) => {
@focusout=${handleFocusout}
>
<${Toolbar} />
<div class=${styles.main}>
${cache(
settings.canvasType === CanvasType.ERD ? html`<${Erd} />` : null
)}
${settings.canvasType === CanvasType.visualization
? html`<${Visualization} />`
: settings.canvasType === CanvasType.schemaSQL
? html`<${SchemaSQL} isDarkMode=${isDarkMode} />`
: settings.canvasType === CanvasType.generatorCode
? html`<${GeneratorCode} isDarkMode=${isDarkMode} />`
: settings.canvasType === CanvasType.settings
? html`<${Settings} />`
: null}
</div>
${cache(
settings.canvasType === CanvasType.ERD
? html`<div class=${styles.scope}><${Erd} /></div>`
: null
)}
${settings.canvasType === CanvasType.visualization
? html`<div class=${styles.scope}><${Visualization} /></div>`
: settings.canvasType === CanvasType.schemaSQL
? html`
<div class=${styles.scope}>
<${SchemaSQL} isDarkMode=${isDarkMode} />
</div>
`
: settings.canvasType === CanvasType.generatorCode
? html`
<div class=${styles.scope}>
<${GeneratorCode} isDarkMode=${isDarkMode} />
</div>
`
: settings.canvasType === CanvasType.settings
? html`<div class=${styles.scope}><${Settings} /></div>`
: null}
<${ToastContainer} />
${text.span}
</div>
Expand Down
31 changes: 22 additions & 9 deletions packages/erd-editor/src/components/erd/Erd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import ErdContextMenu, {
ErdContextMenuType,
} from '@/components/erd/erd-context-menu/ErdContextMenu';
import Minimap from '@/components/erd/minimap/Minimap';
import TableProperties from '@/components/erd/table-properties/TableProperties';
import ColorPicker from '@/components/primitives/color-picker/ColorPicker';
import { useContextMenuRootProvider } from '@/components/primitives/context-menu/context-menu-root/contextMenuRootContext';
import { Open } from '@/constants/open';
import {
changeColorAllAction$,
unselectAllAction$,
Expand Down Expand Up @@ -58,6 +60,7 @@ const Erd: FC<ErdProps> = (props, ctx) => {
colorPickerY: 0,
colorPickerViewport: null as Viewport | null,
colorPickerInitialColor: '',
tablePropertiesId: '',
});
useErdShortcut(ctx);

Expand Down Expand Up @@ -186,14 +189,17 @@ const Erd: FC<ErdProps> = (props, ctx) => {
closeColorPicker: () => {
state.colorPickerShow = false;
},
openTableProperties: ({ payload: { tableId } }) => {
state.tablePropertiesId = tableId;
},
})
);
});

return () => {
const { store } = app.value;
const {
editor: { drawRelationship, runAutomaticTablePlacement },
editor: { drawRelationship, openMap },
} = store.state;

const cursor = drawRelationship
Expand Down Expand Up @@ -225,13 +231,17 @@ const Erd: FC<ErdProps> = (props, ctx) => {
/>
`
: null}
<${ErdContextMenu}
type=${state.contextMenuType}
canvas=${canvas}
relationshipId=${state.relationshipId}
tableId=${state.tableId}
.onClose=${handleContextmenuClose}
/>
${contextMenu.state.show
? html`
<${ErdContextMenu}
type=${state.contextMenuType}
canvas=${canvas}
relationshipId=${state.relationshipId}
tableId=${state.tableId}
.onClose=${handleContextmenuClose}
/>
`
: null}
${state.colorPickerShow
? html`
<${ColorPicker}
Expand All @@ -243,7 +253,7 @@ const Erd: FC<ErdProps> = (props, ctx) => {
/>
`
: null}
${runAutomaticTablePlacement
${openMap[Open.automaticTablePlacement]
? html`
<div>
<${AutomaticTablePlacement}
Expand All @@ -253,6 +263,9 @@ const Erd: FC<ErdProps> = (props, ctx) => {
</div>
`
: null}
${openMap[Open.tableProperties]
? html`<${TableProperties} tableId=${state.tablePropertiesId} />`
: null}
</div>
`;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import Canvas from '@/components/erd/canvas/Canvas';
import Minimap from '@/components/erd/minimap/Minimap';
import Button from '@/components/primitives/button/Button';
import Toast from '@/components/primitives/toast/Toast';
import { Open } from '@/constants/open';
import { CANVAS_ZOOM_MIN } from '@/constants/schema';
import { endAutomaticTablePlacementAction } from '@/engine/modules/editor/atom.actions';
import { changeOpenMapAction } from '@/engine/modules/editor/atom.actions';
import { initialLoadJsonAction$ } from '@/engine/modules/editor/generator.actions';
import {
changeZoomLevelAction,
Expand Down Expand Up @@ -93,7 +94,9 @@ const AutomaticTablePlacement: FC<AutomaticTablePlacementProps> = (

const handleCancel = () => {
onClose();
prevApp.store.dispatch(endAutomaticTablePlacementAction());
prevApp.store.dispatch(
changeOpenMapAction({ [Open.automaticTablePlacement]: false })
);
};

if (!tables.length) {
Expand Down Expand Up @@ -144,9 +147,7 @@ const AutomaticTablePlacement: FC<AutomaticTablePlacementProps> = (
simulation.on('end', handleStop);
addUnsubscribe(
shortcut$.subscribe(({ type }) => {
if (type === KeyBindingName.stop) {
handleCancel();
}
type === KeyBindingName.stop && handleCancel();
})
);
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { FC, html, Ref } from '@dineug/r-html';
import { FC, html, onMounted, Ref } from '@dineug/r-html';

import { useAppContext } from '@/components/appContext';
import ContextMenu from '@/components/primitives/context-menu/ContextMenu';
import Icon from '@/components/primitives/icon/Icon';
import Kbd from '@/components/primitives/kbd/Kbd';
import { startAutomaticTablePlacementAction } from '@/engine/modules/editor/atom.actions';
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 { addTableAction$ } from '@/engine/modules/table/generator.actions';
import { changeColumnPrimaryKeyAction$ } from '@/engine/modules/table-column/generator.actions';
import { useUnmounted } from '@/hooks/useUnmounted';
import { ValuesType } from '@/internal-types';
import { query } from '@/utils/collection/query';
import { openColorPickerAction } from '@/utils/emitter';
import {
openColorPickerAction,
openTablePropertiesAction,
} from '@/utils/emitter';
import { KeyBindingName } from '@/utils/keyboard-shortcut';

import { createDatabaseMenus } from './menus/databaseMenus';
import { createDrawRelationshipMenus } from './menus/drawRelationshipMenus';
Expand All @@ -38,6 +44,7 @@ export type ErdContextMenuProps = {
const ErdContextMenu: FC<ErdContextMenuProps> = (props, ctx) => {
const app = useAppContext(ctx);
const chevronRightIcon = html`<${Icon} name="chevron-right" size=${14} />`;
const { addUnsubscribe } = useUnmounted();

const handleAddTable = () => {
const { store } = app.value;
Expand All @@ -53,7 +60,9 @@ const ErdContextMenu: FC<ErdContextMenuProps> = (props, ctx) => {

const handleAutomaticTablePlacement = () => {
const { store } = app.value;
store.dispatch(startAutomaticTablePlacementAction());
store.dispatch(
changeOpenMapAction({ [Open.automaticTablePlacement]: true })
);
props.onClose();
};

Expand Down Expand Up @@ -84,8 +93,10 @@ const ErdContextMenu: FC<ErdContextMenuProps> = (props, ctx) => {

const handleOpenTableProperties = () => {
if (!props.tableId) return;
// TODO: handleOpenTableProperties
console.log('handleOpenTableProperties');

const { store, emitter } = app.value;
emitter.emit(openTablePropertiesAction({ tableId: props.tableId }));
store.dispatch(changeOpenMapAction({ [Open.tableProperties]: true }));
props.onClose();
};

Expand All @@ -109,6 +120,16 @@ const ErdContextMenu: FC<ErdContextMenuProps> = (props, ctx) => {
props.onClose();
};

onMounted(() => {
const { shortcut$ } = app.value;

addUnsubscribe(
shortcut$.subscribe(({ type }) => {
type === KeyBindingName.stop && props.onClose();
})
);
});

return () => {
const { keyBindingMap } = app.value;

Expand Down
30 changes: 30 additions & 0 deletions packages/erd-editor/src/components/erd/erdShortcutPerformCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Observable } from 'rxjs';

import { Open } from '@/constants/open';
import { CanvasType } from '@/constants/schema';
import { RootState } from '@/engine/state';

export const erdShortcutPerformCheck =
({ editor, settings }: RootState) =>
<T>(source$: Observable<T>) =>
new Observable<T>(subscriber =>
source$.subscribe({
next: value => {
const showAutomaticTablePlacement =
editor.openMap[Open.automaticTablePlacement];
const showTableProperties = editor.openMap[Open.tableProperties];
const isCanvasType = settings.canvasType === CanvasType.ERD;

const canPerform =
isCanvasType &&
!showAutomaticTablePlacement &&
!showTableProperties;

if (canPerform) {
subscriber.next(value);
}
},
error: err => subscriber.error(err),
complete: () => subscriber.complete(),
})
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { css } from '@dineug/r-html';

export const root = css`
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
padding: 16px;
&::after {
content: '';
position: absolute;
inset: 0;
background-color: rgba(0, 0, 0, 0.5);
}
`;

export const container = css`
width: 100%;
max-width: 900px;
max-height: calc(100% - 32px);
overflow: auto;
z-index: 1;
border-radius: 6px;
padding: 12px;
background-color: var(--context-menu-background);
border: 1px solid var(--context-menu-border);
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { FC, html, onMounted } from '@dineug/r-html';

import { useAppContext } from '@/components/appContext';
import { Open } from '@/constants/open';
import { changeOpenMapAction } from '@/engine/modules/editor/atom.actions';
import { useUnmounted } from '@/hooks/useUnmounted';
import { onStop } from '@/utils/domEvent';
import { KeyBindingName } from '@/utils/keyboard-shortcut';

import * as styles from './TableProperties.styles';

export type TablePropertiesProps = {
tableId: string;
};

const TableProperties: FC<TablePropertiesProps> = (props, ctx) => {
const app = useAppContext(ctx);
const { addUnsubscribe } = useUnmounted();

const handleClose = () => {
const { store } = app.value;
store.dispatch(changeOpenMapAction({ [Open.tableProperties]: false }));
};

const handleOutsideClick = (event: MouseEvent) => {
const el = event.target as HTMLElement | null;
if (!el) return;

const canClose = !el.closest(`.${styles.container}`);
canClose && handleClose();
};

onMounted(() => {
const { shortcut$ } = app.value;

addUnsubscribe(
shortcut$.subscribe(({ type }) => {
type === KeyBindingName.stop && handleClose();
})
);
});

return () => html`
<div
class=${styles.root}
@contextmenu=${onStop}
@mousedown=${onStop}
@touchstart=${onStop}
@wheel=${onStop}
@click=${handleOutsideClick}
>
<div class=${['scrollbar', styles.container]}>
<div style=${{ width: '800px', height: '400px' }}>TableProperties</div>
</div>
</div>
`;
};

export default TableProperties;
Loading

0 comments on commit dceb413

Please sign in to comment.