Skip to content

Commit

Permalink
#25 - translate resource
Browse files Browse the repository at this point in the history
  • Loading branch information
sivaavkd committed Jul 5, 2021
1 parent d5f9799 commit 054321d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bb-tech/ra-treemenu",
"version": "1.0.5",
"version": "1.0.6",
"description": "A tree-like menu implementation for react-admin applications.",
"author": "BigBasket Tech",
"repository": "BigBasket/ra-treemenu",
Expand Down Expand Up @@ -32,9 +32,9 @@
"deploy": "gh-pages -d examples/ra-3_x/build"
},
"peerDependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-admin": "~3.0.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-admin": "^3.0.0",
"@material-ui/core": "~1.4.0",
"@material-ui/icons": "~1.0.0",
"prop-types": "^15.7.2",
Expand Down
25 changes: 17 additions & 8 deletions src/TreeMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,26 @@ const Menu = (props) => {
resource.options.hasOwnProperty('menuParent') &&
resource.options.menuParent == parentResource.name
);
const geResourceName = (slug) => {
if (!slug) return;
var words = slug.toString().split('_');
for (var i = 0; i < words.length; i++) {
var word = words[i];
words[i] = word.charAt(0).toUpperCase() + word.slice(1);
}
return words.join(' ');
}

const getPrimaryTextForResource = (resource) => {
if (resource.options.label)
return translate(resource.options.label);
else {
/**
* Capitalize in case of default label
*/
let primaryText = translate(resource.name);
return primaryText.charAt(0).toUpperCase() + primaryText.slice(1);
let resourcename = '';
if (resource.options && resource.options.label)
resourcename = resource.options.label;
else if (resource.name) {
resourcename = translate(`resources.${resource.name}.name`);
if (resourcename.startsWith('resources.'))
resourcename = geResourceName(resource.name);
}
return resourcename;
}

const MenuItem = (resource) => (
Expand Down

0 comments on commit 054321d

Please sign in to comment.