-
Notifications
You must be signed in to change notification settings - Fork 13.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: DBC-UI Globally available across the app 🌎 #18722
Changes from 38 commits
681c20e
a4bbd5e
2ae8696
237263a
04d1ff9
1c0f383
760d8c6
717c5bb
2502a9a
123eff6
785f74b
757d502
2780d60
8052f1f
b68aa95
a6c0bbe
0e9abe9
70e7ba4
117261e
4fc95cd
dca3be1
b45184b
c42491d
9eac285
a3cc781
e64d6eb
6e9eb0c
9121e01
e9152e4
5b27726
9b2bf5f
56902d3
3af0404
e43fbd9
0f55d41
5af39b6
0507aaa
bd4a8bf
58d7607
b1aeaa4
e2b0570
192a7f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import React from 'react'; | ||
import React, { useState } from 'react'; | ||
import { MainNav as Menu } from 'src/common/components'; | ||
import { t, styled, css, SupersetTheme } from '@superset-ui/core'; | ||
import { Link } from 'react-router-dom'; | ||
|
@@ -29,6 +29,7 @@ import { | |
} from 'src/types/bootstrapTypes'; | ||
import LanguagePicker from './LanguagePicker'; | ||
import { NavBarProps, MenuObjectProps } from './Menu'; | ||
import DatabaseModal from '../CRUD/data/database/DatabaseModal'; | ||
|
||
export const dropdownItems: MenuObjectProps[] = [ | ||
{ | ||
|
@@ -114,6 +115,11 @@ interface RightMenuProps { | |
isFrontendRoute: (path?: string) => boolean; | ||
} | ||
|
||
export enum GlobalMenuDataOptions { | ||
GOOGLE_SHEETS = '1', | ||
DB_CONNECTION = '2', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just fyi, you don't need to initialize the values if they're going to auto increment |
||
} | ||
|
||
const RightMenu = ({ | ||
align, | ||
settings, | ||
|
@@ -123,11 +129,19 @@ const RightMenu = ({ | |
const { roles } = useSelector<any, UserWithPermissionsAndRoles>( | ||
state => state.user, | ||
); | ||
const [showModal, setShowModal] = useState<boolean>(false); | ||
const [engine, setEngine] = useState<string>(''); | ||
// @ts-ignore | ||
const { CSV_EXTENSIONS, COLUMNAR_EXTENSIONS, EXCEL_EXTENSIONS } = useSelector< | ||
any, | ||
CommonBootstrapData | ||
>(state => state.common.conf); | ||
|
||
// @ts-ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curious what ts is complaining about here |
||
const { SHOW_GLOBAL_GSHEETS } = useSelector<any, CommonBootstrapData>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be able to get rid of this ts-ignore if you replace CommonBootstrapData with a new type. For ex... |
||
state => state.common.conf, | ||
); | ||
|
||
// if user has any of these roles the dropdown will appear | ||
const configMap = { | ||
'Upload a CSV': CSV_EXTENSIONS, | ||
|
@@ -144,9 +158,30 @@ const RightMenu = ({ | |
{menu.label} | ||
</> | ||
); | ||
|
||
const handleMenuSelection = (itemChose: React.Key) => { | ||
if (itemChose === GlobalMenuDataOptions.DB_CONNECTION) { | ||
setShowModal(true); | ||
setEngine(''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this to clear out the value if google sheets was selected at some point? If so, can we reset the value on modal close instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried moving this logic to the into component, but since we are managing the state in the upper component (MenuRight) it doesn't reset. Open to other strategies here, but was having a hard time getting it to work without reseting from the upper component There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's ok to leave the logic here for which engine was chosen, but maybe instead of clearing it out on menu selection, we can clear out the engine value on the dbmodal onHide event? |
||
} | ||
if (itemChose === GlobalMenuDataOptions.GOOGLE_SHEETS) { | ||
setShowModal(true); | ||
setEngine('Google Sheets'); | ||
} | ||
}; | ||
|
||
return ( | ||
<StyledDiv align={align}> | ||
<Menu mode="horizontal"> | ||
<DatabaseModal | ||
onHide={() => setShowModal(false)} | ||
show={showModal} | ||
dbEngine={engine} | ||
/> | ||
<Menu | ||
selectable={false} | ||
mode="horizontal" | ||
onClick={({ key }) => handleMenuSelection(key)} | ||
> | ||
{!navbarRight.user_is_anonymous && showActionDropdown && ( | ||
<SubMenu | ||
data-test="new-dropdown" | ||
|
@@ -163,6 +198,15 @@ const RightMenu = ({ | |
className="data-menu" | ||
title={menuIconAndLabel(menu)} | ||
> | ||
<Menu.Item key={GlobalMenuDataOptions.DB_CONNECTION}> | ||
Connect Database | ||
</Menu.Item> | ||
{SHOW_GLOBAL_GSHEETS && ( | ||
<Menu.Item key={GlobalMenuDataOptions.GOOGLE_SHEETS}> | ||
Connect Google Sheet | ||
</Menu.Item> | ||
)} | ||
<Menu.Divider /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest since we have the data object above that we're looping over, to try to move this into that data structure so that we can keep this as modular as possible. |
||
{menu.childs.map(item => | ||
typeof item !== 'string' && | ||
item.name && | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,8 @@ | |
from superset.commands.exceptions import CommandException, CommandInvalidError | ||
from superset.connectors.sqla import models | ||
from superset.datasets.commands.exceptions import get_dataset_exist_error_msg | ||
from superset.db_engine_specs import get_available_engine_specs | ||
from superset.db_engine_specs.gsheets import GSheetsEngineSpec | ||
from superset.errors import ErrorLevel, SupersetError, SupersetErrorType | ||
from superset.exceptions import ( | ||
SupersetErrorException, | ||
|
@@ -366,6 +368,12 @@ def common_bootstrap_payload() -> Dict[str, Any]: | |
ReportRecipientType.EMAIL, | ||
] | ||
|
||
available_specs = get_available_engine_specs() | ||
if available_specs[GSheetsEngineSpec]: | ||
frontend_config["SHOW_GLOBAL_GSHEETS"] = True | ||
else: | ||
frontend_config["SHOW_GLOBAL_GSHEETS"] = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this by dry-ed up a bit by something like:
Also nit, but can we decouple the backend config by naming this something more generic perhaps? Since the value is whether the driver is installed, the backend doesn't need to know how the client side is using this value, i.e., whether to show gsheets globally, just needs to know that the driver is installed. |
||
|
||
bootstrap_data = { | ||
"flash_messages": messages, | ||
"conf": frontend_config, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this live in a types.ts file?