Skip to content

Commit

Permalink
Migrate to Storybook 8; update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
corovcam committed Jun 10, 2024
1 parent a530298 commit 933930d
Show file tree
Hide file tree
Showing 6 changed files with 8,148 additions and 21,382 deletions.
8 changes: 3 additions & 5 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ const config = {
"@storybook/addon-essentials",
"@storybook/addon-interactions",
'@storybook/addon-storysource',
"@chromatic-com/storybook"
],
framework: {
name: "@storybook/preact-vite",
options: {},
},
docs: {
autodocs: "tag",
},
docs: {},
core: {
builder: "@storybook/builder-vite",
disableTelemetry: true,
disableTelemetry: true
},
async viteFinal (config, options) {
return config;
Expand Down
219 changes: 100 additions & 119 deletions .storybook/msw-mock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { rest } from "msw";
import { http, HttpResponse } from "msw";
import article from "../mock/__fixtures__/article.pdf";
import article2 from "../mock/__fixtures__/article2.pdf";
import article3 from "../mock/__fixtures__/article3.pdf";
Expand All @@ -7,11 +7,8 @@ import figure from "../mock/__fixtures__/figure.png";
const baseUrl = window.location.origin;

const handlers = [
rest.get(`${baseUrl}/api/records/:id/files`, (req, res, ctx) => {
const query = req.params;

return res(
ctx.json({
http.get(`${baseUrl}/api/records/:id/files`, ({ params }) => {
return HttpResponse.json({
default_preview: null,
enabled: true,
entries: [
Expand All @@ -32,9 +29,9 @@ const handlers = [
"bucket_id": "90b5b318-114a-4b87-bc9d-0d018b9363d3",
"storage_class": "S",
"links": {
"content": `${baseUrl}/api/records/${query.id}/files/figure.png/content`,
"self": `${baseUrl}/api/records/${query.id}/files/figure.png`,
"commit": `${baseUrl}/api/records/${query.id}/files/figure.png/commit`
"content": `${baseUrl}/api/records/${params.id}/files/figure.png/content`,
"self": `${baseUrl}/api/records/${params.id}/files/figure.png`,
"commit": `${baseUrl}/api/records/${params.id}/files/figure.png/commit`
}
},
{
Expand All @@ -51,9 +48,9 @@ const handlers = [
"bucket_id": "90b5b318-114a-4b87-bc9d-0d0f439363d3",
"storage_class": "S",
"links": {
"content": `${baseUrl}/api/records/${query.id}/files/article.pdf/content`,
"self": `${baseUrl}/api/records/${query.id}/files/article.pdf`,
"commit": `${baseUrl}/api/records/${query.id}/files/article.pdf/commit`
"content": `${baseUrl}/api/records/${params.id}/files/article.pdf/content`,
"self": `${baseUrl}/api/records/${params.id}/files/article.pdf`,
"commit": `${baseUrl}/api/records/${params.id}/files/article.pdf/commit`
}
},
{
Expand All @@ -70,9 +67,9 @@ const handlers = [
"bucket_id": "90b5b318-114a-4b87-bc9d-0d0f439363d3",
"storage_class": "S",
"links": {
"content": `${baseUrl}/api/records/${query.id}/files/article2.pdf/content`,
"self": `${baseUrl}/api/records/${query.id}/files/article2.pdf`,
"commit": `${baseUrl}/api/records/${query.id}/files/article2.pdf/commit`
"content": `${baseUrl}/api/records/${params.id}/files/article2.pdf/content`,
"self": `${baseUrl}/api/records/${params.id}/files/article2.pdf`,
"commit": `${baseUrl}/api/records/${params.id}/files/article2.pdf/commit`
}
},
{
Expand All @@ -89,24 +86,23 @@ const handlers = [
"bucket_id": "90b5b318-114a-4b87-bc9d-0d0f439363d3",
"storage_class": "S",
"links": {
"content": `${baseUrl}/api/records/${query.id}/files/article3.pdf/content`,
"self": `${baseUrl}/api/records/${query.id}/files/article3.pdf`,
"commit": `${baseUrl}/api/records/${query.id}/files/article3.pdf/commit`
"content": `${baseUrl}/api/records/${params.id}/files/article3.pdf/content`,
"self": `${baseUrl}/api/records/${params.id}/files/article3.pdf`,
"commit": `${baseUrl}/api/records/${params.id}/files/article3.pdf/commit`
}
}
],
links: {
self: `${baseUrl}/api/records/${query.id}/files`,
self: `${baseUrl}/api/records/${params.id}/files`,
},
order: [],
})
);
});
}),
// Download file
rest.get(
http.get(
`${baseUrl}/api/records/:id/files/:fileName/content`,
async (req, res, ctx) => {
const fileName = req.params.fileName.replace(/\.[^/.]+$/, "");
async ({ request, params }) => {
const fileName = params.fileName.replace(/\.[^/.]+$/, "");
const importedFile =
fileName === "article"
? article
Expand All @@ -121,25 +117,23 @@ const handlers = [
const pdfFile = await fetch(importedFile).then((res) =>
res.arrayBuffer()
);
return res(
ctx.set("Content-Type", "application/pdf"),
ctx.set("Content-Disposition", "inline"),
ctx.body(pdfFile)
);
return HttpResponse.arrayBuffer(pdfFile, {
headers: {
"Content-Type": "application/pdf",
"Content-Disposition": "inline",
},
});
}
),
rest.post(`${baseUrl}/api/records/:id/files`, async (req, res, ctx) => {
const body = await req.json();
const query = req.params;
http.post(`${baseUrl}/api/records/:id/files`, async ({ request, params }) => {
const body = await request.json();

// Invalid file name being a trigger for server error
if (body.some((obj) => obj.key.startsWith("invalid"))) {
return res(
ctx.status(400),
ctx.json({
"message": `File with key ${body[0].key} already exists.`
})
);
return new HttpResponse(null, {
status: 400,
statusText: `File with key ${body[0].key} already exists.`,
});
}

const entries = body.map((obj) => ({
Expand All @@ -149,31 +143,27 @@ const handlers = [
metadata: null,
status: "pending",
links: {
content: `/api/records/${query.id}/draft/files/${obj.key}/content`,
self: `/api/records/${query.id}/draft/files/${obj.key}`,
commit: `/api/records/${query.id}/draft/files/${obj.key}/commit`,
content: `/api/records/${params.id}/draft/files/${obj.key}/content`,
self: `/api/records/${params.id}/draft/files/${obj.key}`,
commit: `/api/records/${params.id}/draft/files/${obj.key}/commit`,
},
}));

return res(
ctx.json({
enabled: true,
default_preview: null,
order: [],
entries,
links: {
self: `/api/records/${query.id}/files`,
},
})
);
return HttpResponse.json({
enabled: true,
default_preview: null,
order: [],
entries,
links: {
self: `/api/records/${params.id}/files`,
},
});
}),
// metadata:
rest.put(
http.put(
`${baseUrl}/api/records/:id/files/:fileName`,
async (req, res, ctx) => {
const body = await req.json();
const query = req.params;

async ({ request, params }) => {
const body = await request.json();
// Invalid file name being a trigger for server error
// if (query.fileName.startsWith("invalid")) {
// return res(
Expand All @@ -193,77 +183,68 @@ const handlers = [
// );
// }

return res(
ctx.json({
key: query.fileName,
updated: "2020-11-27 11:17:11.002624",
created: "2020-11-27 11:17:10.998919",
metadata: body,
status: "pending",
links: {
content: `/api/records/${query.id}/draft/files/${query.fileName}/content`,
self: `/api/records/${query.id}/draft/files/${query.fileName}`,
commit: `/api/records/${query.id}/draft/files/${query.fileName}/commit`,
},
})
);
return HttpResponse.json({
key: params.fileName,
updated: "2020-11-27 11:17:11.002624",
created: "2020-11-27 11:17:10.998919",
metadata: body,
status: "pending",
links: {
content: `/api/records/${params.id}/draft/files/${params.fileName}/content`,
self: `/api/records/${params.id}/draft/files/${params.fileName}`,
commit: `/api/records/${params.id}/draft/files/${params.fileName}/commit`,
},
});
}
),
rest.put(
http.put(
`${baseUrl}/api/records/:id/files/:fileName/content`,
async (req, res, ctx) => {
const query = req.params;
return res(
ctx.json({
key: query.fileName,
// data: body,
updated: "2020-11-27 11:17:11.002624",
created: "2020-11-27 11:17:10.998919",
metadata: null,
status: "pending",
links: {
content: `/api/records/${query.id}/draft/files/${query.fileName}/content`,
self: `/api/records/${query.id}/draft/files/${query.fileName}`,
commit: `/api/records/${query.id}/draft/files/${query.fileName}/commit`,
},
})
);
async ({ request, params }) => {
return HttpResponse.json({
key: params.fileName,
// data: body,
updated: "2020-11-27 11:17:11.002624",
created: "2020-11-27 11:17:10.998919",
metadata: null,
status: "pending",
links: {
content: `/api/records/${params.id}/draft/files/${params.fileName}/content`,
self: `/api/records/${params.id}/draft/files/${params.fileName}`,
commit: `/api/records/${params.id}/draft/files/${params.fileName}/commit`,
},
});
}
),
rest.post(
http.post(
`${baseUrl}/api/records/:id/files/:fileName/commit`,
(req, res, ctx) => {
const query = req.params;
return res(
ctx.json({
key: query.fileName,
updated: "2020-11-27 11:26:04.607831",
created: "2020-11-27 11:17:10.998919",
checksum: "md5:6ef4267f0e710357c895627e931f16cd",
mimetype: "image/png",
size: 89364.0,
status: "completed",
metadata: null,
file_id: "2151fa94-6dc3-4965-8df9-ec73ceb9175c",
version_id: "57ad8c66-b934-49c9-a46f-38bf5aa0374f",
bucket_id: "90b5b318-114a-4b87-bc9d-0d018b9363d3",
storage_class: "S",
links: {
content: `/api/records/${query.id}/draft/files/${query.fileName}/content`,
self: `/api/records/${query.id}/draft/files/${query.fileName}`,
commit: `/api/records/${query.id}/draft/files/${query.fileName}/commit`,
},
})
);
({ params }) => {
return HttpResponse.json({
key: params.fileName,
updated: "2020-11-27 11:26:04.607831",
created: "2020-11-27 11:17:10.998919",
checksum: "md5:6ef4267f0e710357c895627e931f16cd",
mimetype: "image/png",
size: 89364.0,
status: "completed",
metadata: null,
file_id: "2151fa94-6dc3-4965-8df9-ec73ceb9175c",
version_id: "57ad8c66-b934-49c9-a46f-38bf5aa0374f",
bucket_id: "90b5b318-114a-4b87-bc9d-0d018b9363d3",
storage_class: "S",
links: {
content: `/api/records/${params.id}/draft/files/${params.fileName}/content`,
self: `/api/records/${params.id}/draft/files/${params.fileName}`,
commit: `/api/records/${params.id}/draft/files/${params.fileName}/commit`,
},
});
}
),
rest.delete(
http.delete(
`${baseUrl}/api/records/:id/files/:fileName`,
(req, res, ctx) => {
return res(
ctx.status(204),
// ctx.status(400)
);
() => {
return new HttpResponse(null, {
status: 204,
});
}
),
];
Expand Down
Loading

0 comments on commit 933930d

Please sign in to comment.