-
Notifications
You must be signed in to change notification settings - Fork 804
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(flat-components): add Cloud Storage panel container (#444)
* feat(flat-components): add CloudStorageContainer * refactor(flat-components): update upload panel icon logic * refactor(flat-components): use Number.isNaN instead of isNaN
- Loading branch information
Showing
14 changed files
with
533 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...s/src/components/CloudStorage/CloudStorageUploadTitle/CloudStorageUploadTitle.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from "react"; | ||
import { Story, Meta } from "@storybook/react"; | ||
import faker from "faker"; | ||
|
||
import { CloudStorageUploadTitle, CloudStorageUploadTitleProps } from "./index"; | ||
import { Chance } from "chance"; | ||
|
||
const chance = new Chance(); | ||
|
||
const storyMeta: Meta = { | ||
title: "CloudStorage/CloudStorageUploadTitle", | ||
component: CloudStorageUploadTitle, | ||
}; | ||
|
||
export default storyMeta; | ||
|
||
export const Overview: Story<CloudStorageUploadTitleProps> = args => ( | ||
<CloudStorageUploadTitle {...args} /> | ||
); | ||
Overview.args = { | ||
finishWithError: faker.random.boolean(), | ||
total: chance.integer({ min: 0, max: 200 }), | ||
}; | ||
Overview.args.finished = chance.integer({ min: 0, max: Overview.args.total! }); | ||
|
||
export const Uploading: Story<CloudStorageUploadTitleProps> = args => ( | ||
<CloudStorageUploadTitle {...args} /> | ||
); | ||
Uploading.args = { | ||
finishWithError: false, | ||
total: chance.integer({ min: 0, max: 200 }), | ||
}; | ||
Uploading.args.finished = chance.integer({ min: 0, max: Uploading.args.total! - 1 }); | ||
|
||
export const Error: Story<CloudStorageUploadTitleProps> = args => ( | ||
<CloudStorageUploadTitle {...args} /> | ||
); | ||
Error.args = { | ||
finishWithError: true, | ||
total: chance.integer({ min: 0, max: 200 }), | ||
}; | ||
Error.args.finished = chance.integer({ min: 0, max: Error.args.total! }); | ||
|
||
export const Success: Story<CloudStorageUploadTitleProps> = args => ( | ||
<CloudStorageUploadTitle {...args} /> | ||
); | ||
Success.args = { | ||
finishWithError: false, | ||
total: chance.integer({ min: 0, max: 200 }), | ||
}; | ||
Success.args.finished = Success.args.total!; |
42 changes: 42 additions & 0 deletions
42
packages/flat-components/src/components/CloudStorage/CloudStorageUploadTitle/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import "./style.less"; | ||
|
||
import { ExclamationCircleOutlined } from "@ant-design/icons"; | ||
import { Progress } from "antd"; | ||
import React from "react"; | ||
|
||
export interface CloudStorageUploadTitleProps { | ||
finishWithError?: boolean; | ||
finished: number; | ||
total: number; | ||
} | ||
|
||
export const CloudStorageUploadTitle = React.memo<CloudStorageUploadTitleProps>( | ||
function CloudStorageUploadTitle({ finishWithError, finished, total }) { | ||
const percent = finished && total ? (finished / total) * 100 : 0; | ||
const isFinish = percent >= 100; | ||
|
||
return ( | ||
<div className="cloud-storage-upload-title"> | ||
{finishWithError ? ( | ||
<ExclamationCircleOutlined className="cloud-storage-upload-title-error" /> | ||
) : ( | ||
<Progress | ||
type="circle" | ||
percent={percent} | ||
width={20} | ||
strokeWidth={isFinish ? 8 : 10} | ||
showInfo={isFinish} | ||
/> | ||
)} | ||
<h1 className="cloud-storage-upload-title-content"> | ||
{finishWithError ? "上传异常" : isFinish ? "上传完成" : "传输列表"} | ||
</h1> | ||
{!isFinish && !finishWithError && total && !Number.isNaN(finished) && ( | ||
<span className="cloud-storage-upload-title-count"> | ||
{finished}/{total} | ||
</span> | ||
)} | ||
</div> | ||
); | ||
}, | ||
); |
27 changes: 27 additions & 0 deletions
27
packages/flat-components/src/components/CloudStorage/CloudStorageUploadTitle/style.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.cloud-storage-upload-title { | ||
display: flex; | ||
align-items: center; | ||
|
||
.ant-progress { | ||
font-size: 0; // remove space | ||
} | ||
} | ||
|
||
.cloud-storage-upload-title-error { | ||
color: #f45454; | ||
font-size: 20px; | ||
} | ||
|
||
.cloud-storage-upload-title-content { | ||
margin: 0 8px 0; | ||
padding: 0; | ||
font-size: 16px; | ||
font-weight: 500; | ||
line-height: 1; | ||
} | ||
|
||
.cloud-storage-upload-title-count { | ||
font-size: 14px; | ||
color: #7a7b7c; | ||
line-height: 1; | ||
} |
14 changes: 3 additions & 11 deletions
14
packages/flat-components/src/components/CloudStorage/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,3 @@ | ||
import "./style.less"; | ||
|
||
import React from "react"; | ||
import { observer } from "mobx-react-lite"; | ||
|
||
export interface CloudStorageProps {} | ||
|
||
export const CloudStorage = observer<CloudStorageProps>(function CloudStorage() { | ||
// @TODO | ||
return <></>; | ||
}); | ||
export * from "./CloudStorageFileList"; | ||
export * from "./CloudStorageUploadItem"; | ||
export * from "./CloudStorageUploadPanel"; |
3 changes: 0 additions & 3 deletions
3
packages/flat-components/src/components/CloudStorage/style.less
This file was deleted.
Oops, something went wrong.
100 changes: 100 additions & 0 deletions
100
...es/flat-components/src/containers/CloudStorageContainer/CloudStorageContainer.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
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 { CloudStorageContainer, CloudStorageStore } from "./index"; | ||
|
||
const chance = new Chance(); | ||
|
||
const storyMeta: Meta = { | ||
title: "CloudStorage/CloudStorageContainer", | ||
component: CloudStorageContainer, | ||
argTypes: { | ||
store: { control: false }, | ||
}, | ||
}; | ||
|
||
export default storyMeta; | ||
|
||
const fakeStoreImplProps = [ | ||
"onBatchDelete", | ||
"onUpload", | ||
"onUploadCancel", | ||
"onUploadPanelClose", | ||
"onUploadRetry", | ||
] as const; | ||
|
||
type FakeStoreImplProps = typeof fakeStoreImplProps[number]; | ||
|
||
type FakeStoreConfig = Pick<CloudStorageStore, FakeStoreImplProps>; | ||
|
||
class FakeStore extends CloudStorageStore { | ||
onBatchDelete; | ||
onUpload; | ||
onUploadCancel; | ||
onUploadPanelClose; | ||
onUploadRetry; | ||
|
||
constructor(config: FakeStoreConfig) { | ||
super(); | ||
|
||
this.onBatchDelete = config.onBatchDelete; | ||
this.onUpload = config.onUpload; | ||
this.onUploadCancel = config.onUploadCancel; | ||
this.onUploadPanelClose = config.onUploadPanelClose; | ||
this.onUploadRetry = config.onUploadRetry; | ||
|
||
makeObservable( | ||
this, | ||
fakeStoreImplProps.reduce((o, k) => { | ||
o[k] = action; | ||
return o; | ||
}, {} as AnnotationsMap<this, never>), | ||
); | ||
} | ||
} | ||
|
||
function createFakeStore(config: FakeStoreConfig): FakeStore { | ||
const store = new FakeStore(config); | ||
store.totalUsage = chance.integer({ min: 0, max: 1000 * 1000 * 1000 }); | ||
store.files = Array(25) | ||
.fill(0) | ||
.map(() => { | ||
return { | ||
fileUUID: faker.random.uuid(), | ||
fileName: faker.random.words() + "." + faker.system.commonFileExt(), | ||
fileSize: chance.integer({ min: 0, max: 1000 * 1000 * 100 }), | ||
createAt: faker.date.past(), | ||
}; | ||
}); | ||
store.uploadTotalCount = chance.integer({ min: 0, max: 200 }); | ||
store.uploadFinishedCount = chance.integer({ min: 0, max: store.uploadTotalCount }); | ||
store.uploadStatuses = Array(store.uploadTotalCount) | ||
.fill(0) | ||
.map(() => ({ | ||
fileUUID: faker.random.uuid(), | ||
fileName: faker.random.word() + "." + faker.system.commonFileExt(), | ||
status: chance.pickone(["idle", "error", "success", "uploading"]), | ||
percent: chance.integer({ min: 0, max: 100 }), | ||
})); | ||
return store; | ||
} | ||
|
||
function fakeStoreArgTypes(): ArgTypes { | ||
return fakeStoreImplProps.reduce((o, k) => { | ||
o[k] = { table: { disable: true } }; | ||
return o; | ||
}, {} as ArgTypes); | ||
} | ||
|
||
export const Overview: Story<FakeStoreConfig> = config => { | ||
const [store] = useState(() => createFakeStore(config)); | ||
return ( | ||
<div className="ba br3 b--light-gray" style={{ height: 600, maxHeight: "80vh" }}> | ||
<CloudStorageContainer store={store} /> | ||
</div> | ||
); | ||
}; | ||
Overview.argTypes = fakeStoreArgTypes(); |
16 changes: 16 additions & 0 deletions
16
.../flat-components/src/containers/CloudStorageContainer/CloudStorageUploadItemContainer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from "react"; | ||
import { observer } from "mobx-react-lite"; | ||
import { toJS } from "mobx"; | ||
import { CloudStorageUploadItem, CloudStorageUploadItemProps } from "../../components/CloudStorage"; | ||
import { CloudStorageUploadStatus } from "../../components/CloudStorage/types"; | ||
|
||
export type CloudStorageUploadItemContainerProps = { | ||
status: CloudStorageUploadStatus; | ||
} & Pick<CloudStorageUploadItemProps, "onCancel" | "onRetry">; | ||
|
||
/** Reduce re-rendering */ | ||
export const CloudStorageUploadItemContainer = observer<CloudStorageUploadItemContainerProps>( | ||
function CloudStorageUploadItemContainer({ status, onCancel, onRetry }) { | ||
return <CloudStorageUploadItem {...toJS(status)} onCancel={onCancel} onRetry={onRetry} />; | ||
}, | ||
); |
28 changes: 28 additions & 0 deletions
28
.../flat-components/src/containers/CloudStorageContainer/CloudStorageUploadListContainer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from "react"; | ||
import { observer } from "mobx-react-lite"; | ||
import { CloudStorageUploadStatus } from "../../components/CloudStorage/types"; | ||
import { | ||
CloudStorageUploadItemContainer, | ||
CloudStorageUploadItemContainerProps, | ||
} from "./CloudStorageUploadItemContainer"; | ||
|
||
export type CloudStorageUploadListContainerProps = { | ||
statuses: CloudStorageUploadStatus[]; | ||
} & Pick<CloudStorageUploadItemContainerProps, "onCancel" | "onRetry">; | ||
|
||
export const CloudStorageUploadListContainer = observer<CloudStorageUploadListContainerProps>( | ||
function CloudStorageUploadListContainer({ statuses, onCancel, onRetry }) { | ||
return ( | ||
<> | ||
{statuses.map(status => ( | ||
<CloudStorageUploadItemContainer | ||
key={status.fileUUID} | ||
status={status} | ||
onCancel={onCancel} | ||
onRetry={onRetry} | ||
/> | ||
))} | ||
</> | ||
); | ||
}, | ||
); |
Oops, something went wrong.