Skip to content

Commit

Permalink
delete unneeded code
Browse files Browse the repository at this point in the history
  • Loading branch information
wykhuh committed May 20, 2024
1 parent 8148cac commit 5f44adb
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 201 deletions.
2 changes: 0 additions & 2 deletions build/root.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Slider from "./slider";
import Viewer from "./viewer";
import {
parseAnnotationTarget,
parseAnnotationsFromAnnotationResources,
} from "./annotation-helpers";
import { createOpenSeadragonRect } from "./openseadragon-helpers";

Expand All @@ -16,7 +15,6 @@ export {
Slider,
Viewer,
parseAnnotationTarget,
parseAnnotationsFromAnnotationResources,
createOpenSeadragonRect
};

Expand Down
2 changes: 0 additions & 2 deletions build/root.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const Slider = require("./slider");
const Viewer = require("./viewer");
const {
parseAnnotationTarget,
parseAnnotationsFromAnnotationResources
} = require("./annotation_helpers");
const { createOpenSeadragonRect } = require("./openseadragon-helpers");

Expand All @@ -19,6 +18,5 @@ module.exports = {
Slider,
Viewer,
parseAnnotationTarget,
parseAnnotationsFromAnnotationResources,
createOpenSeadragonRect
};
18 changes: 7 additions & 11 deletions src/components/Viewer/Viewer/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import Media from "src/components/Viewer/Media/Media";
import Painting from "../Painting/Painting";
import React from "react";
import { useViewerState } from "src/context/viewer-context";
import ErrorFallback from "src/components/UI/ErrorFallback/ErrorFallback";
import { ErrorBoundary } from "react-error-boundary";

