Skip to content

Commit 46860ab

Browse files
pierrejeambrunYour friendly bot
authored andcommitted
[v3-1-test] Expand and collapse group component (#56293)
* Extract component for expand and collapse button group * Refactor toggle groups buttons (cherry picked from commit 6d1991d) Co-authored-by: Pierre Jeambrun <[email protected]>
1 parent 1da7340 commit 46860ab

File tree

4 files changed

+87
-60
lines changed

4 files changed

+87
-60
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*!
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
import { ButtonGroup, IconButton } from "@chakra-ui/react";
20+
import { MdCompress, MdExpand } from "react-icons/md";
21+
22+
type Props = {
23+
readonly collapseLabel: string;
24+
readonly expandLabel: string;
25+
readonly isCollapseDisabled?: boolean;
26+
readonly isExpandDisabled?: boolean;
27+
readonly onCollapse: () => void;
28+
readonly onExpand: () => void;
29+
};
30+
31+
export const ExpandCollapseButtons = ({
32+
collapseLabel,
33+
expandLabel,
34+
isCollapseDisabled,
35+
isExpandDisabled,
36+
onCollapse,
37+
onExpand,
38+
...rest
39+
}: Props) => (
40+
<ButtonGroup attached size="sm" variant="surface" {...rest}>
41+
<IconButton
42+
aria-label={expandLabel}
43+
disabled={isExpandDisabled}
44+
onClick={onExpand}
45+
size="sm"
46+
title={expandLabel}
47+
>
48+
<MdExpand />
49+
</IconButton>
50+
<IconButton
51+
aria-label={collapseLabel}
52+
disabled={isCollapseDisabled}
53+
onClick={onCollapse}
54+
size="sm"
55+
title={collapseLabel}
56+
>
57+
<MdCompress />
58+
</IconButton>
59+
</ButtonGroup>
60+
);

airflow-core/src/airflow/ui/src/layouts/Details/ToggleGroups.tsx

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
import { type ButtonGroupProps, IconButton, ButtonGroup } from "@chakra-ui/react";
19+
import type { ButtonGroupProps } from "@chakra-ui/react";
2020
import { useTranslation } from "react-i18next";
21-
import { MdExpand, MdCompress } from "react-icons/md";
2221

22+
import { ExpandCollapseButtons } from "src/components/ExpandCollapseButtons";
2323
import { useOpenGroups } from "src/context/openGroups";
2424

2525
export const ToggleGroups = (props: ButtonGroupProps) => {
@@ -46,25 +46,14 @@ export const ToggleGroups = (props: ButtonGroupProps) => {
4646
const collapseLabel = translate("dag:taskGroups.collapseAll");
4747

4848
return (
49-
<ButtonGroup attached size="sm" variant="outline" {...props}>
50-
<IconButton
51-
aria-label={expandLabel}
52-
disabled={isExpandDisabled}
53-
onClick={onExpand}
54-
size="sm"
55-
title={expandLabel}
56-
>
57-
<MdExpand />
58-
</IconButton>
59-
<IconButton
60-
aria-label={collapseLabel}
61-
disabled={isCollapseDisabled}
62-
onClick={onCollapse}
63-
size="sm"
64-
title={collapseLabel}
65-
>
66-
<MdCompress />
67-
</IconButton>
68-
</ButtonGroup>
49+
<ExpandCollapseButtons
50+
collapseLabel={collapseLabel}
51+
expandLabel={expandLabel}
52+
isCollapseDisabled={isCollapseDisabled}
53+
isExpandDisabled={isExpandDisabled}
54+
onCollapse={onCollapse}
55+
onExpand={onExpand}
56+
{...props}
57+
/>
6958
);
7059
};

airflow-core/src/airflow/ui/src/pages/Events/Events.tsx

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
import { ButtonGroup, Code, Flex, Heading, IconButton, useDisclosure, VStack } from "@chakra-ui/react";
19+
import { Code, Flex, Heading, useDisclosure, VStack } from "@chakra-ui/react";
2020
import type { ColumnDef } from "@tanstack/react-table";
2121
import dayjs from "dayjs";
2222
import { useTranslation } from "react-i18next";
23-
import { MdCompress, MdExpand } from "react-icons/md";
2423
import { useParams, useSearchParams } from "react-router-dom";
2524

2625
import { useEventLogServiceGetEventLogs } from "openapi/queries";
2726
import type { EventLogResponse } from "openapi/requests/types.gen";
2827
import { DataTable } from "src/components/DataTable";
2928
import { useTableURLState } from "src/components/DataTable/useTableUrlState";
3029
import { ErrorAlert } from "src/components/ErrorAlert";
30+
import { ExpandCollapseButtons } from "src/components/ExpandCollapseButtons";
3131
import RenderedJsonField from "src/components/RenderedJsonField";
3232
import Time from "src/components/Time";
3333
import { SearchParamsKeys, type SearchParamsKeysType } from "src/constants/searchParams";
@@ -214,24 +214,12 @@ export const Events = () => {
214214
) : undefined}
215215
<Flex alignItems="center" justifyContent="space-between">
216216
<EventsFilters urlDagId={dagId} urlRunId={runId} urlTaskId={taskId} />
217-
<ButtonGroup attached mt="1" size="sm" variant="surface">
218-
<IconButton
219-
aria-label={translate("auditLog.actions.expandAllExtra")}
220-
onClick={onOpen}
221-
size="sm"
222-
title={translate("auditLog.actions.expandAllExtra")}
223-
>
224-
<MdExpand />
225-
</IconButton>
226-
<IconButton
227-
aria-label={translate("auditLog.actions.collapseAllExtra")}
228-
onClick={onClose}
229-
size="sm"
230-
title={translate("auditLog.actions.collapseAllExtra")}
231-
>
232-
<MdCompress />
233-
</IconButton>
234-
</ButtonGroup>
217+
<ExpandCollapseButtons
218+
collapseLabel={translate("auditLog.actions.collapseAllExtra")}
219+
expandLabel={translate("auditLog.actions.expandAllExtra")}
220+
onCollapse={onClose}
221+
onExpand={onOpen}
222+
/>
235223
</Flex>
236224

237225
<ErrorAlert error={error} />

airflow-core/src/airflow/ui/src/pages/XCom/XCom.tsx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
import { Box, Heading, Link, Flex, ButtonGroup, IconButton, useDisclosure } from "@chakra-ui/react";
19+
import { Box, Heading, Link, Flex, useDisclosure } from "@chakra-ui/react";
2020
import type { ColumnDef } from "@tanstack/react-table";
2121
import { useTranslation } from "react-i18next";
22-
import { MdCompress, MdExpand } from "react-icons/md";
2322
import { Link as RouterLink, useParams, useSearchParams } from "react-router-dom";
2423

2524
import { useXcomServiceGetXcomEntries } from "openapi/queries";
2625
import type { XComResponse } from "openapi/requests/types.gen";
2726
import { DataTable } from "src/components/DataTable";
2827
import { useTableURLState } from "src/components/DataTable/useTableUrlState";
2928
import { ErrorAlert } from "src/components/ErrorAlert";
29+
import { ExpandCollapseButtons } from "src/components/ExpandCollapseButtons";
3030
import { TruncatedText } from "src/components/TruncatedText";
3131
import { SearchParamsKeys, type SearchParamsKeysType } from "src/constants/searchParams";
3232
import { getTaskInstanceLink } from "src/utils/links";
@@ -162,22 +162,12 @@ export const XCom = () => {
162162

163163
<Flex alignItems="center" justifyContent="space-between">
164164
<XComFilters />
165-
<ButtonGroup attached mt="1" size="sm" variant="surface">
166-
<IconButton
167-
aria-label={translate("auditLog.actions.expandAllExtra")}
168-
onClick={onOpen}
169-
title={translate("auditLog.actions.expandAllExtra")}
170-
>
171-
<MdExpand />
172-
</IconButton>
173-
<IconButton
174-
aria-label={translate("auditLog.actions.collapseAllExtra")}
175-
onClick={onClose}
176-
title={translate("auditLog.actions.collapseAllExtra")}
177-
>
178-
<MdCompress />
179-
</IconButton>
180-
</ButtonGroup>
165+
<ExpandCollapseButtons
166+
collapseLabel={translate("auditLog.actions.collapseAllExtra")}
167+
expandLabel={translate("auditLog.actions.expandAllExtra")}
168+
onCollapse={onClose}
169+
onExpand={onOpen}
170+
/>
181171
</Flex>
182172

183173
<ErrorAlert error={error} />

0 commit comments

Comments
 (0)