Skip to content

chore(site): remove template ACL XService #10332

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

Merged
merged 5 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Extract loading template ACL
  • Loading branch information
BrunoQuaresma committed Oct 18, 2023
commit 8f5f6da990cc5a41dc85baf7c57f454b9fd7c59b
7 changes: 7 additions & 0 deletions site/src/api/queries/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ export const templates = (orgId: string) => {
};
};

export const templateACL = (templateId: string) => {
return {
queryKey: ["templateAcl", templateId],
queryFn: () => API.getTemplateACL(templateId),
};
};

export const templateExamples = (orgId: string) => {
return {
queryKey: [...getTemplatesQueryKey(orgId), "examples"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { templateACLMachine } from "xServices/template/templateACLXService";
import { useTemplateSettings } from "../TemplateSettingsLayout";
import { TemplatePermissionsPageView } from "./TemplatePermissionsPageView";
import { docs } from "utils/docs";
import { useQuery } from "react-query";
import { templateACL } from "api/queries/templates";

export const TemplatePermissionsPage: FC<
React.PropsWithChildren<unknown>
Expand All @@ -23,7 +25,13 @@ export const TemplatePermissionsPage: FC<
const [state, send] = useMachine(templateACLMachine, {
context: { templateId: template.id },
});
const { templateACL, userToBeUpdated, groupToBeUpdated } = state.context;
const { userToBeUpdated, groupToBeUpdated } = state.context;
const templateACLQuery = useQuery({
...templateACL(template.id),
onSuccess: (data) => {
send({ type: "LOAD", data });
},
});

return (
<>
Expand Down Expand Up @@ -58,7 +66,7 @@ export const TemplatePermissionsPage: FC<
<TemplatePermissionsPageView
organizationId={organizationId}
templateID={template.id}
templateACL={templateACL}
templateACL={templateACLQuery.data}
canUpdatePermissions={Boolean(permissions?.canUpdateTemplate)}
onAddUser={(user, role, reset) => {
send("ADD_USER", { user, role, onDone: reset });
Expand Down
12 changes: 7 additions & 5 deletions site/src/xServices/template/templateACLXService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getTemplateACL, updateTemplateACL } from "api/api";
import { updateTemplateACL } from "api/api";
import {
TemplateACL,
TemplateGroup,
Expand Down Expand Up @@ -43,6 +43,10 @@ export const templateACLMachine = createMachine(
};
},
events: {} as // User
| {
type: "LOAD";
data: TemplateACL;
}
| {
type: "ADD_USER";
user: TemplateUser;
Expand Down Expand Up @@ -80,9 +84,8 @@ export const templateACLMachine = createMachine(
initial: "loading",
states: {
loading: {
invoke: {
src: "loadTemplateACL",
onDone: {
on: {
LOAD: {
actions: ["assignTemplateACL"],
target: "idle",
},
Expand Down Expand Up @@ -183,7 +186,6 @@ export const templateACLMachine = createMachine(
},
{
services: {
loadTemplateACL: ({ templateId }) => getTemplateACL(templateId),
// User
addUser: ({ templateId }, { user, role }) =>
updateTemplateACL(templateId, {
Expand Down