diff --git a/frontend/src/metabase/admin/permissions/pages/DataPermissionsPage/DataPermissionsPage.jsx b/frontend/src/metabase/admin/permissions/pages/DataPermissionsPage/DataPermissionsPage.jsx index 5e3cb7ad43af74614d649b800b62ab881a6a780b..45cedb1b2d35e7bdf1dda42d544c2b5e6dc03d89 100644 --- a/frontend/src/metabase/admin/permissions/pages/DataPermissionsPage/DataPermissionsPage.jsx +++ b/frontend/src/metabase/admin/permissions/pages/DataPermissionsPage/DataPermissionsPage.jsx @@ -93,6 +93,8 @@ DataPermissionsPage.propTypes = propTypes; export default _.compose( Groups.loadList(), - Databases.loadList(), + Databases.loadList({ + selectorName: "getListUnfiltered", + }), connect(mapStateToProps, mapDispatchToProps), )(DataPermissionsPage); diff --git a/frontend/src/metabase/admin/permissions/selectors/data-permissions/diff.ts b/frontend/src/metabase/admin/permissions/selectors/data-permissions/diff.ts index 35c4f47bf483ec68547bafc313309a334dda6821..e3cdaa12f4104353f1bc8ec0d99df0d7ae2a02d1 100644 --- a/frontend/src/metabase/admin/permissions/selectors/data-permissions/diff.ts +++ b/frontend/src/metabase/admin/permissions/selectors/data-permissions/diff.ts @@ -1,37 +1,11 @@ import { createSelector } from "@reduxjs/toolkit"; -import type { Selector } from "@reduxjs/toolkit"; import _ from "underscore"; import { diffDataPermissions } from "metabase/admin/permissions/utils/graph"; -import Groups from "metabase/entities/groups"; import { PLUGIN_DATA_PERMISSIONS } from "metabase/plugins"; - -import { Database } from "metabase-types/api"; +import { Group } from "metabase-types/api"; import { State } from "metabase-types/store"; -import { isVirtualCardId } from "metabase-lib/metadata/utils/saved-questions"; - -const getDatabasesWithTables: Selector<State, Database[]> = createSelector( - (state: State) => state.entities.databases, - (state: State) => state.entities.tables, - (databases, tables) => { - if (!databases || !tables) { - return []; - } - const databasesList = Object.values(databases); - const tablesList = Object.values(tables); - - return databasesList.map(database => { - const databaseTables = tablesList.filter( - table => table.db_id === database.id && !isVirtualCardId(table.id), - ); - - return { - ...database, - tables: databaseTables, - }; - }); - }, -); +import Database from "metabase-lib/metadata/Database"; export const getIsDirty = createSelector( (state: State) => state.admin.permissions.dataPermissions, @@ -41,9 +15,14 @@ export const getIsDirty = createSelector( !_.isEqual(permissions, originalPermissions) || hasExtraChanges, ); +interface DiffProps { + databases: Database[]; + groups: Group[]; +} + export const getDiff = createSelector( - getDatabasesWithTables, - Groups.selectors.getList, + (state: State, { databases }: DiffProps) => databases, + (state: State, { groups }: DiffProps) => groups, (state: State) => state.admin.permissions.dataPermissions, (state: State) => state.admin.permissions.originalDataPermissions, (databases, groups, permissions, originalPermissions) => diff --git a/frontend/src/metabase/admin/permissions/utils/graph/permissions-diff.ts b/frontend/src/metabase/admin/permissions/utils/graph/permissions-diff.ts index d1e943aa4221eb7db35fa394fa0777cb2ac454f0..477692655cceedb3287c9e12b4dca62fffd84fc7 100644 --- a/frontend/src/metabase/admin/permissions/utils/graph/permissions-diff.ts +++ b/frontend/src/metabase/admin/permissions/utils/graph/permissions-diff.ts @@ -1,9 +1,9 @@ import type { ConcreteTableId, - Database, Group, GroupsPermissions, } from "metabase-types/api"; +import Database from "metabase-lib/metadata/Database"; import { getFieldsPermission, getNativePermission, diff --git a/frontend/src/metabase/entities/databases.js b/frontend/src/metabase/entities/databases.js index ba94a37f000e1a9575262574ff5bbfcb6596633c..4ef0a69c4ecda3e0fb6821991138669e2a223164 100644 --- a/frontend/src/metabase/entities/databases.js +++ b/frontend/src/metabase/entities/databases.js @@ -12,7 +12,11 @@ import { DatabaseSchema } from "metabase/schema"; import Fields from "metabase/entities/fields"; import Schemas from "metabase/entities/schemas"; -import { getMetadata, getFields } from "metabase/selectors/metadata"; +import { + getMetadata, + getFields, + getMetadataUnfiltered, +} from "metabase/selectors/metadata"; // OBJECT ACTIONS export const FETCH_DATABASE_METADATA = @@ -74,6 +78,16 @@ const Databases = createEntity({ selectors: { getObject: (state, { entityId }) => getMetadata(state).database(entityId), + // these unfiltered selectors include hidden tables/fields for display in the admin panel + getObjectUnfiltered: (state, { entityId }) => + getMetadataUnfiltered(state).database(entityId), + getListUnfiltered: (state, { entityQuery }) => { + const entityIds = + Databases.selectors.getEntityIds(state, { entityQuery }) ?? []; + return entityIds.map(entityId => + Databases.selectors.getObjectUnfiltered(state, { entityId }), + ); + }, getHasSampleDatabase: (state, props) => _.any(Databases.selectors.getList(state, props), db => db.is_sample),