Skip to content

Commit

Permalink
chore(fe): unify TaggedObject type usage + corresponding refactor
Browse files Browse the repository at this point in the history
Signed-off-by: hainenber <[email protected]>
  • Loading branch information
hainenber committed Jan 23, 2025
1 parent fcd1661 commit 05b11af
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion superset-frontend/cypress-base/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Cypress.Commands.add('login', () => {
}).then(response => {
if (response.status === 302) {
// If there's a redirect, follow it manually
const redirectUrl = response.headers['location'];
const redirectUrl = response.headers.location;
cy.request({
method: 'GET',
url: redirectUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Tag from 'src/types/TagType';
import Owner from 'src/types/Owner';
import { EmptyState } from 'src/components/EmptyState';
import { NumberParam, useQueryParam } from 'use-query-params';
import { ConfigType } from 'dayjs';

const MAX_TAGS_TO_SHOW = 3;
const PAGE_SIZE = 10;
Expand All @@ -49,12 +50,12 @@ const AllEntitiesTableContainer = styled.div`
}
`;

interface TaggedObject {
export interface TaggedObject {
id: number;
type: string;
name: string;
url: string;
changed_on: string | number | Date;
changed_on: ConfigType;
created_by: number | undefined;
creator: string;
owners: Owner[];
Expand Down
5 changes: 1 addition & 4 deletions superset-frontend/src/features/tags/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,7 @@ export function fetchObjects(
}

export function fetchObjectsByTagIds(
{
tagIds = [],
types,
}: { tagIds: number[] | undefined; types: string | null },
{ tagIds = [], types }: { tagIds: number[] | string; types: string | null },
callback: (json: JsonObject) => void,
error: (response: Response) => void,
) {
Expand Down
24 changes: 8 additions & 16 deletions superset-frontend/src/pages/AllEntities/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useEffect, useState } from 'react';
import { styled, t, css, SupersetTheme } from '@superset-ui/core';
import { NumberParam, useQueryParam } from 'use-query-params';
import AllEntitiesTable, {
TaggedObject,
TaggedObjects,
} from 'src/features/allEntities/AllEntitiesTable';
import Button from 'src/components/Button';
Expand All @@ -36,19 +37,6 @@ import withToasts, { useToasts } from 'src/components/MessageToasts/withToasts';
import { fetchObjectsByTagIds, fetchSingleTag } from 'src/features/tags/tags';
import Loading from 'src/components/Loading';
import getOwnerName from 'src/utils/getOwnerName';
import { ConfigType } from 'dayjs';

interface TaggedObject {
id: number;
type: string;
name: string;
url: string;
changed_on: ConfigType;
created_by: number | undefined;
creator: string;
owners: Owner[];
tags: Tag[];
}

const additionalItemsStyles = (theme: SupersetTheme) => css`
display: flex;
Expand Down Expand Up @@ -152,12 +140,16 @@ function AllEntities() {
return;
}
fetchObjectsByTagIds(
{ tagIds: [tag?.id] || '', types: null },
{ tagIds: tag ? [tag.id] : '', types: null },
(data: TaggedObject[]) => {
const objects = { dashboard: [], chart: [], query: [] };
const objects = {
dashboard: [],
chart: [],
query: [],
} as TaggedObjects;
data.forEach(function (object) {
const object_type = object.type;
objects[object_type].push(object);
objects[object_type as keyof TaggedObjects].push(object);
});
setObjects(objects);
setLoading(false);
Expand Down

0 comments on commit 05b11af

Please sign in to comment.