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

feat(welcome): make examples tab customizable #22302

Merged
merged 14 commits into from
Dec 21, 2022
54 changes: 54 additions & 0 deletions superset-frontend/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
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 @@ -141,3 +143,55 @@ export const SLOW_DEBOUNCE = 500;
* Display null as `N/A`
*/
export const NULL_DISPLAY = 'N/A';

export const DEFAULT_COMMON_BOOTSTRAP_DATA: CommonBootstrapData = {
flash_messages: [],
conf: {},
locale: 'en',
feature_flags: {},
language_pack: {
domain: '',
locale_data: {
superset: {
'': {
domain: 'superset',
lang: 'en',
plural_forms: '',
},
},
},
},
extra_categorical_color_schemes: [],
extra_sequential_color_schemes: [],
theme_overrides: {},
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,
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* 'License'); you may not use this file except in compliance
* "License"); you may not use this file except in compliance
michael-s-molina marked this conversation as resolved.
Show resolved Hide resolved
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* 'License'); you may not use this file except in compliance
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { FeatureFlagMap, FeatureFlag } from '@superset-ui/core';
export { FeatureFlag } from '@superset-ui/core';
export type { FeatureFlagMap } from '@superset-ui/core';

export function initFeatureFlags(featureFlags: FeatureFlagMap) {
export function initFeatureFlags(featureFlags?: FeatureFlagMap) {
if (!window.featureFlags) {
window.featureFlags = featureFlags || {};
}
Expand Down
16 changes: 7 additions & 9 deletions superset-frontend/src/preamble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,20 @@ import setupClient from './setup/setupClient';
import setupColors from './setup/setupColors';
import setupFormatters from './setup/setupFormatters';
import setupDashboardComponents from './setup/setupDasboardComponents';
import { BootstrapUser, User } from './types/bootstrapTypes';
import { BootstrapData, User } from './types/bootstrapTypes';
import { initFeatureFlags } from './featureFlags';
import { DEFAULT_COMMON_BOOTSTRAP_DATA } from './constants';

if (process.env.WEBPACK_MODE === 'development') {
setHotLoaderConfig({ logLevel: 'debug', trackTailUpdates: false });
}

// eslint-disable-next-line import/no-mutable-exports
export let bootstrapData: {
user?: BootstrapUser;
common?: any;
config?: any;
embedded?: {
dashboard_id: string;
};
} = {};
export let bootstrapData: BootstrapData = {
common: {
...DEFAULT_COMMON_BOOTSTRAP_DATA,
},
};

// Configure translation
if (typeof window !== 'undefined') {
Expand Down
82 changes: 79 additions & 3 deletions superset-frontend/src/types/bootstrapTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { JsonObject, Locale } from '@superset-ui/core';
import {
ColorSchemeConfig,
FeatureFlagMap,
JsonObject,
LanguagePack,
Locale,
SequentialSchemeConfig,
} 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 @@ -74,11 +83,78 @@ 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: string[][];
flash_messages: FlashMessage[];
conf: JsonObject;
locale: Locale;
feature_flags: Record<string, boolean>;
feature_flags: FeatureFlagMap;
michael-s-molina marked this conversation as resolved.
Show resolved Hide resolved
language_pack: LanguagePack;
extra_categorical_color_schemes: ColorSchemeConfig[];
extra_sequential_color_schemes: SequentialSchemeConfig[];
theme_overrides: JsonObject;
menu_data: MenuData;
}

export interface BootstrapData {
user?: BootstrapUser;
common: CommonBootstrapData;
config?: any;
embedded?: {
dashboard_id: string;
};
}

export function isUser(user: any): user is User {
Expand Down
26 changes: 26 additions & 0 deletions superset-frontend/src/utils/getBootstrapData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

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

export default function getBootstrapData(): BootstrapData {
michael-s-molina marked this conversation as resolved.
Show resolved Hide resolved
const appContainer = document.getElementById('app');
const dataBootstrap = appContainer?.getAttribute('data-bootstrap');
return dataBootstrap ? JSON.parse(dataBootstrap) : {};
}
9 changes: 4 additions & 5 deletions superset-frontend/src/utils/localStorageHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
* under the License.
*/

import { TableTabTypes } from 'src/views/CRUD/types';
import { SetTabType } from 'src/views/CRUD/welcome/ActivityTable';
import { TableTab } from 'src/views/CRUD/types';
import { DashboardContextForExplore } from 'src/types/DashboardContextForExplore';

export enum LocalStorageKeys {
Expand Down Expand Up @@ -65,11 +64,11 @@ export type LocalStorageValues = {
controls_width: number;
datasource_width: number;
is_datapanel_open: boolean;
homepage_chart_filter: TableTabTypes;
homepage_dashboard_filter: TableTabTypes;
homepage_chart_filter: TableTab;
homepage_dashboard_filter: TableTab;
homepage_collapse_state: string[];
datasetname_set_successful: boolean;
homepage_activity_filter: SetTabType | null;
homepage_activity_filter: TableTab | null;
sqllab__is_autocomplete_enabled: boolean;
explore__data_table_original_formatted_time_columns: Record<string, string[]>;
dashboard__custom_filter_bar_widths: Record<string, number>;
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/utils/urlUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* 'License'); you may not use this file except in compliance
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/utils/urlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* 'License'); you may not use this file except in compliance
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
Expand Down
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
19 changes: 11 additions & 8 deletions superset-frontend/src/views/CRUD/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ export type FavoriteStatus = {
[id: number]: boolean;
};

export enum TableTabTypes {
FAVORITE = 'Favorite',
MINE = 'Mine',
EXAMPLES = 'Examples',
export enum TableTab {
Favorite = 'Favorite',
Mine = 'Mine',
Other = 'Other',
Viewed = 'Viewed',
Created = 'Created',
Edited = 'Edited',
}

export type Filters = {
export type Filter = {
col: string;
opr: string;
value: string | number;
Expand All @@ -39,12 +42,12 @@ export type Filters = {
export interface DashboardTableProps {
addDangerToast: (message: string) => void;
addSuccessToast: (message: string) => void;
search: string;
user?: User;
mine: Array<Dashboard>;
showThumbnails?: boolean;
featureFlag?: boolean;
examples: Array<Dashboard>;
otherTabData: Array<Dashboard>;
otherTabFilters: Filter[];
otherTabTitle: string;
}

export interface Dashboard {
Expand Down
Loading