Skip to content

Commit

Permalink
Merge pull request #113 from Lemoncode/feature/#85-Edit-table-edit-ta…
Browse files Browse the repository at this point in the history
…ble-name

Feature/#85 edit table edit table name
  • Loading branch information
brauliodiez authored Jan 15, 2024
2 parents f79560c + e4ec7ff commit a11ff41
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 40 deletions.
8 changes: 0 additions & 8 deletions src/common/components/modal-dialog/modal-dialog.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ export const ModalDialog: React.FC = () => {
<div className={styles.dialog} role="dialog">
<div className={styles.dialogHeader}>
<h2 className={styles.dialogTitle}>{modalDialog.title}</h2>
{modalDialog.subtitle && (
<>
<span>&gt;</span>
<h3 className={styles.dialogSubtitle}>
{modalDialog.subtitle}
</h3>
</>
)}
<button className={styles.dialogButton} onClick={handleClick}>
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,16 @@ export interface ModalDialogModel {
isOpen: boolean;
selectedComponent: React.ReactNode | null;
title: string;
subtitle?: string;
}

export const createInitialModalDialog = (): ModalDialogModel => ({
isOpen: false,
selectedComponent: null,
title: '',
subtitle: undefined,
});

export interface ModalDialogContextModel {
openModal: (
component: React.ReactNode | null,
title: string,
subtitle?: string
) => void;
openModal: (component: React.ReactNode | null, title: string) => void;
closeModal: () => void;
modalDialog: ModalDialogModel;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,11 @@ export const ModalDialogProvider: React.FC<Props> = props => {
createInitialModalDialog()
);

const openModal = (
component: React.ReactNode | null,
title: string,
subtitle?: string
) => {
const openModal = (component: React.ReactNode | null, title: string) => {
setModalDialog({
isOpen: true,
selectedComponent: component,
title,
subtitle,
});
};

Expand All @@ -33,7 +28,6 @@ export const ModalDialogProvider: React.FC<Props> = props => {
isOpen: false,
selectedComponent: null,
title: '',
subtitle: undefined,
});
};
return (
Expand Down
3 changes: 1 addition & 2 deletions src/pods/canvas/canvas.pod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ export const CanvasPod: React.FC = () => {
relations={canvasSchema.relations}
onSave={handleTableEditUpdate}
/>,
EDIT_TABLE_TITLE,
tableInfo.tableName
EDIT_TABLE_TITLE
);
};

Expand Down
49 changes: 36 additions & 13 deletions src/pods/edit-table/edit-table.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ interface Props {
) => void;
onDeleteField: (fieldId: GUID) => void;
onAddField: (fieldId: GUID, isChildren: boolean) => void;
updateTableName: (value: string) => void;
}

export const EditTableComponent: React.FC<Props> = props => {
const { table, updateFieldValue, onDeleteField, onAddField } = props;
const {
table,
updateFieldValue,
onDeleteField,
onAddField,
updateTableName,
} = props;
const [expandedFields, setExpandedFields] = useState<Set<string>>(new Set());

const expandField = (fieldId: string) => {
Expand All @@ -41,18 +48,34 @@ export const EditTableComponent: React.FC<Props> = props => {
});
};

const handleChangeTableName = (e: React.ChangeEvent<HTMLInputElement>) => {
updateTableName(e.currentTarget.value);
};

return (
<div className={classes.tableEditor}>
<NestedFieldGrid
fields={table.fields}
level={0}
expandedFields={expandedFields}
toggleExpand={toggleExpand}
expandField={expandField}
updateFieldValue={updateFieldValue}
onDeleteField={onDeleteField}
onAddField={onAddField}
/>
</div>
<>
<div className={classes.tableName}>
<label>
Table:
<input
type="text"
value={table.tableName}
onChange={handleChangeTableName}
/>
</label>
</div>
<div className={classes.tableEditor}>
<NestedFieldGrid
fields={table.fields}
level={0}
expandedFields={expandedFields}
toggleExpand={toggleExpand}
expandField={expandField}
updateFieldValue={updateFieldValue}
onDeleteField={onDeleteField}
onAddField={onAddField}
/>
</div>
</>
);
};
17 changes: 17 additions & 0 deletions src/pods/edit-table/edit-table.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,20 @@
.indent7 {
margin-left: 140px;
}

.table-name {
position: sticky;
top: 40px;
left: 0px;
padding-top: 10px;
padding-bottom: 10px;
z-index: 2;
text-align: left;
background-color: var(--primary-background);
border-bottom: 1px solid #ccc;
}
.table-name label {
display: flex;
align-items: baseline;
gap: 10px;
}
5 changes: 4 additions & 1 deletion src/pods/edit-table/edit-table.pod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,17 @@ export const EditTablePod: React.FC<Props> = props => {
addFieldLogic(currentTable, fieldId, isChildren)
);
};

const updateTableName = (tableName: string) => {
setEditTable({ ...editTable, tableName });
};
return (
<>
<EditTableComponent
table={editTable}
updateFieldValue={updateFieldValue}
onDeleteField={onDeleteField}
onAddField={onAddField}
updateTableName={updateTableName}
/>
<button onClick={() => handleSubmit(editTable)}>Apply</button>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export const EditButton = () => {
relations={canvasSchema.relations}
onSave={handleAddTable}
/>,
EDIT_TABLE_TITLE,
'New Table'
EDIT_TABLE_TITLE
);
};
return (
Expand Down

0 comments on commit a11ff41

Please sign in to comment.