Skip to content

Commit 65004df

Browse files
authored
Display MenuItem within mantine Menu (#23573)
* Display MenuItem within mantine Menu * Use better named props * Fixing lint
1 parent fc27a27 commit 65004df

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

graylog2-web-interface/src/views/components/dashboard/DashboardsOverview/Constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ const getDashboardTableElements = (pluggableAttributes?: {
2121
attributeNames?: Array<string>;
2222
attributes?: Array<Attribute>;
2323
}) => {
24-
const getDefaultLayout = (isEvidenceModal: boolean) => ({
24+
const getDefaultLayout = (hideAdditionalColumns: boolean) => ({
2525
entityTableId: 'dashboards',
2626
defaultPageSize: 20,
2727
defaultSort: { attributeId: 'title', direction: 'asc' } as Sort,
28-
defaultDisplayedAttributes: isEvidenceModal
28+
defaultDisplayedAttributes: hideAdditionalColumns
2929
? ['title', 'description', 'summary']
3030
: ['title', 'description', 'summary', 'favorite', ...(pluggableAttributes?.attributeNames || [])],
3131
});

graylog2-web-interface/src/views/components/dashboard/DashboardsOverview/DashboardActions.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ const _extractErrorMessage = (error: FetchError) =>
4545

4646
type Props = {
4747
dashboard: View;
48-
isEvidenceModal?: boolean;
48+
hideDelete?: boolean;
49+
hideShare?: boolean;
4950
};
5051

5152
const usePluggableDashboardActions = (dashboard: View) => {
@@ -81,11 +82,11 @@ const usePluggableDashboardActions = (dashboard: View) => {
8182
const DashboardDeleteAction = ({
8283
dashboard,
8384
refetchDashboards,
84-
isEvidenceModal = false,
85+
hideDelete = false,
8586
}: {
8687
dashboard: View;
8788
refetchDashboards: () => void;
88-
isEvidenceModal?: boolean;
89+
hideDelete?: boolean;
8990
}) => {
9091
const { deselectEntity } = useSelectedEntities();
9192
const paginationQueryParameter = usePaginationQueryParameter();
@@ -112,39 +113,40 @@ const DashboardDeleteAction = ({
112113
}
113114
}, [dashboard, deselectEntity, refetchDashboards, paginationQueryParameter]);
114115

115-
return isEvidenceModal ? null : <DeleteMenuItem onClick={onDashboardDelete} />;
116+
return hideDelete ? null : <DeleteMenuItem onClick={onDashboardDelete} />;
116117
};
117118

118-
const DashboardActions = ({ dashboard, isEvidenceModal = false }: Props) => {
119+
const DashboardActions = ({ dashboard, hideDelete = false, hideShare = false }: Props) => {
119120
const [showShareModal, setShowShareModal] = useState(false);
120121
const { actions: pluggableActions, actionModals: pluggableActionModals } = usePluggableDashboardActions(dashboard);
121122
const currentUser = useCurrentUser();
122123
const { refetch } = useTableFetchContext();
123124

124125
const moreActions = [
125126
pluggableActions.length ? pluggableActions : null,
126-
pluggableActions.length && !isEvidenceModal ? <MenuItem divider key="divider" /> : null,
127+
pluggableActions.length && !hideDelete ? <MenuItem divider key="divider" /> : null,
127128
isAnyPermitted(currentUser.permissions, [`view:edit:${dashboard.id}`, 'view:edit']) ? (
128129
<DashboardDeleteAction
129130
dashboard={dashboard}
130131
refetchDashboards={refetch}
131132
key="delete-action"
132-
isEvidenceModal={isEvidenceModal}
133+
hideDelete={hideDelete}
133134
/>
134135
) : null,
135136
].filter(Boolean);
136137

137138
return (
138139
<>
139-
{isEvidenceModal || (
140+
{hideShare || (
140141
<ShareButton
141142
bsSize="xsmall"
142143
entityId={dashboard.id}
143144
entityType="dashboard"
144145
onClick={() => setShowShareModal(true)}
145146
/>
146147
)}
147-
{!!moreActions.length && isEvidenceModal ? moreActions[0] : <MoreActions>{moreActions}</MoreActions>}
148+
<MoreActions>{moreActions}</MoreActions>
149+
148150
{showShareModal && (
149151
<EntityShareModal
150152
entityId={dashboard.id}

graylog2-web-interface/src/views/components/dashboard/DashboardsOverview/DashboardsOverview.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,20 @@ import usePluggableEntityTableElements from 'hooks/usePluggableEntityTableElemen
2828
import BulkActions from './BulkActions';
2929

3030
type Props = {
31-
isEvidenceModal?: boolean;
31+
hideShare?: boolean;
32+
hideAdditionalColumns?: boolean;
33+
hideDelete?: boolean;
3234
};
3335

34-
const DashboardsOverview = ({ isEvidenceModal = false }: Props) => {
36+
const DashboardsOverview = ({ hideAdditionalColumns = false, hideShare = false, hideDelete = false }: Props) => {
3537
const { pluggableColumnRenderers, pluggableAttributes, pluggableExpandedSections } =
3638
usePluggableEntityTableElements<View>(null, 'dashboard');
3739
const { getDefaultLayout, columnOrder, additionalAttributes } = getDashboardTableElements(pluggableAttributes);
3840
const customColumnRenderers = useColumnRenderers(pluggableColumnRenderers);
3941

4042
const renderDashboardActions = useCallback(
41-
(dashboard: View) => <DashboardActions dashboard={dashboard} isEvidenceModal={isEvidenceModal} />,
42-
[isEvidenceModal],
43+
(dashboard: View) => <DashboardActions dashboard={dashboard} hideDelete={hideDelete} hideShare={hideShare} />,
44+
[hideDelete, hideShare],
4345
);
4446
const expandedSections = useMemo(
4547
() => ({
@@ -56,7 +58,7 @@ const DashboardsOverview = ({ isEvidenceModal = false }: Props) => {
5658
<QueryHelper entityName="dashboard" commonFields={['id', 'title', 'description', 'summary']} />
5759
}
5860
entityActions={renderDashboardActions}
59-
tableLayout={getDefaultLayout(isEvidenceModal)}
61+
tableLayout={getDefaultLayout(hideAdditionalColumns)}
6062
fetchEntities={fetchDashboards}
6163
additionalAttributes={additionalAttributes}
6264
expandedSectionsRenderer={expandedSections}

0 commit comments

Comments
 (0)