Skip to content

Commit 35df361

Browse files
data table margin fix
1 parent db2bc20 commit 35df361

File tree

5 files changed

+174
-86
lines changed

5 files changed

+174
-86
lines changed

main.js

Lines changed: 86 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
const {
2-
app, BrowserWindow, Menu, shell, dialog, ipcMain,
3-
} = require('electron');
2+
app,
3+
BrowserWindow,
4+
Menu,
5+
shell,
6+
dialog,
7+
ipcMain
8+
} = require("electron");
49

510
// Uncomment below for hot reloading during development
6-
require('electron-reload')(__dirname);
11+
require("electron-reload")(__dirname);
712

813
// const isDev = true;
9-
const isDev = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';
14+
const isDev =
15+
process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
1016

1117
// Keep a global reference of the window object, if you don't, the window will
1218
// be closed automatically when the JavaScript object is garbage collected.
@@ -16,76 +22,76 @@ let mainWindow;
1622
function openFile() {
1723
// Opens file dialog looking for markdown
1824
const files = dialog.showOpenDialog(mainWindow, {
19-
properties: ['openFile'],
25+
properties: ["openFile"],
2026
filters: [
2127
{
22-
name: 'Images',
23-
extensions: ['jpeg', 'jpg', 'png', 'gif', 'pdf'],
24-
},
25-
],
28+
name: "Images",
29+
extensions: ["jpeg", "jpg", "png", "gif", "pdf"]
30+
}
31+
]
2632
});
2733

2834
// if no files
2935
if (!files) return;
3036
const file = files[0];
3137

3238
// Send fileContent to renderer
33-
mainWindow.webContents.send('new-file', file);
39+
mainWindow.webContents.send("new-file", file);
3440
}
3541

3642
// Choose directory
37-
ipcMain.on('choose_app_dir', (event) => {
43+
ipcMain.on("choose_app_dir", event => {
3844
const directory = dialog.showOpenDialog(mainWindow, {
39-
properties: ['openDirectory'],
40-
buttonLabel: 'Export',
45+
properties: ["openDirectory"],
46+
buttonLabel: "Export"
4147
});
4248

4349
if (!directory) return;
44-
event.sender.send('app_dir_selected', directory[0]);
50+
event.sender.send("app_dir_selected", directory[0]);
4551
});
4652

47-
ipcMain.on('view_app_dir', (event, appDir) => {
53+
ipcMain.on("view_app_dir", (event, appDir) => {
4854
shell.openItem(appDir);
4955
});
5056

5157
// Update file
52-
ipcMain.on('update-file', () => {
58+
ipcMain.on("update-file", () => {
5359
openFile();
5460
});
5561

5662
const createWindow = () => {
5763
// Create the browser window.
5864
// eslint-disable-next-line
59-
const { width, height } = require('electron').screen.getPrimaryDisplay().size;
65+
const { width, height } = require("electron").screen.getPrimaryDisplay().size;
6066
mainWindow = new BrowserWindow({
6167
width,
6268
height,
6369
webPreferences: {
64-
zoomFactor: 0.9,
65-
'node-Integration': false,
70+
zoomFactor: 0.7,
71+
"node-Integration": false
6672
},
67-
show: false,
73+
show: false
6874
});
6975

7076
// and load the index.html of the app.
7177
mainWindow.loadURL(`file://${__dirname}/build/index.html`);
7278
// load page once window is loaded
73-
mainWindow.once('ready-to-show', () => {
79+
mainWindow.once("ready-to-show", () => {
7480
mainWindow.show();
7581
});
7682

7783
const template = [
7884
{
79-
label: 'File',
85+
label: "File",
8086
submenu: [
8187
{
82-
label: 'Open File',
83-
accelerator: process.platform === 'darwin' ? 'Cmd+O' : 'Ctrl+Shift+O',
88+
label: "Open File",
89+
accelerator: process.platform === "darwin" ? "Cmd+O" : "Ctrl+Shift+O",
8490
click() {
8591
openFile();
86-
},
87-
},
88-
],
92+
}
93+
}
94+
]
8995
},
9096
// {
9197
// label: 'Edit',
@@ -102,89 +108,90 @@ const createWindow = () => {
102108
// ],
103109
// },
104110
{
105-
label: 'View',
111+
label: "View",
106112
submenu: [
107-
{ role: 'reload' },
108-
{ role: 'forcereload' },
109-
{ type: 'separator' },
110-
{ role: 'resetzoom' },
111-
{ role: 'zoomin' },
112-
{ role: 'zoomout' },
113-
{ type: 'separator' },
114-
{ role: 'togglefullscreen' },
115-
],
113+
{ role: "reload" },
114+
{ role: "forcereload" },
115+
{ type: "separator" },
116+
{ role: "resetzoom" },
117+
{ role: "zoomin" },
118+
{ role: "zoomout" },
119+
{ type: "separator" },
120+
{ role: "togglefullscreen" }
121+
]
116122
},
117123
{
118-
role: 'window',
119-
submenu: [{ role: 'minimize' }, { role: 'close' }],
124+
role: "window",
125+
submenu: [{ role: "minimize" }, { role: "close" }]
120126
},
121127
{
122-
role: 'help',
128+
role: "help",
123129
submenu: [
124130
{
125-
label: 'Learn More',
131+
label: "Learn More",
126132
click() {
127-
shell.openExternal('https://electronjs.org');
128-
},
129-
},
130-
],
133+
shell.openExternal("https://electronjs.org");
134+
}
135+
}
136+
]
131137
},
132138
{
133-
label: 'Developer',
139+
label: "Developer",
134140
submenu: [
135141
{
136-
label: 'Toggle Developer Tools',
137-
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
142+
label: "Toggle Developer Tools",
143+
accelerator:
144+
process.platform === "darwin" ? "Alt+Command+I" : "Ctrl+Shift+I",
138145
click() {
139146
mainWindow.webContents.toggleDevTools();
140-
},
141-
},
142-
],
143-
},
147+
}
148+
}
149+
]
150+
}
144151
];
145152

