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.
Add
TableInfoPopover
and add it to Table cards on the /browse
rou…
…te (metabase#19322) * add TableInfoPopover * Finish TableInfo implementation * Add TableInfoPopover to TableBrowser * TableInfo & TableInfoPopover styling tweaks * add a cypress test for the /browse popover * TableInfo unit tests update * fix smoketest test * shorter delay * Add loading state for table metadata * Fix table fk link * make everything typescript * add more unit tests * fix types * fix e2e test * styles cleanup * review changes Co-authored-by: Maz Ameli <[email protected]>
- Loading branch information
1 parent
98da3e5
commit 67ed5c3
Showing
27 changed files
with
625 additions
and
145 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { PRODUCTS } from "__support__/sample_dataset_fixture"; | ||
import Table from "./Table"; | ||
|
||
describe("Table", () => { | ||
const productsTable = new Table(PRODUCTS); | ||
|
||
describe("numFields", () => { | ||
it("should return the number of fields", () => { | ||
expect(productsTable.numFields()).toBe(8); | ||
}); | ||
|
||
it("should handle scenario where fields prop is missing", () => { | ||
const table = new Table({}); | ||
expect(table.numFields()).toBe(0); | ||
}); | ||
}); | ||
|
||
describe("connectedTables", () => { | ||
it("should return a list of table instances connected to it via fk", () => { | ||
const table = new Table({ | ||
fks: [ | ||
{ | ||
origin: { table: PRODUCTS }, | ||
}, | ||
], | ||
}); | ||
|
||
expect(table.connectedTables()).toEqual([productsTable]); | ||
}); | ||
}); | ||
}); |
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
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
51 changes: 0 additions & 51 deletions
51
frontend/src/metabase/components/MetadataInfo/MetadataInfo.styled.jsx
This file was deleted.
Oops, something went wrong.
95 changes: 95 additions & 0 deletions
95
frontend/src/metabase/components/MetadataInfo/MetadataInfo.styled.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,95 @@ | ||
import styled from "styled-components"; | ||
|
||
import { space } from "metabase/styled-components/theme"; | ||
import { color } from "metabase/lib/colors"; | ||
import Icon from "metabase/components/Icon"; | ||
import { isReducedMotionPreferred } from "metabase/lib/dom"; | ||
import _LoadingSpinner from "metabase/components/LoadingSpinner"; | ||
|
||
const TRANSITION_DURATION = () => (isReducedMotionPreferred() ? "0" : "0.25s"); | ||
|
||
export const Container = styled.div` | ||
position: relative; | ||
display: flex; | ||
flex-direction: column; | ||
gap: ${space(1)}; | ||
overflow: auto; | ||
`; | ||
|
||
export const AbsoluteContainer = styled.div` | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
`; | ||
|
||
export const InfoContainer = styled(Container)` | ||
padding: ${space(2)}; | ||
`; | ||
|
||
export const Description = styled.div` | ||
font-size: 14px; | ||
white-space: pre-line; | ||
max-height: 200px; | ||
overflow: auto; | ||
`; | ||
|
||
export const EmptyDescription = styled(Description)` | ||
color: ${color("text-light")}; | ||
font-weight: 700; | ||
`; | ||
|
||
export const LabelContainer = styled.div` | ||
display: inline-flex; | ||
align-items: center; | ||
column-gap: ${space(0)}; | ||
font-size: 12px; | ||
color: ${({ color: _color = "brand" }) => color(_color)}; | ||
`; | ||
|
||
export const Label = styled.span` | ||
font-weight: bold; | ||
font-size: 1em; | ||
`; | ||
|
||
export const RelativeSizeIcon = styled(Icon)` | ||
height: 1em; | ||
width: 1em; | ||
`; | ||
|
||
export const InvertedColorRelativeSizeIcon = styled(RelativeSizeIcon)` | ||
padding: ${space(0)}; | ||
background-color: ${color("brand")}; | ||
color: ${color("white")}; | ||
border-radius: ${space(0)}; | ||
padding: ${space(0)}; | ||
`; | ||
|
||
type FadeProps = { | ||
visible?: boolean; | ||
}; | ||
|
||
export const Fade = styled.div<FadeProps>` | ||
width: 100%; | ||
transition: opacity ${TRANSITION_DURATION} linear; | ||
opacity: ${({ visible }) => (visible ? "1" : "0")}; | ||
`; | ||
|
||
export const FadeAndSlide = styled.div<FadeProps>` | ||
width: 100%; | ||
transition: opacity ${TRANSITION_DURATION} linear, | ||
transform ${TRANSITION_DURATION} linear; | ||
opacity: ${({ visible }) => (visible ? "1" : "0")}; | ||
`; | ||
|
||
export const LoadingSpinner = styled(_LoadingSpinner)` | ||
display: flex; | ||
flex-grow: 1; | ||
align-self: center; | ||
justify-content: center; | ||
color: ${color("brand")}; | ||
`; |
28 changes: 28 additions & 0 deletions
28
frontend/src/metabase/components/MetadataInfo/TableInfo/ColumnCount.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,28 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import { msgid, ngettext } from "ttag"; | ||
|
||
import Table from "metabase-lib/lib/metadata/Table"; | ||
|
||
import { Label, LabelContainer } from "../MetadataInfo.styled"; | ||
|
||
ColumnCount.propTypes = { | ||
table: PropTypes.instanceOf(Table).isRequired, | ||
}; | ||
|
||
function ColumnCount({ table }: { table: Table }) { | ||
const fieldCount = table.numFields(); | ||
return ( | ||
<LabelContainer color="text-dark"> | ||
<Label> | ||
{ngettext( | ||
msgid`${fieldCount} column`, | ||
`${fieldCount} columns`, | ||
fieldCount, | ||
)} | ||
</Label> | ||
</LabelContainer> | ||
); | ||
} | ||
|
||
export default ColumnCount; |
33 changes: 33 additions & 0 deletions
33
frontend/src/metabase/components/MetadataInfo/TableInfo/ColumnCount.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,33 @@ | ||
import React from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
|
||
import Table from "metabase-lib/lib/metadata/Table"; | ||
|
||
import ColumnCount from "./ColumnCount"; | ||
|
||
function setup(table: Table) { | ||
return render(<ColumnCount table={table} />); | ||
} | ||
|
||
describe("ColumnCount", () => { | ||
it("should show a non-plural label for a table with a single field", () => { | ||
const table = new Table({ fields: [{}] }); | ||
setup(table); | ||
|
||
expect(screen.getByText("1 column")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should show a plural label for a table with multiple fields", () => { | ||
const table = new Table({ fields: [{}, {}] }); | ||
setup(table); | ||
|
||
expect(screen.getByText("2 columns")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should handle a scenario where a table has no fields property", () => { | ||
const table = new Table({ id: 123, display_name: "Foo" }); | ||
setup(table); | ||
|
||
expect(screen.getByText("0 columns")).toBeInTheDocument(); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
frontend/src/metabase/components/MetadataInfo/TableInfo/ConnectedTables.styled.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,14 @@ | ||
import styled from "styled-components"; | ||
|
||
import { color } from "metabase/lib/colors"; | ||
|
||
import TableLabel from "../TableLabel/TableLabel"; | ||
|
||
export const InteractiveTableLabel = styled(TableLabel)` | ||
cursor: pointer; | ||
color: ${color("text-light")}; | ||
&:hover { | ||
color: ${color("brand")}; | ||
} | ||
`; |
Oops, something went wrong.