Skip to content

Commit

Permalink
Merge pull request #785 from Arnei/typing-acldetails
Browse files Browse the repository at this point in the history
Add typing to acl details
  • Loading branch information
Arnei committed Jul 5, 2024
2 parents dff23eb + 77cc6a3 commit 6f65015
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 22 deletions.
13 changes: 8 additions & 5 deletions src/components/users/partials/modal/AclDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { NewAclSchema } from "../../../../utils/validate";
import ModalNavigation from "../../../shared/modals/ModalNavigation";
import { checkAcls } from "../../../../slices/aclSlice";
import { useAppDispatch, useAppSelector } from "../../../../store";
import { updateAclDetails } from "../../../../slices/aclDetailsSlice";
import { TransformedAcls, updateAclDetails } from "../../../../slices/aclDetailsSlice";

/**
* This component manages the pages of the acl details modal
Expand Down Expand Up @@ -47,13 +47,16 @@ const AclDetails = ({
},
];

// @ts-expect-error TS(7006): Parameter 'tabNr' implicitly has an 'any' type.
const openTab = (tabNr) => {
const openTab = (tabNr: number) => {
setPage(tabNr);
};

// @ts-expect-error TS(7006): Parameter 'values' implicitly has an 'any' type.
const handleSubmit = (values) => {
const handleSubmit = (
values: {
name: string,
acls: TransformedAcls,
}
) => {
dispatch(updateAclDetails({values: values, aclId: aclDetails.id}));
close();
};
Expand Down
9 changes: 6 additions & 3 deletions src/components/users/partials/modal/AclDetailsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import { availableHotkeys } from "../../../../configs/hotkeysConfig";
* This component renders the modal for displaying acl details
*/
const AclDetailsModal = ({
close,
aclName
}: any) => {
close,
aclName
}: {
close: () => void,
aclName: string,
}) => {
const { t } = useTranslation();

useHotkeys(
Expand Down
3 changes: 1 addition & 2 deletions src/components/users/partials/wizard/AclAccessPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ const AclAccessPage = <T extends RequiredFormProps>({
fetchData();
}, []);

// @ts-expect-error TS(7006): Parameter 'value' implicitly has an 'any' type.
const handleTemplateChange = async (value) => {
const handleTemplateChange = async (value: string) => {
// fetch information about chosen template from backend
const template = await fetchAclTemplateById(value);

Expand Down
11 changes: 5 additions & 6 deletions src/components/users/partials/wizard/NewAclWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ const NewAclWizard = ({
}) => {
const dispatch = useAppDispatch();

const initialValues = initialFormValuesNewAcl;
const initialValues = {
...initialFormValuesNewAcl,
aclTemplate: "",
}

const {
snapshot,
Expand Down Expand Up @@ -49,8 +52,7 @@ const NewAclWizard = ({

const currentValidationSchema = NewAclSchema[page];

// @ts-expect-error TS(7006): Parameter 'values' implicitly has an 'any' type.
const handleSubmit = (values) => {
const handleSubmit = (values: typeof initialFormValuesNewAcl) => {
const response = dispatch(postNewAcl(values));
console.info(response);
close();
Expand Down Expand Up @@ -93,11 +95,8 @@ const NewAclWizard = ({
)}
{page === 1 && (
<AclAccessPage
// @ts-expect-error: Type-checking gets confused by redux-connect in the child
formik={formik}
// @ts-expect-error: Type-checking gets confused by redux-connect in the child
nextPage={nextPage}
// @ts-expect-error: Type-checking gets confused by redux-connect in the child
previousPage={previousPage}
/>
)}
Expand Down
5 changes: 4 additions & 1 deletion src/configs/modalConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ export const initialFormValuesNewThemes = {

// All fields for new acl form that are fix and not depending on response of backend
// InitialValues of Formik form (others computed dynamically depending on responses from backend)
export const initialFormValuesNewAcl = {
export const initialFormValuesNewAcl: {
name: string,
acls: TransformedAcl[],
} = {
name: "",
acls: [],
};
Expand Down
10 changes: 5 additions & 5 deletions src/slices/aclSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { addNotification, removeNotificationWizardAccess } from './notificationS
import { getUserInformation } from "../selectors/userInfoSelectors";
import { AppDispatch } from '../store';
import { createAppAsyncThunk } from '../createAsyncThunkWithTypes';
import { initialFormValuesNewAcl } from "../configs/modalConfig";
import { TransformedAcl } from './aclDetailsSlice';

/**
* This file contains redux reducer for actions affecting the state of acls
Expand Down Expand Up @@ -119,8 +121,7 @@ export const fetchRolesWithTarget = async (target: string) => {
};

// post new acl to backend
// @ts-expect-error TS(7006): Parameter 'values' implicitly has an 'any' type.
export const postNewAcl = (values) => async (dispatch: AppDispatch) => {
export const postNewAcl = (values: typeof initialFormValuesNewAcl) => async (dispatch: AppDispatch) => {
let acls = prepareAccessPolicyRulesForPost(values.acls);

let data = new URLSearchParams();
Expand All @@ -143,8 +144,7 @@ export const postNewAcl = (values) => async (dispatch: AppDispatch) => {
});
};
// delete acl with provided id
// @ts-expect-error TS(7006): Parameter 'id' implicitly has an 'any' type.
export const deleteAcl = (id) => async (dispatch: AppDispatch) => {
export const deleteAcl = (id: string) => async (dispatch: AppDispatch) => {
axios
.delete(`/admin-ng/acl/${id}`)
.then((res) => {
Expand All @@ -160,7 +160,7 @@ export const deleteAcl = (id) => async (dispatch: AppDispatch) => {
};

// @ts-expect-error TS(7006):
export const checkAcls = (acls) => async (dispatch: AppDispatch, getState) => {
export const checkAcls = (acls: TransformedAcl[]) => async (dispatch: AppDispatch, getState) => {
// Remove old notifications of context event-access
// Helps to prevent multiple notifications for same problem
dispatch(removeNotificationWizardAccess());
Expand Down

0 comments on commit 6f65015

Please sign in to comment.