fix: update codes

This commit is contained in:
qinluhe 2024-06-27 13:49:09 +08:00
parent a5cb427a8a
commit 3f05ac8f62
13 changed files with 117 additions and 86 deletions

View File

@ -24,7 +24,7 @@
"coverage": "pnpm run test:unit && pnpm run test:components"
},
"dependencies": {
"@appflowyinc/client-api-wasm": "0.0.6",
"@appflowyinc/client-api-wasm": "0.1.1",
"@atlaskit/primitives": "^5.5.3",
"@emoji-mart/data": "^1.1.2",
"@emoji-mart/react": "^1.1.1",

View File

@ -1,13 +1,9 @@
lockfileVersion: '6.0'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
dependencies:
'@appflowyinc/client-api-wasm':
specifier: 0.0.6
version: 0.0.6
specifier: 0.1.1
version: 0.1.1
'@atlaskit/primitives':
specifier: ^5.5.3
version: 5.7.0(@types/react@18.2.66)(react@18.2.0)
@ -451,8 +447,8 @@ packages:
'@jridgewell/gen-mapping': 0.3.5
'@jridgewell/trace-mapping': 0.3.25
/@appflowyinc/client-api-wasm@0.0.6:
resolution: {integrity: sha512-qx6NlHwBUDRMTDzy2hqi5fiTk/F8aV+QbUBlwrQIp+te+OC1akXmuBOGVehXJlycHfWfD/6ua1AyL6nf3QDAZQ==}
/@appflowyinc/client-api-wasm@0.1.1:
resolution: {integrity: sha512-7+/TCmzMi9KrxX3HFLJv9R6ON2AO5xQavV547ii7RZM8+5bZJakuf6+pnyCzOquQX07q3ZYwJCa3MIgDvficaA==}
dev: false
/@atlaskit/analytics-next-stable-react-context@1.0.1(react@18.2.0):
@ -11666,3 +11662,7 @@ packages:
resolution: {integrity: sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==}
engines: {node: '>=12.20'}
dev: true
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false

View File

@ -0,0 +1,35 @@
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const jestCoverageFile = path.join(__dirname, '../coverage/jest/coverage-final.json');
const cypressCoverageFile = path.join(__dirname, '../coverage/cypress/coverage-final.json');
const nycOutputDir = path.join(__dirname, '../coverage/.nyc_output');
// Ensure .nyc_output directory exists
if (fs.existsSync(nycOutputDir)) {
fs.rmSync(nycOutputDir, { recursive: true });
}
fs.mkdirSync(nycOutputDir, { recursive: true });
if (fs.existsSync(path.join(__dirname, '../coverage/merged'))) {
fs.rmSync(path.join(__dirname, '../coverage/merged'), { recursive: true });
}
// Copy Jest coverage file
fs.copyFileSync(jestCoverageFile, path.join(nycOutputDir, 'jest-coverage.json'));
// Copy Cypress E2E coverage file
fs.copyFileSync(cypressCoverageFile, path.join(nycOutputDir, 'cypress-coverage.json'));
// Merge coverage files
execSync('nyc merge ./coverage/.nyc_output ./coverage/merged/coverage-final.json', { stdio: 'inherit' });
// Move the merged result to the .nyc_output directory
fs.rmSync(nycOutputDir, { recursive: true });
fs.mkdirSync(nycOutputDir, { recursive: true });
fs.copyFileSync(path.join(__dirname, '../coverage/merged/coverage-final.json'), path.join(nycOutputDir, 'out.json'));
// Generate final merged report
execSync('nyc report --reporter=html --reporter=text-summary --report-dir=coverage/merged --temp-dir=coverage/.nyc_output', { stdio: 'inherit' });
console.log(`Merged coverage report written to coverage/merged`);

View File

@ -636,3 +636,27 @@ export enum LineHeightLayout {
normal = 'normal',
large = 'large',
}
export interface ViewMetaIcon {
ty: number;
value: string;
}
export interface PublishViewInfo {
view_id: string;
name: string;
icon: ViewMetaIcon | null;
extra: string | null;
layout: number;
created_at: string;
created_by: string;
last_edited_time: string;
last_edited_by: string;
child_views: PublishViewInfo[] | null;
}
export interface PublishViewMetaData {
view: PublishViewInfo;
child_views: PublishViewInfo[];
ancestor_views: PublishViewInfo[];
}

View File

@ -1,23 +1,12 @@
import { Table } from 'dexie';
export interface MetaData {
view_id: string;
name: string;
icon: string | null;
layout: number;
extra: string | null;
created_by: string | null;
last_edited_by: string | null;
last_edited_time: string;
created_at: string;
}
import { PublishViewInfo } from '@/application/collab.type';
export type ViewMeta = {
publish_name: string;
child_views: MetaData[];
ancestor_views: MetaData[];
} & MetaData;
child_views: PublishViewInfo[];
ancestor_views: PublishViewInfo[];
} & PublishViewInfo;
export type ViewMetasTable = {
view_metas: Table<ViewMeta>;

View File

@ -1,5 +1,11 @@
import { MetaData } from '@/application/db/tables/view_metas';
import { CollabType, YDoc, YjsEditorKey, YSharedRoot } from '@/application/collab.type';
import {
CollabType,
PublishViewInfo,
PublishViewMetaData,
YDoc,
YjsEditorKey,
YSharedRoot,
} from '@/application/collab.type';
import { applyYDoc } from '@/application/ydoc/apply';
import { db, openCollabDB } from '@/application/db';
import { Fetcher, StrategyType } from '@/application/services/js-services/cache/types';
@ -49,11 +55,9 @@ export async function hasViewMetaCache(name: string) {
export async function getPublishViewMeta<
T extends {
metadata: {
view: MetaData;
child_views: MetaData[];
ancestor_views: MetaData[];
};
view: PublishViewInfo;
child_views: PublishViewInfo[];
ancestor_views: PublishViewInfo[];
}
>(
fetcher: Fetcher<T>,
@ -107,11 +111,9 @@ export async function getPublishView<
T extends {
data: number[];
meta: {
metadata: {
view: MetaData;
child_views: MetaData[];
ancestor_views: MetaData[];
};
view: PublishViewInfo;
child_views: PublishViewInfo[];
ancestor_views: PublishViewInfo[];
};
}
>(
@ -167,21 +169,19 @@ export async function getPublishView<
export async function revalidatePublishViewMeta<
T extends {
metadata: {
view: MetaData;
child_views: MetaData[];
ancestor_views: MetaData[];
};
view: PublishViewInfo;
child_views: PublishViewInfo[];
ancestor_views: PublishViewInfo[];
}
>(name: string, fetcher: Fetcher<T>) {
const { metadata } = await fetcher();
const { view, child_views, ancestor_views } = await fetcher();
await db.view_metas.put(
{
publish_name: name,
...metadata.view,
child_views: metadata.child_views,
ancestor_views: metadata.ancestor_views,
...view,
child_views: child_views,
ancestor_views: ancestor_views,
},
name
);
@ -193,13 +193,7 @@ export async function revalidatePublishView<
T extends {
data: number[];
rows?: Record<string, number[]>;
meta: {
metadata: {
view: MetaData;
child_views: MetaData[];
ancestor_views: MetaData[];
};
};
meta: PublishViewMetaData;
}
>(name: string, fetcher: Fetcher<T>, collab: YDoc) {
const { data, meta, rows } = await fetcher();
@ -207,9 +201,9 @@ export async function revalidatePublishView<
await db.view_metas.put(
{
publish_name: name,
...meta.metadata.view,
child_views: meta.metadata.child_views,
ancestor_views: meta.metadata.ancestor_views,
...meta.view,
child_views: meta.child_views,
ancestor_views: meta.ancestor_views,
},
name
);

View File

@ -1,5 +1,6 @@
import { ClientAPI } from '@appflowyinc/client-api-wasm';
import { AFCloudConfig } from '@/application/services/services.type';
import { PublishViewMetaData } from '@/application/collab.type';
let client: ClientAPI;
@ -37,7 +38,12 @@ export function initAPIService(
}
export async function getPublishView(publishNamespace: string, publishName: string) {
return client.get_publish_view(publishNamespace, publishName);
const data = await client.get_publish_view(publishNamespace, publishName);
return {
data: data.data,
meta: JSON.parse(data.meta.data) as PublishViewMetaData,
};
}
export async function getPublishInfoWithViewId(viewId: string) {
@ -45,5 +51,8 @@ export async function getPublishInfoWithViewId(viewId: string) {
}
export async function getPublishViewMeta(publishNamespace: string, publishName: string) {
return client.get_publish_view_meta(publishNamespace, publishName);
const data = await client.get_publish_view_meta(publishNamespace, publishName);
const metadata = JSON.parse(data.data) as PublishViewMetaData;
return metadata;
}

View File

@ -5,7 +5,6 @@ import { ReactComponent as CalendarSvg } from '$icons/16x/date.svg';
import { ViewLayout } from '@/application/collab.type';
import { ViewMeta } from '@/application/db/tables/view_metas';
import { useEditorContext } from '@/components/editor/EditorContext';
import { ViewMetaIcon } from '@/components/view-meta';
import React, { useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
@ -31,15 +30,7 @@ function MentionPage({ pageId }: { pageId: string }) {
}, [loadViewMeta, pageId]);
const icon = useMemo(() => {
if (meta?.icon) {
try {
return JSON.parse(meta.icon) as ViewMetaIcon;
} catch (e) {
return;
}
}
return;
return meta?.icon;
}, [meta?.icon]);
const defaultIcon = useMemo(() => {

View File

@ -17,7 +17,7 @@ export function PublishViewHeader() {
try {
const extra = ancestor?.extra ? JSON.parse(ancestor.extra) : {};
icon = extra.icon?.value || JSON.parse(ancestor.icon || '')?.value;
icon = extra.icon?.value || ancestor.icon?.value;
} catch (e) {
// ignore
}

View File

@ -1,6 +1,6 @@
import { usePublishContext } from '@/application/publish';
import { EditorLayoutStyle } from '@/components/editor/EditorContext';
import { ViewMetaCover, ViewMetaIcon } from '@/components/view-meta';
import { ViewMetaCover } from '@/components/view-meta';
import { useEffect, useMemo } from 'react';
export function useViewMeta() {
@ -63,17 +63,7 @@ export function useViewMeta() {
});
}, [layoutStyle.font]);
const icon = useMemo(() => {
if (viewMeta?.icon) {
try {
return JSON.parse(viewMeta.icon) as ViewMetaIcon;
} catch (e) {
return;
}
}
return;
}, [viewMeta?.icon]);
const icon = viewMeta?.icon || undefined;
const cover = extra?.cover as ViewMetaCover;

View File

@ -7,11 +7,7 @@ import BuiltInImage6 from '@/assets/cover/m_cover_image_6.png';
import ViewCover, { CoverType } from '@/components/view-meta/ViewCover';
import React, { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
export interface ViewMetaIcon {
type: number;
value: string;
}
import { ViewMetaIcon } from '@/application/collab.type';
export interface ViewMetaCover {
type: CoverType;

View File

@ -1 +1 @@
export * from 'src/components/view-meta/ViewMetaPreview';
export * from './ViewMetaPreview';

View File

@ -1992,12 +1992,14 @@ dependencies = [
"flowy-notification",
"flowy-search-pub",
"flowy-sqlite",
"futures",
"lazy_static",
"lib-dispatch",
"lib-infra",
"nanoid",
"parking_lot 0.12.1",
"protobuf",
"regex",
"serde",
"serde_json",
"strum_macros 0.21.1",
@ -2018,6 +2020,7 @@ dependencies = [
"collab-entity",
"collab-folder",
"lib-infra",
"serde",
"tokio",
"uuid",
]