Skip to content

Commit 8942187

Browse files
feat: App Logs Collapse All (RocketChat#36558)
1 parent 5f3ac3a commit 8942187

8 files changed

Lines changed: 102 additions & 26 deletions

File tree

.changeset/soft-suns-sip.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@rocket.chat/meteor": minor
3+
"@rocket.chat/i18n": minor
4+
---
5+
6+
Adds a "Collapse All" button to the Apps Logs Filter and moves existing "Expand All" button to a kebab menu

apps/meteor/client/views/marketplace/AppDetailsPage/tabs/AppLogs/AppLogs.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ import { useLogs } from '../../../hooks/useLogs';
1616

1717
function expandedReducer(
1818
expandedStates: { id: string; expanded: boolean }[],
19-
action: { type: 'update'; id: string; expanded: boolean } | { type: 'expand-all' } | { type: 'reset'; logs: ILogItem[] },
19+
action:
20+
| { type: 'update'; id: string; expanded: boolean }
21+
| { type: 'expand-all' }
22+
| { type: 'reset-all' }
23+
| { type: 'reset'; logs: ILogItem[] },
2024
) {
2125
switch (action.type) {
2226
case 'update':
@@ -28,6 +32,9 @@ function expandedReducer(
2832
case 'reset':
2933
return action.logs.map((log) => ({ id: log._id, expanded: false }));
3034

35+
case 'reset-all':
36+
return expandedStates.map((state) => ({ ...state, expanded: false }));
37+
3138
default:
3239
return expandedStates;
3340
}
@@ -48,6 +55,8 @@ const AppLogs = ({ id }: { id: string }): ReactElement => {
4855

4956
const handleExpandAll = () => dispatch({ type: 'expand-all' });
5057

58+
const handleCollapseAll = () => dispatch({ type: 'reset-all' });
59+
5160
const { data, isSuccess, isError, error, refetch, isFetching } = useLogs({
5261
appId: id,
5362
current,
@@ -84,6 +93,7 @@ const AppLogs = ({ id }: { id: string }): ReactElement => {
8493
noResults={isFetching || !isSuccess || data?.logs?.length === 0}
8594
isLoading={isFetching}
8695
expandAll={() => handleExpandAll()}
96+
collapseAll={() => handleCollapseAll()}
8797
refetchLogs={() => refetch()}
8898
/>
8999
</Box>

apps/meteor/client/views/marketplace/AppDetailsPage/tabs/AppLogs/Filters/AppLogsFilter.stories.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,11 @@ export default {
3535
} satisfies Meta<typeof AppLogsFilter>;
3636

3737
export const Default = () => (
38-
<AppLogsFilter appId='app-id' expandAll={action('expandAll')} refetchLogs={action('refetchLogs')} isLoading={false} />
38+
<AppLogsFilter
39+
appId='app-id'
40+
expandAll={action('expandAll')}
41+
collapseAll={action('collapseAll')}
42+
refetchLogs={action('refetchLogs')}
43+
isLoading={false}
44+
/>
3945
);

apps/meteor/client/views/marketplace/AppDetailsPage/tabs/AppLogs/Filters/AppLogsFilter.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useRouter, useSetModal } from '@rocket.chat/ui-contexts';
33
import { Controller } from 'react-hook-form';
44
import { useTranslation } from 'react-i18next';
55

6+
import AppsLogsFilterOptions from './AppLogsFilterOptions';
67
import CompactFilterOptions from './CompactFilterOptions';
78
import { EventFilterSelect } from './EventFilterSelect';
89
import { InstanceFilterSelect } from './InstanceFilterSelect';
@@ -15,12 +16,13 @@ import { ExportLogsModal } from './ExportLogsModal';
1516
type AppsLogsFilterProps = {
1617
appId: string;
1718
expandAll: () => void;
19+
collapseAll: () => void;
1820
refetchLogs: () => void;
1921
isLoading: boolean;
2022
noResults?: boolean;
2123
};
2224

23-
export const AppLogsFilter = ({ appId, expandAll, refetchLogs, isLoading, noResults = false }: AppsLogsFilterProps) => {
25+
export const AppLogsFilter = ({ appId, expandAll, collapseAll, refetchLogs, isLoading, noResults = false }: AppsLogsFilterProps) => {
2426
const { t } = useTranslation();
2527

2628
const { control, getValues } = useAppLogsFilterFormContext();
@@ -95,11 +97,6 @@ export const AppLogsFilter = ({ appId, expandAll, refetchLogs, isLoading, noResu
9597
<Controller control={control} name='severity' render={({ field }) => <SeverityFilterSelect id='severityFilter' {...field} />} />
9698
</Box>
9799
)}
98-
{!compactMode && (
99-
<Button alignSelf='flex-end' icon='arrow-expand' secondary mie={10} onClick={() => openAllLogs()}>
100-
{t('Expand_all')}
101-
</Button>
102-
)}
103100
{!compactMode && (
104101
<IconButton
105102
title={isLoading ? t('Loading') : t('Refresh_logs')}
@@ -129,8 +126,15 @@ export const AppLogsFilter = ({ appId, expandAll, refetchLogs, isLoading, noResu
129126
{t('Filters')}
130127
</Button>
131128
)}
129+
{!compactMode && <AppsLogsFilterOptions onExpandAll={openAllLogs} onCollapseAll={collapseAll} />}
132130
{compactMode && (
133-
<CompactFilterOptions isLoading={isLoading} onExportLogs={openExportModal} onExpandAll={openAllLogs} onRefreshLogs={refreshLogs} />
131+
<CompactFilterOptions
132+
isLoading={isLoading}
133+
onExportLogs={openExportModal}
134+
onExpandAll={openAllLogs}
135+
onCollapseAll={collapseAll}
136+
onRefreshLogs={refreshLogs}
137+
/>
134138
)}
135139
</Box>
136140
);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Box, Icon, Menu } from '@rocket.chat/fuselage';
2+
import { useTranslation } from 'react-i18next';
3+
4+
type AppsLogsFilterOptionsProps = {
5+
onExpandAll: () => void;
6+
onCollapseAll: () => void;
7+
};
8+
9+
const AppsLogsFilterOptions = ({ onExpandAll, onCollapseAll, ...props }: AppsLogsFilterOptionsProps) => {
10+
const { t } = useTranslation();
11+
12+
const menuOptions = {
13+
expandAll: {
14+
label: (
15+
<Box>
16+
<Icon name='arrow-expand' size='x16' marginInlineEnd={4} />
17+
{t('Expand_all')}
18+
</Box>
19+
),
20+
action: onExpandAll,
21+
},
22+
collapseAll: {
23+
label: (
24+
<Box>
25+
<Icon name='arrow-collapse' size='x16' marginInlineEnd={4} />
26+
{t('Collapse_all')}
27+
</Box>
28+
),
29+
action: onCollapseAll,
30+
},
31+
};
32+
return <Menu title={t('Options')} small={false} alignSelf='flex-end' options={menuOptions} {...props} />;
33+
};
34+
35+
export default AppsLogsFilterOptions;

apps/meteor/client/views/marketplace/AppDetailsPage/tabs/AppLogs/Filters/CompactFilterOptions.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,20 @@ import { useTranslation } from 'react-i18next';
33

44
type CompactFilterOptionsProps = {
55
onExpandAll: () => void;
6+
onCollapseAll: () => void;
67
onRefreshLogs: () => void;
78
onExportLogs: () => void;
89
isLoading: boolean;
910
};
1011

11-
const CompactFilterOptions = ({ onExportLogs, onExpandAll, onRefreshLogs, isLoading, ...props }: CompactFilterOptionsProps) => {
12+
const CompactFilterOptions = ({
13+
onExportLogs,
14+
onExpandAll,
15+
onCollapseAll,
16+
onRefreshLogs,
17+
isLoading,
18+
...props
19+
}: CompactFilterOptionsProps) => {
1220
const { t } = useTranslation();
1321

1422
const menuOptions = {
@@ -30,6 +38,15 @@ const CompactFilterOptions = ({ onExportLogs, onExpandAll, onRefreshLogs, isLoad
3038
),
3139
action: onExpandAll,
3240
},
41+
collapseAll: {
42+
label: (
43+
<Box>
44+
<Icon name='arrow-collapse' size='x16' marginInlineEnd={4} />
45+
{t('Collapse_all')}
46+
</Box>
47+
),
48+
action: onCollapseAll,
49+
},
3350
refreshLogs: {
3451
label: (
3552
<Box>

apps/meteor/client/views/marketplace/AppDetailsPage/tabs/AppLogs/Filters/__snapshots__/AppLogsFilterExpanded.spec.tsx.snap

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -204,22 +204,6 @@ exports[`renders AppLogsItem without crashing 1`] = `
204204
</i>
205205
</button>
206206
</div>
207-
<button
208-
class="rcx-box rcx-box--full rcx-button--secondary rcx-button rcx-css-qv9v2f"
209-
type="button"
210-
>
211-
<span
212-
class="rcx-button--content"
213-
>
214-
<i
215-
aria-hidden="true"
216-
class="rcx-box rcx-box--full rcx-icon--name-arrow-expand rcx-icon rcx-css-1hdf9ok"
217-
>
218-
219-
</i>
220-
Expand_all
221-
</span>
222-
</button>
223207
<button
224208
class="rcx-box rcx-box--full rcx-button--large-square rcx-button--icon-secondary rcx-button--square rcx-button--icon rcx-button rcx-css-qv9v2f"
225209
title="Refresh_logs"
@@ -246,6 +230,19 @@ exports[`renders AppLogsItem without crashing 1`] = `
246230
247231
</i>
248232
</button>
233+
<button
234+
class="rcx-box rcx-box--full rcx-button--large-square rcx-button--square rcx-button--icon rcx-button rcx-css-17zzf5z"
235+
data-testid="menu"
236+
title="Options"
237+
type="button"
238+
>
239+
<i
240+
aria-hidden="true"
241+
class="rcx-box rcx-box--full rcx-icon--name-kebab rcx-icon rcx-css-1x2l7ts"
242+
>
243+
244+
</i>
245+
</button>
249246
</div>
250247
</div>
251248
</div>

packages/i18n/src/locales/en.i18n.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,7 @@
10881088
"Cloud_workspace_support": "If you have trouble with a cloud service, please try to sync first. Should the issue persist, please open a support ticket in the Cloud Console.",
10891089
"Collaborative": "Collaborative",
10901090
"Collapse": "Collapse",
1091+
"Collapse_all": "Collapse All",
10911092
"Collapse_Embedded_Media_By_Default": "Collapse Embedded Media by Default",
10921093
"Color": "Color",
10931094
"Colors": "Colors",

0 commit comments

Comments
 (0)