Skip to content

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

Migrate ActionPicker from Emotion to CSS Modules (#84054)

Nick Fitzpatrick9b6dc6db05f2
diff --git a/frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/ActionPicker.module.css b/frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/ActionPicker.module.css
new file mode 100644
index 00000000000..764bc48f087
--- /dev/null
+++ b/frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/ActionPicker.module.css
@@ -0,0 +1,17 @@
+.modelCollapseSection {
+ margin-bottom: 0.5rem;
+}
+
+.itemBackground {
+ &.selected {
+ background-color: var(--mb-color-background_surface-brand-subtle);
+ }
+
+ &:hover {
+ background-color: var(--mb-color-background_surface-hover);
+ }
+}
+
+.emptyState {
+ margin-bottom: 1rem;
+}
diff --git a/frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/ActionPicker.styled.tsx b/frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/ActionPicker.styled.tsx
deleted file mode 100644
index f442162f2c3..00000000000
--- a/frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/ActionPicker.styled.tsx
+++ /dev/null
@@ -1,47 +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 { CollapseSection } from "metabase/common/components/CollapseSection";
-import { EmptyState as UnstyledEmptyState } from "metabase/common/components/EmptyState";
-
-export const ModelCollapseSection = styled(CollapseSection)`
- margin-bottom: var(--mantine-spacing-sm);
-`;
-
-export const ActionsList = styled.ul`
- list-style: none;
- padding: 0.5rem 1rem;
-`;
-
-export const ActionItem = styled.li<{ isSelected?: boolean }>`
- display: flex;
- font-weight: bold;
- color: var(--mb-color-core-brand);
- justify-content: space-between;
- padding: 0.5rem 0.75rem;
- margin-bottom: 1px;
- border-radius: var(--mantine-spacing-xxs);
- cursor: pointer;
-
- ${({ isSelected }) =>
- isSelected &&
- css`
- background-color: var(--mb-color-background_surface-brand-subtle);
- `}
-
- &:hover {
- background-color: var(--mb-color-background_surface-hover);
- }
-`;
-
-export const EmptyState = styled(UnstyledEmptyState)`
- margin-bottom: var(--mantine-spacing-lg);
-`;
-
-export const EmptyModelStateContainer = styled.div`
- padding: var(--mantine-spacing-lg);
- color: var(--mb-color-text-secondary);
- text-align: center;
-`;
diff --git a/frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/ActionPicker.tsx b/frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/ActionPicker.tsx
index efc7c95f508..bd0c01d60c5 100644
--- a/frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/ActionPicker.tsx
+++ b/frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/ActionPicker.tsx
@@ -1,28 +1,27 @@
+import cx from "classnames";
import type { MouseEvent } from "react";
import { useMemo, useState } from "react";
import { t } from "ttag";
import { useListActionsQuery, useSearchQuery } from "metabase/api";
+import { CollapseSection } from "metabase/common/components/CollapseSection";
+import { EmptyState } from "metabase/common/components/EmptyState";
import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
import { useToggle } from "metabase/common/hooks/use-toggle";
import CS from "metabase/css/core/index.css";
import { ActionCreator } from "metabase/querying/action-creator";
import {
ActionIcon,
+ Box,
Button,
+ Flex,
Icon,
Modal,
PREVENT_AUTOCOMPLETE_CLIPPING_MODAL_PROPS,
} from "metabase/ui";
import type { Card, WritebackAction } from "metabase-types/api";
-import {
- ActionItem,
- ActionsList,
- EmptyModelStateContainer,
- EmptyState,
- ModelCollapseSection,
-} from "./ActionPicker.styled";
+import S from "./ActionPicker.module.css";
import { sortAndGroupActions } from "./utils";
type ActionPickerModel = Pick<Card, "id" | "name" | "database_id">;
@@ -59,6 +58,7 @@ export function ActionPicker({
))}
{!sortedModels.length && (
<EmptyState
+ className={S.emptyState}
message={t`No models found`}
action={t`Create new model`}
link={"/model/new"}
@@ -111,17 +111,29 @@ function ModelActionPicker({
return (
<>
- <ModelCollapseSection
+ <CollapseSection
+ className={S.modelCollapseSection}
header={<h4>{model.name}</h4>}
initialState={hasCurrentAction ? "expanded" : "collapsed"}
>
{actions.length ? (
- <ActionsList>
+ <Box component="ul" px="lg" py="sm">
{actions.map((action) => (
- <ActionItem
+ <Flex
key={action.id}
+ component="li"
+ className={cx(CS.cursorPointer, S.itemBackground, {
+ [S.selected]: currentAction?.id === action.id,
+ })}
+ justify="space-between"
+ align="center"
+ px="md"
+ py="xs"
+ mb={1}
+ bdrs="xxs"
+ c="core-brand"
+ fw="bold"
role="button"
- isSelected={currentAction?.id === action.id}
aria-selected={currentAction?.id === action.id}
onClick={() => onClick(action)}
data-testid={`action-item-${action.name}`}
@@ -138,17 +150,17 @@ function ModelActionPicker({
>
<Icon name="pencil" />
</ActionIcon>
- </ActionItem>
+ </Flex>
))}
{newActionButton}
- </ActionsList>
+ </Box>
) : (
- <EmptyModelStateContainer>
+ <Box p="lg" c="text-secondary" ta="center">
<div>{t`There are no actions for this model`}</div>
{newActionButton}
- </EmptyModelStateContainer>
+ </Box>
)}
- </ModelCollapseSection>
+ </CollapseSection>
<Modal
{...PREVENT_AUTOCOMPLETE_CLIPPING_MODAL_PROPS}
opened={isActionCreatorOpen}