fix(fe/panels): sort entries in refreshing

This commit is contained in:
hexxa 2022-02-27 11:22:39 +08:00 committed by Hexxa
parent 6bd5343673
commit 7831aa7de5
6 changed files with 74 additions and 23 deletions

View file

@ -53,7 +53,22 @@ describe("FilesPanel", () => {
expect(updater().props.filesInfo.dirPath).toEqual(newCwd);
expect(updater().props.filesInfo.isSharing).toEqual(true);
expect(updater().props.filesInfo.items).toEqual(
List(filesResps.listHomeMockResp.data.metadatas)
List([
{
name: "mock_dir",
size: 0,
modTime: "0",
isDir: true,
sha1: "",
},
{
name: "mock_file",
size: 5,
modTime: "0",
isDir: false,
sha1: "mock_file_sha1",
},
])
);
});

View file

@ -70,7 +70,22 @@ describe("State Manager", () => {
);
expect(coreState.filesInfo.items).toEqual(
List(filesResps.listHomeMockResp.data.metadatas)
List([
{
name: "mock_dir",
size: 0,
modTime: "0",
isDir: true,
sha1: "",
},
{
name: "mock_file",
size: 5,
modTime: "0",
isDir: false,
sha1: "mock_file_sha1",
},
])
);
// login
@ -182,7 +197,22 @@ describe("State Manager", () => {
expect(coreState.filesInfo.dirPath.join("/")).toEqual(sharingPath);
expect(coreState.filesInfo.isSharing).toEqual(true);
expect(coreState.filesInfo.items).toEqual(
List(filesResps.listMockResp.data.metadatas)
List([
{
name: "mock_dir",
size: 0,
modTime: "0",
isDir: true,
sha1: "",
},
{
name: "mock_file",
size: 5,
modTime: "0",
isDir: false,
sha1: "mock_file_sha1",
},
])
);
expect(coreState.sharingsInfo.sharings).toEqual(Map<string, string>());
expect(coreState.uploadingsInfo.uploadings).toEqual(List<UploadEntry>([]));

View file

@ -767,7 +767,12 @@ export class FilesPanel extends React.Component<Props, State, {}> {
};
orderBy = (columnName: string) => {
updater().sortFiles(columnName);
const order =
this.props.filesInfo.orderBy === columnName
? !this.props.filesInfo.order
: true;
updater().sortFiles(columnName, order);
this.props.update(updater().updateFilesInfo);
};

View file

@ -41,15 +41,15 @@ export class SharingsPanel extends React.Component<Props, State, {}> {
}
componentDidMount(): void {
CronTable().setInterval("refreshUploadings", {
func: updater().refreshUploadings,
CronTable().setInterval("listSharings", {
func: updater().listSharings,
args: [],
delay: 5000,
});
}
componentWillUnmount() {
CronTable().clearInterval("refreshUploadings");
CronTable().clearInterval("listSharings");
}
setLoading = (state: boolean) => {
@ -153,7 +153,8 @@ export class SharingsPanel extends React.Component<Props, State, {}> {
};
orderBy = (columnName: string) => {
updater().sortSharings(columnName);
const order = !this.props.sharingsInfo.order;
updater().sortSharings(columnName, order);
this.props.update(updater().updateSharingsInfo);
};

View file

@ -184,7 +184,8 @@ export class UploadingsPanel extends React.Component<Props, State, {}> {
};
orderBy = (columnName: string) => {
updater().sortUploadings(columnName);
const order = !this.props.uploadingsInfo.order;
updater().sortUploadings(columnName, order);
this.props.update(updater().updateUploadingsInfo);
};

View file

@ -129,6 +129,10 @@ export class Updater {
return errServer;
}
this.props.sharingsInfo.sharings = Map<string, string>(resp.data.IDs);
this.sortSharings(
this.props.sharingsInfo.orderBy,
this.props.sharingsInfo.order
);
return "";
};
@ -242,12 +246,11 @@ export class Updater {
if (status !== "") {
return status;
}
// TODO: this part is duplicated in the panel_files.tsx
const sortKeys = List<string>([
this.props.msg.pkg.get("item.type"),
this.props.msg.pkg.get("item.name"),
]);
// const sortKeys = List<string>([
// this.props.msg.pkg.get("item.type"),
// this.props.msg.pkg.get("item.name"),
// ]);
};
setItems = async (dirParts: List<string>): Promise<string> => {
@ -257,6 +260,7 @@ export class Updater {
if (listResp.status === 200) {
this.props.filesInfo.dirPath = dirParts;
this.props.filesInfo.items = List<MetadataResp>(listResp.data.metadatas);
this.sortFiles(this.props.filesInfo.orderBy, this.props.filesInfo.order);
return "";
}
this.props.filesInfo.dirPath = List<string>([]);
@ -270,6 +274,7 @@ export class Updater {
if (listResp.status === 200) {
this.props.filesInfo.dirPath = List<string>(listResp.data.cwd.split("/"));
this.props.filesInfo.items = List<MetadataResp>(listResp.data.metadatas);
this.sortFiles(this.props.filesInfo.orderBy, this.props.filesInfo.order);
return "";
}
this.props.filesInfo.dirPath = List<string>([]);
@ -880,7 +885,7 @@ export class Updater {
this.props.sharingsInfo.order = order;
};
sortFiles = (columnName: string) => {
sortFiles = (columnName: string, order: boolean) => {
let orderByKey = 0;
switch (columnName) {
case this.props.msg.pkg.get("item.name"):
@ -892,10 +897,6 @@ export class Updater {
default:
orderByKey = 2;
}
const order =
this.props.filesInfo.orderBy === columnName
? !this.props.filesInfo.order
: true;
const rows = this.props.filesInfo.items.map((item: MetadataResp): Row => {
return {
val: item,
@ -913,9 +914,8 @@ export class Updater {
this.updateItems(sortedFiles);
};
sortUploadings = (columnName: string) => {
sortUploadings = (columnName: string, order: boolean) => {
const orderByKey = 0;
const order = !this.props.uploadingsInfo.order;
const rows = this.props.uploadingsInfo.uploadings.map(
(uploading: UploadEntry): Row => {
return {
@ -933,9 +933,8 @@ export class Updater {
this.updateUploadings(sorted);
};
sortSharings = (columnName: string) => {
sortSharings = (columnName: string, order: boolean) => {
const orderByKey = 0;
const order = !this.props.sharingsInfo.order;
const rows = this.props.sharingsInfo.sharings
.keySeq()
.map((sharingPath: string): Row => {