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: Org Browser refresh works for custom objects with a namespace #5403

Merged
merged 15 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
7 changes: 5 additions & 2 deletions packages/salesforcedx-utils-vscode/src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ export const isNullOrUndefined = (object: any): object is null | undefined => {
};

export const extractJsonObject = (str: string): any => {
const jsonString = str.substring(str.indexOf('{'), str.lastIndexOf('}') + 1);
const isPlainText = str.includes('{') ? false : true;
peternhale marked this conversation as resolved.
Show resolved Hide resolved
const jsonString = isPlainText
? str
: str.substring(str.indexOf('{'), str.lastIndexOf('}') + 1);

return JSON.parse(jsonString);
return isPlainText ? jsonString : JSON.parse(jsonString);
};

// There's a bug in VS Code where, after a file has been renamed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ export class ComponentUtils {
if (!isNullOrUndefined(cmpArray)) {
cmpArray = cmpArray instanceof Array ? cmpArray : [cmpArray];
for (const cmp of cmpArray) {
const { fullName, manageableState } = cmp;
const { fullName, manageableState, namespacePrefix } = cmp;
if (
!isNullOrUndefined(fullName) &&
validManageableStates.has(manageableState)
) {
components.push(fullName);
components.push(
CristiCanizales marked this conversation as resolved.
Show resolved Hide resolved
namespacePrefix ? `${namespacePrefix}__${fullName}` : fullName
);
}
}
}
Expand Down Expand Up @@ -128,9 +130,8 @@ export class ComponentUtils {
if (folderName) {
metadataQuery.folder = folderName;
}
const metadataFileProperties = await connection.metadata.list(
metadataQuery
);
const metadataFileProperties =
await connection.metadata.list(metadataQuery);
const result = { status: 0, result: metadataFileProperties };
const jsonResult = JSON.stringify(result, null, 2);
fs.writeFileSync(componentsPath, jsonResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ import {
} from './index';

export class MetadataOutlineProvider
implements vscode.TreeDataProvider<BrowserNode> {
implements vscode.TreeDataProvider<BrowserNode>
{
private defaultOrg: string | undefined;
private toRefresh: boolean = false;

private internalOnDidChangeTreeData: vscode.EventEmitter<
BrowserNode | undefined
> = new vscode.EventEmitter<BrowserNode | undefined>();
public readonly onDidChangeTreeData: vscode.Event<
BrowserNode | undefined
> = this.internalOnDidChangeTreeData.event;
public readonly onDidChangeTreeData: vscode.Event<BrowserNode | undefined> =
this.internalOnDidChangeTreeData.event;

constructor(defaultOrg: string | undefined) {
this.defaultOrg = defaultOrg;
Expand Down Expand Up @@ -154,7 +154,7 @@ export class MetadataOutlineProvider
}
}

export function parseErrors(error: any): Error {
export const parseErrors = (error: any): Error => {
peternhale marked this conversation as resolved.
Show resolved Hide resolved
try {
const errMsg = typeof error === 'string' ? error : error.message;
const e = extractJsonObject(errMsg);
Expand All @@ -177,4 +177,4 @@ export function parseErrors(error: any): Error {
} catch (e) {
return new Error(e);
}
}
};
11 changes: 8 additions & 3 deletions packages/salesforcedx-vscode-core/src/orgBrowser/nodeTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ export enum NodeType {
Folder = 'folder'
}

export class BrowserNode extends vscode.TreeItem
implements RetrieveMetadataTrigger {
export class BrowserNode
extends vscode.TreeItem
implements RetrieveMetadataTrigger
{
public toRefresh: boolean = false;
public readonly fullName: string;
public suffix?: string;
Expand Down Expand Up @@ -76,9 +78,12 @@ export class BrowserNode extends vscode.TreeItem
}

fullNames.forEach(fullName => {
const hasNamespacePrefix = fullName.includes('__');
CristiCanizales marked this conversation as resolved.
Show resolved Hide resolved
const label =
this.type === NodeType.Folder
? fullName.substr(fullName.indexOf('/') + 1)
? fullName.substring(fullName.indexOf('/') + 1)
: hasNamespacePrefix
? fullName.substring(fullName.indexOf('_') + 2)
: fullName;
const child = new BrowserNode(label, type, fullName);
child._parent = this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ describe('build metadata components list', () => {
fullName: 'fakeName1',
type: 'ApexClass',
manageableState: 'unmanaged'
},
{
fullName: 'fakeName3',
type: 'ApexClass',
manageableState: 'unmanaged',
namespacePrefix: 'sf_namespace'
peternhale marked this conversation as resolved.
Show resolved Hide resolved
}
]
});
Expand All @@ -160,6 +166,7 @@ describe('build metadata components list', () => {
if (!isNullOrUndefined(fullNames)) {
expect(fullNames[0]).to.equal('fakeName1');
expect(fullNames[1]).to.equal('fakeName2');
expect(fullNames[2]).to.equal('sf_namespace__fakeName3');
expect(readFileStub.called).to.equal(false);
}
});
Expand All @@ -179,6 +186,12 @@ describe('build metadata components list', () => {
fullName: 'fakeName1',
type: 'ApexClass',
manageableState: 'unmanaged'
},
{
fullName: 'fakeName3',
type: 'ApexClass',
manageableState: 'unmanaged',
namespacePrefix: 'sf_namespace'
}
]
});
Expand All @@ -192,6 +205,7 @@ describe('build metadata components list', () => {
if (!isNullOrUndefined(fullNames)) {
expect(fullNames[0]).to.equal('fakeName1');
expect(fullNames[1]).to.equal('fakeName2');
expect(fullNames[2]).to.equal('sf_namespace__fakeName3');
expect(readFileStub.called).to.equal(true);
}
});
Expand Down
Loading