Seems like a simple thing. How do I put a title on the navbar? Here's my App.js:
import React from 'react';
import { Admin, Resource } from 'react-admin';
import { UserList } from './Users';
import { ItemList, ItemEdit, ItemCreate } from './Items';
import { ProductTypeList, ProductTypeEdit, ProductTypeCreate } from './ProductType'
import Dashboard from './Dashboard'
import jsonServerProvider from 'ra-data-json-server';
import dataProvider from './dataProvider';
import ItemIcon from '#material-ui/icons/ViewListRounded';
import ProductTypeIcon from '#material-ui/icons/LocalOffer';
import UserIcon from '#material-ui/icons/Group';
import authProvider from './authProvider'
const App = () => (
<Admin
dashboard={Dashboard}
authProvider={authProvider}
dataProvider={dataProvider} >
<Resource
name="items"
list={ItemList}
edit={ItemEdit}
create={ItemCreate}
icon={ItemIcon} />
{<Resource
name="productTypes"
options={{ label: 'Product Types' }}
list={ProductTypeList}
edit={ProductTypeEdit}
create={ProductTypeCreate}
icon={ProductTypeIcon} />}
<Resource
name="users"
list={UserList}
icon={UserIcon} />
</Admin >
);
export default App;
Running react-admin version 3.4.2. In the tutorial it shows "React Admin" as the title after adding the Dashboard. But after recreating a fresh app using npm create-react-app and going through the tutorial, I don't see a title in the navbar. Is this something that should be possible out of the box or do I need to create a custom navbar?
Train (above) led me to think of the component. I imported it and used it within and set title="My Title" and it did show in the navbar. Maybe I misread the docs, but I don't remember seeing anything about , just the title= attribute of , like so:
<Admin
// layout={CustomLayout}
dashboard={Dashboard}
authProvider={authProvider}
dataProvider={dataProvider} >
<Title title="g3tools Admin" />
<Resource
name="items"
list={ItemList}
edit={ItemEdit}
create={ItemCreate}
icon={ItemIcon} />
But, thankfully, it gets me to the next step: Now the title shows up in the navbar but when I choose a resource from the left menu, the resource name appends to the title.
Any suggestions on how to avoid the resource title cramming into the admin title? I'm sure I'm missing something obvious. Options would be: a) Dynamically ad a space or dash after title when resource title is displayed, or b) don't display the resource title (how would I do that?)
I think ultimately, I'd rather have a breadcrumb or show the resource title in the center of the navbar, but maybe I'll need a custom navbar for that?? Any guidance is welcome.
UPDATE:
I see in the docs for Customizing the AppBar how to not show the individual resource page title: Just remove the id="react-admin-title" from the component and then add text to the element:
<AppBar {...props}>
<Typography
variant="h6"
color="inherit"
className={classes.title}
>g3tools Admin</Typography>
</AppBar>
take a look in the docs, try this
<Admin
// add the title prop below
title="my page title"
dashboard={Dashboard}
authProvider={authProvider}
dataProvider={dataProvider} >
Related
In the following code, you can see My layout component:
Although I followed the instructions in the link below, I could not show modal the ApiaryUpdateList component on the ApiaryList component So That This component was visible behind the ApiaryUpdateList component.
https://codesandbox.io/s/react-router-modal-gallery-utwzzo?from-embed=&file=/example.js:3645-3828
layout component is:
import React from "react";
import { Route, Switch, Redirect, withRouter,useLocation } from "react-router-dom";
import useStyles from "./styles";
import ApiaryList from "../../pages/candoProject/ApiaryList/ApiaryList";
import ApiaryUpdateList from "../Form/ApiaryList/ApiaryUpdateList";
function Layout(props) {
let location = useLocation();
let background = location.state && location.state.background;
console.log("background",background)
console.log("location",location)
var classes = useStyles();
return (
<div className={classes.root}>
<div className={classes.fakeToolbar} />
<Switch location={background || location}>
<Route path="/app/ApiaryList/" component={ApiaryList} />
<Route path="/app/modal/:id" component={ApiaryUpdateList} />
</Switch>
{background && <Route path="/app/modal/:id" component={<ApiaryUpdateList />} />}
</div>
);
}
export default withRouter(Layout);
and you can see my ApiaryList component :
In this component, I have received the id correctly from API and I have passed it correctly to the URL with the help of Link React Reactor router component.
<Link
to={{pathname:`/app/modal/${rowData._id}` , state: {background: location }}}
onClick={handleClickEdit("body")}
>
<Edit style={{ marginLeft: "16px" }} />
ویرایش
</Link>
the first picture of ApiaryList component:
and the second picture of ApiaryUpdateList component:
and the third picture :
But I have to follow the third picture from Zeppelin site, but according to the above description, when I run my code, it shows me the second image and it leaves the modal mode and does not show the ApiaryList component in the background .
I want to DRY the way my <Resource /> components are organized in my project. This way, my App.jsx file won't be bloated by a lot of code.
For example, let's say I have a <EmployeeResource /> component like this:
// ./resources/Employee.jsx
import React from "react";
import { Resource } from "react-admin";
const EmployeeResource = (props) => <Resource {...props} name="employees" />;
export default EmployeeResource;
Now I want to use it in my <Admin /> component like this:
// ./App.jsx
// other imports
import EmployeeResource from "./resources/Employee";
const App = () => (
<Admin
{...otherNecessaryProps}
>
<EmployeeResource />
</Admin>
);
Even if it's registered by react-admin and that I can see its link in the sidebar, its route doesn't work. If I click on the menu item I see a Not Found page, but if I navigate to /undefined in my browser, now I see its content.
Is there a way to DRY many <Resource /> components in one sub folder?
I have a weird issue with Lottie animations in React/Gatsby. I've tried many plugins like react-lottie, lottie-react, lottie-web etc. They all start bottlenecking the dom while navigating back and forth pages.
I've made an example with the issue: https://elegant-aryabhata-490c95.netlify.app/
If you navigate between the pages Go to page 2 and Go back to the homepage soon enough the DOM stops and the animation starts rendering extra stuff as well.
I am rendering the animations like so:
import * as React from "react"
import { Link } from "gatsby"
import Layout from "../components/layout"
import SEO from "../components/seo"
import Lottie from "lottie-react"
import contactAnimation from "../components/assets/contact.json"
const SecondPage = () => (
<Layout>
<SEO title="Page two" />
<h1>Hi from the second page</h1>
<p>Welcome to page 2</p>
<Link to="/">Go back to the homepage</Link>
<Lottie animationData={contactAnimation} style={{ width: "600px" }} />
</Layout>
)
export default SecondPage
It looks like a memory leak or something but have no idea how to debug this.
Well, I sorted it out myself, turns out it is a memory leak and happens if some of the Lottie animations us a 'repeater'
Solved it by stringify the JSON: const contactAnimation = JSON.parse(JSON.stringify(data))
So full code becomes:
import * as React from "react"
import { Link } from "gatsby"
import Layout from "../components/layout"
import SEO from "../components/seo"
import Lottie from "lottie-react"
import data from "../components/assets/contact.json"
const SecondPage = () => {
const contactAnimation = JSON.parse(JSON.stringify(data))
return (
<Layout>
<SEO title="Page two" />
<h1>Hi from the second page</h1>
<p>Welcome to page 2</p>
<Link to="/">Go back to the homepage</Link>
<Lottie animationData={contactAnimation} style={{ width: "600px" }} />
</Layout>
)
}
export default SecondPage
I am having trouble getting images to display on github pages. I am using a repository based page. I have added in a simple img tag with in the JSX and tried using the method described in the Gatsby documentation. I feel like I'm missing something obvious.
Here is the code
import React, { useContext } from 'react';
import AnchorLink from 'react-anchor-link-smooth-scroll';
import { ThemeContext } from 'providers/ThemeProvider';
import { Header } from 'components/theme';
import { Container, Button } from 'components/common';
import dev from 'assets/illustrations/dev.svg';
import { Wrapper, IntroWrapper, Details, Thumbnail } from './styles';
import { withPrefix } from 'gatsby'
import HeadShotPlaceHolder from 'assets/images/HeadShotPlaceHolder.jpeg'
export const Intro = () => {
const { theme } = useContext(ThemeContext);
console.log(HeadShotPlaceHolder)
return (
<Wrapper>
<Header />
<IntroWrapper as={Container}>
<Details theme={theme}>
{/* <h1>Hi There!</h1> */}
<h1>Pamela Welch</h1>
{/* <h4>I’m John and I’m a JAMStack engineer!</h4> */}
<h4>A proven professional with extensive experience in all facets of communication and marketing.</h4>
<Button as={AnchorLink} href="#contact">
Hire me
</Button>
</Details>
<Thumbnail>
{/* This is where the image tag giving me the problem is */}
<img src={ withPrefix(HeadShotPlaceHolder) } alt="I’m John and I’m a JAMStack engineer!" />
</Thumbnail>
</IntroWrapper>
</Wrapper>
);
};
and here is the result
Image Link Broken
Your code looks good, your image has its path prefixed. However, to make it effective you need to run the following snippet in the deploy command:
{
"scripts": {
"deploy": "gatsby build --prefix-paths && gh-pages -d public"
}
}
Note the --prefix-paths flag.
More information in How Gatsby Works in GitHub Pages.
I have problems importing UI libraries, I had problem with ant design library so I decided to try different one, now I have problem importing Grommet.
What am I doing wrong? I added dependencies according documentation and added examples included in documentation yet still not working.
I am trying to execute this code from documentation
But it doesn't look the same at all
I work with codesandbox.io, here is link for the code on it
import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
import Heading from "grommet/components/Heading";
import Box from "grommet/components/Box";
import Header from "grommet/components/Header";
import Title from "grommet/components/Title";
import Search from "grommet/components/Search";
import Menu from "grommet/components/Menu";
import Anchor from "grommet/components/Anchor";
import "grommet-css";
class HelloWorldApp extends React.Component {
render() {
return (
<div>
<Header>
<Title>Sample Title</Title>
<Box flex={true} justify="end" direction="row" responsive={false}>
<Search
inline={true}
fill={true}
size="medium"
placeHolder="Search"
dropAlign={{right: "right"}}
/>
<Menu dropAlign={{right: "right"}}>
<Anchor href="#" className="active">
First
</Anchor>
<Anchor href="#">Second</Anchor>
<Anchor href="#">Third</Anchor>
</Menu>
</Box>
</Header>
<Box>
<Heading>
Hello, I'm a Grommet Component styled with
grommet-css
</Heading>
</Box>
</div>
);
}
}
var element = document.getElementById("root");
ReactDOM.render(<HelloWorldApp />, element);
So according to your code:
<Menu dropAlign={{right: "right"}}>
was missing the icon attribute, without which the Menu component directly renders the Anchor, the menu-items component.
add import for the icon of your choosing, i.e: Actions ( from the example )
import Actions from 'grommet/components/icons/base/Actions';
add the icon attribute to the Menu component:
<Menu
icon={<Actions />}
dropAlign={{ right: 'right' }}
>
<Anchor href="#" className="active">First</Anchor>
<Anchor href="#">Second</Anchor>
<Anchor href="#">Third</Anchor>
</Menu>
here's a codesandbox.io link which fixes your issue:
https://codesandbox.io/s/237xo7y48p