146-
if (process.platform === 'darwin') {
153+
if (process.platform === "darwin") {
147154
template.unshift({
148155
label: app.getName(),
149156
submenu: [
150-
{ role: 'about' },
151-
{ type: 'separator' },
152-
{ role: 'services', submenu: [] },
153-
{ type: 'separator' },
154-
{ role: 'hide' },
155-
{ role: 'hideothers' },
156-
{ role: 'unhide' },
157-
{ type: 'separator' },
158-
{ role: 'quit' },
159-
],
157+
{ role: "about" },
158+
{ type: "separator" },
159+
{ role: "services", submenu: [] },
160+
{ type: "separator" },
161+
{ role: "hide" },
162+
{ role: "hideothers" },
163+
{ role: "unhide" },
164+
{ type: "separator" },
165+
{ role: "quit" }
166+
]
160167
});
161168

162169
// Edit menu
163170
template[2].submenu.push(
164171
{
165-
type: 'separator',
172+
type: "separator"
166173
},
167174
{
168-
label: 'Speech',
169-
submenu: [{ role: 'startspeaking' }, { role: 'stopspeaking' }],
170-
},
175+
label: "Speech",
176+
submenu: [{ role: "startspeaking" }, { role: "stopspeaking" }]
177+
}
171178
);
172179

173180
// Window menu
174181
template[4].submenu = [
175-
{ role: 'close' },
176-
{ role: 'minimize' },
177-
{ role: 'zoom' },
178-
{ type: 'separator' },
179-
{ role: 'front' },
182+
{ role: "close" },
183+
{ role: "minimize" },
184+
{ role: "zoom" },
185+
{ type: "separator" },
186+
{ role: "front" }
180187
];
181188
}
182189

183190
const menu = Menu.buildFromTemplate(template);
184191
Menu.setApplicationMenu(menu);
185192

