forked from metabase/metabase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the flow for adding a question to a dashboard (metabase#30347)
- Loading branch information
1 parent
871a03f
commit a2c8b6d
Showing
20 changed files
with
552 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
frontend/src/metabase/common/hooks/use-collection-query/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./use-collection-query"; |
18 changes: 18 additions & 0 deletions
18
frontend/src/metabase/common/hooks/use-collection-query/use-collection-query.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Collections from "metabase/entities/collections"; | ||
import { Collection, CollectionId } from "metabase-types/api"; | ||
import { | ||
useEntityQuery, | ||
UseEntityQueryProps, | ||
UseEntityQueryResult, | ||
} from "../use-entity-query"; | ||
|
||
export const useCollectionQuery = ( | ||
props: UseEntityQueryProps<CollectionId, unknown>, | ||
): UseEntityQueryResult<Collection> => { | ||
return useEntityQuery(props, { | ||
fetch: Collections.actions.fetch, | ||
getObject: Collections.selectors.getObject, | ||
getLoading: Collections.selectors.getLoading, | ||
getError: Collections.selectors.getError, | ||
}); | ||
}; |
57 changes: 57 additions & 0 deletions
57
frontend/src/metabase/common/hooks/use-collection-query/use-collection-query.unit.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from "react"; | ||
import LoadingAndErrorWrapper from "metabase/components/LoadingAndErrorWrapper"; | ||
import { createMockCollection } from "metabase-types/api/mocks"; | ||
import { | ||
setupCollectionsEndpoints, | ||
setupCollectionByIdEndpoint, | ||
} from "__support__/server-mocks"; | ||
import { | ||
renderWithProviders, | ||
screen, | ||
waitForElementToBeRemoved, | ||
} from "__support__/ui"; | ||
import { useCollectionQuery } from "./use-collection-query"; | ||
|
||
const TEST_COLLECTION = createMockCollection(); | ||
|
||
const TestComponent = () => { | ||
const { data, isLoading, error } = useCollectionQuery({ | ||
id: TEST_COLLECTION.id, | ||
}); | ||
|
||
if (isLoading || error) { | ||
return <LoadingAndErrorWrapper loading={isLoading} error={error} />; | ||
} | ||
|
||
return <div>{data?.name}</div>; | ||
}; | ||
|
||
const setup = ({ error }: { error?: string } = {}) => { | ||
setupCollectionsEndpoints([TEST_COLLECTION]); | ||
setupCollectionByIdEndpoint({ collections: [TEST_COLLECTION], error }); | ||
renderWithProviders(<TestComponent />); | ||
}; | ||
|
||
describe("useCollectionQuery", () => { | ||
it("should be initially loading", () => { | ||
setup(); | ||
expect(screen.getByText("Loading...")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should display error", async () => { | ||
const ERROR = "Server error"; | ||
setup({ | ||
error: ERROR, | ||
}); | ||
|
||
await waitForElementToBeRemoved(() => screen.queryByText("Loading...")); | ||
|
||
expect(screen.getByText(ERROR)).toBeInTheDocument(); | ||
}); | ||
|
||
it("should show data from the response", async () => { | ||
setup(); | ||
await waitForElementToBeRemoved(() => screen.queryByText("Loading...")); | ||
expect(screen.getByText(TEST_COLLECTION.name)).toBeInTheDocument(); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
frontend/src/metabase/common/hooks/use-most-recently-viewed-dashboard/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./use-most-recently-viewed-dashboard"; |
18 changes: 18 additions & 0 deletions
18
...ase/common/hooks/use-most-recently-viewed-dashboard/use-most-recently-viewed-dashboard.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useAsync } from "react-use"; | ||
import { Dashboard } from "metabase-types/api"; | ||
import { ActivityApi } from "metabase/services"; | ||
|
||
export const useMostRecentlyViewedDashboard = () => { | ||
const { | ||
loading: isLoading, | ||
error, | ||
value: data, | ||
} = useAsync(async () => { | ||
const dashboard: Dashboard | undefined = | ||
await ActivityApi.most_recently_viewed_dashboard(); | ||
|
||
return dashboard; | ||
}); | ||
|
||
return { data, isLoading, error }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.