Skip to content

Commit

Permalink
lots of refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Dec 15, 2022
1 parent e63231d commit 201e447
Show file tree
Hide file tree
Showing 17 changed files with 262 additions and 225 deletions.
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
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
6 changes: 3 additions & 3 deletions superset-frontend/src/utils/localStorageHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

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

Expand Down Expand Up @@ -65,8 +65,8 @@ 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;
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
16 changes: 9 additions & 7 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',
OTHER = 'Other',
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,11 @@ 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;
otherTabData: Array<Dashboard>;
otherTabFilters: Filter[];
otherTabTitle: string;
}

Expand Down
8 changes: 4 additions & 4 deletions superset-frontend/src/views/CRUD/utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/
import rison from 'rison';
import {
isNeedsPassword,
isAlreadyExists,
getPasswordsNeeded,
checkUploadExtensions,
getAlreadyExists,
getPasswordsNeeded,
hasTerminalValidation,
checkUploadExtensions,
isAlreadyExists,
isNeedsPassword,
} from 'src/views/CRUD/utils';

const terminalErrors = {
Expand Down
73 changes: 68 additions & 5 deletions superset-frontend/src/views/CRUD/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ import Chart from 'src/types/Chart';
import { intersection } from 'lodash';
import rison from 'rison';
import { getClientErrorObject } from 'src/utils/getClientErrorObject';
import { FetchDataConfig } from 'src/components/ListView';
import { FetchDataConfig, FilterValue } from 'src/components/ListView';
import SupersetText from 'src/utils/textUtils';
import { findPermission } from 'src/utils/findPermission';
import { Dashboard, Filters } from './types';
import { Dashboard, Filter, TableTab } from './types';
import { User } from 'src/types/bootstrapTypes';
import { WelcomeTable } from './welcome/types';

// Modifies the rison encoding slightly to match the backend's rison encoding/decoding. Applies globally.
// Code pulled from rison.js (https://github.com/Nanonid/rison), rison is licensed under the MIT license.
Expand Down Expand Up @@ -120,7 +122,7 @@ const createFetchResourceMethod =
};

export const PAGE_SIZE = 5;
const getParams = (filters?: Array<Filters>) => {
const getParams = (filters?: Filter[]) => {
const params = {
order_column: 'changed_on_delta_humanized',
order_direction: 'desc',
Expand Down Expand Up @@ -164,7 +166,7 @@ export const getEditedObjects = (userId: string | number) => {
export const getUserOwnedObjects = (
userId: string | number,
resource: string,
filters: Array<Filters> = [
filters: Filter[] = [
{
col: 'owners',
opr: 'rel_m_m',
Expand All @@ -180,7 +182,7 @@ export const getRecentAcitivtyObjs = (
userId: string | number,
recent: string,
addDangerToast: (arg1: string, arg2: any) => any,
filters: Filters[],
filters: Filter[],
) =>
SupersetClient.get({ endpoint: recent }).then(recentsRes => {
const res: any = {};
Expand Down Expand Up @@ -436,3 +438,64 @@ export const uploadUserPerms = (
canUploadData: canUploadCSV || canUploadColumnar || canUploadExcel,
};
};

export function getFilterValues(
tab: TableTab,
welcomeTable: WelcomeTable,
user?: User,
otherTabFilters?: Filter[],
): FilterValue[] {
if (welcomeTable === WelcomeTable.SavedQueries && tab === TableTab.Mine) {
return [
{
id: 'created_by',
operator: 'rel_o_m',
value: `${user?.userId}`,
},
];
}
if (welcomeTable === WelcomeTable.SavedQueries) {
return [
{
id: 'id',
operator: 'saved_query_is_fav',
value: true,
},
];
}
if (tab === TableTab.Created && user) {
return [
{
id: 'created_by',
operator: 'rel_o_m',
value: `${user.userId}`,
},
];
}
if (tab === TableTab.Mine && user) {
return [
{
id: 'owners',
operator: 'rel_m_m',
value: `${user.userId}`,
},
];
}
if (tab === TableTab.Favorite) {
return [
{
id: 'id',
operator: 'dashboard_is_favorite',
value: true,
},
];
}
if (tab === TableTab.Other) {
return (otherTabFilters || []).map(flt => ({
id: flt.col,
operator: flt.opr,
value: flt.value,
}));
}
return [];
}
7 changes: 5 additions & 2 deletions superset-frontend/src/views/CRUD/welcome/ActivityTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { setItem, LocalStorageKeys } from 'src/utils/localStorageHelpers';
import { Link } from 'react-router-dom';
import ListViewCard from 'src/components/ListViewCard';
import SubMenu from 'src/views/components/SubMenu';
import { TableTab } from 'src/views/CRUD/types';
import { ActivityData, LoadingCards } from 'src/views/CRUD/welcome/Welcome';
import {
CardContainer,
Expand Down Expand Up @@ -148,7 +149,7 @@ export default function ActivityTable({
};

useEffect(() => {
if (activeChild === 'Edited') {
if (activeChild === TableTab.Edited) {
setLoadingState(true);
getEditedCards();
}
Expand Down Expand Up @@ -214,7 +215,9 @@ export default function ActivityTable({
<Styles>
<SubMenu activeChild={activeChild} tabs={tabs} />
{activityData[activeChild]?.length > 0 ||
(activeChild === 'Edited' && editedObjs && editedObjs.length > 0) ? (
(activeChild === TableTab.Edited &&
editedObjs &&
editedObjs.length > 0) ? (
<CardContainer className="recentCards">
{renderActivity()}
</CardContainer>
Expand Down
10 changes: 9 additions & 1 deletion superset-frontend/src/views/CRUD/welcome/ChartTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ describe('ChartTable', () => {
user: {
userId: '2',
},
mine: [],
otherTabData: [],
otherTabFilters: [],
otherTabTitle: 'Other',
showThumbnails: false,
};

let wrapper: ReactWrapper;
Expand Down Expand Up @@ -93,9 +98,12 @@ describe('ChartTable', () => {
await act(async () => {
wrapper = mount(
<ChartTable
chartFilter="Mine"
user={{ userId: '2' }}
mine={[]}
otherTabData={[]}
otherTabFilters={[]}
otherTabTitle="Other"
showThumbnails={false}
store={store}
/>,
);
Expand Down
Loading

0 comments on commit 201e447

Please sign in to comment.