Created
May 31, 2020 09:09
-
-
Save dhaniksahni/ed6515f66b4ab0ed135f0cdaacac692a to your computer and use it in GitHub Desktop.
Metadata Information using Lightning Tree Node
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
<template> | |
<h2>Hkhdshsa</h2> | |
<lightning-card title="Used Custom Metadata" icon-name="custom:custom10"> | |
<div class="slds-grid"> | |
<div class="slds-size--1-of-1"> | |
<div> | |
<lightning-button label="Export in CSV" onclick={handleFileDownload}></lightning-button> | |
</div> | |
</div> | |
</div> | |
<div class="slds-m-top_medium slds-m-bottom_x-large"> | |
<!-- Simple --> | |
<div class="slds-p-around_medium lgc-bg"> | |
<lightning-tree-grid | |
columns={columns} | |
data={gridData} | |
key-field="MetadataComponentName" | |
></lightning-tree-grid> | |
</div> | |
</div> | |
</lightning-card> | |
</template> |
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
import { LightningElement,track,wire,api } from 'lwc'; | |
import getMetadata from '@salesforce/apex/MetadataController.getMetadata'; | |
export const COLUMNS_DEFINITION = [ | |
{ | |
type: 'text', | |
fieldName: 'MetadataComponentName', | |
label: 'Metadata Name', | |
initialWidth: 300, | |
}, | |
{ | |
type: 'text', | |
fieldName: 'RefMetadataComponentType', | |
label: 'Ref Metadata Type', | |
}, | |
{ | |
type: 'text', | |
fieldName: 'RefMetadataComponentName', | |
label: 'Reference Metadata Name', | |
}, | |
]; | |
export default class Dependencynfo extends LightningElement { | |
@track gridData= []; | |
@track columns=COLUMNS_DEFINITION; | |
error; | |
@wire(getMetadata) | |
wiredObject({ error, data }) { | |
if (data) { | |
var result=[]; | |
data.forEach(child => { | |
var ch=JSON.parse(JSON.stringify(child)); | |
if(ch.children!==undefined && ch.children.length>0) | |
{ | |
ch._children=ch.children; | |
} | |
ch.children=null; | |
result.push(ch); | |
}); | |
this.gridData=result; | |
this.error = undefined; | |
} else if (error) { | |
this.error = error; | |
} | |
} | |
handleFileDownload(event) | |
{ | |
if(this.gridData!==undefined) | |
{ | |
let csvContent = "data:text/csv;charset=utf-8,"; | |
this.gridData.forEach(function(rowArray) { | |
let row = rowArray.MetadataComponentName+","+rowArray.RefMetadataComponentType+","+rowArray.RefMetadataComponentName+","; | |
console.log(rowArray._children); | |
if(rowArray._children!==undefined) | |
{ | |
rowArray._children.forEach(function(child) { | |
csvContent += row + "\r\n"; | |
row = child.MetadataComponentName+","+child.RefMetadataComponentType+","+child.RefMetadataComponentName+","; | |
}); | |
} | |
csvContent += row + "\r\n"; | |
}); | |
var encodedUri = encodeURI(csvContent); | |
var link = document.createElement("a"); | |
link.setAttribute("href", encodedUri); | |
link.setAttribute("download", "File.csv"); | |
document.body.appendChild(link); | |
link.click(); | |
} | |
} | |
} |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata"> | |
<apiVersion>48.0</apiVersion> | |
<isExposed>true</isExposed> | |
<targets> | |
<target>lightningCommunity__Page</target> | |
<target>lightningCommunity__Default</target> | |
<target>lightning__RecordPage</target> | |
<target>lightning__AppPage</target> | |
<target>lightning__HomePage</target> | |
</targets> | |
</LightningComponentBundle> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment