Skip to content
Snippets Groups Projects
Unverified Commit b07dd59d authored by Cal Herries's avatar Cal Herries Committed by GitHub
Browse files

Show collection in data reference for questions/models (#26063)

* Show collection in data reference

* Fix type check

* Revert "Fix type check"

This reverts commit 3eef7cd21c8c6c1677fc427ac72a581cd8580bb4.

* Use Collections selector instead of question.card().collection

* fetch collection in loadMetadataForCard

* Replace getCollectionFromCard with Collections selector and rename question -> card
parent 08220938
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ import { DatasetQuery } from "./query"; ...@@ -2,6 +2,7 @@ import { DatasetQuery } from "./query";
export interface Card extends UnsavedCard { export interface Card extends UnsavedCard {
id: CardId; id: CardId;
collection_id: number | null;
name: string; name: string;
description: string | null; description: string | null;
dataset: boolean; dataset: boolean;
......
...@@ -16,6 +16,7 @@ export const createMockCard = (opts?: Partial<Card>): Card => ({ ...@@ -16,6 +16,7 @@ export const createMockCard = (opts?: Partial<Card>): Card => ({
dataset: false, dataset: false,
can_write: false, can_write: false,
cache_ttl: null, cache_ttl: null,
collection_id: null,
last_query_start: null, last_query_start: null,
archived: false, archived: false,
...opts, ...opts,
......
...@@ -8,9 +8,12 @@ import { ...@@ -8,9 +8,12 @@ import {
Description, Description,
EmptyDescription, EmptyDescription,
} from "metabase/components/MetadataInfo/MetadataInfo.styled"; } from "metabase/components/MetadataInfo/MetadataInfo.styled";
import Collections from "metabase/entities/collections";
import Questions from "metabase/entities/questions"; import Questions from "metabase/entities/questions";
import SidebarContent from "metabase/query_builder/components/SidebarContent"; import SidebarContent from "metabase/query_builder/components/SidebarContent";
import { getQuestionFromCard } from "metabase/query_builder/selectors"; import { getQuestionFromCard } from "metabase/query_builder/selectors";
import type { Card } from "metabase-types/api/card";
import type { Collection } from "metabase-types/api/collection";
import type { State } from "metabase-types/store"; import type { State } from "metabase-types/store";
import Table from "metabase-lib/lib/metadata/Table"; import Table from "metabase-lib/lib/metadata/Table";
import Question from "metabase-lib/lib/Question"; import Question from "metabase-lib/lib/Question";
...@@ -29,16 +32,19 @@ interface QuestionPaneProps { ...@@ -29,16 +32,19 @@ interface QuestionPaneProps {
onItemClick: (type: string, item: unknown) => void; onItemClick: (type: string, item: unknown) => void;
onBack: () => void; onBack: () => void;
onClose: () => void; onClose: () => void;
card: Card;
question: Question; question: Question;
collection: Collection | null;
} }
const mapStateToProps = (state: State, props: QuestionPaneProps) => ({ const mapStateToProps = (state: State, { card }: QuestionPaneProps) => ({
question: getQuestionFromCard(state, props.question), question: getQuestionFromCard(state, card),
}); });
const QuestionPane = ({ const QuestionPane = ({
onItemClick, onItemClick,
question, question,
collection,
onBack, onBack,
onClose, onClose,
}: QuestionPaneProps) => { }: QuestionPaneProps) => {
...@@ -72,6 +78,12 @@ const QuestionPane = ({ ...@@ -72,6 +78,12 @@ const QuestionPane = ({
<QuestionPaneIcon name="label" /> <QuestionPaneIcon name="label" />
<QuestionPaneDetailText>{t`ID #${question.id()}`}</QuestionPaneDetailText> <QuestionPaneDetailText>{t`ID #${question.id()}`}</QuestionPaneDetailText>
</QuestionPaneDetail> </QuestionPaneDetail>
<QuestionPaneDetail>
<QuestionPaneIcon name="all" />
<QuestionPaneDetailText>
{collection?.name ?? t`Our analytics`}
</QuestionPaneDetailText>
</QuestionPaneDetail>
<QuestionPaneDetail> <QuestionPaneDetail>
<QuestionPaneIcon name="calendar" /> <QuestionPaneIcon name="calendar" />
<QuestionPaneDetailText> <QuestionPaneDetailText>
...@@ -98,6 +110,11 @@ const QuestionPane = ({ ...@@ -98,6 +110,11 @@ const QuestionPane = ({
export default _.compose( export default _.compose(
Questions.load({ Questions.load({
id: (_state: State, props: QuestionPaneProps) => props.question.id, id: (_state: State, props: QuestionPaneProps) => props.question.id,
entityAlias: "card",
}),
Collections.load({
id: (_state: State, props: QuestionPaneProps) => props.card.collection_id,
loadingAndErrorWrapper: false,
}), }),
connect(mapStateToProps), connect(mapStateToProps),
)(QuestionPane); )(QuestionPane);
import { restore, openNativeEditor } from "__support__/e2e/helpers"; import {
restore,
openNativeEditor,
openQuestionActions,
} from "__support__/e2e/helpers";
describe("scenarios > native question > data reference sidebar", () => { describe("scenarios > native question > data reference sidebar", () => {
beforeEach(() => { beforeEach(() => {
...@@ -38,11 +42,18 @@ describe("scenarios > native question > data reference sidebar", () => { ...@@ -38,11 +42,18 @@ describe("scenarios > native question > data reference sidebar", () => {
}, },
{ visitQuestion: true }, { visitQuestion: true },
); );
// Move question to personal collection
openQuestionActions();
cy.findByTestId("move-button").click();
cy.findByText("My personal collection").click();
cy.findByText("Move").click();
openNativeEditor(); openNativeEditor();
cy.icon("reference").click(); cy.icon("reference").click();
cy.findByText("1 model"); cy.findByText("1 model");
cy.findByText("Native Products Model").click(); cy.findByText("Native Products Model").click();
cy.findByText("A model of the Products table"); cy.findByText("A model of the Products table"); // description
cy.findByText("Bobby Tables's Personal Collection"); // collection
cy.findByText("1 column"); cy.findByText("1 column");
cy.findByText("RENAMED_ID").click(); cy.findByText("RENAMED_ID").click();
cy.findByText("No description"); cy.findByText("No description");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment