diff --git a/frontend/src/metabase/admin/datamodel/containers/MetadataEditorApp.jsx b/frontend/src/metabase/admin/datamodel/containers/MetadataEditorApp.jsx index 3e0bd8dce21da4018d9aca5b49ef99b876fda2a3..4d93baede74307be9ae7d8ffdb080fd661b35be1 100644 --- a/frontend/src/metabase/admin/datamodel/containers/MetadataEditorApp.jsx +++ b/frontend/src/metabase/admin/datamodel/containers/MetadataEditorApp.jsx @@ -17,6 +17,18 @@ import { fields as Fields, } from "metabase/entities"; +const propTypes = { + databaseId: PropTypes.number, + database: PropTypes.object, + loading: PropTypes.bool, + tableId: PropTypes.number, + selectDatabase: PropTypes.func.isRequired, + selectTable: PropTypes.func.isRequired, + idfields: PropTypes.array, + updateField: PropTypes.func.isRequired, + onRetireMetric: PropTypes.func.isRequired, +}; + const mapStateToProps = (state, { params }) => { const databaseId = params.databaseId ? parseInt(params.databaseId) @@ -45,7 +57,11 @@ const mapDispatchToProps = { mapStateToProps, mapDispatchToProps, ) -export default class MetadataEditor extends Component { +@Databases.load({ + id: (state, props) => props.databaseId, + loadingAndErrorWrapper: false, +}) +class MetadataEditor extends Component { constructor(props, context) { super(props, context); this.toggleShowSchema = this.toggleShowSchema.bind(this); @@ -55,16 +71,6 @@ export default class MetadataEditor extends Component { }; } - static propTypes = { - databaseId: PropTypes.number, - tableId: PropTypes.number, - selectDatabase: PropTypes.func.isRequired, - selectTable: PropTypes.func.isRequired, - idfields: PropTypes.array, - updateField: PropTypes.func.isRequired, - onRetireMetric: PropTypes.func.isRequired, - }; - toggleShowSchema() { this.setState({ isShowingSchema: !this.state.isShowingSchema }); MetabaseAnalytics.trackEvent( @@ -75,7 +81,8 @@ export default class MetadataEditor extends Component { } render() { - const { databaseId, tableId } = this.props; + const { databaseId, tableId, database, loading } = this.props; + const hasLoadedDatabase = !loading && database; return ( <div className="p4"> <MetadataHeader @@ -88,7 +95,7 @@ export default class MetadataEditor extends Component { style={{ minHeight: "60vh" }} className="flex flex-row flex-full mt2 full-height" > - {databaseId && ( + {hasLoadedDatabase && ( <MetadataTablePicker tableId={tableId} databaseId={databaseId} @@ -109,9 +116,15 @@ export default class MetadataEditor extends Component { ) ) : ( <div style={{ paddingTop: "10rem" }} className="full text-centered"> - <AdminEmptyText - message={t`Select any table to see its schema and add or edit metadata.`} - /> + {!loading && ( + <AdminEmptyText + message={ + hasLoadedDatabase + ? t`Select any table to see its schema and add or edit metadata.` + : t`The page you asked for couldn't be found.` + } + /> + )} </div> )} </div> @@ -119,3 +132,7 @@ export default class MetadataEditor extends Component { ); } } + +MetadataEditor.propTypes = propTypes; + +export default MetadataEditor; diff --git a/frontend/src/metabase/query_builder/components/DataSelector.jsx b/frontend/src/metabase/query_builder/components/DataSelector.jsx index 46b7a47c54cf1304b0b16496af153e99d925efd1..c92b71826ae79d30a165610e8e4fb105331460ce 100644 --- a/frontend/src/metabase/query_builder/components/DataSelector.jsx +++ b/frontend/src/metabase/query_builder/components/DataSelector.jsx @@ -234,7 +234,7 @@ export class UnconnectedDataSelector extends Component { if (!schemas && database) { schemas = database.schemas; } - if (!tables && schemas.length === 1) { + if (!tables && Array.isArray(schemas) && schemas.length === 1) { tables = schemas[0].tables; } } diff --git a/frontend/test/metabase/scenarios/admin/datamodel/table.cy.spec.js b/frontend/test/metabase/scenarios/admin/datamodel/table.cy.spec.js index 135f635b0fd3a765801afb61a9cf3b6d6efba2d9..8b9f82024780fc0793f88e9d86f8f94ec7c2d75b 100644 --- a/frontend/test/metabase/scenarios/admin/datamodel/table.cy.spec.js +++ b/frontend/test/metabase/scenarios/admin/datamodel/table.cy.spec.js @@ -30,6 +30,13 @@ describe("scenarios > admin > databases > table", () => { ); }); + it("should show 404 if database does not exist (metabase#14652)", () => { + cy.visit("/admin/datamodel/database/54321"); + cy.get(".AdminList-item").should("have.length", 0); + cy.findByText("The page you asked for couldn't be found."); + cy.findByText("Select a database"); + }); + describe("in orders table", () => { beforeEach(() => { cy.visit("/admin/datamodel/database/1/table/2");