Skip to content

Commit

Permalink
more fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Dec 15, 2022
1 parent d2a5d0f commit e63231d
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 76 deletions.
33 changes: 31 additions & 2 deletions superset-frontend/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { CommonBootstrapData } from './types/bootstrapTypes';
import { BootstrapData, CommonBootstrapData } from './types/bootstrapTypes';

export const DATETIME_WITH_TIME_ZONE = 'YYYY-MM-DD HH:mm:ssZ';
export const TIME_WITH_MS = 'HH:mm:ss.SSS';
Expand Down Expand Up @@ -164,5 +164,34 @@ export const DEFAULT_COMMON_BOOTSTRAP_DATA: CommonBootstrapData = {
extra_categorical_color_schemes: [],
extra_sequential_color_schemes: [],
theme_overrides: {},
menu_data: {},
menu_data: {
menu: [],
brand: {
path: '',
icon: '',
alt: '',
tooltip: '',
text: '',
},
navbar_right: {
show_watermark: true,
languages: {},
show_language_picker: true,
user_is_anonymous: false,
user_info_url: '',
user_login_url: '',
user_logout_url: '',
user_profile_url: '',
locale: '',
},
settings: [],
environment_tag: {
text: '',
color: '',
},
},
};

export const DEFAULT_BOOTSTRAP_DATA: BootstrapData = {
common: DEFAULT_COMMON_BOOTSTRAP_DATA,
};
56 changes: 55 additions & 1 deletion superset-frontend/src/types/bootstrapTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@superset-ui/core';
import { isPlainObject } from 'lodash';
import { FlashMessage } from '../components/FlashProvider';
import { Languages } from '../views/components/LanguagePicker';

/**
* Licensed to the Apache Software Foundation (ASF) under one
Expand Down Expand Up @@ -82,6 +83,59 @@ export type ChartResponse = {
result: ChartData[];
};

export interface BrandProps {
path: string;
icon: string;
alt: string;
tooltip: string;
text: string;
}

export interface NavBarProps {
show_watermark: boolean;
bug_report_url?: string;
version_string?: string;
version_sha?: string;
build_number?: string;
documentation_url?: string;
languages: Languages;
show_language_picker: boolean;
user_is_anonymous: boolean;
user_info_url: string;
user_login_url: string;
user_logout_url: string;
user_profile_url: string | null;
locale: string;
}

export interface MenuObjectChildProps {
label: string;
name?: string;
icon?: string;
index?: number;
url?: string;
isFrontendRoute?: boolean;
perm?: string | boolean;
view?: string;
disable?: boolean;
}

export interface MenuObjectProps extends MenuObjectChildProps {
childs?: (MenuObjectChildProps | string)[];
isHeader?: boolean;
}

export interface MenuData {
menu: MenuObjectProps[];
brand: BrandProps;
navbar_right: NavBarProps;
settings: MenuObjectProps[];
environment_tag: {
text: string;
color: string;
};
}

export interface CommonBootstrapData {
flash_messages: FlashMessage[];
conf: JsonObject;
Expand All @@ -91,7 +145,7 @@ export interface CommonBootstrapData {
extra_categorical_color_schemes: ColorSchemeConfig[];
extra_sequential_color_schemes: SequentialSchemeConfig[];
theme_overrides: JsonObject;
menu_data: JsonObject;
menu_data: MenuData;
}

export interface BootstrapData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,11 @@
* under the License.
*/

import { useEffect, useState } from 'react';

import { BootstrapData } from 'src/types/bootstrapTypes';

