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

Enhance Object Browser filter's Object field #1780

Merged
merged 18 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
22 changes: 21 additions & 1 deletion src/api/IBMiContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,25 @@ export default class IBMiContent {
throw new Error(`Library ${library} does not exist.`);
}

const object = (filters.object && filters.object !== `*` ? filters.object.toUpperCase() : `*ALL`);
let hasEndsWith = false;
const objects = filters.object?.split(',')
.map(pattern => {
if (pattern.startsWith('*')) {
hasEndsWith = true;
return (name: string) => name.endsWith(pattern.substring(1));
}
else if (pattern.endsWith('*')) {
return (name: string) => name.startsWith(pattern.substring(0, pattern.length - 1));
}
else {
return (name: string) => name === pattern;
}
})
|| [];

const filterNames = objects.length && (objects.length > 1 || hasEndsWith) ? (file: IBMiFile) => objects.some(test => test(file.name)) : undefined;

const object = filters.object && !filterNames && filters.object !== `*` ? filters.object.toUpperCase() : `*ALL`;
const sourceFilesOnly = (filters.types && filters.types.includes(`*SRCPF`));

const tempLib = this.config.tempLibrary;
Expand All @@ -473,6 +491,7 @@ export default class IBMiContent {
text: String(object.PHTXT),
count: Number(object.PHNOMB),
} as IBMiFile))
.filter(object => !filterNames || filterNames(object))
.sort((a, b) => a.library.localeCompare(b.library) || a.name.localeCompare(b.name));
} else {
const objectTypes = (filters.types && filters.types.length ? filters.types.map(type => type.toUpperCase()).join(` `) : `*ALL`);
Expand All @@ -494,6 +513,7 @@ export default class IBMiContent {
attribute: String(object.ODOBAT),
text: String(object.ODOBTX)
} as IBMiFile))
.filter(object => !filterNames || filterNames(object))
.sort((a, b) => {
if (a.library.localeCompare(b.library) != 0) {
return a.library.localeCompare(b.library)
Expand Down
9 changes: 8 additions & 1 deletion src/webviews/filters/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ConnectionConfiguration } from "../../api/Configuration";
import { CustomUI } from "../../api/CustomUI";
import { Tools } from "../../api/Tools";
import { instance } from "../../instantiate";

export async function editFilter(filter?: ConnectionConfiguration.ObjectFilters, copy = false) {
Expand Down Expand Up @@ -41,7 +42,7 @@ export async function editFilter(filter?: ConnectionConfiguration.ObjectFilters,
const page = await new CustomUI()
.addInput(`name`, `Filter name`, `The filter name should be unique.`, { default: filter.name })
.addInput(`library`, `Library`, `Library name. Cannot be generic name with an asterisk.`, { default: filter.library })
.addInput(`object`, `Object`, `Object name. Can be generic name with an asterisk. For example: <code>*</code>, or <code>Q*</code>.`, { default: filter.object })
.addInput(`object`, `Objects`, `Object names. Comma-separated list of object names. Name can starts or ends with an asterisk (i.e. select names that <code>end with</code> or <code>start with</code>). Examples: <code>*</code>, <code>Q*</code> or <code>*SRC</code>.`, { default: filter.object })
.addInput(`types`, `Object type filter`, `A comma delimited list of object types. For example <code>*ALL</code>, or <code>*PGM, *SRVPGM</code>. <code>*SRCPF</code> is a special type which will return only source files.`, { default: filter.types.join(`, `) })
.addInput(`member`, `Member`, `Member name. Can be multi-generic value. Examples: <code>*CL</code> or <code>CL*ABC*</code>. A single <code>*</code> will return all members.`, { default: filter.member })
.addInput(`memberType`, `Member type`, `Member type. Can be multi-generic value. Examples: <code>RPG*</code> or <code>SQL*LE</code>. A single <code>*</code> will return all member types.`, { default: filter.memberType || `*` })
Expand All @@ -64,6 +65,12 @@ export async function editFilter(filter?: ConnectionConfiguration.ObjectFilters,
data[key] = String(data[key]).split(`,`).map(item => item.trim().toUpperCase()).filter(item => item !== ``);
break;
case `object`:
data[key] = (String(data[key].trim()) || `*`)
.split(',')
.map(o => o.trim().toLocaleUpperCase())
.filter(Tools.distinct)
.join(",");
break;
case `member`:
case `memberType`:
data[key] = String(data[key].trim()) || `*`;
Expand Down