Skip to content
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
2 changes: 1 addition & 1 deletion src/gmp/commands/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {isDefined} from 'gmp/utils/identity';
interface ReportCommandImportParams {
task_id: string;
in_assets?: YesNo;
xml_file?: string;
xml_file?: File;
}

interface ReportCommandAssetsParams {
Expand Down
1 change: 1 addition & 0 deletions src/web/pages/reports/ReportImportDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const ReportImportDialog = ({
</FormGroup>
<FormGroup direction="row" title={_('Import Task')}>
<Select
disabled={tasks.length <= 1}
grow="1"
items={renderSelectItems(tasks as RenderSelectItemProps[])}
name="task_id"
Expand Down
8 changes: 5 additions & 3 deletions src/web/pages/reports/ReportListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import ReportsDashboard, {
REPORTS_DASHBOARD_ID,
} from 'web/pages/reports/dashboard';
import ReportFilterDialog from 'web/pages/reports/ReportFilterDialog';
import ReportImportDialog from 'web/pages/reports/ReportImportDialog';
import ReportImportDialog, {
type ReportImportDialogData,
} from 'web/pages/reports/ReportImportDialog';
import ReportsTable from 'web/pages/reports/ReportTable';
import ImportTaskDialog from 'web/pages/tasks/ImportTaskDialog';
import {
Expand Down Expand Up @@ -124,10 +126,10 @@ const ReportListPage = ({
closeImportDialog();
};

const handleImportReport = data => {
const handleImportReport = (data: ReportImportDialogData) => {
return gmp.report
.import(data)
.then(onChanged, onError)
.then(onChanged)
.then(() => closeImportDialog());
};

Expand Down
34 changes: 34 additions & 0 deletions src/web/pages/reports/__tests__/ReportImportDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,44 @@ describe('ReportImportDialog tests', () => {
expect(screen.getByText('Import Report')).toBeInTheDocument();
expect(screen.getByRole('button', {name: 'Import'})).toBeInTheDocument();
expect(screen.getByName('task_id')).toHaveValue('1');
expect(screen.getByName('task_id')).toBeEnabled();
expect(screen.getByTestId('new-import-task')).toBeInTheDocument();
expect(screen.getByName('in_assets')).toBeChecked();
});

test('should disable task selection if there are no tasks', async () => {
const onSave = testing.fn();
const onClose = testing.fn();

render(
<ReportImportDialog
task_id=""
tasks={[]}
onClose={onClose}
onSave={onSave}
/>,
);

expect(screen.getByName('task_id')).toBeDisabled();
});

test('should disable task selection if there is only one task', async () => {
const tasks = [new Task({id: '1', name: 'Task 1'})];
const onSave = testing.fn();
const onClose = testing.fn();

render(
<ReportImportDialog
task_id="1"
tasks={tasks}
onClose={onClose}
onSave={onSave}
/>,
);

expect(screen.getByName('task_id')).toBeDisabled();
});

test('should call onSave', async () => {
const tasks = [
new Task({id: '1', name: 'Task 1'}),
Expand Down
11 changes: 4 additions & 7 deletions src/web/pages/tasks/TaskComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -940,13 +940,10 @@ const TaskComponent = ({
};

const handleReportImport = (data: ReportImportDialogData) => {
return (
gmp.report
// @ts-expect-error
.import(data)
.then(onReportImported, onReportImportError)
.then(() => closeReportImportDialog())
);
return gmp.report
.import(data)
.then(onReportImported, onReportImportError)
Comment thread
ozgen marked this conversation as resolved.
.then(() => closeReportImportDialog());
};

const handleScanConfigChange = (configId?: string) => {
Expand Down
Loading