Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(storybook): add mock data to the cloudStorageContainer component #1460

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 2 additions & 16 deletions desktop/renderer-app/src/pages/CloudStoragePage/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,9 @@ export class CloudStorageStore extends CloudStorageStoreBase {
public insertCourseware: (file: CloudStorageFile) => void;
public onCoursewareInserted?: () => void;

public cloudStorageSinglePageFiles = 50;

/** In order to avoid multiple calls the fetchMoreCloudStorageData
* when request fetchMoreCloudStorageData after files length is 0 */
public hasMoreFile = false;
public isFetchingFiles = false;
public hasMoreFile = true;

// a set of taskUUIDs representing querying tasks
private convertStatusManager = new ConvertStatusManager();
Expand All @@ -80,15 +77,12 @@ export class CloudStorageStore extends CloudStorageStoreBase {

makeObservable(this, {
filesMap: observable,
isFetchingFiles: observable,

pendingUploadTasks: computed,
uploadingUploadTasks: computed,
successUploadTasks: computed,
failedUploadTasks: computed,
files: computed,
currentFilesLength: computed,
cloudStorageDataPagination: computed,

fileMenus: action,
onItemMenuClick: action,
Expand Down Expand Up @@ -123,14 +117,6 @@ export class CloudStorageStore extends CloudStorageStoreBase {
return observable.array([...this.filesMap.values()]);
}

public get currentFilesLength(): number {
return this.filesMap.size;
}

public get cloudStorageDataPagination(): number {
return Math.ceil(this.currentFilesLength / this.cloudStorageSinglePageFiles);
}

/** Render file menus item base on fileUUID */
public fileMenus = (
file: CloudStorageFileUI,
Expand Down Expand Up @@ -308,7 +294,7 @@ export class CloudStorageStore extends CloudStorageStoreBase {
const cloudStorageTotalPagesFilesCount =
this.cloudStorageDataPagination * this.cloudStorageSinglePageFiles;

if (this.currentFilesLength >= cloudStorageTotalPagesFilesCount && this.hasMoreFile) {
if (this.filesMap.size >= cloudStorageTotalPagesFilesCount && this.hasMoreFile) {
this.isFetchingFiles = true;

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState } from "react";
import { Story, Meta, ArgTypes } from "@storybook/react";
import Chance from "chance";
import faker from "faker";
import { action, AnnotationsMap, makeObservable } from "mobx";
import { action, AnnotationsMap, makeObservable, observable } from "mobx";
import { Modal } from "antd";
import { CloudStorageContainer, CloudStorageStore } from "./index";
import { CloudStorageUploadTask } from "../../components/CloudStorage/types";
Expand Down Expand Up @@ -34,6 +34,7 @@ const fakeStoreImplProps = [
"onNewFileName",
"addExternalFile",
"onDropFile",
"fetchMoreCloudStorageData",
] as const;

type FakeStoreImplProps = typeof fakeStoreImplProps[number];
Expand All @@ -51,6 +52,7 @@ class FakeStore extends CloudStorageStore {
public onNewFileName: FakeStoreConfig["onNewFileName"];
public addExternalFile;
public onDropFile: FakeStoreConfig["onDropFile"];
public fetchMoreCloudStorageData;

public pendingUploadTasks: CloudStorageStore["pendingUploadTasks"] = [];
public uploadingUploadTasks: CloudStorageStore["uploadingUploadTasks"] = [];
Expand All @@ -61,7 +63,7 @@ class FakeStore extends CloudStorageStore {
public constructor(config: FakeStoreConfig) {
super();

this.files = Array(25)
this.files = Array(this.cloudStorageSinglePageFiles)
.fill(0)
.map(() => ({
fileUUID: faker.datatype.uuid(),
Expand Down Expand Up @@ -154,13 +156,53 @@ class FakeStore extends CloudStorageStore {
});
}
};
this.fetchMoreCloudStorageData = async (page: number): Promise<void> => {
if (this.isFetchingFiles || this.files.length > 300) {
console.warn("the cloud storage files is enough");
return Promise.resolve();
}

const cloudStorageTotalPagesFilesCount =
this.cloudStorageDataPagination * this.cloudStorageSinglePageFiles;

if (this.files.length >= cloudStorageTotalPagesFilesCount) {
this.isFetchingFiles = true;

const newFilesData = Array(this.cloudStorageSinglePageFiles * page)
.fill(0)
.map(() => ({
fileUUID: faker.datatype.uuid(),
fileName: faker.random.words() + "." + faker.system.commonFileExt(),
fileSize: chance.integer({ min: 0, max: 1000 * 1000 * 100 }),
convert: chance.pickone(["idle", "error", "success", "converting"]),
createAt: faker.date.past(),
}));

for (const { fileName, fileSize } of newFilesData) {
this.files.push({
fileUUID: faker.datatype.uuid(),
fileName: fileName,
fileSize: fileSize,
convert: "idle",
createAt: faker.date.past(),
});
}

this.isFetchingFiles = false;
}
};

makeObservable(
this,
fakeStoreImplProps.reduce((o, k) => {
o[k] = action;
return o;
}, {} as AnnotationsMap<this, never>),
fakeStoreImplProps.reduce(
(o, k) => {
o[k] = action;
return o;
},
{
files: observable,
} as AnnotationsMap<this, never>,
),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export abstract class CloudStorageStore {
public isUploadPanelExpand = false;
/** UUID of file that is under renaming */
public renamingFileUUID?: FileUUID = "";
/** Cloud storage single page data returned by the server */
public cloudStorageSinglePageFiles = 50;
/** In order to avoid multiple calls the fetchMoreCloudStorageData when fetching data */
public isFetchingFiles = false;

/** Display upload panel */
public get isUploadPanelVisible(): boolean {
Expand All @@ -32,6 +36,11 @@ export abstract class CloudStorageStore {
return Number.isNaN(this.totalUsage) ? "" : prettyBytes(this.totalUsage);
}

/** get fetch data pagination value of cloudStorage. */
public get cloudStorageDataPagination(): number {
return Math.ceil(this.files.length / this.cloudStorageSinglePageFiles);
}

/** Uploading -> Error -> Idle -> Success */
public get sortedUploadTasks(): CloudStorageUploadTask[] {
return observable.array([
Expand Down Expand Up @@ -68,6 +77,7 @@ export abstract class CloudStorageStore {
selectedFileUUIDs: observable,
isUploadPanelExpand: observable,
renamingFileUUID: observable,
isFetchingFiles: observable,

isUploadPanelVisible: computed,
totalUsageHR: computed,
Expand Down Expand Up @@ -122,9 +132,6 @@ export abstract class CloudStorageStore {
/** User cloud storage files */
public abstract files: CloudStorageFile[];

/** get fetch data pagination value of cloudStorage. */
public abstract cloudStorageDataPagination: number;

/** Render file menus item base on fileUUID */
public abstract fileMenus: (
file: CloudStorageFile,
Expand Down Expand Up @@ -164,12 +171,6 @@ export abstract class CloudStorageStore {
/** When file(s) are dropped in the container. */
public abstract onDropFile(files: FileList): void;

/** In order to avoid multiple calls the fetchMoreCloudStorageData when fetching data */
public abstract isFetchingFiles: boolean;

/** Cloud storage single page data returned by the server */
public abstract cloudStorageSinglePageFiles: number;

/** When cloudStorage files is 50 or more, pull up to bottom that loading will fetch more pagination Data of the cloudStorage. */
public abstract fetchMoreCloudStorageData: (page: number) => Promise<void>;
}
16 changes: 1 addition & 15 deletions web/flat-web/src/pages/CloudStoragePage/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,9 @@ export class CloudStorageStore extends CloudStorageStoreBase {
public insertCourseware: (file: CloudStorageFile) => void;
public onCoursewareInserted?: () => void;

public cloudStorageSinglePageFiles = 50;

/** In order to avoid multiple calls the fetchMoreCloudStorageData
* when request fetchMoreCloudStorageData after files length is 0 */
public hasMoreFile = true;
public isFetchingFiles = false;

// a set of taskUUIDs representing querying tasks
private convertStatusManager = new ConvertStatusManager();
Expand All @@ -80,15 +77,12 @@ export class CloudStorageStore extends CloudStorageStoreBase {

makeObservable(this, {
filesMap: observable,
isFetchingFiles: observable,

pendingUploadTasks: computed,
uploadingUploadTasks: computed,
successUploadTasks: computed,
failedUploadTasks: computed,
files: computed,
currentFilesLength: computed,
cloudStorageDataPagination: computed,

fileMenus: action,
onItemMenuClick: action,
Expand Down Expand Up @@ -123,14 +117,6 @@ export class CloudStorageStore extends CloudStorageStoreBase {
return observable.array([...this.filesMap.values()]);
}

public get currentFilesLength(): number {
return this.filesMap.size;
}

public get cloudStorageDataPagination(): number {
return Math.ceil(this.currentFilesLength / this.cloudStorageSinglePageFiles);
}

/** Render file menus item base on fileUUID */
public fileMenus = (
file: CloudStorageFileUI,
Expand Down Expand Up @@ -304,7 +290,7 @@ export class CloudStorageStore extends CloudStorageStoreBase {
const cloudStorageTotalPagesFilesCount =
this.cloudStorageDataPagination * this.cloudStorageSinglePageFiles;

if (this.currentFilesLength >= cloudStorageTotalPagesFilesCount && this.hasMoreFile) {
if (this.filesMap.size >= cloudStorageTotalPagesFilesCount && this.hasMoreFile) {
this.isFetchingFiles = true;

try {
Expand Down