Skip to content

Commit

Permalink
Merge pull request #571 from digirati-co-uk/feature/may-bug-fixes
Browse files Browse the repository at this point in the history
May: bug fixes
  • Loading branch information
stephenwf authored May 6, 2022
2 parents d3180b5 + 9ea7ac7 commit ced9a92
Show file tree
Hide file tree
Showing 19 changed files with 151 additions and 116 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Regression with dropdown (reverts fix for overflow bug in popup)
- Fist selection on reviewer dashboard
- Fixed caching on languages
- Fixed rendering bugs with annotations
- Fixed cache time bug in Firefox
- Fixed vertical alignment of breadcrumbs

### Changed
- Updated react query to latest 2.x version (3.x is a breaking change)

<!--
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion services/madoc-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
"react-i18next": "^11.7.2",
"react-intersection-observer": "^8.26.2",
"react-mosaic-component": "^4.1.1",
"react-query": "^2.16.0",
"react-query": "^2.26.4",
"react-router-config": "^5.1.1",
"react-router-dom": "^5.1.2",
"react-rte": "0.16.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { ProjectTemplate } from '../types';

type MetadataSuggestionsOptions = {
bulkMetadata: string;
allowCustomPairs: boolean;
};

export const metadataSuggestions: ProjectTemplate<MetadataSuggestionsOptions> = {
Expand All @@ -26,6 +25,28 @@ export const metadataSuggestions: ProjectTemplate<MetadataSuggestionsOptions> =
label: 'Metadata suggestions',
description: 'Crowd source the metadata for your canvases or manifests',
version: '1.0.0',
thumbnail: `<svg width="109px" height="109px" viewBox="0 0 109 109" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g transform="translate(-96.000000, -719.000000)">
<g transform="translate(96.000000, 719.000000)">
<rect stroke="#E7E9EC" stroke-width="2" x="1" y="1" width="107" height="107" rx="5"></rect>
<rect fill="#BFBFBF" x="17" y="15" width="28" height="3"></rect>
<rect fill="#E7E9EC" x="17" y="21" width="45" height="5"></rect>
<rect fill="#5B78E5" x="17" y="21" width="45" height="5"></rect>
<rect fill="#BFBFBF" x="17" y="32" width="28" height="3"></rect>
<rect fill="#E7E9EC" x="17" y="38" width="39" height="5"></rect>
<rect fill="#BFBFBF" x="17" y="49" width="28" height="3"></rect>
<rect fill="#E7E9EC" x="17" y="55" width="33" height="5"></rect>
<rect fill="#BFBFBF" x="17" y="66" width="28" height="3"></rect>
<rect fill="#BFBFBF" x="17" y="83" width="28" height="3"></rect>
<rect fill="#E7E9EC" x="17" y="72" width="41" height="5"></rect>
<rect fill="#E7E9EC" x="17" y="89" width="39" height="5"></rect>
<rect fill="#5B78E5" x="17" y="55" width="33" height="5"></rect>
<rect fill="#5B78E5" x="17" y="89" width="39" height="5"></rect>
</g>
</g>
</g>
</svg>`,
},
captureModel: {
document: captureModelShorthand({}),
Expand Down Expand Up @@ -104,10 +125,6 @@ export const metadataSuggestions: ProjectTemplate<MetadataSuggestionsOptions> =
multiline: true,
minLines: 10,
} as Partial<TextFieldProps>,
allowCustomPairs: {
type: 'checkbox-field',
label: 'Populate existing metadata values',
},
},
modelPreview: function ModelPreview(options) {
const doc = useMemo(() => {
Expand All @@ -132,7 +149,6 @@ export const metadataSuggestions: ProjectTemplate<MetadataSuggestionsOptions> =
},
defaults: {
bulkMetadata: '',
allowCustomPairs: false,
},
async beforeForkDocument(doc: any, { options }) {
if (options.bulkMetadata) {
Expand All @@ -141,18 +157,6 @@ export const metadataSuggestions: ProjectTemplate<MetadataSuggestionsOptions> =
Object.assign(doc.properties, secondDoc.properties);
}
}

if (options.allowCustomPairs) {
const custom = captureModelShorthand({
label: { type: 'international-field', label: 'Label', value: [{ none: '' }] },
value: { type: 'international-field', label: 'Value', value: [{ none: '' }] },
});
custom.allowMultiple = true;
custom.label = 'Custom metadata';
custom.labelledBy = `{label} - {value}`;
doc.properties.customMetadata = [custom];
}

return doc;
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,27 @@ export function toStyle(style: any) {

return css(style);
}

export const AnnotationStyleBigBackground = styled.div`
padding: 2em;
position: relative;
background: linear-gradient(
270deg,
rgba(255, 121, 0, 1) 13%,
rgb(50, 141, 147) 29%,
rgb(107, 18, 182) 45%,
rgba(255, 255, 255, 1) 57%,
rgba(255, 255, 255, 1) 70%,
rgba(0, 0, 0, 1) 85%
);
`;

export const AnnotationStyleBigBox = styled.div`
position: relative;
text-align: center;
padding: 1em;
width: 100%;
color: #fff;
text-shadow: #000 1px 0 5px;
margin-bottom: 1em;
`;
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useEffect, useRef, useState } from 'react';
import { Helmet } from 'react-helmet';
import { useTranslation } from 'react-i18next';
import { useMutation } from 'react-query';
import { useHistory } from 'react-router-dom';
import { AnnotationBuckets, AnnotationStyles } from '../../../../types/annotation-styles';
import { HotSpot } from '../../../shared/atoms/HotSpot';
import { SystemListItem } from '../../../shared/atoms/SystemListItem';
import { SystemBackground, SystemGrid, SystemMenu, SystemMenuItem } from '../../../shared/atoms/SystemUI';
import { getDefaultAnnotationStyles } from '../../../shared/capture-models/AnnotationStyleContext';
Expand All @@ -15,6 +15,8 @@ import { ButtonRow, Button } from '../../../shared/navigation/Button';
import { AdminHeader } from '../../molecules/AdminHeader';
import {
annotationBucketOrder,
AnnotationStyleBigBackground,
AnnotationStyleBigBox,
AnnotationStylePreview,
AnnotationStylePreviewList,
} from '../../molecules/AnnotationStylePreview';
Expand Down Expand Up @@ -42,6 +44,7 @@ export function CreateAnnotationStyle({ existing }: { existing?: AnnotationStyle
const { t } = useTranslation();
const canvas = useRef<any>();
const displayAnno = useRef<any>();
const [toApply, setToApply] = useState<any>();
const [newConfig, setNewConfig] = useState<AnnotationStyles['theme']>(existing?.theme || getDefaultStyles);
const [current, setCurrent] = useState<AnnotationBuckets>('highlighted');
const [title, setTitle] = useState(existing?.name || 'Untitled style');
Expand Down Expand Up @@ -70,58 +73,34 @@ export function CreateAnnotationStyle({ existing }: { existing?: AnnotationStyle
}, [existing, title, newConfig]);

useEffect(() => {
if (canvas.current) {
// eslint-disable-next-line no-inner-declarations
function createInitial() {
const linkingAnno = {
type: 'Annotation',
motivation: ['linking'],
target: 'https://digirati-co-uk.github.io/wunder/canvases/0#300,900,500,500',
};
canvas.current.vault.load('fake-id', linkingAnno).then((linkingAnnoWithId: any) => {
displayAnno.current = canvas.current.createAnnotationDisplay(linkingAnnoWithId);
displayAnno.current.applyStyle(newConfig[current] || { backgroundColor: 'none', borderWidth: '0' });
canvas.current.annotations.add(displayAnno.current);
});
}
const toApply = { backgroundColor: 'none', borderWidth: '0', ...(newConfig[current] || {}) };

if (canvas.current.ready) {
createInitial();
} else {
canvas.current.addEventListener('ready', createInitial);
}
if (!toApply[':hover']) {
toApply[':hover'] = {
backgroundColor: toApply.backgroundColor,
borderColor: toApply.borderColor,
borderStyle: toApply.borderStyle,
borderWidth: toApply.borderWidth,
};
}
}, []);

useEffect(() => {
if (displayAnno.current) {
const toApply = { backgroundColor: 'none', borderWidth: '0', ...(newConfig[current] || {}) };

if (!toApply[':hover']) {
toApply[':hover'] = {
backgroundColor: toApply.backgroundColor,
borderColor: toApply.borderColor,
borderStyle: toApply.borderStyle,
borderWidth: toApply.borderWidth,
};
}
if (!toApply[':active']) {
toApply[':active'] = {
backgroundColor: toApply.backgroundColor,
borderColor: toApply.borderColor,
borderStyle: toApply.borderStyle,
borderWidth: toApply.borderWidth,
};
}

displayAnno.current.applyStyle(toApply);
if (!toApply[':active']) {
toApply[':active'] = {
backgroundColor: toApply.backgroundColor,
borderColor: toApply.borderColor,
borderStyle: toApply.borderStyle,
borderWidth: toApply.borderWidth,
};
}

setToApply(toApply as any);
}, [newConfig, current]);

function menu(name: AnnotationBuckets) {
return { onClick: () => setCurrent(name), $active: current === name };
}

const hotspot = newConfig[current].hotspot ? <HotSpot $size={newConfig[current].hotspotSize || 'lg'} /> : null;

return (
<>
<AdminHeader
Expand All @@ -142,7 +121,9 @@ export function CreateAnnotationStyle({ existing }: { existing?: AnnotationStyle
<SystemMenuItem {...menu('contributedDocument')}>Document panel</SystemMenuItem>
<SystemMenuItem {...menu('submissions')}>Submission panel</SystemMenuItem>
<SystemMenuItem>
<span {...menu('topLevel')}>Current submission</span>
<SystemMenuItem as="span" {...menu('topLevel')}>
Current submission
</SystemMenuItem>
<SystemMenu>
<SystemMenuItem {...menu('topLevel')}>Top level</SystemMenuItem>
<SystemMenuItem {...menu('currentLevel')}>Current level</SystemMenuItem>
Expand Down Expand Up @@ -176,17 +157,15 @@ export function CreateAnnotationStyle({ existing }: { existing?: AnnotationStyle

<SystemListItem $block>
<div style={{ marginBottom: '2em' }}>
<Helmet>
<script src="https://cdn.jsdelivr.net/npm/@digirati/[email protected]/dist/bundle.js" />
</Helmet>
{/* @ts-ignore */}
<canvas-panel
ref={canvas}
height={350}
target="200,800,800,800"
manifest-id="https://digirati-co-uk.github.io/wunder.json"
canvas-id={'https://digirati-co-uk.github.io/wunder/canvases/0'}
/>
<AnnotationStyleBigBackground>
{toApply ? (
<>
<AnnotationStyleBigBox style={toApply}>{hotspot}Normal</AnnotationStyleBigBox>
<AnnotationStyleBigBox style={toApply[':hover']}>{hotspot}Hover</AnnotationStyleBigBox>
<AnnotationStyleBigBox style={toApply[':active']}>{hotspot}Active</AnnotationStyleBigBox>
</>
) : null}
</AnnotationStyleBigBackground>
</div>

<AnnotationStyleForm
Expand Down
4 changes: 2 additions & 2 deletions services/madoc-ts/src/frontend/admin/query-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ReactQueryConfig } from 'react-query';
export const queryConfig: ReactQueryConfig = {
queries: {
staleTime: 0,
cacheTime: 0,
refetchOnMount: true,
cacheTime: 1000 * 60 * 60,
refetchOnMount: false,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,58 @@ import { ReadOnlyAnnotation } from '../hooks/use-read-only-annotations';
// Avoid bad types from Atlas.
const CustomHTMLPortal = HTMLPortal as any;

export function ViewReadOnlyAnnotation({ style, ...props }: ReadOnlyAnnotation) {
export function ViewReadOnlyAnnotation({ id, style, target, ...props }: ReadOnlyAnnotation) {
const [isOpen, setIsOpen] = useState(false);
const [isHover, setIsHover] = useState(false);
const { interactive, hotspot, hotspotSize, hidden, ...allStyles } = style;

const styleToApply = useMemo(() => {
if (hotspot) {
const { ':hover': hoverStyles, ':active': activeStyles, ...styles } = allStyles;
return isOpen ? mergeStyles(styles, activeStyles) : isHover ? mergeStyles(styles, hoverStyles) : styles;
return isOpen ? activeStyles : isHover ? hoverStyles : styles;
}
return allStyles;
}, [allStyles, hotspot, isHover, isOpen]);

if (hotspot) {
return (
<>
<box interactive={interactive} {...props} style={styleToApply} />
<CustomHTMLPortal
relativeStyle
relativeSize={false}
interactive
target={props.target}
style={{ overflow: 'visible' }}
>
<HotSpot
$size={hotspotSize || 'md'}
$active={isOpen}
onClick={() => setIsOpen(o => !o)}
onMouseEnter={() => setIsHover(true)}
onMouseLeave={() => setIsHover(false)}
return (
<world-object id="readonly-" x={target.x} y={target.y} width={target.width} height={target.height}>
{hotspot ? (
<>
<box
id={`hotspot/${id}`}
html
interactive={interactive}
{...props}
style={styleToApply}
target={{ x: 0, y: 0, width: target.width, height: target.height }}
/>
</CustomHTMLPortal>
</>
);
}

return <box interactive={interactive} {...props} style={styleToApply} />;
<CustomHTMLPortal
id={`portal/${id}`}
relativeStyle
relativeSize={false}
interactive
target={{ x: 0, y: 0, width: target.width, height: target.height }}
style={{ overflow: 'visible' }}
>
<HotSpot
$size={hotspotSize || 'lg'}
$active={isOpen}
onClick={() => setIsOpen(o => !o)}
onMouseEnter={() => setIsHover(true)}
onMouseLeave={() => setIsHover(false)}
/>
</CustomHTMLPortal>
</>
) : (
<box
id={`non-hotspot/${id}`}
html
interactive={interactive}
{...props}
style={styleToApply}
target={{ x: 0, y: 0, width: target.width, height: target.height }}
/>
)}
</world-object>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const RegionHighlight: React.FC<{
onSave={saveCallback}
>
<box
html
id={`${id}/box`}
relativeStyle
interactive={interactive}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export function AnnotationStyleForm(props: AnnotationStyleFormProps) {
<Input
type="button"
value="Small"
$inactive={!state.hotspotSize || state.hotspotSize === 'sm'}
$inactive={state.hotspotSize === 'sm'}
onClick={e => {
e.preventDefault();
dispatch({ type: ThemeActionTypes.SET_HOTSPOT_SIZE, value: 'sm' });
Expand All @@ -148,7 +148,7 @@ export function AnnotationStyleForm(props: AnnotationStyleFormProps) {
<Input
type="button"
value="Large"
$inactive={state.hotspotSize === 'lg'}
$inactive={!state.hotspotSize || state.hotspotSize === 'lg'}
onClick={e => {
e.preventDefault();
dispatch({ type: ThemeActionTypes.SET_HOTSPOT_SIZE, value: 'lg' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const AtlasTiledImages: React.FC<{ canvas: CanvasNormalized; service: Ima
if (!tile) {
return (
<worldObject height={canvas.height} width={canvas.width}>
<box target={{ x: 0, y: 0, width: canvas.width, height: canvas.height }} id="123" backgroundColor="#000" />
<box html target={{ x: 0, y: 0, width: canvas.width, height: canvas.height }} id="123" backgroundColor="#000" />
</worldObject>
);
}
Expand Down
Loading

0 comments on commit ced9a92

Please sign in to comment.