186193
// Emitted when the window is closed.
187-
mainWindow.on('closed', () => {
194+
mainWindow.on("closed", () => {
188195
// Dereference the window object, usually you would store windows
189196
// in an array if your app supports multi windows, this is the time
190197
// when you should delete the corresponding element.
@@ -195,13 +202,13 @@ const createWindow = () => {
195202
// This method will be called when Electron has finished
196203
// initialization and is ready to create browser windows.
197204
// Some APIs can only be used after this event occurs.
198-
app.on('ready', () => {
205+
app.on("ready", () => {
199206
if (isDev) {
200207
const {
201208
default: installExtension,
202209
REACT_DEVELOPER_TOOLS,
203-
REDUX_DEVTOOLS,
204-
} = require('electron-devtools-installer');
210+
REDUX_DEVTOOLS
211+
} = require("electron-devtools-installer");
205212

206213
installExtension([REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS])
207214
.then(() => {
@@ -214,15 +221,15 @@ app.on('ready', () => {
214221
});
215222

216223
// Quit when all windows are closed.
217-
app.on('window-all-closed', () => {
224+
app.on("window-all-closed", () => {
218225
// On OS X it is common for applications and their menu bar
219226
// to stay active until the user quits explicitly with Cmd + Q
220-
if (process.platform !== 'darwin') {
227+
if (process.platform !== "darwin") {
221228
app.quit();
222229
}
223230
});
224231

225-
app.on('activate', () => {
232+
app.on("activate", () => {
226233
// On OS X it's common to re-create a window in the app when the
227234
// dock icon is clicked and there are no other windows open.
228235
if (mainWindow === null) {

src/components/DataTable.tsx

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import React from "react";
2+
// import PropTypes from 'prop-types';
3+
import { withStyles } from "@material-ui/core/styles";
4+
import Table from "@material-ui/core/Table";
5+
import TableBody from "@material-ui/core/TableBody";
6+
import TableCell from "@material-ui/core/TableCell";
7+
import TableHead from "@material-ui/core/TableHead";
8+
import TableRow from "@material-ui/core/TableRow";
9+
import Paper from "@material-ui/core/Paper";
10+
import Button from "@material-ui/core/Button";
11+
import DeleteIcon from "@material-ui/icons/Delete";
12+
import { IconButton } from "@material-ui/core";
13+
14+
const styles = (theme: any) => ({
15+
root: {
16+
width: "80%",
17+
marginTop: theme.spacing.unit * 3,
18+
marginRight: "100px"
19+
// overflowX: "auto"
20+
},
21+
table: {
22+
minWidth: 500,
23+
marginRight: "100px"
24+
}
25+
});
26+
27+
/** **************************
28+
* cannot have a row header or a key in the data called "key"
29+
* ,ust have unique id
30+
* ****************************** */
31+
32+
function dataTable(props: any) {
33+
const { classes, rowData, rowHeader, deletePropHandler } = props;
34+
35+
const renderHeader = rowHeader.map((col: any, idx: number) => (
36+
<TableCell key={`head_+${idx}`}>{col}</TableCell>
37+
));
38+
39+
function renderRowCells(row: any) {
40+
if (!row) return;
41+
// for some reason we must put each value in a div.
42+
return rowHeader.map((header: string, idx: number) => (
43+
<TableCell align={"center"} key={`td_${idx}`}>
44+
{/* <div align={'center'} padding = {'none'} >{typeof row[header] === 'string' ? row[header] : row[header].toString()}</div> */}
45+
{/* {row[header]} */}
46+
{typeof row[header] === "string" ? row[header] : row[header].toString()}
47+
</TableCell>
48+
));
49+
}
50+
// style={{height: 30}}
51+
const renderRows = rowData.map((row: any) => (
52+
<TableRow key={`row-${row.id}`}>
53+
{renderRowCells(row)}
54+
<TableCell align={"center"} padding={"none"}>
55+
<IconButton
56+
color="default"
57+
fontSize="small"
58+
onClick={() => deletePropHandler(row.id)}
59+
>
60+
<DeleteIcon />
61+
</IconButton>
62+
{/* <Button style={{height: 20}} onClick={() => deletePropHandler(row.id)}>Delete</Button> */}
63+
</TableCell>
64+
</TableRow>
65+
));
66+
67+
return (
68+
<Paper className={classes.root}>
69+
<Table className={classes.table} selectable={"true"}>
70+
<TableHead>
71+
<TableRow>{renderHeader}</TableRow>
72+
</TableHead>
73+
<TableBody>{renderRows}</TableBody>
74+
</Table>
75+
</Paper>
76+
);
77+
}
78+
79+
// dataTable.propTypes = {
80+
// classes: PropTypes.object.isRequired,
81+
// };
82+
83+
export default withStyles(styles)(dataTable);

src/components/Props.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class Props extends Component {
181181
<Fragment>
182182
<div className="props-container" style={{ marginTop: '20px', width: '90%', height: '80%' }}>
183183
<Grid container spacing={8}>
184-
<Grid item xs={4}>
184+
<Grid item xs={3}>
185185
<form className="props-input" onSubmit={this.handleAddProp}>
186186
<Grid container spacing={8}>
187187
<Grid item xs={6}>
@@ -266,6 +266,7 @@ class Props extends Component {
266266
<Grid item xs={8}>
267267
<DataTable rowHeader={rowHeader} rowData={propsRows} deletePropHandler={deleteProp} />
268268
</Grid>
269+
<Grid item xs={1} />
269270
</Grid>
270271
{/* <div className="chips">
271272
{focusComponent.props.map(({

0 commit comments

Comments
 (0)