Skip to content

Commit

Permalink
Merge pull request #572 from digirati-co-uk/feature/hotfix-2.0.6
Browse files Browse the repository at this point in the history
Hotfix 2.0.6
  • Loading branch information
stephenwf authored May 16, 2022
2 parents 2387ff5 + c449cd1 commit d079fd7
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 50 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/digirati-co-uk/madoc-platform/compare/v2.0.5...main)
## [Unreleased](https://github.com/digirati-co-uk/madoc-platform/compare/v2.0.6...main)

<!--
### Fixed
Expand All @@ -14,6 +14,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security
-->

## [2.0.6](https://github.com/digirati-co-uk/madoc-platform/releases/tag/v2.0.6) - 2022-05-16
This is a hot fix release.


### Fixed
- Fixed cache invalidation bug on Admin
- Reverted change to cache time on FireFox
- Fixed invalid translations for static models
- Missing translations for configuration
- New configuration for pooled connections
- Fixed query string language config


## [2.0.5](https://github.com/digirati-co-uk/madoc-platform/releases/tag/v2.0.5) - 2022-05-06

Expand Down
2 changes: 1 addition & 1 deletion services/madoc-ts/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export async function createApp(config: ExternalConfig, env: EnvConfig) {
}

app.use(k2c(cookieParser(app.keys)));
app.use(postgresConnection(pool));
app.use(postgresConnection(pool, config.pooledDatabase));
app.use(json({ pretty: process.env.NODE_ENV !== 'production' }));
app.use(logger());
// Disabled for now, causing issues logging in.
Expand Down
2 changes: 1 addition & 1 deletion services/madoc-ts/src/frontend/admin/query-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export const queryConfig: ReactQueryConfig = {
queries: {
staleTime: 0,
cacheTime: 1000 * 60 * 60,
refetchOnMount: false,
refetchOnMount: true,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export const EditShorthandCaptureModel: React.FC<{
features={{
autosave: false,
revisionEditMode: true,
translationNamespace: 'madoc',
}}
captureModel={rev.model}
initialRevision={rev.revisionId}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React, { createContext, ReactElement, useContext } from 'react';
import { useTranslation, UseTranslationOptions } from 'react-i18next';

const ModelNamespace = createContext('capture-models');

export function WithModelNamespace(props: { namespace: string; children: ReactElement }) {
return <ModelNamespace.Provider value={props.namespace}>{props.children}</ModelNamespace.Provider>;
}

export function useModelTranslation(options?: UseTranslationOptions) {
const ns = useContext(ModelNamespace);

return useTranslation(ns || 'capture-models', options);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { AnnotationStyles } from '../../../../../types/annotation-styles';
import { AnnotationStyleProvider } from '../../AnnotationStyleContext';
import { WithModelNamespace } from '../../hooks/use-model-translation';
import { CaptureModel } from '../../types/capture-model';
import { AutosaveRevision } from '../features/AutosaveRevision';
import { AutoSelectDefineRegion } from '../features/AutoSelectDefineRegion';
Expand All @@ -20,6 +21,7 @@ export type RevisionProviderFeatures = {
directEdit?: boolean;
preventMultiple?: boolean;
basicUnNesting?: boolean;
translationNamespace?: string;
};

export const RevisionProviderWithFeatures: React.FC<{
Expand Down Expand Up @@ -50,34 +52,37 @@ export const RevisionProviderWithFeatures: React.FC<{
directEdit = false,
preventMultiple = false,
basicUnNesting = true,
translationNamespace = 'capture-models',
} = features || {};
const { components, editor } = slotConfig || {};

return (
<ContributorProvider value={captureModel?.contributors || {}}>
<AnnotationStyleProvider theme={annotationTheme}>
<Revisions.Provider
key={captureModel?.id}
revision={revision}
captureModel={captureModel}
excludeStructures={excludeStructures}
initialRevision={initialRevision}
>
{/*<DebugRevisionSwitcher contributors={captureModel?.contributors} />*/}
<AutoSelectDefineRegion />
{autosave ? <AutosaveRevision minutes={2} /> : null}
{revisionEditMode ? <SwitchFieldAfterRevises /> : null}
{revisionEditMode ? <SwitchEditMode /> : null}
{autoSelectingRevision ? (
<AutoSelectingRevision directEdit={directEdit} preventMultiple={preventMultiple} />
) : null}
{basicUnNesting ? <BasicUnNesting /> : null}
<CorrectingRevisionSubtree />
<EditorSlots.Provider config={editor} components={components}>
{children}
</EditorSlots.Provider>
</Revisions.Provider>
</AnnotationStyleProvider>
<WithModelNamespace namespace={translationNamespace || 'capture-models'}>
<AnnotationStyleProvider theme={annotationTheme}>
<Revisions.Provider
key={captureModel?.id}
revision={revision}
captureModel={captureModel}
excludeStructures={excludeStructures}
initialRevision={initialRevision}
>
{/*<DebugRevisionSwitcher contributors={captureModel?.contributors} />*/}
<AutoSelectDefineRegion />
{autosave ? <AutosaveRevision minutes={2} /> : null}
{revisionEditMode ? <SwitchFieldAfterRevises /> : null}
{revisionEditMode ? <SwitchEditMode /> : null}
{autoSelectingRevision ? (
<AutoSelectingRevision directEdit={directEdit} preventMultiple={preventMultiple} />
) : null}
{basicUnNesting ? <BasicUnNesting /> : null}
<CorrectingRevisionSubtree />
<EditorSlots.Provider config={editor} components={components}>
{children}
</EditorSlots.Provider>
</Revisions.Provider>
</AnnotationStyleProvider>
</WithModelNamespace>
</ContributorProvider>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ export const useBlockEditor = (
features={{
autoSelectingRevision: true,
autosave: false,
translationNamespace: 'madoc',
}}
>
<OnChangeDocument
Expand Down
28 changes: 15 additions & 13 deletions services/madoc-ts/src/middleware/i18n/i18next.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function createBackend(slug: string, jwt?: string, languages?: stri
saveMissing: true,
keySeparator: false,
detection: {
order: [/*'querystring', 'cookie', */ 'localStorage', 'sessionStorage', 'navigator', 'htmlTag'],
order: ['querystring', /* 'cookie', */ 'localStorage', 'sessionStorage', 'navigator', 'htmlTag'],
lookupQuerystring: 'lng',
lookupCookie: 'i18next',
lookupLocalStorage: 'i18nextLng',
Expand All @@ -38,18 +38,20 @@ export async function createBackend(slug: string, jwt?: string, languages?: stri
].filter(Boolean),
backendOptions: [
process.env.NODE_ENV === 'production' ? {} : null, // primary
{
loadPath: `/s/${slug}/madoc/api/locales/{{lng}}/{{ns}}`, // xhr load path for my own fallback
addPath: `/s/${slug}/madoc/api/locales/{{lng}}/{{ns}}`, // xhr load path for my own fallback
customHeaders: jwt
? {
Accept: 'application/json',
Authorization: `Bearer ${jwt}`,
}
: {
Accept: 'application/json',
},
},
process.env.NODE_ENV !== 'production'
? {
loadPath: `/s/${slug}/madoc/api/locales/{{lng}}/{{ns}}`, // xhr load path for my own fallback
addPath: `/s/${slug}/madoc/api/locales/{{lng}}/{{ns}}`, // xhr load path for my own fallback
customHeaders: jwt
? {
Accept: 'application/json',
Authorization: `Bearer ${jwt}`,
}
: {
Accept: 'application/json',
},
}
: null,
].filter(Boolean),
},
});
Expand Down
20 changes: 15 additions & 5 deletions services/madoc-ts/src/middleware/postgres-connection.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { Middleware } from 'koa';
import { DatabasePoolType } from 'slonik';
import { DatabasePoolConnectionType, DatabasePoolType } from 'slonik';
import { ChangeDiscoveryRepository } from '../activity-streams/change-discovery-repository';
import { AnnotationStylesRepository } from '../repository/annotation-styles-repository';
import { MediaRepository } from '../repository/media-repository';
import { NotificationRepository } from '../repository/notification-repository';
import { PageBlocksRepository } from '../repository/page-blocks-repository';
import { PluginRepository } from '../repository/plugin-repository';
import { ProjectRepository } from '../repository/project-repository';
import { SiteUserRepository } from '../repository/site-user-repository';
import { ThemeRepository } from '../repository/theme-repository';

export const postgresConnection = (pool: DatabasePoolType): Middleware => async (context, next) => {
await pool.connect(async connection => {
export const postgresConnection = (pool: DatabasePoolType, useConnections = false): Middleware => async (
context,
next
) => {
async function handleConnection(connection: DatabasePoolConnectionType) {
context.connection = connection;

// Set up repositories.
Expand All @@ -25,5 +27,13 @@ export const postgresConnection = (pool: DatabasePoolType): Middleware => async
context.annotationStyles = new AnnotationStylesRepository(connection);

await next();
});
}

if (useConnections) {
await pool.connect(async connection => {
await handleConnection(connection);
});
} else {
await handleConnection(pool);
}
};
2 changes: 1 addition & 1 deletion services/madoc-ts/src/repository/page-blocks-repository.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InternationalString } from '@hyperion-framework/types/iiif/descriptive';
import { InternationalString } from '@hyperion-framework/types';
import { sql } from 'slonik';
import * as editorial from '../database/queries/site-editorial';
import {
Expand Down
1 change: 1 addition & 0 deletions services/madoc-ts/src/types/external-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type ExternalConfig = {
cookieName?: string;
tokenExpires?: number;
tokenRefresh?: number;
pooledDatabase?: boolean;
defaultSiteConfiguration: ProjectConfiguration;
permissions: {
[role: string]: string[];
Expand Down
Loading

0 comments on commit d079fd7

Please sign in to comment.