export interface ViewerContentProps {
activeCanvas: string;
Expand Down Expand Up @@ -87,15 +85,13 @@ const ViewerContent: React.FC<ViewerContentProps> = ({
{(isAside || isForcedAside) && (
<Aside>
<CollapsibleContent>
<ErrorBoundary FallbackComponent={ErrorFallback}>
<InformationPanel
activeCanvas={activeCanvas}
annotationResources={annotationResources}
searchServiceUrl={searchServiceUrl}
setContentSearchResource={setContentSearchResource}
contentSearchResource={contentSearchResource}
/>
</ErrorBoundary>
<InformationPanel
activeCanvas={activeCanvas}
annotationResources={annotationResources}
searchServiceUrl={searchServiceUrl}
setContentSearchResource={setContentSearchResource}
contentSearchResource={contentSearchResource}
/>
</CollapsibleContent>
</Aside>
)}
Expand Down
2 changes: 0 additions & 2 deletions src/context/viewer-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export type ViewerConfigOptions = {
overlays?: OverlayOptions;
};
ignoreCaptionLabels?: string[];
ignoreAnnotationOverlaysLabels?: string[];
informationPanel?: {
open?: boolean;
renderAbout?: boolean;
Expand Down Expand Up @@ -101,7 +100,6 @@ const defaultConfigOptions = {
},
},
ignoreCaptionLabels: [],
ignoreAnnotationOverlaysLabels: [],
informationPanel: {
vtt: {
autoScroll: {
Expand Down
2 changes: 0 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Slider from "src/components/Slider";
import Viewer from "src/components/Viewer";
import {
parseAnnotationTarget,
parseAnnotationsFromAnnotationResources,
type AnnotationTargetExtended,
} from "src/lib/annotation-helpers";
import { createOpenSeadragonRect } from "src/lib/openseadragon-helpers";
Expand All @@ -18,7 +17,6 @@ export {
Slider,
Viewer,
parseAnnotationTarget,
parseAnnotationsFromAnnotationResources,
type AnnotationTargetExtended,
createOpenSeadragonRect,
type Plugin,
Expand Down
148 changes: 0 additions & 148 deletions src/lib/annotation-helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import {
parseAnnotationTarget,
AnnotationTargetExtended,
parseAnnotationsFromAnnotationResources,
} from "./annotation-helpers";
import { Vault } from "@iiif/vault";
import {
simpleTagging,
multiplePages,
} from "src/fixtures/use-iiif/get-annotation-resources";

import { getAnnotationResources } from "src/hooks/use-iiif/getAnnotationResources";

describe("parseAnnotationTarget", () => {
it("handles target strings with xywh", () => {
Expand Down Expand Up @@ -118,143 +110,3 @@ describe("parseAnnotationTarget", () => {
expect(result).toEqual(expected);
});
});

describe("parseAnnotationsFromAnnotationResources", () => {
it("returns annotations from annotation resource", async () => {
const config = {};
const vault = new Vault();
await vault.loadManifest("", structuredClone(simpleTagging));
const annotationResources = await getAnnotationResources(
vault,
simpleTagging.items[0].id,
);

const res = parseAnnotationsFromAnnotationResources(
annotationResources,
vault,
config,
);

const expected = [
{
body: [
{
id: "vault://605b9d93",
type: "ContentResource",
},
],
id: "https://iiif.io/api/cookbook/recipe/0021-tagging/annotation/p0002-tag",
motivation: ["tagging"],
target:
"https://iiif.io/api/cookbook/recipe/0021-tagging/canvas/p1#xywh=265,661,1260,1239",
type: "Annotation",
},
];
expect(res).toStrictEqual(expected);
});

it("returns annotations if annotation resource has multiple annotation pages", async () => {
const config = {};
const vault = new Vault();
await vault.loadManifest("", structuredClone(multiplePages));
const annotationResources = await getAnnotationResources(
vault,
multiplePages.items[0].id,
);

const res = parseAnnotationsFromAnnotationResources(
annotationResources,
vault,
config,
);

const expected = [
{
body: [
{
id: "vault://772e4338",
type: "ContentResource",
},
],
id: "http://localhost:3000/manifest/newspaper/newspaper_issue_1-anno_p1.json-1",
motivation: ["highlighting"],
target:
"http://localhost:3000/manifest/newspaper/canvas/i1p1#xywh=839,3259,118,27",
type: "Annotation",
},
{
body: [
{
id: "vault://772e4338",
type: "ContentResource",
},
],
id: "http://localhost:3000/manifest/newspaper/newspaper_issue_1-anno_p2.json-2",
motivation: ["commenting"],
target:
"http://localhost:3000/manifest/newspaper/canvas/i1p2#xywh=161,459,1063,329",
type: "Annotation",
},
];
expect(res).toStrictEqual(expected);
});

it("ignores annotations in ignoreAnnotationOverlaysLabels", async () => {
const config = { ignoreAnnotationOverlaysLabels: ["Clippings"] };
const vault = new Vault();
await vault.loadManifest("", structuredClone(multiplePages));
const annotationResources = await getAnnotationResources(
vault,
multiplePages.items[0].id,
);

const res = parseAnnotationsFromAnnotationResources(
annotationResources,
vault,
config,
);

const expected = [
{
body: [
{
id: "vault://772e4338",
type: "ContentResource",
},
],
id: "http://localhost:3000/manifest/newspaper/newspaper_issue_1-anno_p1.json-1",
motivation: ["highlighting"],
target:
"http://localhost:3000/manifest/newspaper/canvas/i1p1#xywh=839,3259,118,27",
type: "Annotation",
},
];
expect(res).toStrictEqual(expected);
});

it("returns empty array if annotation resource is empty array", () => {
const config = {};
const annotationResources = [];
const vault = new Vault();

const res = parseAnnotationsFromAnnotationResources(
annotationResources,
vault,
config,
);

expect(res).toStrictEqual([]);
});
});

/*
{
selector :{
conformsTo:"http://www.w3.org/TR/media-frags/",
type:"FragmentSelector",
value:"xywh=86.18675994873047,1189.02587890625,910.7970657348633,653.7779541015625"
}
source:"https://iiif.io/api/image/3.0/example/reference/4ce82cef49fb16798f4c2440307c3d6f-newspaper-p1"
type:"SpecificResource"
}
*/
36 changes: 2 additions & 34 deletions src/lib/annotation-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { AnnotationTarget, AnnotationNormalized } from "@iiif/presentation-3";
import { AnnotationTarget } from "@iiif/presentation-3";
import { ParsedAnnotationTarget } from "src/types/annotations";
import { getLabel } from "src/hooks/use-iiif";
import { AnnotationResources } from "src/types/annotations";
import { type ViewerConfigOptions } from "src/context/viewer-context";

export type AnnotationTargetExtended = AnnotationTarget & {
selector?: any;
Expand Down Expand Up @@ -82,33 +79,4 @@ const parseAnnotationTarget = (target: AnnotationTargetExtended | string) => {
return parsedTarget;
};

const parseAnnotationsFromAnnotationResources = (
annotationResources: AnnotationResources,
vault: any,
configOptions: ViewerConfigOptions,
) => {
const annotations: Array<AnnotationNormalized> = [];
annotationResources
.filter((annotationResource) => {
if (annotationResource.label) {
const label = getLabel(annotationResource.label);
if (Array.isArray(label)) {
return !label.some((value) =>
configOptions.ignoreAnnotationOverlaysLabels?.includes(value),
);
}
}

return true;
})
.forEach((annotationResource) => {
annotationResource?.items?.forEach((item) => {
const annotation = vault.get(item.id);
annotations.push(annotation as unknown as AnnotationNormalized);
});
});

return annotations;
};

export { parseAnnotationTarget, parseAnnotationsFromAnnotationResources };
export { parseAnnotationTarget };

0 comments on commit 5f44adb

Please sign in to comment.