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

fix: update the secrets API after breaking change #3253

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"storybook-wait-server": "wait-on http://127.0.0.1:6006",
"storybook-test": "test-storybook",
"storybook-compile-and-test": "concurrently -k -s first -n 'BUILD,TEST' -c 'magenta,blue' 'npm run storybook-build && npm run storybook-start-server' 'npm run storybook-wait-server && npm run storybook-test'",
"generate-api": "npm run generate-api:dataServicesUser && npm run generate-api:namespaceV2 && npm run generate-api:projectV2 && generate-api:platform && npm run generate-api:searchV2",
"generate-api": "npm run generate-api:dataServicesUser && npm run generate-api:namespaceV2 && npm run generate-api:projectV2 && npm run generate-api:platform && npm run generate-api:searchV2",
"generate-api:dataServicesUser": "rtk-query-codegen-openapi src/features/user/dataServicesUser.api/dataServicesUser.api-config.ts",
"generate-api:namespaceV2": "rtk-query-codegen-openapi src/features/projectsV2/api/namespace.api-config.ts",
"generate-api:projectV2": "rtk-query-codegen-openapi src/features/projectsV2/api/projectV2.api-config.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
useGetNamespacesByNamespaceSlugQuery,
useGetProjectsByProjectIdMembersQuery,
} from "../../../projectsV2/api/projectV2.enhanced-api";
import { useGetUsersByUserIdQuery } from "../../../user/dataServicesUser.api";
import { useGetUsersByUserIdQuery } from "../../../user/dataServicesUser.api/dataServicesUser.api";
import { useProject } from "../../ProjectPageContainer/ProjectPageContainer";
import MembershipGuard from "../../utils/MembershipGuard";
import { toSortedMembers } from "../../utils/roleUtils";
Expand Down
9 changes: 5 additions & 4 deletions client/src/features/ProjectPageV2/utils/MembershipGuard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
*/

import { skipToken } from "@reduxjs/toolkit/query";
import { useGetUserQuery } from "../../../features/user/dataServicesUser.api";

import { useGetUserQuery } from "../../../features/user/dataServicesUser.api/dataServicesUser.api";
import useLegacySelector from "../../../utils/customHooks/useLegacySelector.hook";
import type {
ProjectMemberListResponse,
ProjectMemberResponse,
} from "../../projectsV2/api/projectV2.api.ts";
import AccessGuard from "./AccessGuard.tsx";
import { toNumericRole } from "./roleUtils.ts";
} from "../../projectsV2/api/projectV2.api";
import AccessGuard from "./AccessGuard";
import { toNumericRole } from "./roleUtils";

