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

Taboule fixes #713

Open
wants to merge 43 commits into
base: daily
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2732651
fix(shared): add errors UI for extension (#830)
ascariandrea Dec 12, 2022
05c013f
fix(yt:shared): defined metadata filters based on nature type
ascariandrea Nov 22, 2022
7420944
fix(taboule): tag codec for supporter in personal stats request
ascariandrea Sep 29, 2022
3a5c3ec
fix(taboule): fix taboule metadata
rekoke Oct 7, 2022
e42bdb3
fix(taboule): add the explandable list to display recommended videos …
rekoke Oct 10, 2022
7cb0364
fix(taboule): add platform naming to dropdown list
rekoke Oct 10, 2022
b494635
fix(taboule): extension of the downloaded file to csv
rekoke Oct 10, 2022
0a63a5c
fix(taboule): delete unused var
rekoke Oct 10, 2022
44d940c
fix(taboule): add reload button to run taboule again without reloadin…
rekoke Oct 10, 2022
a9a4729
fix(taboule): no partial and fix search results list
rekoke Oct 11, 2022
b7f5ae1
fix(taboule): revert to localhost:14000
rekoke Oct 11, 2022
9eafd2a
fix(taboule): prefixes to query values everyewhere
rekoke Oct 11, 2022
434373e
fix(taboule): avoid type duplication
rekoke Oct 11, 2022
533884e
fix(taboule): reload button inside tabule and styles fixing
rekoke Oct 11, 2022
67d8770
fix(taboule): assets into root, make tests happy
rekoke Oct 11, 2022
146e142
fix(taboule): assets into src
rekoke Oct 11, 2022
e6980d2
fix(taboule): add png file type to jest config
rekoke Oct 12, 2022
11d5ae1
feat(storybook): add expandable taboule sidebar to storybook
rekoke Oct 12, 2022
650c6bb
chore(storybook): ts config for png resolution
ascariandrea Oct 13, 2022
c6a8c56
refactor(yt:backend): moved metadata arbs info yt:shared package
ascariandrea Oct 13, 2022
9d6cc7c
fix(taboule): expect 'publicKey' to be passed as query param
ascariandrea Oct 17, 2022
bfa1724
chore(storybook): added stories for taboule
ascariandrea Oct 25, 2022
5b21c31
fix(taboule): yt paginated results with GET /v2/metadata
ascariandrea Oct 25, 2022
f51e0a2
fix(taboule): tk paginated metadata with GET /v2/metadata
ascariandrea Oct 26, 2022
ab3be56
fix(taboule): error card ui
ascariandrea Nov 15, 2022
747ffe5
chore(storybook): added stories for taboule
ascariandrea Oct 27, 2022
d33a937
fix(taboule): display many Taboule instances in tabs
ascariandrea Nov 17, 2022
2c5d2ac
fix(taboule): make ExpandView receive children
ascariandrea Nov 23, 2022
c16ed85
fix(taboule): csv download action for all possible queries
ascariandrea Nov 23, 2022
8756cef
fix(shared): api provider option to exclude output validation
ascariandrea Dec 6, 2022
4fa3b67
fix(taboule): codec for list metadata query import
ascariandrea Dec 12, 2022
b0340a8
chore(storybook): update ExpandedView story with new props
ascariandrea Dec 12, 2022
ffbdb9b
chore(workspace): update test coverage output with pre-push hook
ascariandrea Dec 12, 2022
ef153f6
chore(taboule): skip output validation for yt home metadata query
ascariandrea Dec 12, 2022
5069058
docs(shared): api provider comments
ascariandrea Dec 12, 2022
f1a2f6a
fix(taboule): backward compatibility with production data
ascariandrea Dec 14, 2022
4d19231
fix(tk:backend): parser error reporter path
ascariandrea Dec 14, 2022
f572d6d
fix(taboule): moved api query inside related configurations
ascariandrea Dec 14, 2022
260b942
chore(taboule): added some comments to new taboule query configuratio…
ascariandrea Dec 14, 2022
3add6fa
fix(taboule): clean query configuration query filters
ascariandrea Dec 14, 2022
b102bd9
fix(taboule): relative imports for config module
ascariandrea Dec 14, 2022
40e89a3
chore(storybook): upgrade @storybook@^6.5.14
ascariandrea Dec 16, 2022
703316b
fix(taboule): expand view for tiktok search
ascariandrea Dec 16, 2022
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
2 changes: 1 addition & 1 deletion .husky/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ yarn yt:backend clean-test-db
# yarn pm2 save

# run tests one after the other to be sure the data doesn't overlap and make some of them fail
yarn test --ci --bail --forceExit
yarn test --ci --bail --forceExit --coverage

# restart backends and parsers with 'development' environment
# yarn pm2 restart -a --env development platforms/ecosystem.dev.config.js
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions jest.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ module.exports = {
coverageThreshold: {
global: {
branches: 30,
functions: 60,
lines: 60,
statements: 60,
functions: 44,
lines: 53,
statements: 54,
},
},
coveragePathIgnorePatterns: [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"@types/react": "^17"
},
"dependencies": {
"@react-theming/storybook-addon": "^1.1.7",
"@react-theming/storybook-addon": "^1.1.10",
"pm2": "^5.2.2"
}
}
4 changes: 3 additions & 1 deletion packages/shared/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ const jestBaseConfig = require('../../jest.config.base');
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
...jestBaseConfig,
rootDir: __dirname,
testEnvironment: 'jsdom',
displayName: '@shared',
moduleNameMapper: {
'\\.(css)$': '<rootDir>/../../__mocks__/styleMock.js',
},
modulePathIgnorePatterns: [
...jestBaseConfig.modulePathIgnorePatterns,
'profiles',
Expand Down
25 changes: 10 additions & 15 deletions packages/shared/src/components/Error/ErrorBox.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Card, CardContent, Typography } from '@material-ui/core';
import { Card } from '@material-ui/core';
import { Alert, AlertTitle } from '@material-ui/lab';
import * as React from 'react';
import { isAPIError } from '../../errors/APIError';
Expand All @@ -10,25 +10,20 @@ export const ErrorBox = (e: unknown): React.ReactElement<any, string> => {
const errorName = isAPIError(e) ? e.name : 'Error';
const message = isAPIError(e) ? e.message : 'Unknown Error';
return (
<Card>
<Alert severity="error">
<Card style={{ height: '100%' }}>
<Alert severity="error" style={{ height: '50%' }}>
<AlertTitle>{errorName}</AlertTitle>
<p>{message}</p>
{isAPIError(e) && e.details?.kind === 'DecodingError' ? (
<ul>
{(e.details.errors ?? []).map((d: any) => (
<li key={d}>{d}</li>
))}
</ul>
<div style={{ overflow: 'auto', height: '100%' }}>
<ul>
{((e.details.errors as any[]) ?? []).map((d: any) => (
<li key={d}>{d}</li>
))}
</ul>
</div>
) : null}
</Alert>

<CardContent>
<Typography variant="h6">Debug</Typography>
<pre style={{ backgroundColor: 'white' }}>
<code>{JSON.stringify(e, null, 2)}</code>
</pre>
</CardContent>
</Card>
);
};
3 changes: 2 additions & 1 deletion packages/shared/src/components/ErrorModal/errorModal.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.ErrorModal{
.ErrorModal {
width: 100%;
max-width: 500px;
overflow: hidden;
background: white;
border: 2px solid #de605f;
border-radius: 3px;
justify-content: space-between;
Expand Down
9 changes: 5 additions & 4 deletions packages/shared/src/components/ErrorModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ export interface ErrorModalProps {
message: string;
details: string[];
position?: string[];
style?: React.CSSProperties;
onClick: (action: string) => void;
}

const ErrorModal = (props: ErrorModalProps): JSX.Element => {
const { name, message, details, position, onClick } = props;
const { name, message, details, position, style, onClick } = props;
const [detailsShown, setDetailsShown] = React.useState(false);

const handleDetailsClick = (): void => {
Expand All @@ -25,7 +26,7 @@ const ErrorModal = (props: ErrorModalProps): JSX.Element => {
};

return (
<Box className={`ErrorModal ${position}`}>
<Box className={`ErrorModal ${position}`} style={style}>
<div className="ErrorModal__container">
<div
className="ErrorModal__container__content"
Expand All @@ -43,8 +44,8 @@ const ErrorModal = (props: ErrorModalProps): JSX.Element => {
})}
>
<ul className="ErrorModal__container__details__box__detail">
{details.map((d) => (
<li key={d}>
{details.map((d, i) => (
<li key={i}>
<Typography>{d}</Typography>
</li>
))}
Expand Down
9 changes: 8 additions & 1 deletion packages/shared/src/errors/AppError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export class AppError extends IOError {
}

export const toAppError = (e: unknown): AppError => {

if (isAPIError(e)) {
return {
...e,
Expand Down Expand Up @@ -34,3 +33,11 @@ export const toAppError = (e: unknown): AppError => {
},
};
};

export const appErrorDetailsToString = (e: AppError): string[] => {
if (e.details.kind === 'DecodingError') {
return e.details.errors as string[];
}

return [e.details.kind, e.details.status, JSON.stringify(e.details.meta)];
};
58 changes: 39 additions & 19 deletions packages/shared/src/extension/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import log from './logger';
import HubEvent from './models/HubEvent';
import { ServerLookup } from './models/Message';
import UserSettings from './models/UserSettings';
import { addCommonPageUI } from './ui';
import { bo } from './utils/browser.utils';

// instantiate a proper logger
Expand Down Expand Up @@ -88,6 +89,12 @@ export interface BootOpts {
onRegister: (h: Hub<HubEvent>, config: UserSettings) => void;
};
onAuthenticated: (res: any) => void;
ui?: {
common: {
id?: string;
errors?: boolean;
};
};
}

/**
Expand All @@ -107,7 +114,7 @@ let oldHref: string;
*/
function setupObserver(
{ handlers: _handlers, platformMatch, onLocationChange }: SetupObserverOpts,
config: UserSettings
settings: UserSettings
): MutationObserver {
// group handlers by type and `ObserverHandler.observe?`
// to subscribe them to proper DOM and location changes
Expand Down Expand Up @@ -147,7 +154,7 @@ function setupObserver(
appLog.debug('handler listen for mutation %O', handler);
dom.on(handler.match.selector, (node) =>
handle(node, handler, h, {
...config,
...settings,
href: window.location.toString(),
} as any)
);
Expand All @@ -171,7 +178,7 @@ function setupObserver(
// appLog.debug('Mutation target %s', (r.target as Element).id);
if (`#${(r.target as any).id}` === handler.match.selector) {
// appLog.debug('Target match %O', (r.target as any).id);
handle(r.target as any, handler, h, config);
handle(r.target as any, handler, h, settings);
}
});
}
Expand Down Expand Up @@ -205,7 +212,7 @@ function setupObserver(
);

handle(window.document.body, routeHandlerOpts, routeHandler[0], {
...config,
...settings,
href: window.location.toString(),
} as any);
}
Expand All @@ -225,9 +232,9 @@ function setupObserver(

window.addEventListener('unload', () => {
appLog.debug('Window unloading, disconnect the observer...');
if (observer) {
observer.disconnect();
}
observer?.disconnect();
// TODO: maybe destroy the app?
// app?.destroy();
});

if (body) {
Expand All @@ -249,8 +256,6 @@ export interface App {
destroy: () => void;
}

let config: any;

/**
* Transform functions that send messages to background
* to promises for better code flow.
Expand All @@ -269,6 +274,8 @@ const serverHandshakeP = (

let loading = false;
let app: App | undefined;
let config: any;

export async function boot(opts: BootOpts): Promise<App> {
if (app) {
appLog.debug('App already booted!');
Expand Down Expand Up @@ -326,8 +333,8 @@ export async function boot(opts: BootOpts): Promise<App> {

// merge settings taken from db with ones defined in settings.json, giving the precedence to the latter
const settings: UserSettings = {
...localSettings.result,
...jsonSettings.result,
...localSettings.result,
} as any;

if (!settings.publicKey || !settings.secretKey) {
Expand Down Expand Up @@ -374,6 +381,14 @@ export async function boot(opts: BootOpts): Promise<App> {
// register platform specific event handlers
opts.hub.onRegister(opts.hub.hub, config);

// enable the ui

addCommonPageUI(
opts.ui?.common.id ?? 'trex-extension-common-ui',
opts.hub.hub,
{ errors: true }
);

// 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.
Expand Down Expand Up @@ -401,22 +416,27 @@ export async function boot(opts: BootOpts): Promise<App> {
const handshakeResponse = await serverHandshakeP(config);

appLog.info('Server lookup cb %O', handshakeResponse);
let observer: MutationObserver | undefined;
if (handshakeResponse.type === 'Error') {
throw handshakeResponse.error;
}

// setup the dom mutation observer
let observer = setupObserver(opts.observe, config);
opts.hub.hub.dispatch({
type: 'ErrorEvent',
payload: handshakeResponse.error,
});
// throw handshakeResponse.error;
} else {
// invoke callback for successful authentication
opts.onAuthenticated(handshakeResponse.result);

// invoke callback for successful authentication
opts.onAuthenticated(handshakeResponse.result);
// setup the dom mutation observer
observer = setupObserver(opts.observe, config);
}

// define the app context to return
app = {
config,
reload: (c) => {
appLog.debug('Reloading app with config %O', c);
observer.disconnect();
observer?.disconnect();
opts.hub.hub.dispatch({
type: 'WindowUnload',
});
Expand All @@ -426,7 +446,7 @@ export async function boot(opts: BootOpts): Promise<App> {
observer = setupObserver(opts.observe, c);
},
destroy: () => {
observer.disconnect();
observer?.disconnect();
opts.hub.hub.clear();
app = undefined;
},
Expand Down
4 changes: 3 additions & 1 deletion packages/shared/src/extension/background/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ export async function handleSettingsLookup(

log.info(
'Loaded experiment info from file experiment.json: %j',
settingsJson
experimentInfo
);

const settings = { ...DEFAULT_SETTINGS, ...settingsJson, ...experimentInfo };

log.info('Final settings: %j', settings);

return sendResponse(settings);
}

Expand Down
26 changes: 14 additions & 12 deletions packages/shared/src/extension/background/sendMessage.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable node/no-callback-literal */
import { isLeft } from 'fp-ts/lib/Either';
import * as t from 'io-ts';
import { PathReporter } from 'io-ts/lib/PathReporter';
import { isAPIError } from '../../errors/APIError';
import { HandshakeResponse } from '../../models/HandshakeBody';
import log from '../logger';
import { Message, ServerLookup } from '../models/Message';
import { UserSettings } from '../models/UserSettings';
import { bo } from '../utils/browser.utils';
import * as E from 'fp-ts/Either';
import { toValidationError } from '../../errors/ValidationError';

interface ErrorResponse {
type: 'Error';
Expand All @@ -26,25 +27,26 @@ const ifValid =
(m: Message['type'], cb: SendResponse<t.TypeOf<C>>) =>
(x: unknown): void => {
log.debug('Check response is valid %O', x);
if (isAPIError(x)) {
// eslint-disable-next-line n/no-callback-literal
cb({ type: 'Error', error: x });
return;
}

const v = codec.decode(x);

if (isLeft(v)) {
const msg = `Error decoding backend response:\n${PathReporter.report(
v
).join('\n')}`;
log.error(msg);
if (E.isLeft(v)) {
// eslint-disable-next-line n/no-callback-literal
cb({
type: 'Error',
error: new Error(
`Error during '${m}' on codec ${codec.name} validation \n\n`.concat(
PathReporter.report(v).join('\n')
)
error: toValidationError(
`Error decoding ${m} output with ${codec.name}`,
v.left
),
});
} else {
// eslint-disable-next-line n/no-callback-literal
cb({ type: 'Success', result: v.right });
cb({ type: 'Success', result: x });
}
};

Expand Down
8 changes: 7 additions & 1 deletion packages/shared/src/extension/models/HubEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ export interface HubEventBase {
payload?: unknown;
}

export interface ErrorEvent extends HubEventBase {
type: 'ErrorEvent';
payload: unknown;
}

export interface APIEvent extends HubEventBase {
type: 'APIEvent';
payload: {
Expand Down Expand Up @@ -57,8 +62,9 @@ export interface WindowUnloadEvent extends HubEventBase {
}

export type HubEvent =
| ErrorEvent
| WindowUnloadEvent
/* | FullSaveEvent<any> -- issue #444 */
/* | FullSaveEvent<any> -- issue #444 */
| SyncResponseEvent
| APISyncResponseEvent
| APIEvent;
Expand Down
Loading