Skip to content
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

fix: Logic for showing extension in Global Nav #19158

Merged
merged 5 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions superset-frontend/src/views/CRUD/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,9 @@ export const hasTerminalValidation = (errors: Record<string, any>[]) =>
),
);

export const checkUploadExtensions = (
perm: Array<any> | string | undefined | boolean,
cons: Array<any>,
) => {
export const checkUploadExtensions = (perm: Array<any>, cons: Array<any>) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, but I think an array of strings is the only type that would make sense, if you want to be more specific.

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