dbgate/packages/web/src/appobj/databaseAppObject.js

41 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-01-05 09:25:10 +00:00
import React from 'react';
2020-04-04 16:36:16 +00:00
import _ from 'lodash';
2020-01-05 18:55:04 +00:00
import { DatabaseIcon } from '../icons';
2020-01-05 09:25:10 +00:00
import { DropDownMenuItem } from '../modals/DropDownMenu';
import showModal from '../modals/showModal';
import ConnectionModal from '../modals/ConnectionModal';
import axios from '../utility/axios';
function Menu({ data, makeAppObj }) {
const handleEdit = () => {
showModal(modalState => <ConnectionModal modalState={modalState} connection={data} />);
};
const handleDelete = () => {
axios.post('connections/delete', data);
};
return (
<>
<DropDownMenuItem onClick={handleEdit}>Edit</DropDownMenuItem>
<DropDownMenuItem onClick={handleDelete}>Delete</DropDownMenuItem>
</>
);
}
2020-04-04 16:36:16 +00:00
const databaseAppObject = flags => ({ name, connection }) => {
const { boldCurrentDatabase } = flags || {};
2020-01-05 09:25:10 +00:00
const title = name;
const key = name;
const Icon = DatabaseIcon;
2020-04-04 16:36:16 +00:00
const isBold = boldCurrentDatabase
? ({ currentDatabase }) => {
return (
_.get(currentDatabase, 'connection._id') == _.get(connection, '_id') && _.get(currentDatabase, 'name') == name
);
}
: null;
2020-01-05 09:25:10 +00:00
2020-04-04 16:36:16 +00:00
return { title, key, Icon, Menu, isBold };
};
export default databaseAppObject;