Commit 997f86a5 authored by Bruno d'Auria's avatar Bruno d'Auria Committed by Thomas Untoja
Browse files

Migrate to node 16 and npm 7

parent 6f47d46c
This diff is collapsed.
......@@ -24,7 +24,7 @@
"@babel/preset-env": "^7.10.4",
"@babel/preset-react": "^7.10.4",
"@babel/preset-typescript": "^7.10.4",
"@centreon/frontend-core": "centreon/frontend-core#20.10.x",
"@centreon/frontend-core": "git+https://centreon@github.com/centreon/frontend-core#20.10.x",
"@svgr/webpack": "^5.4.0",
"@testing-library/jest-dom": "^5.11.2",
"@testing-library/react": "^10.4.7",
......@@ -68,7 +68,7 @@
"lodash": "^4.17.19",
"mini-css-extract-plugin": "^0.9.0",
"mockdate": "^3.0.2",
"node-sass": "^4.14.1",
"node-sass": "^6.0.0",
"postcss-loader": "^3.0.0",
"postcss-safe-parser": "^4.0.2",
"prettier": "^2.0.5",
......@@ -77,7 +77,7 @@
"react-mock-router": "^1.0.15",
"redux-mock-store": "^1.5.4",
"resolve-url-loader": "^3.1.1",
"sass-loader": "^9.0.2",
"sass-loader": "^10.0.0",
"terser-webpack-plugin": "^3.0.8",
"thread-loader": "^2.1.3",
"ts-loader": "^8.0.1",
......@@ -90,7 +90,7 @@
"webpack-merge": "^5.0.9"
},
"dependencies": {
"@centreon/ui": "github:centreon/centreon-ui#20.10.x",
"@centreon/ui": "git+https://centreon@github.com/centreon/centreon-ui#20.10.x",
"@date-io/moment": "1.3.13",
"@hot-loader/react-dom": "^16.13.0",
"@material-ui/core": "^4.11.0",
......@@ -147,4 +147,4 @@
"suiteName": "jest tests",
"output": "./jest-test-results.xml"
}
}
\ No newline at end of file
}
......@@ -50,11 +50,8 @@ interface Props {
const RefreshActions = ({ onRefresh }: Props): JSX.Element => {
const { t } = useTranslation();
const {
enabledAutorefresh,
setEnabledAutorefresh,
sending,
} = useResourceContext();
const { enabledAutorefresh, setEnabledAutorefresh, sending } =
useResourceContext();
const toggleAutorefresh = (): void => {
setEnabledAutorefresh(!enabledAutorefresh);
......
......@@ -48,10 +48,8 @@ const DialogAcknowledge = ({
}: Props): JSX.Element => {
const { t } = useTranslation();
const {
getAcknowledgementDeniedTypeAlert,
canAcknowledgeServices,
} = useAclQuery();
const { getAcknowledgementDeniedTypeAlert, canAcknowledgeServices } =
useAclQuery();
const deniedTypeAlert = getAcknowledgementDeniedTypeAlert(resources);
......
......@@ -11,19 +11,21 @@ interface ResourcesWithDisacknowledgeParams {
resources: Array<Resource>;
}
const disacknowledgeResources = (cancelToken: CancelToken) => ({
resources,
disacknowledgeAttachedResources,
}: ResourcesWithDisacknowledgeParams): Promise<Array<AxiosResponse>> => {
return axios.delete(disacknowledgeEndpoint, {
cancelToken,
data: {
disacknowledgement: {
with_services: disacknowledgeAttachedResources,
const disacknowledgeResources =
(cancelToken: CancelToken) =>
({
resources,
disacknowledgeAttachedResources,
}: ResourcesWithDisacknowledgeParams): Promise<Array<AxiosResponse>> => {
return axios.delete(disacknowledgeEndpoint, {
cancelToken,
data: {
disacknowledgement: {
with_services: disacknowledgeAttachedResources,
},
resources: map(pick(['type', 'id', 'parent']), resources),
},
resources: map(pick(['type', 'id', 'parent']), resources),
},
});
};
});
};
export { disacknowledgeResources, disacknowledgeEndpoint };
......@@ -32,10 +32,8 @@ const DisacknowledgeForm = ({
}: Props): JSX.Element | null => {
const { t } = useTranslation();
const { showMessage } = useSnackbar();
const [
disacknowledgeAttachedResources,
setDisacknowledgeAttachedResources,
] = React.useState(true);
const [disacknowledgeAttachedResources, setDisacknowledgeAttachedResources] =
React.useState(true);
const {
sendRequest: sendDisacknowledgeResources,
......@@ -44,10 +42,8 @@ const DisacknowledgeForm = ({
request: disacknowledgeResources,
});
const {
getDisacknowledgementDeniedTypeAlert,
canDisacknowledgeServices,
} = useAclQuery();
const { getDisacknowledgementDeniedTypeAlert, canDisacknowledgeServices } =
useAclQuery();
const deniedTypeAlert = getDisacknowledgementDeniedTypeAlert(resources);
......
......@@ -104,9 +104,11 @@ const DialogDowntime = ({
const hasHosts = resources.find((resource) => resource.type === 'host');
const changeDate = (field) => (value): void => {
setFieldValue(field, value);
};
const changeDate =
(field) =>
(value): void => {
setFieldValue(field, value);
};
React.useEffect(() => {
moment.locale(locale);
......
......@@ -13,26 +13,28 @@ interface ResourceWithSubmitStatusParams {
statusId: number;
}
const submitResourceStatus = (cancelToken: CancelToken) => ({
resource,
statusId,
output,
performanceData,
}: ResourceWithSubmitStatusParams): Promise<Array<AxiosResponse>> => {
return axios.post(
submitStatusEndpoint,
{
resources: [
{
...pick(['type', 'id', 'parent'], resource),
output,
performance_data: performanceData,
status: statusId,
},
],
},
{ cancelToken },
);
};
const submitResourceStatus =
(cancelToken: CancelToken) =>
({
resource,
statusId,
output,
performanceData,
}: ResourceWithSubmitStatusParams): Promise<Array<AxiosResponse>> => {
return axios.post(
submitStatusEndpoint,
{
resources: [
{
...pick(['type', 'id', 'parent'], resource),
output,
performance_data: performanceData,
status: statusId,
},
],
},
{ cancelToken },
);
};
export { submitResourceStatus, submitStatusEndpoint };
......@@ -53,8 +53,10 @@ const useAclQuery = (): AclQuery => {
)(resources);
};
const cannot = (action) => (resources): boolean =>
!can({ action, resources });
const cannot =
(action) =>
(resources): boolean =>
!can({ action, resources });
const getDeniedTypeAlert = ({ resources, action }): string | undefined => {
const isHost = propEq('type', 'host');
......
......@@ -40,15 +40,11 @@ const ResourceActions = (): JSX.Element => {
const { t } = useTranslation();
const { cancel, token } = useCancelTokenSource();
const { showMessage } = useSnackbar();
const [
moreActionsMenuAnchor,
setMoreActionsMenuAnchor,
] = React.useState<Element | null>(null);
const [
resourceToSubmitStatus,
setresourceToSubmitStatus,
] = React.useState<Resource | null>();
const [moreActionsMenuAnchor, setMoreActionsMenuAnchor] =
React.useState<Element | null>(null);
const [resourceToSubmitStatus, setresourceToSubmitStatus] =
React.useState<Resource | null>();
const {
resourcesToCheck,
......
......@@ -22,23 +22,25 @@ interface ResourcesWithAcknowledgeParams {
resources: Array<Resource>;
}
const acknowledgeResources = (cancelToken: CancelToken) => ({
resources,
params,
}: ResourcesWithAcknowledgeParams): Promise<Array<AxiosResponse>> => {
return axios.post(
acknowledgeEndpoint,
{
acknowledgement: {
comment: params.comment,
is_notify_contacts: params.notify,
with_services: params.acknowledgeAttachedResources,
const acknowledgeResources =
(cancelToken: CancelToken) =>
({
resources,
params,
}: ResourcesWithAcknowledgeParams): Promise<Array<AxiosResponse>> => {
return axios.post(
acknowledgeEndpoint,
{
acknowledgement: {
comment: params.comment,
is_notify_contacts: params.notify,
with_services: params.acknowledgeAttachedResources,
},
resources: map(pick(['type', 'id', 'parent']), resources),
},
resources: map(pick(['type', 'id', 'parent']), resources),
},
{ cancelToken },
);
};
{ cancelToken },
);
};
interface DowntimeParams {
comment: string;
......@@ -55,26 +57,28 @@ interface ResourcesWithDowntimeParams {
resources: Array<Resource>;
}
const setDowntimeOnResources = (cancelToken: CancelToken) => ({
resources,
params,
}: ResourcesWithDowntimeParams): Promise<Array<AxiosResponse>> => {
return axios.post(
downtimeEndpoint,
{
downtime: {
comment: params.comment,
duration: params.duration,
end_time: formatISO(params.endTime),
is_fixed: params.fixed,
start_time: formatISO(params.startTime),
with_services: params.downtimeAttachedResources,
const setDowntimeOnResources =
(cancelToken: CancelToken) =>
({
resources,
params,
}: ResourcesWithDowntimeParams): Promise<Array<AxiosResponse>> => {
return axios.post(
downtimeEndpoint,
{
downtime: {
comment: params.comment,
duration: params.duration,
end_time: formatISO(params.endTime),
is_fixed: params.fixed,
start_time: formatISO(params.startTime),
with_services: params.downtimeAttachedResources,
},
resources: map(pick(['type', 'id', 'parent']), resources),
},
resources: map(pick(['type', 'id', 'parent']), resources),
},
{ cancelToken },
);
};
{ cancelToken },
);
};
interface ResourcesWithRequestParams {
cancelToken: CancelToken;
......
......@@ -259,12 +259,8 @@ describe(Actions, () => {
);
it('sends an acknowledgement request when Resources are selected and the Ackowledgement action is clicked and confirmed', async () => {
const {
getByText,
getByLabelText,
findByLabelText,
getAllByText,
} = renderActions();
const { getByText, getByLabelText, findByLabelText, getAllByText } =
renderActions();
const selectedResources = [host, service];
......@@ -363,12 +359,8 @@ describe(Actions, () => {
});
it('cannot send a downtime request when Downtime action is clicked, type is flexible and duration is empty', async () => {
const {
findByText,
getAllByText,
getByLabelText,
getByDisplayValue,
} = renderActions();
const { findByText, getAllByText, getByLabelText, getByDisplayValue } =
renderActions();
const selectedResources = [host];
......@@ -393,12 +385,8 @@ describe(Actions, () => {
});
it('cannot send a downtime request when Downtime action is clicked and start date is greater than end date', async () => {
const {
container,
getByLabelText,
getAllByText,
findByText,
} = renderActions();
const { container, getByLabelText, getAllByText, findByText } =
renderActions();
const selectedResources = [host];
......
......@@ -32,10 +32,8 @@ const useActions = (): ActionsState => {
const [resourcesToCheck, setResourcesToCheck] = React.useState<
Array<Resource>
>([]);
const [
resourcesToDisacknowledge,
setResourcesToDisacknowledge,
] = React.useState<Array<Resource>>([]);
const [resourcesToDisacknowledge, setResourcesToDisacknowledge] =
React.useState<Array<Resource>>([]);
return {
resourcesToAcknowledge,
......
......@@ -64,10 +64,8 @@ const GraphTab = ({ details }: TabProps): JSX.Element => {
const endpoint = path(['links', 'endpoints', 'performance_graph'], details);
const [
selectedTimePeriod,
setSelectedTimePeriod,
] = React.useState<TimePeriod>(defaultTimePeriod);
const [selectedTimePeriod, setSelectedTimePeriod] =
React.useState<TimePeriod>(defaultTimePeriod);
const getQueryParams = (timePeriod): string => {
const now = new Date(Date.now()).toISOString();
......
......@@ -18,17 +18,17 @@ const buildListServicesEndpoint = ({ parameters, hostId }): string => {
});
};
const listServices = (cancelToken: CancelToken) => (
hostId: number,
): Promise<ServiceListing> => {
return getData<ServiceListing>(cancelToken)(
buildListServicesEndpoint({
hostId,
parameters: {
limit: 100,
},
}),
);
};
const listServices =
(cancelToken: CancelToken) =>
(hostId: number): Promise<ServiceListing> => {
return getData<ServiceListing>(cancelToken)(
buildListServicesEndpoint({
hostId,
parameters: {
limit: 100,
},
}),
);
};
export { listServices };
......@@ -73,32 +73,30 @@ const Events = ({
return (
<div>
{eventsByDate.map(
([date, events]): JSX.Element => {
const isLastDate = equals(last(dates), date);
return (
<div key={date}>
<div className={classes.events}>
<Typography variant="h6">{date}</Typography>
{events.map((event) => {
const { id, type } = event;
const Event = TimelineEventByType[type];
return (
<Paper key={`${id}-${type}`}>
<Event event={event} />
</Paper>
);
})}
</div>
{isLastDate && <div ref={infiniteScrollTriggerRef} />}
{eventsByDate.map(([date, events]): JSX.Element => {
const isLastDate = equals(last(dates), date);
return (
<div key={date}>
<div className={classes.events}>
<Typography variant="h6">{date}</Typography>
{events.map((event) => {
const { id, type } = event;
const Event = TimelineEventByType[type];
return (
<Paper key={`${id}-${type}`}>
<Event event={event} />
</Paper>
);
})}
</div>
);
},
)}
{isLastDate && <div ref={infiniteScrollTriggerRef} />}
</div>
);
})}
</div>
);
};
......
......@@ -23,13 +23,15 @@ const buildListTimelineEventsEndpoint = ({
parameters,
});
const listTimelineEvents = (cancelToken: CancelToken) => ({
endpoint,
parameters,
}: ListTimeLineEventsProps): Promise<ListingModel<TimelineEvent>> => {
return getData<ListingModel<TimelineEvent>>(cancelToken)(
buildListTimelineEventsEndpoint({ endpoint, parameters }),
);
};
const listTimelineEvents =
(cancelToken: CancelToken) =>
({
endpoint,
parameters,
}: ListTimeLineEventsProps): Promise<ListingModel<TimelineEvent>> => {
return getData<ListingModel<TimelineEvent>>(cancelToken)(
buildListTimelineEventsEndpoint({ endpoint, parameters }),
);
};
export { listTimelineEvents, buildListTimelineEventsEndpoint };
......@@ -73,9 +73,8 @@ const TimelineTab = ({ details }: TabProps): JSX.Element => {
})) as Array<Type>;
const [timeline, setTimeline] = React.useState<Array<TimelineEvent>>();
const [selectedTypes, setSelectedTypes] = React.useState<Array<Type>>(
translatedTypes,
);
const [selectedTypes, setSelectedTypes] =
React.useState<Array<Type>>(translatedTypes);
const [page, setPage] = React.useState(1);
const [total, setTotal] = React.useState(0);
const [limit] = React.useState(30);
......
......@@ -48,26 +48,17 @@ export interface DetailsState {
}
const useDetails = (): DetailsState => {
const [openDetailsTabId, setOpenDetailsTabId] = React.useState<TabId>(
detailsTabId,
);
const [
selectedResourceUuid,
setSelectedResourceUuid,
] = React.useState<string>();
const [openDetailsTabId, setOpenDetailsTabId] =
React.useState<TabId>(detailsTabId);
const [selectedResourceUuid, setSelectedResourceUuid] =
React.useState<string>();
const [selectedResourceId, setSelectedResourceId] = React.useState<number>();
const [
selectedResourceParentId,
setSelectedResourceParentId,
] = React.useState<number>();
const [
selectedResourceType,
setSelectedResourceType,
] = React.useState<string>();
const [
selectedResourceParentType,
setSelectedResourceParentType,
] = React.useState<string>();
const [selectedResourceParentId, setSelectedResourceParentId] =
React.useState<number>();
const [selectedResourceType, setSelectedResourceType] =
React.useState<string>();
const [selectedResourceParentType, setSelectedResourceParentType] =
React.useState<string>();
const [details, setDetails] = React.useState<ResourceDetails>();
const { t } = useTranslation();
......@@ -84,20 +75,15 @@ const useDetails = (): DetailsState => {
React.useEffect(() => {
const urlQueryParameters = getUrlQueryParameters();
const detailsUrlQueryParameters = urlQueryParameters.details as DetailsUrlQueryParameters;
const detailsUrlQueryParameters =
urlQueryParameters.details as DetailsUrlQueryParameters;
if (isNil(detailsUrlQueryParameters)) {
return;
}
const {
uuid,
id,
parentId,
type,
parentType,
tab,
} = detailsUrlQueryParameters;
const { uuid, id, parentId, type, parentType, tab } =
detailsUrlQueryParameters;
if (!isNil(tab)) {
setOpenDetailsTabId(getTabIdFromLabel(tab));
......