Skip to content

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

Uxw 3685 emotion css mantine model actions (#84319)

Nick Fitzpatrick409163293818
diff --git a/frontend/src/metabase/models/components/ModelActions/EmptyState.styled.tsx b/frontend/src/metabase/models/components/ModelActions/EmptyState.styled.tsx
deleted file mode 100644
index d64e4422ec6..00000000000
--- a/frontend/src/metabase/models/components/ModelActions/EmptyState.styled.tsx
+++ /dev/null
@@ -1,31 +0,0 @@
-// eslint-disable-next-line eslint-js/no-restricted-imports
-import styled from "@emotion/styled";
-
-export const EmptyStateContainer = styled.div`
- display: flex;
- height: 100%;
- gap: 0.5rem;
- flex-direction: column;
- justify-content: center;
- text-align: center;
- margin: auto;
- max-width: 400px;
-`;
-
-export const EmptyStateTitle = styled.h4`
- font-size: 1rem;
- font-weight: 700;
- color: var(--mb-color-text-primary);
-`;
-
-export const EmptyStateMessage = styled.p`
- color: var(--mb-color-text-secondary);
- font-size: 0.875rem;
- font-weight: 400;
- line-height: 1.18rem;
- margin-top: 0.5rem;
-`;
-
-export const EmptyStateActionContainer = styled.div`
- margin-top: 1rem;
-`;
diff --git a/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/ModelActionDetails.styled.tsx b/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/ModelActionDetails.styled.tsx
deleted file mode 100644
index 7dbfe8652b9..00000000000
--- a/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/ModelActionDetails.styled.tsx
+++ /dev/null
@@ -1,28 +0,0 @@
-// eslint-disable-next-line eslint-js/no-restricted-imports
-import styled from "@emotion/styled";
-
-import { breakpointMaxMedium } from "metabase/styled-components/theme";
-
-export const Root = styled.div`
- width: 100%;
- height: 100%;
-`;
-
-export const ActionsHeader = styled.div`
- display: flex;
- justify-content: flex-end;
- align-items: center;
-`;
-
-export const ActionList = styled.ul`
- width: 70%;
- margin-top: 1rem;
-
- li:not(:first-of-type) {
- margin-top: 2.25rem;
- }
-
- ${breakpointMaxMedium} {
- width: 100%;
- }
-`;
diff --git a/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/ModelActionDetails.tsx b/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/ModelActionDetails.tsx
index 5dd4684ef93..87a3a19439f 100644
--- a/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/ModelActionDetails.tsx
+++ b/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/ModelActionDetails.tsx
@@ -10,7 +10,18 @@ import {
import { useSetArchive } from "metabase/archive/hooks";
import { Link } from "metabase/common/components/Link";
import { useConfirmation } from "metabase/common/hooks/use-confirmation";
-import { ActionIcon, Alert, Button, Icon, Menu } from "metabase/ui";
+import {
+ ActionIcon,
+ Alert,
+ Box,
+ Button,
+ Flex,
+ Icon,
+ Menu,
+ Stack,
+ Text,
+ Title,
+} from "metabase/ui";
import * as Urls from "metabase/urls";
import { parseTimestamp } from "metabase/utils/time-dayjs";
import type Question from "metabase-lib/v1/Question";
@@ -21,26 +32,16 @@ import {
} from "metabase-lib/v1/actions/utils";
import type { Database, WritebackAction } from "metabase-types/api";
-import {
- EmptyStateActionContainer,
- EmptyStateContainer,
- EmptyStateMessage,
- EmptyStateTitle,
-} from "../EmptyState.styled";
-
-import { ActionList, ActionsHeader, Root } from "./ModelActionDetails.styled";
-import ModelActionListItem from "./ModelActionListItem";
+import { ModelActionListItem } from "./ModelActionListItem";
import { useEnableImplicitActionsForModel } from "./useEnableImplicitActionsForModel";
-interface OwnProps {
+const EMPTY_DATABASE_LIST: Database[] = [];
+
+interface ModelActionDetailsProps {
model: Question;
}
-type Props = OwnProps;
-
-const EMPTY_DATABASE_LIST: Database[] = [];
-
-function ModelActionDetails({ model }: Props) {
+export function ModelActionDetails({ model }: ModelActionDetailsProps) {
const { data: databasesResponse } = useListDatabasesQuery();
const databases = databasesResponse?.data ?? EMPTY_DATABASE_LIST;
const { data: actions = [] } = useListActionsQuery({
@@ -115,9 +116,13 @@ function ModelActionDetails({ model }: Props) {
const newActionUrl = Urls.newAction(model.card());
return (
- <Root data-testid="model-action-details">
+ <Box w="100%" h="100%" data-testid="model-action-details">
{canWrite && (
- <ActionsHeader data-testid="model-actions-header">
+ <Flex
+ justify="flex-end"
+ align="center"
+ data-testid="model-actions-header"
+ >
<Button component={Link} to={newActionUrl}>{t`New action`}</Button>
{hasActionsMenu && (
<Menu position="bottom-end">
@@ -145,7 +150,7 @@ function ModelActionDetails({ model }: Props) {
</Menu.Dropdown>
</Menu>
)}
- </ActionsHeader>
+ </Flex>
)}
{database && !hasActionsEnabled && (
<Alert
@@ -158,9 +163,15 @@ function ModelActionDetails({ model }: Props) {
</Alert>
)}
{actions.length > 0 ? (
- <ActionList aria-label={t`Action list`}>
+ <Stack
+ component="ul"
+ gap="2.25rem"
+ w={{ base: "100%", md: "70%" }}
+ mt="lg"
+ aria-label={t`Action list`}
+ >
{actionsSorted.map(renderActionListItem)}
- </ActionList>
+ </Stack>
) : (
<NoActionsState
hasCreateButton={canWrite && supportsImplicitActions}
@@ -168,30 +179,41 @@ function ModelActionDetails({ model }: Props) {
/>
)}
{confirmationModal}
- </Root>
+ </Box>
);
}
+interface NoActionsStateProps {
+ hasCreateButton: boolean;
+ onCreateClick: () => void;
+}
+
function NoActionsState({
hasCreateButton,
onCreateClick,
-}: {
- hasCreateButton: boolean;
- onCreateClick: () => void;
-}) {
+}: NoActionsStateProps) {
return (
- <EmptyStateContainer>
- <EmptyStateTitle>{t`No actions have been created yet.`}</EmptyStateTitle>
- <EmptyStateMessage>{t`Get started quickly with some basic actions to create, edit and delete, or create your own from scratch.`}</EmptyStateMessage>
+ <Stack justify="center" gap="sm" h="100%" maw="25rem" m="auto" ta="center">
+ <Title
+ order={4}
+ fz="1rem"
+ lh="normal"
+ c="text-primary"
+ >{t`No actions have been created yet.`}</Title>
+ <Text
+ component="p"
+ mt="sm"
+ c="text-secondary"
+ >{t`Get started quickly with some basic actions to create, edit and delete, or create your own from scratch.`}</Text>
{hasCreateButton && (
- <EmptyStateActionContainer>
+ <Box mt="lg">
<Button
leftSection={<Icon name="bolt" />}
onClick={onCreateClick}
>{t`Create basic actions`}</Button>
- </EmptyStateActionContainer>
+ </Box>
)}
- </EmptyStateContainer>
+ </Stack>
);
}
@@ -199,6 +221,3 @@ function mostRecentFirst(action: WritebackAction) {
const createdAt = parseTimestamp(action["created_at"]);
return -createdAt.valueOf();
}
-
-// eslint-disable-next-line import/no-default-export -- deprecated usage
-export default ModelActionDetails;
diff --git a/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/ModelActionListItem.module.css b/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/ModelActionListItem.module.css
new file mode 100644
index 00000000000..83bd37add95
--- /dev/null
+++ b/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/ModelActionListItem.module.css
@@ -0,0 +1,5 @@
+.dotSeparated:not(:last-child)::after {
+ content: "·";
+ margin-left: 0.375rem;
+ margin-right: 0.375rem;
+}
diff --git a/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/ModelActionListItem.styled.tsx b/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/ModelActionListItem.styled.tsx
deleted file mode 100644
index fc0bb2a3bb0..00000000000
--- a/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/ModelActionListItem.styled.tsx
+++ /dev/null
@@ -1,88 +0,0 @@
-// eslint-disable-next-line eslint-js/no-restricted-imports
-import { css } from "@emotion/react";
-// eslint-disable-next-line eslint-js/no-restricted-imports
-import styled from "@emotion/styled";
-
-import { Link } from "metabase/common/components/Link";
-import { Icon } from "metabase/ui";
-import { color } from "metabase/ui/utils/colors";
-
-export const ActionHeader = styled.div`
- display: flex;
- align-items: flex-end;
- justify-content: space-between;
-`;
-
-export const ActionTitle = styled(Link)`
- font-size: 1rem;
- font-weight: 700;
- color: var(--mb-color-text-primary);
- cursor: ${(props) => (props.to ? "pointer" : "unset")};
-
- &:hover {
- color: ${(props) => props.to && color("core-brand")};
- }
-`;
-
-export const ActionSubtitle = styled.span`
- display: block;
- font-size: 0.75rem;
- font-weight: 700;
- line-height: 0.875rem;
- color: var(--mb-color-text-secondary);
- margin-top: 4px;
-`;
-
-export const ActionSubtitlePart = styled.span`
- &:not(:last-child)::after {
- content: "·";
- margin-left: 6px;
- margin-right: 6px;
- }
-`;
-
-export const MenuIcon = styled(Icon)`
- color: var(--mb-color-text-primary);
- cursor: pointer;
-
- &:hover {
- color: var(--mb-color-core-brand);
- }
-`;
-
-export const ActionCardContainer = styled.div`
- position: relative;
- margin-top: 0.75rem;
-`;
-
-const baseActionCardStyles = css`
- padding: 1rem;
- border-radius: 6px;
-`;
-
-export const CodeBlock = styled.pre`
- ${baseActionCardStyles}
-
- font-family: var(--mb-default-monospace-font-family);
- font-size: 0.7rem;
- white-space: pre-wrap;
- margin: 0;
- color: var(--mb-color-text-primary-inverse);
- background-color: var(--mb-color-text-primary);
-`;
-
-export const ActionRunButtonContainer = styled.div`
- position: absolute;
- top: 0.5rem;
- right: 0.5rem;
-`;
-
-export const ImplicitActionCardContentRoot = styled.div`
- ${baseActionCardStyles};
-
- display: flex;
- align-items: center;
- color: var(--mb-color-text-secondary);
- background-color: var(--mb-color-background_page-tertiary);
- font-weight: 400;
-`;
diff --git a/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/ModelActionListItem.tsx b/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/ModelActionListItem.tsx
index bb3e08277e8..91915e1262b 100644
--- a/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/ModelActionListItem.tsx
+++ b/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/ModelActionListItem.tsx
@@ -1,36 +1,45 @@
import { useDisclosure } from "@mantine/hooks";
-import { useCallback } from "react";
+import cx from "classnames";
+import { type ReactNode, useCallback } from "react";
import { t } from "ttag";
import { ActionExecuteModal } from "metabase/actions/containers/ActionExecuteModal";
-import { ForwardRefLink } from "metabase/common/components/Link";
+import { ForwardRefLink, Link } from "metabase/common/components/Link";
import { useConfirmation } from "metabase/common/hooks/use-confirmation";
-import { ActionIcon, Icon, Menu, Tooltip } from "metabase/ui";
+import CS from "metabase/css/core/index.css";
+import { ActionIcon, Box, Flex, Icon, Menu, Text, Tooltip } from "metabase/ui";
import * as Lib from "metabase-lib";
import Question from "metabase-lib/v1/Question";
import type { WritebackAction, WritebackQueryAction } from "metabase-types/api";
-import {
- ActionCardContainer,
- ActionHeader,
- ActionRunButtonContainer,
- ActionSubtitle,
- ActionSubtitlePart,
- ActionTitle,
- CodeBlock,
- ImplicitActionCardContentRoot,
-} from "./ModelActionListItem.styled";
+import S from "./ModelActionListItem.module.css";
-interface Props {
- action: WritebackAction;
- actionUrl: string;
- canRun: boolean;
- canEdit: boolean;
- canArchive: boolean;
- onArchive: (action: WritebackAction) => void;
+interface CodeBlockProps {
+ children: ReactNode;
}
-function QueryActionCardContent({ action }: { action: WritebackQueryAction }) {
+function CodeBlock({ children }: CodeBlockProps) {
+ return (
+ <Box
+ component="pre"
+ className={cx(CS.textMonospace, CS.textPreWrap)}
+ p="lg"
+ m={0}
+ fz="xs"
+ c="text-primary-inverse"
+ bg="text-primary"
+ bdrs="xs"
+ >
+ {children}
+ </Box>
+ );
+}
+
+interface QueryActionCardContentProps {
+ action: WritebackQueryAction;
+}
+
+function QueryActionCardContent({ action }: QueryActionCardContentProps) {
const question = Question.create({ dataset_query: action.dataset_query });
if (!question.isNative()) {
return (
@@ -48,20 +57,29 @@ function QueryActionCardContent({ action }: { action: WritebackQueryAction }) {
function ImplicitActionCardContent() {
return (
- <ImplicitActionCardContentRoot>
- <div>{t`Auto tracking schema`}</div>
- </ImplicitActionCardContentRoot>
+ <Flex align="center" p="lg" bg="background_page-tertiary" bdrs="xs">
+ <Text c="text-secondary">{t`Auto tracking schema`}</Text>
+ </Flex>
);
}
-function ModelActionListItem({
+interface ModelActionListItemProps {
+ action: WritebackAction;
+ actionUrl: string;
+ canRun: boolean;
+ canEdit: boolean;
+ canArchive: boolean;
+ onArchive: (action: WritebackAction) => void;
+}
+
+export function ModelActionListItem({
action,
actionUrl,
canRun,
canEdit,
canArchive,
onArchive,
-}: Props) {
+}: ModelActionListItemProps) {
const { show: askConfirmation, modalContent: confirmationModal } =
useConfirmation();
const [
@@ -79,22 +97,30 @@ function ModelActionListItem({
return (
<>
- <ActionHeader>
+ <Flex align="flex-end" justify="space-between">
<div>
- <ActionTitle to={actionUrl}>{action.name}</ActionTitle>
- <ActionSubtitle>
+ <Box
+ component={Link}
+ className={cx(CS.textDefault, CS.textBrandHover)}
+ to={actionUrl}
+ fz="1rem"
+ fw={700}
+ >
+ {action.name}
+ </Box>
+ <Text mt="xxs" size="sm" fw={700} lh="0.875rem" c="text-secondary">
{action.type === "implicit" && (
- <ActionSubtitlePart>{t`Basic action`}</ActionSubtitlePart>
+ <span className={S.dotSeparated}>{t`Basic action`}</span>
)}
{action.public_uuid && (
- <ActionSubtitlePart>{t`Public action form`}</ActionSubtitlePart>
+ <span className={S.dotSeparated}>{t`Public action form`}</span>
)}
{action.creator && (
- <ActionSubtitlePart>
+ <span className={S.dotSeparated}>
{t`Created by ${action.creator.common_name}`}
- </ActionSubtitlePart>
+ </span>
)}
- </ActionSubtitle>
+ </Text>
</div>
<Menu position="bottom-end">
<Menu.Target>
@@ -123,8 +149,8 @@ function ModelActionListItem({
)}
</Menu.Dropdown>
</Menu>
- </ActionHeader>
- <ActionCardContainer>
+ </Flex>
+ <Box pos="relative" mt="md">
{action.type === "query" ? (
<QueryActionCardContent action={action} />
) : action.type === "implicit" ? (
@@ -132,7 +158,7 @@ function ModelActionListItem({
) : null}
{canRun && (
<>
- <ActionRunButtonContainer>
+ <Box pos="absolute" top="0.5rem" right="0.5rem">
<Tooltip label={t`Run`}>
<ActionIcon
variant="subtle"
@@ -144,7 +170,7 @@ function ModelActionListItem({
<Icon name="play" />
</ActionIcon>
</Tooltip>
- </ActionRunButtonContainer>
+ </Box>
<ActionExecuteModal
opened={executeModalOpened}
actionId={action.id}
@@ -152,11 +178,8 @@ function ModelActionListItem({
/>
</>
)}
- </ActionCardContainer>
+ </Box>
{confirmationModal}
</>
);
}
-
-// eslint-disable-next-line import/no-default-export -- deprecated usage
-export default ModelActionListItem;
diff --git a/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/index.ts b/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/index.ts
index d171631e663..44d789e677a 100644
--- a/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/index.ts
+++ b/frontend/src/metabase/models/components/ModelActions/ModelActionDetails/index.ts
@@ -1,2 +1 @@
-// eslint-disable-next-line import/no-default-export -- deprecated usage
-export { default } from "./ModelActionDetails";
+export { ModelActionDetails } from "./ModelActionDetails";
diff --git a/frontend/src/metabase/models/components/ModelActions/ModelActions.tsx b/frontend/src/metabase/models/components/ModelActions/ModelActions.tsx
index d9592cbd898..c80871160bf 100644
--- a/frontend/src/metabase/models/components/ModelActions/ModelActions.tsx
+++ b/frontend/src/metabase/models/components/ModelActions/ModelActions.tsx
@@ -5,7 +5,7 @@ import { Group, Icon, Paper, Stack, Title } from "metabase/ui";
import * as Urls from "metabase/urls";
import type Question from "metabase-lib/v1/Question";
-import ModelActionDetails from "./ModelActionDetails";
+import { ModelActionDetails } from "./ModelActionDetails";
interface Props {
model: Question;