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

Experimental: etags #3065

Draft
wants to merge 6 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
7 changes: 6 additions & 1 deletion client/src/features/projectsV2/api/projectV2.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
url: `/projects/${queryArg.projectId}`,
method: "PATCH",
body: queryArg.projectPatch,
headers: { "If-Match": queryArg["If-Match"] },
}),
}),
deleteProjectsByProjectId: build.mutation<
Expand Down Expand Up @@ -90,6 +91,8 @@
/** status 200 The patched project */ Project;
export type PatchProjectsByProjectIdApiArg = {
projectId: string;
/** If-Match header, for avoiding mid-air collisions */
"If-Match": ETag;
projectPatch: ProjectPatch;
};
export type DeleteProjectsByProjectIdApiResponse =
Expand Down Expand Up @@ -127,15 +130,17 @@
export type RepositoriesList = Repository[];
export type Visibility = "private" | "public";
export type Description = string;
export type ETag = string;
export type Project = {
id: Ulid;
name: Name;
slug: Slug;
slug?: Slug;
creation_date: CreationDate;
created_by: Member;
repositories?: RepositoriesList;
visibility: Visibility;
description?: Description;
etag?: ETag;

Check warning on line 143 in client/src/features/projectsV2/api/projectV2.api.ts

View workflow job for this annotation

GitHub Actions / test-client

You have a misspelled word: etag on Identifier

Check warning on line 143 in client/src/features/projectsV2/api/projectV2.api.ts

View workflow job for this annotation

GitHub Actions / test-client

You have a misspelled word: etag on Identifier
};
export type ProjectsList = Project[];
export type ErrorResponse = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const injectedApi = api.injectEndpoints({
const enhancedApi = injectedApi.enhanceEndpoints({
addTagTypes: ["Project", "Members"],
endpoints: {
postProjects: {
invalidatesTags: ["Project"],
},
deleteProjectsByProjectId: {
invalidatesTags: ["Project"],
},
Expand Down
33 changes: 24 additions & 9 deletions client/src/features/projectsV2/api/projectV2.openapi.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"openapi": "3.1.0",
"openapi": "3.0.2",
"info": {
"title": "Renku Project Management Service",
"description": "Service that allows creating, updating, deleting, and managing Renku native projects.\nAll errors have the same format as the schema called ErrorResponse.\n",
Expand Down Expand Up @@ -169,6 +169,9 @@
"schema": {
"type": "string"
}
},
{
"$ref": "#/components/parameters/If-Match"
}
],
"requestBody": {
Expand Down Expand Up @@ -395,16 +398,12 @@
},
"description": {
"$ref": "#/components/schemas/Description"
},
"etag": {
"$ref": "#/components/schemas/ETag"
}
},
"required": [
"id",
"name",
"slug",
"created_by",
"creation_date",
"visibility"
],
"required": ["id", "name", "created_by", "creation_date", "visibility"],
"example": {
"id": "01AN4Z79ZS5XN0F25N3DB94T4R",
"name": "Renku R Project",
Expand Down Expand Up @@ -650,6 +649,11 @@
"description": "User email",
"example": "[email protected]"
},
"ETag": {
"type": "string",
"description": "Entity Tag",
"example": "9EE498F9D565D0C41E511377425F32F3"
},
"ErrorResponse": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -688,6 +692,17 @@
}
}
}
},
"parameters": {
"If-Match": {
"in": "header",
"name": "If-Match",
"description": "If-Match header, for avoiding mid-air collisions",
"required": true,
"schema": {
"$ref": "#/components/schemas/ETag"
}
}
}
}
}
21 changes: 16 additions & 5 deletions client/src/features/projectsV2/show/ProjectV2EditForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import ProjectVisibilityFormField from "../fields/ProjectVisibilityFormField";

import { SettingEditOption } from "./projectV2Show.types";
import { RtkErrorAlert } from "../../../components/errors/RtkErrorAlert";

type ProjectV2Metadata = Omit<ProjectPatch, "repositories">;

Expand Down Expand Up @@ -105,7 +106,7 @@
<Button
className="ms-2"
color="danger"
disabled={typedName !== project.slug.trim()}
disabled={typedName !== project.slug?.trim()}
onClick={onDelete}
>
{result.isLoading ? (
Expand Down Expand Up @@ -162,7 +163,7 @@
},
});

const [updateProject, { isLoading, isError }] =
const [updateProject, { isLoading, error }] =
usePatchProjectsByProjectIdMutation();

const isUpdating = isLoading;
Expand All @@ -172,7 +173,11 @@

const onSubmit = useCallback(
(data: ProjectV2Metadata) => {
updateProject({ projectId: project.id, projectPatch: data })
updateProject({
"If-Match": project.etag ?? "",

Check warning on line 177 in client/src/features/projectsV2/show/ProjectV2EditForm.tsx

View workflow job for this annotation

GitHub Actions / test-client

You have a misspelled word: etag on Identifier

Check warning on line 177 in client/src/features/projectsV2/show/ProjectV2EditForm.tsx

View workflow job for this annotation

GitHub Actions / test-client

You have a misspelled word: etag on Identifier
projectId: project.id,
projectPatch: data,
})
.unwrap()
.then(() => setSettingEdit(null));
},
Expand All @@ -196,6 +201,9 @@
project={project}
toggle={toggle}
/>

{error && <RtkErrorAlert error={error} />}

<Form
className="form-rk-green"
noValidate
Expand All @@ -213,7 +221,6 @@
errors={errors}
/>
<ProjectEditSubmitGroup isUpdating={isUpdating} onCancel={onCancel} />
{isError && <div>There was an error</div>}
</Form>
</div>
);
Expand Down Expand Up @@ -350,7 +357,11 @@
const onSubmit = useCallback(
(data: ProjectV2Repositories) => {
const repositories = data.repositories.map((r) => r.url);
updateProject({ projectId: project.id, projectPatch: { repositories } })
updateProject({
"If-Match": project.etag ?? "",

Check warning on line 361 in client/src/features/projectsV2/show/ProjectV2EditForm.tsx

View workflow job for this annotation

GitHub Actions / test-client

You have a misspelled word: etag on Identifier

Check warning on line 361 in client/src/features/projectsV2/show/ProjectV2EditForm.tsx

View workflow job for this annotation

GitHub Actions / test-client

You have a misspelled word: etag on Identifier
projectId: project.id,
projectPatch: { repositories },
})
.unwrap()
.then(() => setSettingEdit(null));
},
Expand Down
Loading