Skip to content
This repository has been archived by the owner on Aug 15, 2023. It is now read-only.

Commit

Permalink
fix(shared): added metadata logger box to extension
Browse files Browse the repository at this point in the history
  • Loading branch information
ascariandrea committed Sep 29, 2022
1 parent 289784a commit 294f813
Show file tree
Hide file tree
Showing 37 changed files with 1,257 additions and 227 deletions.
1 change: 1 addition & 0 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-i18next": "^11.18.0",
"react-json-view": "^1.21.3",
"ts-endpoint": "^2.0.0",
"ts-endpoint-express": "^2.0.0",
"ts-io-error": "^2.0.0",
Expand Down
14 changes: 14 additions & 0 deletions packages/shared/src/arbitraries/Supporter.arb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { getArbitrary } from 'fast-check-io-ts';
import { Supporter } from '../models/Supporter';
import * as t from 'io-ts';

const { creationTime, lastActivity, ...supporterProps } = Supporter.type.props;
export const SupporterArb = getArbitrary(
t.strict({
...supporterProps,
})
).map((cc) => ({
...cc,
creationTime: new Date(),
lastActivity: new Date(),
}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { getArbitrary } from 'fast-check-io-ts';
import {
ADVContributionEvent,
ContributionEvent,
VideoContributionEvent,
} from '../../models/ContributionEvent';
import * as t from 'io-ts';
import fc from 'fast-check';

const { ...videoContributionEventProps } = VideoContributionEvent.type.props;
export const VideoContributionEventArb = getArbitrary(
t.strict({
...videoContributionEventProps,
})
).map((cc): any => ({
...cc,
clientTime: new Date(),
}));

const { ...advContributionEventProps } = ADVContributionEvent.type.props;
export const ADVContributionEventArb = getArbitrary(
t.strict({
...advContributionEventProps,
})
).map((cc) => ({
...cc,
}));

export const ContributionEventArb: fc.Arbitrary<ContributionEvent> = fc.oneof(
VideoContributionEventArb,
ADVContributionEventArb
);
27 changes: 20 additions & 7 deletions packages/shared/src/extension/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _ from 'lodash';
import { ParserConfiguration, ParserFn } from '../providers/parser.provider';
import { HandshakeResponse } from '../models/HandshakeBody';
import { clearCache } from '../providers/dataDonation.provider';
import { FIXED_USER_NAME, initializeKey } from './background/account';
Expand All @@ -16,6 +17,7 @@ import log from './logger';
import HubEvent from './models/HubEvent';
import { ServerLookup } from './models/Message';
import UserSettings from './models/UserSettings';
import { renderUI, RenderUIProps } from './ui';
import { bo } from './utils/browser.utils';

// instantiate a proper logger
Expand Down Expand Up @@ -67,7 +69,12 @@ interface SetupObserverOpts {
onLocationChange: (oldLocation: string, newLocation: string) => void;
}

export interface BootOpts {
export interface BootOpts<
S = any,
M = any,
C extends ParserConfiguration = ParserConfiguration,
PP extends Record<string, ParserFn<S, any, C>> = any
> {
payload: ServerLookup['payload'];
mapLocalConfig: (
c: UserSettings,
Expand All @@ -79,6 +86,7 @@ export interface BootOpts {
onRegister: (h: Hub<HubEvent>, config: UserSettings) => void;
};
onAuthenticated: (res: any) => void;
ui?: Omit<RenderUIProps<S, M, C, PP>, 'hub'>;
}

/**
Expand Down Expand Up @@ -227,7 +235,12 @@ const serverHandshakeP = (

let loading = false;
let app: App | undefined;
export async function boot(opts: BootOpts): Promise<App> {
export async function boot<
S = any,
M = any,
C extends ParserConfiguration = ParserConfiguration,
PP extends Record<string, ParserFn<S, any, C>> = any
>(opts: BootOpts<S, M, C, PP>): Promise<App> {
if (app) {
appLog.debug('App already booted!');
return app;
Expand Down Expand Up @@ -316,12 +329,12 @@ export async function boot(opts: BootOpts): Promise<App> {
// register platform specific event handlers
opts.hub.onRegister(opts.hub.hub, config);

// emergency button should be used when a supported with
// UX hack in place didn't see any UX change, so they
// can report the problem and we can handle it.
// initializeEmergencyButton();
// render shared ui if configuration is given
if (opts.ui) {
renderUI({ hub: opts.hub.hub, ...opts.ui });
}

// because the URL has been for sure reloaded, be sure to also
// because the URL has been for sure reloaded, be sure to also clear cache
clearCache();

// send the configuration to the server to register the extension
Expand Down
23 changes: 0 additions & 23 deletions packages/shared/src/extension/tooltip/index.tsx

This file was deleted.

Loading

0 comments on commit 294f813

Please sign in to comment.