interface SelfOverride {
disabled: React.ReactNode | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
*/

import { skipToken } from "@reduxjs/toolkit/query";
import { useGetUserQuery } from "../../user/dataServicesUser.api/index.ts";
import useLegacySelector from "../../../utils/customHooks/useLegacySelector.hook.ts";
import type { Role } from "../../projectsV2/api/projectV2.api.ts";
import { useGetProjectsByProjectIdMembersQuery } from "../../projectsV2/api/projectV2.enhanced-api.ts";

import useLegacySelector from "../../../utils/customHooks/useLegacySelector.hook";
import type { Role } from "../../projectsV2/api/projectV2.api";
import { useGetProjectsByProjectIdMembersQuery } from "../../projectsV2/api/projectV2.enhanced-api";
import { useGetUserQuery } from "../../user/dataServicesUser.api/dataServicesUser.api";

interface UseProjectAccessArgs {
projectId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import { ABSOLUTE_ROUTES } from "../../../routing/routes.constants";
import { toSortedMembers } from "../../ProjectPageV2/utils/roleUtils";
import type { ProjectMemberResponse } from "../../projectsV2/api/projectV2.api";
import { useGetGroupsByGroupSlugMembersQuery } from "../../projectsV2/api/projectV2.enhanced-api";
import { useGetUsersByUserIdQuery } from "../../user/dataServicesUser.api";
import UserAvatar from "../../usersV2/show/UserAvatar";
import { useGetUsersByUserIdQuery } from "../../user/dataServicesUser.api/dataServicesUser.api";

interface GroupV2MemberListDisplayProps {
group: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
*/

import cx from "classnames";

import { useCallback, useEffect, useState } from "react";
import { PlusLg, XLg } from "react-bootstrap-icons";
import { Controller, useForm } from "react-hook-form";

import { Button, Form, Input, Label, ModalBody, ModalFooter } from "reactstrap";

import { useGetUsersQuery } from "../../user/dataServicesUser.api";
import type { UserWithId } from "../../user/dataServicesUser.api";
import {
useGetUsersQuery,
type UserWithId,
} from "../../user/dataServicesUser.api/dataServicesUser.api";

const emailRegex = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {

import { RtkErrorAlert } from "../../../components/errors/RtkErrorAlert";

import type { UserWithId } from "../../user/dataServicesUser.api";
import type { UserWithId } from "../../user/dataServicesUser.api/dataServicesUser.api";

import type {
GroupMemberResponseList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {

import { RtkErrorAlert } from "../../../components/errors/RtkErrorAlert";

import type { UserWithId } from "../../user/dataServicesUser.api";
import type { UserWithId } from "../../user/dataServicesUser.api/dataServicesUser.api";

import type {
ProjectMemberPatchRequest,
Expand Down
7 changes: 4 additions & 3 deletions client/src/features/secrets/SecretDelete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import { useCallback, useEffect, useState } from "react";
import { TrashFill, XLg } from "react-bootstrap-icons";
import { Button, Modal, ModalBody, ModalFooter, ModalHeader } from "reactstrap";

import { useDeleteSecretMutation } from "./secrets.api";
import { RtkOrNotebooksError } from "../../components/errors/RtkErrorAlert";
import { SecretDetails } from "./secrets.types";
import { useDeleteUserSecretsBySecretIdMutation } from "../user/dataServicesUser.api/dataServicesUser.api";

interface SecretsDeleteProps {
secret: SecretDetails;
Expand All @@ -36,9 +36,10 @@ export default function SecretDelete({ secret }: SecretsDeleteProps) {
}, []);

// Handle posting data
const [deleteSecretMutation, result] = useDeleteSecretMutation();
const [deleteSecretMutation, result] =
useDeleteUserSecretsBySecretIdMutation();
const deleteSecret = useCallback(() => {
deleteSecretMutation(secret.id);
deleteSecretMutation({ secretId: secret.id });
}, [deleteSecretMutation, secret.id]);

// Automatically close the modal when the secret is modified
Expand Down
6 changes: 3 additions & 3 deletions client/src/features/secrets/SecretEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import {
UncontrolledTooltip,
} from "reactstrap";

import { useEditSecretMutation } from "./secrets.api";
import { RtkOrNotebooksError } from "../../components/errors/RtkErrorAlert";
import { usePatchUserSecretsBySecretIdMutation } from "../user/dataServicesUser.api/dataServicesUser.api";
import { EditSecretForm, SecretDetails } from "./secrets.types";
import { SECRETS_VALUE_LENGTH_LIMIT } from "./secrets.utils";

Expand Down Expand Up @@ -75,10 +75,10 @@ export default function SecretEdit({ secret }: SecretsEditProps) {
});

// Handle posting data
const [editSecretMutation, result] = useEditSecretMutation();
const [editSecretMutation, result] = usePatchUserSecretsBySecretIdMutation();
const onSubmit = useCallback(
(newSecret: EditSecretForm) => {
editSecretMutation({ id: secret.id, ...newSecret });
editSecretMutation({ secretId: secret.id, secretPatch: newSecret });
},
[editSecretMutation, secret.id]
);
Expand Down
14 changes: 9 additions & 5 deletions client/src/features/secrets/SecretNew.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ import {
UncontrolledTooltip,
} from "reactstrap";

import secretsApi, { useAddSecretMutation } from "./secrets.api";
import { RtkOrNotebooksError } from "../../components/errors/RtkErrorAlert";
import { Loader } from "../../components/Loader";
import { AddSecretForm } from "./secrets.types";
import { SECRETS_VALUE_LENGTH_LIMIT } from "./secrets.utils";
import {
dataServicesUserApi,
usePostUserSecretsMutation,
} from "../user/dataServicesUser.api/dataServicesUser.api";

import styles from "./secrets.module.scss";

Expand Down Expand Up @@ -69,19 +72,20 @@ export default function SecretsNew() {
});

// Handle fetching/posting data
const [getSecrets, secrets] = secretsApi.useLazyGetSecretsQuery();
const [addSecretMutation, result] = useAddSecretMutation();
const [getSecrets, secrets] =
dataServicesUserApi.useLazyGetUserSecretsQuery();
const [addSecretMutation, result] = usePostUserSecretsMutation();
const onSubmit = useCallback(
(newSecret: AddSecretForm) => {
addSecretMutation(newSecret);
addSecretMutation({ secretPost: { ...newSecret, kind: "general" } });
},
[addSecretMutation]
);

// Force fetching the secrets when trying to add a new one to try to prevent duplicates
useEffect(() => {
if (showModal) {
getSecrets();
getSecrets({});
}
}, [getSecrets, showModal]);

Expand Down
4 changes: 2 additions & 2 deletions client/src/features/secrets/SecretsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import cx from "classnames";
import { Col, Container, Row } from "reactstrap";

import { Loader } from "../../components/Loader";
import { useGetSecretsQuery } from "./secrets.api";
import { RtkOrNotebooksError } from "../../components/errors/RtkErrorAlert";
import SecretsListItem from "./SecretsListItem";
import { useGetUserSecretsQuery } from "../user/dataServicesUser.api/dataServicesUser.api";

export default function SecretsList() {
const secrets = useGetSecretsQuery();
const secrets = useGetUserSecretsQuery({});

if (secrets.isLoading) return <Loader />;

Expand Down
98 changes: 0 additions & 98 deletions client/src/features/secrets/secrets.api.ts

This file was deleted.

2 changes: 1 addition & 1 deletion client/src/features/secrets/secrets.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

export interface SecretDetails {
id: string;
modification_date: Date;
modification_date: string;
name: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ import { useCallback, useEffect, useState } from "react";
import { Link } from "react-router-dom";
import { Button, Card, CardBody, Collapse, Input, Label } from "reactstrap";

import { RtkOrNotebooksError } from "../../../../components/errors/RtkErrorAlert";
import ChevronFlippedIcon from "../../../../components/icons/ChevronFlippedIcon";
import { Loader } from "../../../../components/Loader";
import { User } from "../../../../model/renkuModels.types";
import useLegacySelector from "../../../../utils/customHooks/useLegacySelector.hook";
import { Url } from "../../../../utils/helpers/url";
import ChevronFlippedIcon from "../../../../components/icons/ChevronFlippedIcon";
import { useGetSecretsQuery } from "../../../secrets/secrets.api";
import { RtkOrNotebooksError } from "../../../../components/errors/RtkErrorAlert";
import { setSecretsList, setSecretsPath } from "../../startSessionOptionsSlice";
import useAppDispatch from "../../../../utils/customHooks/useAppDispatch.hook";
import useAppSelector from "../../../../utils/customHooks/useAppSelector.hook";
import useLegacySelector from "../../../../utils/customHooks/useLegacySelector.hook";
import { Url } from "../../../../utils/helpers/url";
import { useGetUserSecretsQuery } from "../../../user/dataServicesUser.api/dataServicesUser.api";
import { SessionSecrets } from "../../startSessionOptions.types";
import { setSecretsList, setSecretsPath } from "../../startSessionOptionsSlice";

export default function SessionUserSecrets() {
const secretsUrl = Url.get(Url.pages.secrets);
Expand Down Expand Up @@ -68,7 +68,7 @@ function SessionUserSecretsSection() {
const toggleIsOpen = useCallback(() => setIsOpen((isOpen) => !isOpen), []);

// Fetch the secrets
const secrets = useGetSecretsQuery();
const secrets = useGetUserSecretsQuery({});

// Get current values from the store
const sessionOptions = useAppSelector((state) => state.startSessionOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import type { ConfigFile } from "@rtk-query/codegen-openapi";
import path from "path";

const config: ConfigFile = {
apiFile: "./dataServicesUser-empty.api.ts",
apiFile: "./dataServicesUser.empty-api.ts",
apiImport: "dataServicesUserEmptyApi",
outputFile: "./dataServicesUser.api.ts",
exportName: "dataServicesUserApi",
outputFile: "./dataServicesUser.generated-api.ts",
exportName: "dataServicesUserGeneratedApi",
hooks: true,
schemaFile: path.join(__dirname, "dataServicesUser.openapi.json"),
};
Expand Down
Loading
Loading