Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NestedFolders: Folder view move folder #65661

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 44 additions & 15 deletions public/app/features/search/components/DashboardActions.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import React from 'react';
import React, { useMemo, useState } from 'react';

import { config, reportInteraction } from '@grafana/runtime';
import { Menu, Dropdown, Button, Icon } from '@grafana/ui';
import { Menu, Dropdown, Button, Icon, HorizontalGroup } from '@grafana/ui';
import { t } from 'app/core/internationalization';
import { FolderDTO } from 'app/types';

import { MoveToFolderModal } from '../page/components/MoveToFolderModal';

export interface Props {
folderUid?: string;
folder: FolderDTO | undefined;
canCreateFolders?: boolean;
canCreateDashboards?: boolean;
}

export const DashboardActions = ({ folderUid, canCreateFolders = false, canCreateDashboards = false }: Props) => {
export const DashboardActions = ({ folder, canCreateFolders = false, canCreateDashboards = false }: Props) => {
const [isMoveModalOpen, setIsMoveModalOpen] = useState(false);
const canMove = config.featureToggles.nestedFolders && (folder?.canSave ?? false);

const moveSelection = useMemo(
() => new Map<string, Set<string>>([['folder', new Set(folder?.uid ? [folder.uid] : [])]]),
[folder]
);

const actionUrl = (type: string) => {
let url = `dashboard/${type}`;
const isTypeNewFolder = type === 'new_folder';
Expand All @@ -19,8 +30,8 @@ export const DashboardActions = ({ folderUid, canCreateFolders = false, canCreat
url = `dashboards/folder/new/`;
}

if (folderUid) {
url += `?folderUid=${folderUid}`;
if (folder?.uid) {
url += `?folderUid=${folder.uid}`;
}

return url;
Expand All @@ -38,7 +49,7 @@ export const DashboardActions = ({ folderUid, canCreateFolders = false, canCreat
}
/>
)}
{canCreateFolders && (config.featureToggles.nestedFolders || !folderUid) && (
{canCreateFolders && (config.featureToggles.nestedFolders || !folder?.uid) && (
<Menu.Item
url={actionUrl('new_folder')}
label={t('search.dashboard-actions.new-folder', 'New Folder')}
Expand All @@ -61,13 +72,31 @@ export const DashboardActions = ({ folderUid, canCreateFolders = false, canCreat
};

return (
<div>
<Dropdown overlay={MenuActions} placement="bottom-start">
<Button variant="primary">
{t('search.dashboard-actions.new', 'New')}
<Icon name="angle-down" />
</Button>
</Dropdown>
</div>
<>
<div>
<HorizontalGroup>
{canMove && (
<Button onClick={() => setIsMoveModalOpen(true)} icon="exchange-alt" variant="secondary">
Move
</Button>
)}
<Dropdown overlay={MenuActions} placement="bottom-start">
<Button variant="primary">
{t('search.dashboard-actions.new', 'New')}
<Icon name="angle-down" />
</Button>
</Dropdown>
</HorizontalGroup>
</div>

{canMove && isMoveModalOpen && (
<MoveToFolderModal
onMoveItems={() => {}}
results={moveSelection}
isOpen={isMoveModalOpen}
onDismiss={() => setIsMoveModalOpen(false)}
/>
)}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const ManageDashboardsNew = React.memo(({ folder }: Props) => {
</div>
{viewActions && (
<DashboardActions
folderUid={folderUid}
folder={folder}
canCreateFolders={canCreateFolders}
canCreateDashboards={canCreateDashboards}
/>
Expand Down