export function useBootstrapData(): BootstrapData {
const [bootstrapData, setBootstrapData] = useState<BootstrapData>({});

useEffect(() => {
const appContainer = document.getElementById('app');
const dataBootstrap = appContainer?.getAttribute('data-bootstrap') || '{}';

setBootstrapData(JSON.parse(dataBootstrap));
}, []);
export default function getBootstrapData(): BootstrapData {
const appContainer = document.getElementById('app');
const dataBootstrap = appContainer?.getAttribute('data-bootstrap') || '{}';

return bootstrapData;
return JSON.parse(dataBootstrap);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import ListView, { FilterOperator, Filters } from 'src/components/ListView';
import handleResourceExport from 'src/utils/export';
import { ExtentionConfigs } from 'src/views/components/types';
import { UserWithPermissionsAndRoles } from 'src/types/bootstrapTypes';
import type { MenuObjectProps } from 'src/views/components/Menu';
import type { MenuObjectProps } from 'src/types/bootstrapTypes';
import DatabaseModal from './DatabaseModal';

import { DatabaseObject } from './types';
Expand Down
5 changes: 3 additions & 2 deletions superset-frontend/src/views/CRUD/welcome/Welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
} from 'src/views/CRUD/utils';
import { FeatureFlag, isFeatureEnabled } from 'src/featureFlags';
import { AntdSwitch } from 'src/components';
import { useBootstrapData } from 'src/hooks/useBootstrapData';
import getBootstrapData from 'src/utils/getBootstrapData';

import { Filters } from '../types';
import ActivityTable from './ActivityTable';
Expand Down Expand Up @@ -140,6 +140,8 @@ const WelcomeNav = styled.div`
`}
`;

const bootstrapData = getBootstrapData();

export const LoadingCards = ({ cover }: LoadingProps) => (
<CardContainer showThumbnails={cover} className="loading-cards">
{[...new Array(loadingCardCount)].map((_, index) => (
Expand All @@ -164,7 +166,6 @@ function Welcome({ user, addDangerToast }: WelcomeProps) {
defaultChecked =
userKey?.thumbnails === undefined ? true : userKey?.thumbnails;
}
const bootstrapData = useBootstrapData();
const [otherTabTitle, setOtherTabTitle] = useState('');
const [otherTabFilters, setOtherTabFilters] = useState<Filters[]>([]);
const [checked, setChecked] = useState(defaultChecked);
Expand Down
61 changes: 7 additions & 54 deletions superset-frontend/src/views/components/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,65 +29,18 @@ import { GenericLink } from 'src/components/GenericLink/GenericLink';
import Icons from 'src/components/Icons';
import { useUiConfig } from 'src/components/UiConfigContext';
import { URL_PARAMS } from 'src/constants';
import {
MenuObjectChildProps,
MenuObjectProps,
MenuData,
} from 'src/types/bootstrapTypes';
import RightMenu from './RightMenu';
import { Languages } from './LanguagePicker';

interface BrandProps {
path: string;
icon: string;
alt: string;
tooltip: string;
text: string;
}

export interface NavBarProps {
show_watermark: boolean;
bug_report_url?: string;
version_string?: string;
version_sha?: string;
build_number?: string;
documentation_url?: string;
languages: Languages;
show_language_picker: boolean;
user_is_anonymous: boolean;
user_info_url: string;
user_login_url: string;
user_logout_url: string;
user_profile_url: string | null;
locale: string;
}

export interface MenuProps {
data: {
menu: MenuObjectProps[];
brand: BrandProps;
navbar_right: NavBarProps;
settings: MenuObjectProps[];
environment_tag: {
text: string;
color: string;
};
};
interface MenuProps {
data: MenuData;
isFrontendRoute?: (path?: string) => boolean;
}

export interface MenuObjectChildProps {
label: string;
name?: string;
icon?: string;
index?: number;
url?: string;
isFrontendRoute?: boolean;
perm?: string | boolean;
view?: string;
disable?: boolean;
}

export interface MenuObjectProps extends MenuObjectChildProps {
childs?: (MenuObjectChildProps | string)[];
isHeader?: boolean;
}

const StyledHeader = styled.header`
${({ theme }) => `
background-color: ${theme.colors.grayscale.light5};
Expand Down
6 changes: 4 additions & 2 deletions superset-frontend/src/views/components/RightMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ import Icons from 'src/components/Icons';
import Label from 'src/components/Label';
import { findPermission } from 'src/utils/findPermission';
import { isUserAdmin } from 'src/dashboard/util/permissionUtils';
import { UserWithPermissionsAndRoles } from 'src/types/bootstrapTypes';
import {
MenuObjectProps,
UserWithPermissionsAndRoles,
} from 'src/types/bootstrapTypes';
import { RootState } from 'src/dashboard/types';
import LanguagePicker from './LanguagePicker';
import DatabaseModal from '../CRUD/data/database/DatabaseModal';
Expand All @@ -48,7 +51,6 @@ import {
GlobalMenuDataOptions,
RightMenuProps,
} from './types';
import { MenuObjectProps } from './Menu';
import AddDatasetModal from '../CRUD/data/dataset/AddDatasetModal';

const extensionsRegistry = getExtensionsRegistry();
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/views/components/SubMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Row } from 'src/components';
import { Menu, MenuMode, MainNav as DropdownMenu } from 'src/components/Menu';
import Button, { OnClickHandler } from 'src/components/Button';
import Icons from 'src/components/Icons';
import { MenuObjectProps } from './Menu';
import { MenuObjectProps } from 'src/types/bootstrapTypes';

const StyledHeader = styled.div`
margin-bottom: ${({ theme }) => theme.gridUnit * 4}px;
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/views/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { NavBarProps, MenuObjectProps } from './Menu';
import { NavBarProps, MenuObjectProps } from 'src/types/bootstrapTypes';

export interface ExtentionConfigs {
ALLOWED_EXTENSIONS: Array<any>;
Expand Down

0 comments on commit e63231d

Please sign in to comment.