Skip to content

Fix sorting of items in Projects Explorer #1246

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

Merged
merged 1 commit into from
Oct 6, 2023
Merged
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
57 changes: 24 additions & 33 deletions src/explorer/models/projectRootNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,46 +68,37 @@ export class ProjectRootNode extends RootNode {
return api
.actionQuery(query, parameters)
.then((data) => data.result.content.map((e) => e.Name))
.then((entries: string[]) => {
// Sort the files and folders separately an case-insensitively
const folders: string[] = [];
const files: string[] = [];
const collator = new Intl.Collator("en");
for (const entry of entries) entry.includes(".") ? files.push(entry) : folders.push(entry);
return [...folders.sort(collator.compare), ...files.sort(collator.compare)];
})
.then((entries: string[]) =>
entries
.sort((a, b) => {
if ((a.match(/\./g) || []).length > (b.match(/\./g) || []).length) {
return 1;
} else if ((a.match(/\./g) || []).length < (b.match(/\./g) || []).length) {
return -1;
entries.map((entry) => {
const fullName = this.fullName.length
? `${this.fullName}${this.category == "CSP" ? "/" : "."}${entry}`
: entry;
if (this.category == "CSP") {
if (entry.includes(".")) {
return new CSPFileNode(entry, fullName, this.options);
} else {
return 0;
return new ProjectRootNode(entry, fullName, "dataNode:cspApplication", this.category, this.options, true);
}
})
.map((entry) => {
const fullName = this.fullName.length
? `${this.fullName}${this.category == "CSP" ? "/" : "."}${entry}`
: entry;
if (this.category == "CSP") {
if (entry.includes(".")) {
return new CSPFileNode(entry, fullName, this.options);
} else {
if (entry.includes(".")) {
if (["mac", "int", "inc"].includes(entry.split(".").pop().toLowerCase())) {
return new RoutineNode(entry, fullName, this.options);
} else {
return new ProjectRootNode(
entry,
fullName,
"dataNode:cspApplication",
this.category,
this.options,
true
);
return new ClassNode(entry, fullName, this.options);
}
} else {
if (entry.includes(".")) {
if (["mac", "int", "inc"].includes(entry.split(".").pop().toLowerCase())) {
return new RoutineNode(entry, fullName, this.options);
} else {
return new ClassNode(entry, fullName, this.options);
}
} else {
return new ProjectRootNode(entry, fullName, "dataNode:packageNode", this.category, this.options);
}
return new ProjectRootNode(entry, fullName, "dataNode:packageNode", this.category, this.options);
}
})
}
})
);
}
public getItems4Export(): Promise<string[]> {
Expand Down