Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

DSN-74 People page should use tabs instead of radios for active/deactivated control (#63817)

Kamil Mielnik85e6e7f779cd
diff --git a/frontend/src/metabase/admin/people/containers/PeopleListingApp.module.css b/frontend/src/metabase/admin/people/containers/PeopleListingApp.module.css
new file mode 100644
index 00000000000..56e849a0eff
--- /dev/null
+++ b/frontend/src/metabase/admin/people/containers/PeopleListingApp.module.css
@@ -0,0 +1,5 @@
+.tabs {
+ &:before {
+ display: none;
+ }
+}
diff --git a/frontend/src/metabase/admin/people/containers/PeopleListingApp.tsx b/frontend/src/metabase/admin/people/containers/PeopleListingApp.tsx
index 9576a3c5683..8ca1088b3a5 100644
--- a/frontend/src/metabase/admin/people/containers/PeopleListingApp.tsx
+++ b/frontend/src/metabase/admin/people/containers/PeopleListingApp.tsx
@@ -1,21 +1,24 @@
+import { useEffect } from "react";
+import { Link } from "react-router";
import { t } from "ttag";
import {
SettingsPageWrapper,
SettingsSection,
} from "metabase/admin/components/SettingsSection";
-import { useListPermissionsGroupsQuery } from "metabase/api";
-import { AdminPaneLayout } from "metabase/common/components/AdminPaneLayout";
+import { useListPermissionsGroupsQuery, useListUsersQuery } from "metabase/api";
import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
import { useSelector } from "metabase/lib/redux";
import * as Urls from "metabase/lib/urls";
import { getUser, getUserIsAdmin } from "metabase/selectors/user";
-import { Flex, Group, Icon, Input, Radio } from "metabase/ui";
+import { Box, Button, Flex, Icon, Input, Stack, Tabs } from "metabase/ui";
import { PeopleList } from "../components/PeopleList";
-import { USER_STATUS } from "../constants";
+import { USER_STATUS, type UserStatus } from "../constants";
import { usePeopleQuery } from "../hooks/use-people-query";
+import S from "./PeopleListingApp.module.css";
+
const PAGE_SIZE = 25;
export function PeopleListingApp({ children }: { children: React.ReactNode }) {
@@ -38,76 +41,107 @@ export function PeopleListingApp({ children }: { children: React.ReactNode }) {
handlePreviousPage,
} = usePeopleQuery(PAGE_SIZE);
+ const { data: usersData } = useListUsersQuery({
+ status: "deactivated",
+ limit: 0,
+ });
+ const hasDeactivatedUsers = usersData && usersData.total > 0;
+
const handleSearchChange = (e: React.ChangeEvent<HTMLInputElement>) => {
updateSearchInputValue(e.target.value);
};
- const headingContent = (
- <Flex align="center" mb="xl">
- <Input
- miw="14rem"
- mr="xl"
- fz="sm"
- type="text"
- placeholder={t`Find someone`}
- value={searchInputValue}
- onChange={handleSearchChange}
- leftSection={<Icon c="text-secondary" name="search" size={16} />}
- rightSectionPointerEvents="all"
- rightSection={
- searchInputValue === "" ? (
- <div /> // rendering null causes width change
- ) : (
- <Input.ClearButton
- c={"text-secondary"}
- onClick={() => updateSearchInputValue("")}
- />
- )
- }
- />
- {isAdmin && (
- <Radio.Group
- value={status}
- onChange={(val) => updateStatus(USER_STATUS[val])}
- >
- <Group>
- <Radio label={t`Active`} value={USER_STATUS.active} />
- <Radio label={t`Deactivated`} value={USER_STATUS.deactivated} />
- </Group>
- </Radio.Group>
- )}
- </Flex>
- );
-
const buttonText =
- isAdmin && status === USER_STATUS.active ? t`Invite someone` : "";
+ isAdmin && status === USER_STATUS.active ? t`Invite someone` : undefined;
+
+ const handleTabChange = (tab: string | null) => {
+ if (tab) {
+ updateStatus(tab as UserStatus);
+ }
+ };
+
+ useEffect(() => {
+ if (!hasDeactivatedUsers) {
+ updateStatus("active");
+ }
+ }, [hasDeactivatedUsers, updateStatus]);
return (
<SettingsPageWrapper title={t`People`}>
- <SettingsSection>
- <LoadingAndErrorWrapper
- error={error}
- loading={isLoading || !currentUser}
- >
- <AdminPaneLayout
- headingContent={headingContent}
- buttonText={buttonText}
- buttonLink={Urls.newUser()}
+ <Stack gap={0}>
+ {isAdmin && hasDeactivatedUsers && (
+ <Tabs value={status} onChange={handleTabChange} pl="md">
+ <Tabs.List className={S.tabs}>
+ <Tabs.Tab value={USER_STATUS.active}>{t`Active`}</Tabs.Tab>
+ <Tabs.Tab
+ value={USER_STATUS.deactivated}
+ >{t`Deactivated`}</Tabs.Tab>
+ </Tabs.List>
+ </Tabs>
+ )}
+
+ <SettingsSection>
+ <LoadingAndErrorWrapper
+ error={error}
+ loading={isLoading || !currentUser}
>
- {currentUser && (
- <PeopleList
- groups={groups}
- isAdmin={isAdmin}
- currentUser={currentUser}
- query={query}
- onNextPage={handleNextPage}
- onPreviousPage={handlePreviousPage}
- />
- )}
- {children}
- </AdminPaneLayout>
- </LoadingAndErrorWrapper>
- </SettingsSection>
+ <div data-testid="admin-panel">
+ <Flex
+ align="center"
+ gap="xl"
+ justify="space-between"
+ mb="xl"
+ wrap="wrap"
+ >
+ <Input
+ miw="14rem"
+ fz="sm"
+ flex="1"
+ type="text"
+ placeholder={t`Find someone`}
+ value={searchInputValue}
+ onChange={handleSearchChange}
+ leftSection={
+ <Icon c="text-secondary" name="search" size={16} />
+ }
+ rightSectionPointerEvents="all"
+ rightSection={
+ searchInputValue === "" ? (
+ <div /> // rendering null causes width change
+ ) : (
+ <Input.ClearButton
+ c={"text-secondary"}
+ onClick={() => updateSearchInputValue("")}
+ />
+ )
+ }
+ />
+
+ {buttonText && (
+ <Box>
+ <Link to={Urls.newUser()}>
+ <Button variant="filled">{buttonText}</Button>
+ </Link>
+ </Box>
+ )}
+ </Flex>
+
+ {currentUser && (
+ <PeopleList
+ groups={groups}
+ isAdmin={isAdmin}
+ currentUser={currentUser}
+ query={query}
+ onNextPage={handleNextPage}
+ onPreviousPage={handlePreviousPage}
+ />
+ )}
+
+ {children}
+ </div>
+ </LoadingAndErrorWrapper>
+ </SettingsSection>
+ </Stack>
</SettingsPageWrapper>
);
}
diff --git a/frontend/src/metabase/admin/people/hooks/use-people-query.ts b/frontend/src/metabase/admin/people/hooks/use-people-query.ts
index c216757e9c1..a8f4e1b6445 100644
--- a/frontend/src/metabase/admin/people/hooks/use-people-query.ts
+++ b/frontend/src/metabase/admin/people/hooks/use-people-query.ts
@@ -1,4 +1,4 @@
-import { useEffect, useMemo, useState } from "react";
+import { useCallback, useEffect, useMemo, useState } from "react";
import { usePagination } from "metabase/common/hooks/use-pagination";
import { SEARCH_DEBOUNCE_DURATION } from "metabase/lib/constants";
@@ -31,10 +31,13 @@ export const usePeopleQuery = (pageSize: number) => {
return () => clearTimeout(timerId);
}, [searchInputValue, setPage]);
- const updateStatus = (status: UserStatus) => {
- setPage(0);
- setStatus(status);
- };
+ const updateStatus = useCallback(
+ (status: UserStatus) => {
+ setPage(0);
+ setStatus(status);
+ },
+ [setPage],
+ );
const query = useMemo(
() => ({