Skip to content

Commit

Permalink
refactor(moderation): move actions ui components
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil committed Oct 7, 2024
1 parent c5ba4d3 commit 0b0a197
Show file tree
Hide file tree
Showing 81 changed files with 1,376 additions and 796 deletions.
Binary file modified bun.lockb
Binary file not shown.
15 changes: 13 additions & 2 deletions hyyypertool.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,17 @@
"problemMatcher": ["$tsc-watch"],
"runOptions": { "instanceLimit": 1 },
},
{
"label": "🧪 Update Test Snapshots : Current file",
"command": "bun test --update-snapshots ${fileDirname}/${fileBasename}",
"type": "shell",
"group": "build",
"options": {
"cwd": "${workspaceFolder:root}",
},
"problemMatcher": ["$tsc-watch"],
"runOptions": { "instanceLimit": 1 },
},
{
"label": "🧪 Watch Test",
"command": "bun test --watch",
Expand All @@ -237,7 +248,7 @@
},
{
"label": "🧪 Cypress Studio",
"command": "pnpm run studio",
"command": "bun run studio",
"type": "shell",
"group": "build",
"options": {
Expand All @@ -248,7 +259,7 @@
},
{
"label": "🧪 Cypress Run : Current file",
"command": "pnpm run test --spec ${fileDirname}/${fileBasename}",
"command": "bun run test --spec ${fileDirname}/${fileBasename}",
"type": "shell",
"group": "build",
"options": {
Expand Down
21 changes: 8 additions & 13 deletions packages/~/app/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,17 @@
"type": "module",
"exports": {
".": "./src/index.ts",
"./config": {
"default": "./src/config/index.ts"
"./config/*": {
"default": "./src/config/*.ts"
},
"./error": {
"default": "./src/error/index.ts"
"./date/*": {
"default": "./src/date/*.ts"
},
"./html": {
"default": "./src/html/index.ts"
},
"./htmx": {
"default": "./src/htmx/index.ts"
},
"./schema": {
"default": "./src/schema/index.ts"
"./schema/*": {
"default": "./src/schema/*.ts"
},
"./*": {
"default": "./src/*.ts"
"default": "./src/*/index.ts"
}
},
"scripts": {
Expand All @@ -30,6 +24,7 @@
"dependencies": {
"modern-errors": "7.0.1",
"ts-pattern": "5.4.0",
"type-fest": "4.26.1",
"zod": "3.23.8"
},
"devDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions packages/~/app/core/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//

export type { SetOptional, Simplify, SimplifyDeep } from "type-fest";
45 changes: 26 additions & 19 deletions packages/~/app/ui/src/testing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,35 @@

import type { Child } from "hono/jsx";
import { renderToReadableStream } from "hono/jsx/dom/server";
import { format } from "prettier";
import { format, type Options } from "prettier";

//

export async function renderHTML(element: Child) {
const textDecoder = new TextDecoder();
const getStringFromStream = async (
stream: ReadableStream<Uint8Array>,
): Promise<string> => {
const reader = stream.getReader();
let str = "";
for (;;) {
const { done, value } = await reader.read();
if (done) {
break;
export const render_html = PrettyRenderer({ parser: "html" });
export const render_md = PrettyRenderer({ parser: "mdx" });

//

export function PrettyRenderer(options: Options) {
return async function render_formated(element: Child) {
const textDecoder = new TextDecoder();
const getStringFromStream = async (
stream: ReadableStream<Uint8Array>,
): Promise<string> => {
const reader = stream.getReader();
let str = "";
for (;;) {
const { done, value } = await reader.read();
if (done) {
break;
}
str += textDecoder.decode(value);
}
str += textDecoder.decode(value);
}
return str;
return str;
};
return format(
await getStringFromStream(await renderToReadableStream(element)),
options,
);
};
return format(
await getStringFromStream(await renderToReadableStream(element)),
{ parser: "html" },
);
}
3 changes: 1 addition & 2 deletions packages/~/app/urls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"dependencies": {
"consola": "3.2.3",
"hono": "4.6.3",
"static-path": "0.0.4",
"type-fest": "4.26.1"
"static-path": "0.0.4"
},
"devDependencies": {
"@~/config.typescript": "workspace:*"
Expand Down
6 changes: 3 additions & 3 deletions packages/~/app/urls/src/hx_urls.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//

import type { SetOptional } from "@~/app.core/types";
import type { Hono, HonoRequest, Schema } from "hono";
import { hc } from "hono/client";
import type { Endpoint } from "hono/types";
import type { HasRequiredKeys, UnionToIntersection } from "hono/utils/types";
import type { SetOptional } from "type-fest";
import type { Router } from "./pattern";

//
Expand Down Expand Up @@ -53,11 +53,11 @@ type HxClientRequest<TSchema extends Schema> = {
? <$Args extends SetOptional<$Input, any>>(
args: $Args,
options?: HxClientRequestOptions,
) => HtmxSpecifiedAttributes<Method, $Args>
) => Promise<HtmxSpecifiedAttributes<Method, $Args>>
: <$Args extends SetOptional<$Input, any>>(
args?: $Args,
options?: HxClientRequestOptions,
) => HtmxSpecifiedAttributes<Method, $Args>
) => Promise<HtmxSpecifiedAttributes<Method, $Args>>
: never
: never
: never
Expand Down
1 change: 1 addition & 0 deletions packages/~/moderations/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@~/organizations.repository": "workspace:*",
"@~/organizations.ui": "workspace:*",
"@~/users.lib": "workspace:*",
"@~/users.ui": "workspace:*",
"@~/zammad.lib": "workspace:*",
"await-to-js": "3.0.0",
"drizzle-orm": "0.33.0",
Expand Down
8 changes: 3 additions & 5 deletions packages/~/moderations/api/src/:id/$procedures/rejected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { zValidator } from "@hono/zod-validator";
import type { Htmx_Header } from "@~/app.core/htmx";
import { Entity_Schema } from "@~/app.core/schema";
import { set_crisp_config } from "@~/crisp.middleware";
import {
RejectedMessage_Schema,
type RejectedModeration_Context,
} from "@~/moderations.lib/context/rejected";
import { type RejectedModeration_Context } from "@~/moderations.lib/context/rejected";
import { MODERATION_EVENTS } from "@~/moderations.lib/event";
import { reject_form_schema } from "@~/moderations.lib/schema/rejected.form";
import { mark_moderation_as } from "@~/moderations.lib/usecase/mark_moderation_as";
import { send_rejected_message_to_user } from "@~/moderations.lib/usecase/send_rejected_message_to_user";
import { get_moderation } from "@~/moderations.repository/get_moderation";
Expand All @@ -21,7 +19,7 @@ export default new Hono<ContextType>().patch(
"/",
set_crisp_config(),
zValidator("param", Entity_Schema),
zValidator("form", RejectedMessage_Schema),
zValidator("form", reject_form_schema),
async function PATH({
text,
req,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { set_moncomptepro_pg } from "@~/app.middleware/set_moncomptepro_pg";
import { set_nonce } from "@~/app.middleware/set_nonce";
import { set_userinfo } from "@~/app.middleware/set_userinfo";
import { anais_tailhade } from "@~/app.middleware/set_userinfo#fixture";
import { validate_form_schema } from "@~/moderations.lib/schema/validate.form";
import {
create_adora_pony_moderation,
create_adora_pony_user,
Expand All @@ -26,7 +27,7 @@ import {
test,
} from "bun:test";
import { Hono } from "hono";
import app, { FORM_SCHEMA } from "./validate";
import app from "./validate";

//

Expand All @@ -45,7 +46,10 @@ test("GET /moderation/:id/$procedures/validate { add_domain: true, add_member: A

const body = new FormData();
body.append("add_domain", "true");
body.append("add_member", FORM_SCHEMA.shape.add_member.Enum.AS_INTERNAL);
body.append(
"add_member",
validate_form_schema.shape.add_member.enum.AS_INTERNAL,
);
const response = await new Hono()
.use(set_config({}))
.use(set_moncomptepro_pg(pg))
Expand Down Expand Up @@ -107,7 +111,10 @@ test("GET /moderation/:id/$procedures/validate { add_domain: false, add_member:

const body = new FormData();
body.append("add_domain", "false");
body.append("add_member", FORM_SCHEMA.shape.add_member.Enum.AS_EXTERNAL);
body.append(
"add_member",
validate_form_schema.shape.add_member.enum.AS_EXTERNAL,
);
const response = await new Hono()
.use(set_config({}))
.use(set_moncomptepro_pg(pg))
Expand Down
13 changes: 2 additions & 11 deletions packages/~/moderations/api/src/:id/$procedures/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { zValidator } from "@hono/zod-validator";
import { HTTPError } from "@~/app.core/error";
import type { Htmx_Header } from "@~/app.core/htmx";
import { Entity_Schema } from "@~/app.core/schema";
import { z_coerce_boolean } from "@~/app.core/schema/z_coerce_boolean";
import { z_email_domain } from "@~/app.core/schema/z_email_domain";
import type { App_Context } from "@~/app.middleware/context";
import { MODERATION_EVENTS } from "@~/moderations.lib/event";
import { validate_form_schema } from "@~/moderations.lib/schema/validate.form";
import { mark_moderation_as } from "@~/moderations.lib/usecase/mark_moderation_as";
import { MemberJoinOrganization } from "@~/moderations.lib/usecase/member_join_organization";
import { GetModerationById } from "@~/moderations.repository";
Expand All @@ -25,22 +25,13 @@ import consola from "consola";
import { eq } from "drizzle-orm";
import { Hono } from "hono";
import { P, match } from "ts-pattern";
import { z } from "zod";

//

export const FORM_SCHEMA = z.object({
add_domain: z.string().default("false").pipe(z_coerce_boolean),
add_member: z.enum(["AS_INTERNAL", "AS_EXTERNAL"]),
send_notitfication: z.string().default("false").pipe(z_coerce_boolean),
});

//

export default new Hono<App_Context>().patch(
"/",
zValidator("param", Entity_Schema),
zValidator("form", FORM_SCHEMA),
zValidator("form", validate_form_schema),
async function PATCH({
text,
req,
Expand Down
50 changes: 0 additions & 50 deletions packages/~/moderations/api/src/:id/Actions.tsx

This file was deleted.

20 changes: 0 additions & 20 deletions packages/~/moderations/api/src/:id/Desicison_Context.tsx

This file was deleted.

Loading

0 comments on commit 0b0a197

Please sign in to comment.