Skip to content
Open
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
17 changes: 12 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dependencies": {
"@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.0",
"@gridsuite/commons-ui": "0.101.0",
"@gridsuite/commons-ui": "file:../commons-ui/gridsuite-commons-ui-0.102.0.tgz",
"@hookform/resolvers": "^4.0.0",
"@mui/icons-material": "^5.16.14",
"@mui/lab": "5.0.0-alpha.175",
Expand Down
2 changes: 2 additions & 0 deletions src/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
NotificationsProvider,
TopBar,
type UserManagerState,
useYupIntl,
} from '@gridsuite/commons-ui';
import { FormattedMessage, useIntl } from 'react-intl';
import PowsyblLogo from '../images/powsybl_logo.svg?react';
Expand Down Expand Up @@ -63,6 +64,7 @@ const App = () => {
const computedLanguage = useIntl().locale;
const theme = useAppSelector((state) => state.theme);
const themeCompiled = useMemo(() => getMuiTheme(theme, computedLanguage), [computedLanguage, theme]);
useYupIntl();

const user = useAppSelector((state) => state.user.user);

Expand Down
3 changes: 2 additions & 1 deletion src/containers/FilterContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
} from '../redux/slices/Mapping';
import Filter from '../components/3-organisms/Filter';
import PropTypes from 'prop-types';
import { CustomFormProvider, EXPERT_FILTER_QUERY, yupConfig as yup } from '@gridsuite/commons-ui';
import * as yup from 'yup';
import { CustomFormProvider, EXPERT_FILTER_QUERY } from '@gridsuite/commons-ui';
import useDataForm from '../hooks/react-hook-form/form/useDataForm';

// we do not need detail schema with all validation test for rqb filter
Expand Down
14 changes: 6 additions & 8 deletions src/hooks/react-hook-form/form/useDataForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import { FieldErrors, FieldValues, useForm } from 'react-hook-form';
import { type FieldErrors, type FieldValues, useForm } from 'react-hook-form';
import { yupResolver } from '@hookform/resolvers/yup';
import useFormInit from './useFormInit';
import { yupConfig as yup } from '@gridsuite/commons-ui';
import type { ObjectSchema } from 'yup';
import useDataUpdate from './useDataUpdate';

const useDataForm = (
formSchema: yup.ObjectSchema<any>,
export default function useDataForm(
formSchema: ObjectSchema<any>,
data: Object,
invalidations: any[],
onValid: (formData: FieldValues) => void,
onInvalid: (errors: FieldErrors) => void
) => {
) {
const formMethods = useForm({
resolver: yupResolver(formSchema),
});
Expand All @@ -30,6 +30,4 @@ const useDataForm = (
useDataUpdate(formMethods, onValid, onInvalid);

return { key, formMethods };
};

export default useDataForm;
}
16 changes: 7 additions & 9 deletions src/redux/slices/Mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {
getExpertFilterEmptyFormData,
importExpertRules,
rqbQuerySchemaValidator,
yupConfig as yup,
} from '@gridsuite/commons-ui';
import * as yup from 'yup';
import { v4 as uuid4 } from 'uuid';
import { enrichIdRqbQuery } from '../../utils/rqb-utils';
import { assignArray } from '../../utils/functions';
Expand Down Expand Up @@ -214,9 +214,7 @@ const checkFilterValidity = (filter, isLast) => {
// only last rule allows empty filter
return !!isLast;
}
const isQueryExist = !_.isEmpty(filter.rules);
const isQueryValid = isQueryExist && rqbQuerySchemaValidator(yup.object()).isValidSync(filter.rules);
return isQueryValid;
return !_.isEmpty(filter.rules) && rqbQuerySchemaValidator(yup.object()).isValidSync(filter.rules); // query exist and is valid
};

export const makeGetIsFilterValid = () =>
Expand Down Expand Up @@ -244,7 +242,7 @@ const checkRuleValidity = (rule, isLast) => {
};

const checkAutomatonValidity = (automaton, automatonDefinition = {}) => {
const result =
return (
!!automaton.family &&
!!automaton.model &&
!!automaton.setGroup &&
Expand All @@ -256,8 +254,8 @@ const checkAutomatonValidity = (automaton, automatonDefinition = {}) => {
? !!automaton.properties.find((elem) => elem.name === propertyName)?.value
: true),
true
);
return result;
)
);
};

const indexingRuleByType = (rules) => {
Expand Down Expand Up @@ -622,8 +620,8 @@ const reducers = {
const foundRule = foundMapping.rules?.find((rule) => rule?.filter?.id === modifiedFilter?.id);

const oldQuery = foundRule?.filter?.rules;
const isDirty = formatQuery(oldQuery, 'json_without_ids') !== formatQuery(newQuery, 'json_without_ids');
modifiedRule.filterDirty = isDirty;
modifiedRule.filterDirty =
formatQuery(oldQuery, 'json_without_ids') !== formatQuery(newQuery, 'json_without_ids');
}
},
deleteFilter: (state, action) => {
Expand Down