Skip to content

Commit

Permalink
Finalize feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Marcellin committed May 15, 2024
1 parent 36aee40 commit 5392845
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/components/dialogs/modify-element-selection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
import React, { useContext, useEffect, useState } from 'react';
import { Button, Grid, Typography } from '@mui/material';
import { FormattedMessage, useIntl } from 'react-intl';
import {
DirectoryItemSelector,
TreeViewFinderNodeProps,
FieldConstants,
} from '@gridsuite/commons-ui';
import { useController } from 'react-hook-form';
import { ElementType } from '@gridsuite/commons-ui';
import { UUID } from 'crypto';
import { FilterContext } from '../filter/filter-context.ts';
import { TreeViewFinderNodeProps } from '../TreeViewFinder';
import { FieldConstants } from '../../utils/field-constants.ts';
import DirectoryItemSelector from '../DirectoryItemSelector/directory-item-selector.tsx';

export interface ModifyElementSelectionProps {
elementType: ElementType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { UUID } from 'crypto';
import { useSnackMessage } from '../../../hooks/useSnackMessage.ts';
import { ElementType } from '../../../utils/ElementType.ts';
import ModifyElementSelection from '../../dialogs/modify-element-selection.tsx';
import { exportFilter } from '../../../services/study';

export const FILTER_EQUIPMENTS_ATTRIBUTES = 'filterEquipmentsAttributes';

Expand Down
3 changes: 3 additions & 0 deletions src/components/filter/filter-creation-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export interface FilterCreationDialogProps {
elementTypes?: string[],
equipmentTypes?: string[]
) => Promise<ElementAttributes[]>;
fetchPath?: (elementUuid: UUID) => Promise<ElementAttributes[]>;
sourceFilterForExplicitNamingConversion?: {
id: UUID;
equipmentType: string;
Expand All @@ -99,6 +100,7 @@ const FilterCreationDialog: FunctionComponent<FilterCreationDialogProps> = ({
fetchDirectoryContent,
fetchRootFolders,
fetchElementsInfos,
fetchPath,
sourceFilterForExplicitNamingConversion = undefined,
}) => {
const { snackError } = useSnackMessage();
Expand Down Expand Up @@ -191,6 +193,7 @@ const FilterCreationDialog: FunctionComponent<FilterCreationDialogProps> = ({
fetchRootFolders: fetchRootFolders,
fetchElementsInfos: fetchElementsInfos,
fetchAppsAndUrls: fetchAppsAndUrls,
fetchPath: fetchPath,
}}
>
<FilterForm
Expand Down
25 changes: 25 additions & 0 deletions src/services/study.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { UUID } from 'crypto';
import { backendFetchJson } from './utils.ts';

const PREFIX_STUDY_QUERIES = import.meta.env.VITE_API_GATEWAY + '/study';

export function exportFilter(
studyUuid: UUID,
filterUuid?: UUID,
token?: string
) {
console.info('get filter export on study root node');
return backendFetchJson(
PREFIX_STUDY_QUERIES +
'/v1/studies/' +
studyUuid +
'/filters/' +
filterUuid +
'/elements',
{
method: 'get',
headers: { 'Content-Type': 'application/json' },
},
token
);
}
9 changes: 8 additions & 1 deletion src/services/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ export const backendFetch = (url: string, init: any, token?: string) => {
return safeFetch(url, initCopy);
};

export const backendFetchJson = (url: string, init: any, token?: string) => {
const initCopy = prepareRequest(init, token);
return safeFetch(url, initCopy).then((safeResponse) =>
safeResponse.status === 204 ? null : safeResponse.json()
);
};

const prepareRequest = (init: any, token?: string) => {
if (!(typeof init === 'undefined' || typeof init === 'object')) {
throw new TypeError(
Expand All @@ -22,7 +29,7 @@ const prepareRequest = (init: any, token?: string) => {
initCopy.headers = new Headers(initCopy.headers || {});
initCopy.headers.append(
'Authorization',
'Bearer ' + token ?? getUserToken()
'Bearer ' + (token ?? getUserToken())
);
return initCopy;
};
Expand Down

0 comments on commit 5392845

Please sign in to comment.