Skip to content

Commit

Permalink
fix: Logic for showing extension in Global Nav (#19158)
Browse files Browse the repository at this point in the history
* fix logic for checking extensions

* add specific types

* fix lint
  • Loading branch information
hughhhh committed Mar 16, 2022
1 parent bb618a4 commit 181ecf4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
7 changes: 3 additions & 4 deletions superset-frontend/src/views/CRUD/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,11 @@ export const hasTerminalValidation = (errors: Record<string, any>[]) =>
);

export const checkUploadExtensions = (
perm: Array<any> | string | undefined | boolean,
cons: Array<any>,
perm: Array<string>,
cons: Array<string>,
) => {
if (perm !== undefined) {
if (typeof perm === 'boolean') return perm;
return intersection(perm, cons).length;
return intersection(perm, cons).length > 0;
}
return false;
};
2 changes: 1 addition & 1 deletion superset-frontend/src/views/components/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ interface MenuObjectChildProps {
index?: number;
url?: string;
isFrontendRoute?: boolean;
perm?: string | Array<any> | boolean;
perm?: string | boolean;
view?: string;
}

Expand Down
17 changes: 10 additions & 7 deletions superset-frontend/src/views/components/MenuRight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ const RightMenu = ({
ALLOWED_EXTENSIONS,
HAS_GSHEETS_INSTALLED,
} = useSelector<any, ExtentionConfigs>(state => state.common.conf);

const [showModal, setShowModal] = useState<boolean>(false);
const [engine, setEngine] = useState<string>('');
const canSql = findPermission('can_sqllab', 'Superset', roles);
Expand Down Expand Up @@ -124,19 +123,25 @@ const RightMenu = ({
label: t('Upload CSV to database'),
name: 'Upload a CSV',
url: '/csvtodatabaseview/form',
perm: CSV_EXTENSIONS && canUploadCSV,
perm:
checkUploadExtensions(CSV_EXTENSIONS, ALLOWED_EXTENSIONS) &&
canUploadCSV,
},
{
label: t('Upload columnar file to database'),
name: 'Upload a Columnar file',
url: '/columnartodatabaseview/form',
perm: COLUMNAR_EXTENSIONS && canUploadColumnar,
perm:
checkUploadExtensions(COLUMNAR_EXTENSIONS, ALLOWED_EXTENSIONS) &&
canUploadColumnar,
},
{
label: t('Upload Excel file to database'),
name: 'Upload Excel',
url: '/exceltodatabaseview/form',
perm: EXCEL_EXTENSIONS && canUploadExcel,
perm:
checkUploadExtensions(EXCEL_EXTENSIONS, ALLOWED_EXTENSIONS) &&
canUploadExcel,
},
],
},
Expand Down Expand Up @@ -209,9 +214,7 @@ const RightMenu = ({
title={menuIconAndLabel(menu)}
>
{menu.childs.map((item, idx) =>
typeof item !== 'string' &&
item.name &&
checkUploadExtensions(item.perm, ALLOWED_EXTENSIONS) ? (
typeof item !== 'string' && item.name && item.perm ? (
<>
{idx === 2 && <Menu.Divider />}
<Menu.Item key={item.name}>
Expand Down
2 changes: 1 addition & 1 deletion superset/utils/async_query_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class AsyncQueryManager:

def __init__(self) -> None:
super().__init__()
self._redis: redis.Redis # type: ignore
self._redis: redis.Redis
self._stream_prefix: str = ""
self._stream_limit: Optional[int]
self._stream_limit_firehose: Optional[int]
Expand Down

0 comments on commit 181ecf4

Please sign in to comment.