Skip to content
Open
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
6 changes: 6 additions & 0 deletions ui/src/react-admin/core/config/config.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ export interface AdminConfig {
// admin-core needing to depend on the client package.
clientSearchUrlToApiSearchUrl: (searchQuery: string) => IeObjectsSearchBody;
};
getIeObjectDetailPath?: (
locale: string,
maintainerSlug: string,
schemaIdentifier: string,
name: string | null | undefined
) => string;
};
components: {
loader: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { tText } from '~shared/helpers/translation-functions';
import type { PlayableDisplayIeObject } from '~shared/services/ie-objects-service/ie-objects.types.ts';
import { HET_ARCHIEF } from '~shared/types';
import './IeObjectMetadata.scss';
import { IeObjectsService } from '~modules/ie-objects/ie-objects.service.ts';

// The call to action names the kind of object it links to, so a newspaper isn't announced as a fragment.
const getCallToActionLabel = (format: IeObjectType | null): string => {
Expand Down Expand Up @@ -70,7 +71,11 @@ export const IeObjectMetadata: FunctionComponent<{
<SmartLink
action={{
type: AvoCoreContentPickerType.INTERNAL_LINK,
value: `/pid/${ieObject?.schemaIdentifier}`,
value: IeObjectsService.getObjectDetailPath(
ieObject?.maintainerSlug,
ieObject?.schemaIdentifier,
ieObject?.name
),
}}
ariaLabel={callToActionLabel}
className="c-ie-object-metadata__cta"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const DEFAULT_OBJECTS_GRID_LIMIT = 24;
interface RawIeObject {
schemaIdentifier: string;
name?: string;
maintainerSlug?: string;
maintainerName?: string;
// dcterms format, e.g. "video" | "audio" | "newspaper".
dctermsFormat?: IeObjectType;
Expand All @@ -35,6 +36,7 @@ const mapRawToGridItem = (raw: RawIeObject): ObjectsGridItem => {
return {
schemaIdentifier: raw.schemaIdentifier,
name: raw.name || '',
maintainerSlug: raw.maintainerSlug || '',
maintainerName: raw.maintainerName,
type,
thumbnailUrl: isAudioFormat(type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,11 @@ export const BlockObjectsGrid: FunctionComponent<BlockObjectsGridProps> = ({
<SmartLink
action={{
type: AvoCoreContentPickerType.INTERNAL_LINK,
value: IeObjectsService.getObjectDetailPath(item.schemaIdentifier),
value: IeObjectsService.getObjectDetailPath(
item.maintainerSlug,
item.schemaIdentifier,
item.name
),
}}
removeStyles={false}
className="c-block-objects-grid__tile-link"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export interface ObjectsGridItem {
schemaIdentifier: string;
// Object title, shown in the title bar.
name: string;
// Provider / maintainer slug, used to link to the object.
maintainerSlug: string;
// Provider / maintainer name, shown in the title bar.
maintainerName?: string;
// Object type, drives the type-icon. Falls back to a generic icon when unknown.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { tText } from '~shared/helpers/translation-functions.ts';

import 'swiper/css';
import './BlockThemeReelsSection.scss';
import { IeObjectsService } from '~modules/ie-objects/ie-objects.service.ts';

export interface BlockThemeReelSectionProps extends DefaultComponentProps {
themeId: string;
Expand Down Expand Up @@ -210,7 +211,10 @@ export const BlockThemeReelSection: FunctionComponent<BlockThemeReelSectionProps
</SwiperSlide>
)}
{theme.ieObjects.map(
({ id, format, maintainerName, schemaIdentifier, thumbnailUrl, name }, index) => {
(
{ id, format, maintainerSlug, maintainerName, schemaIdentifier, thumbnailUrl, name },
index
) => {
const componentClassName = clsx('c-block-theme-reels-section__slide');
return (
<SwiperSlide
Expand All @@ -222,7 +226,11 @@ export const BlockThemeReelSection: FunctionComponent<BlockThemeReelSectionProps
{
type: AvoCoreContentPickerType.INTERNAL_LINK,
target: LinkTarget.Self,
value: `/pid/${schemaIdentifier}`,
value: IeObjectsService.getObjectDetailPath(
maintainerSlug,
schemaIdentifier,
name
),
},
renderSlideContent(
thumbnailUrl,
Expand Down
28 changes: 27 additions & 1 deletion ui/src/react-admin/modules/ie-objects/ie-objects.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AdminConfigManager } from '~core/config';
import { CustomError } from '~shared/helpers/custom-error';
import { isHetArchief } from '~shared/helpers/is-hetarchief';

Expand All @@ -10,12 +11,37 @@ export class IeObjectsService {
* Path of the detail page of an ie-object, relative to the client url.
* ie-objects only exist on hetarchief.be, so this throws on avo.
*/
public static getObjectDetailPath(schemaIdentifier: string): string {
public static getObjectDetailPathViaPid(schemaIdentifier: string): string {
if (!isHetArchief()) {
throw new CustomError('getObjectDetailPath is only available on hetarchief.be', null, {
schemaIdentifier,
});
}
return `${OBJECT_DETAIL_PATH_PREFIX}/${encodeURIComponent(schemaIdentifier)}`;
}

/**
* Path of the detail page of an ie-object, relative to the client url.
* ie-objects only exist on hetarchief.be, so this throws on avo.
*/
public static getObjectDetailPath(
maintainerSlug: string,
schemaIdentifier: string,
objectName: string
): string {
if (!isHetArchief()) {
throw new CustomError('getObjectDetailPath is only available on hetarchief.be', null, {
schemaIdentifier,
});
}

return (
AdminConfigManager.getConfig().services.getIeObjectDetailPath?.(
AdminConfigManager.getConfig().locale,
maintainerSlug,
schemaIdentifier,
objectName
) || IeObjectsService.getObjectDetailPathViaPid(schemaIdentifier)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ export const SmartLink: FunctionComponent<SmartLinkProps> = ({
const anchorId = fullUrl.split('#')[1];
document.getElementById(anchorId)?.scrollIntoView({ behavior: 'instant' });
} else {
scrollTo({ top: 0 });
const targetPathname = fullUrl.split('?')[0].split('#')[0];
// Only scroll to top if we are navigating to the same page (otherwise this will happen by default)
if (window.location.pathname === targetPathname) {
scrollTo({ top: 0 });
}
}
}}
onKeyUp={(evt) => onKeyUpHandler(evt as unknown as KeyboardEvent<HTMLElement>)}
Expand Down Expand Up @@ -216,7 +220,10 @@ export const SmartLink: FunctionComponent<SmartLinkProps> = ({
// ie-objects only exist on hetarchief, render the children unwrapped
break;
}
return renderLink(IeObjectsService.getObjectDetailPath(String(value)), resolvedTarget);
return renderLink(
IeObjectsService.getObjectDetailPathViaPid(String(value)),
resolvedTarget
);
}

case 'ASSIGNMENT': {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/react-admin/modules/shared/helpers/routing/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export const navigateToContentType = (action: ButtonAction) => {
break;
}
navigateToAbsoluteOrRelativeUrl(
IeObjectsService.getObjectDetailPath(String(value)),
IeObjectsService.getObjectDetailPathViaPid(String(value)),
resolvedTarget
);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface PlayableDisplayIeObject {
thumbnailUrl: string | null;
dctermsFormat: IeObjectType;
maintainerId: string;
maintainerSlug: string;
maintainerName: string;
maintainerLogo?: string;
maintainerOverlay: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface ThemeWithObjects extends Theme {
format: IeObjectType;
thumbnailUrl: string;
maintainerId: string;
maintainerSlug: string;
maintainerName: string;
}[];
// The number of ie-objects linked to the theme, which is more than the objects in `ieObjects`
Expand Down