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

[frontend] Add info message of starting date mandatory on scenario #1319

Merged
merged 6 commits into from
Aug 12, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@
HttpServletResponse response) {
try {
String jsonMappers = mapperService.exportMappers(exportMapperInput.getIdsToExport());
String rightNow = DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(LocalDateTime.now());
String filename = MessageFormat.format("mappers_{0}.json", rightNow);

String rightNow = DateTimeFormatter.ofPattern("yyyyMMdd").format(LocalDateTime.now());
String name = exportMapperInput.getName().replace("(Import)", "").replace(" ", "");

Check warning on line 95 in openbas-api/src/main/java/io/openbas/rest/mapper/MapperApi.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/mapper/MapperApi.java#L94-L95

Added lines #L94 - L95 were not covered by tests
String exportFileName = name.length() > 15 ? name.substring(0, 15) : name;
String filename = MessageFormat.format("{0}-{1}.json", exportFileName, rightNow);

Check warning on line 97 in openbas-api/src/main/java/io/openbas/rest/mapper/MapperApi.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/mapper/MapperApi.java#L97

Added line #L97 was not covered by tests

response.addHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + filename);
response.addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
@Data
public class ExportMapperInput {

@JsonProperty("export_mapper_name")
private String name;

Check warning on line 15 in openbas-api/src/main/java/io/openbas/rest/mapper/form/ExportMapperInput.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/mapper/form/ExportMapperInput.java#L15

Added line #L15 was not covered by tests

@NotNull(message = MANDATORY_MESSAGE)
@JsonProperty("ids_to_export")
private List<String> idsToExport;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Autocomplete as MuiAutocomplete, Box, Button, MenuItem, TextField } from '@mui/material';
import { Autocomplete as MuiAutocomplete, Box, Button, MenuItem, TextField, Tooltip } from '@mui/material';
import { TableViewOutlined } from '@mui/icons-material';
import { InformationOutline } from 'mdi-material-ui';
import React, { FunctionComponent, SyntheticEvent, useContext, useEffect, useState } from 'react';
import { Controller, useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
Expand Down Expand Up @@ -230,9 +231,20 @@ const ImportUploaderInjectFromXlsInjects: FunctionComponent<Props> = ({
fullWidth: true,
error: !!fieldState.error,
helperText: fieldState.error && fieldState.error?.message,
label: (
<Box display="flex" alignItems="center">
{t('Start date')}
<Tooltip title={t('The imported file contains absolute dates (ex.: 9h30). A starting date must be provided for the Scenario to be build')}>
<InformationOutline
fontSize="small"
color="primary"
style={{ marginLeft: 4, cursor: 'default' }}
/>
</Tooltip>
</Box>
),
},
}}
label={t('Start date')}
/>
)}
/>}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const XlsMapperPopover: FunctionComponent<Props> = ({
const exportMapperAction = () => {
exportMapper({
ids_to_export: [mapper.import_mapper_id],
export_mapper_name: mapper.import_mapper_name,
}).then(
(result:{ data: string, filename: string }) => {
download(JSON.stringify(result.data, null, 2), result.filename, 'application/json');
Expand Down
1 change: 1 addition & 0 deletions openbas-front/src/utils/Localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,7 @@ const i18n = {
'Do you want to delete this representation?': 'Voulez-vous supprimer cette représentation ?',
'Trigger time': 'Heure de lancement',
'Attribute mapping configuration': 'Configuration d\'attribut de mappeur',
'The imported file contains absolute dates (ex.: 9h30). A starting date must be provided for the Scenario to be build': 'Le fichier importé contient des dates absolues (ex.: 9h30). Une date de début doit être fournie pour que le scénario puisse être créé',
Test: 'Test',
'Do you want to delete this XLS mapper ?': 'Voulez-vous supprimer ce mappage XLS ?',
Expectation_name: 'Nom de l\'attendu',
Expand Down
1 change: 1 addition & 0 deletions openbas-front/src/utils/api-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ export interface ExpectationUpdateInput {

export interface ExportMapperInput {
ids_to_export: string[];
export_mapper_name?: string;
}

export interface Filter {
Expand Down