Tuesday, November 23, 2021

Ninja - React Basic 2 - Component

Component


Let's have this structure

App.js

Navbar.js

BlogDetails.js

Sidebar.js

Categories.js

Tags.js

To Create  a new component - create new js file, better to have inside folder

create "component" folder inside "src" folder

create "Navbar.js"

src/component/Navbar.js


create code

rcc tab


will generate

------------------------

import React, { Component } from 'react';


class Navbar extends Component {

    render() {

        return (

            <div>            

            </div>

        );

    }

}


export default Navbar;


let's write some code block


class Navbar extends Component {

    render() {

        return (

            <nav className="navbar">

                <h1>Dojo blog</h1>

               <div className="links">

                    <a href="/">Home</a>

                    <a href="/create">New Blog</a>

                </div> 

            </nav>

        );

    }

}


Now let's import and use, inside App.js

once you import, you can nest it inside App.js


import Navbar from './component/Navbar'


add self close Navbar tab just above content

 <Navbar />

 

 

Code looks like

-------------


import logo from './logo.svg';

import './App.css';

import Navbar from './component/Navbar'


function App() {

  return (

    <div className="App">

      <Navbar />

      <div className="content">

        <h1>App Component</h1>

      </div>

    </div>

  );

}


export default App;



-------------


Now you can see, Nav bar loaded

http://localhost:3000/


Now let's  create a new component for "Home" page

create home.js file and continue above steps


home.js

rcc tab


------------------------------------------

import React, { Component } from 'react';


class Home extends Component {

    render() {

        return (

            <div> 

            </div>

        );

    }

}


export default Home;



--------------------------------------------


just a add dive tag with className home

add a h2 tag with homepage



import React, { Component } from 'react';


class Home extends Component {

    render() {

        return (

            <div className='home'>

                <h2>Home Page</h2>

            </div>

        );

    }

}


export default Home;



Now you can import in App.js --> 

just remove h1 tag and use <Home />



import logo from './logo.svg';

import './App.css';

import Navbar from './component/Navbar';

import Home from './component/Home';


function App() {

  return (

    <div className="App">

      <Navbar />

      <div className="content">

        <Home />

      </div>

    </div>

  );

}

export default App;

-----------------


Just like that, you can create multiple components , export them and import and use







 



Ninja - React Basic 1

https://www.youtube.com/watch?v=kVeOpcw4GWY&list=PL4cUxeGkcC9gZD-Tvwfod2gaISzfRiP9d&index=2

npx create-react-app dojo-blog


node_modules   - all dependencies

puic - public files

src -  code you write mostly goes here

App.js

index.js -  kick start app


cd dojo-blog

code 

this will open new project inside VS code


we don't need reportWebVitals();

you can remove all


Loaded App.js --> which import App from './App';   in index.js

What you see in browser inside  --> function App() ...

http://localhost:3000/


npm run start

npm install --legacy-peer-deps


function App() ....

return  --> jsx statement which will be convert to javascript

eg: className will  convert to class


Keep div with App and remove all inside <div className="App"> tag

<div className="App">


<div>


Now you should see a blank page 

http://localhost:3000/


Now add below code snipet inside App div tag


<div className="content">

   <h1>App Component</h1>

</div>


you can see, "App Component" h1 tag displayed in browser

http://localhost:3000/


Note: export default App;

-------------------------

right bottom of App.js

to use, we need to export

eg: we are using this inside index.js

here we import

import App from './App';


then after we use inside render. Rendered to DOM


ReactDOM.render(

  <React.StrictMode>

    <App />

  </React.StrictMode>,

  document.getElementById('root')

);

Wednesday, November 3, 2021

Create Table Basic - react-table (step 1)

 1. create sample app table1

npx create-react-app table1

2. verify the sample app

cd table1

npm start

3. add reat-table

npm install react-table

4. we have install the dependancy, now let's create mock values

https://mockaroo.com/

and create data as needed and save and download. 

Create a new folder inside your app 'component'

new data file 'MOCK_DATA.json'

5. create 'column.js' to add column values

// define labels for wach column
export const COLUMNS = [
    {
        Header: 'Id',
        accessor: 'id'
    },
    {
        Header: 'First Name',
        accessor:'first_name'
    },
    {
        Header: 'Last Name',
        accessor:'last_name'
    },
    {
        Header: 'Date of Birth',
        accessor:'date_of_birth'
    },
    {
        Header: 'Country',
        accessor:'country'
    },
    {
        Header: 'Phone',
        accessor:'phone'
    },
]


6. create 'BasicTable.js' to  make table


import React, { ComponentuseMemo } from 'react';
import {useTablefrom 'react-table';
import MOCK_DATA from './MOCK_DATA.json';
import COLUMNS from './columns';

class BasicTable extends Component {

    const columns = useMemo(() => COLUMNS,[])
    const data = useMemo(() => MOCK_DATA,[])

    // useTable({
    //     // columns: COLUMNS,
    //     // data: MOCK_DATA
    //     // can rewrite as

    //     // columns: columns,
    //     // data: data
    //     // further we can simplify
    //     columns,
    //     data
        
    // })

    // next we create a const to store the useTable
    const tableInstance useTable({
        columns,
        data
    })

    //step6 - render table props
    const {
        getTableProps,
        getTableBodyProps,
        headerGroups,
        rows,
        prepareRow
    } = tableInstance

    render() {
        return (
            // step 4 - define table structure
            // convert div tag to table tag with <thead> and tbody
            // then add <tr> to both thead and tbody to add a row
            // in header use <th> and in body use <td> to add values respectively

            <table>
                <thead>
                    <tr>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td></td>
                    </tr>
                </tbody>
            </table>
        );
    }
}

export default BasicTable;

Friday, October 15, 2021

javax.persistence.PersistenceException : (should be mapped with insert="false" update="false")

 Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Repeated column in mapping for entity: com.model.ImprovementInitiative column: investmentQualitative (should be mapped with insert="false" update="false")

Solution

column is repeated.

name of the column is "investmentQualitative "

search that column name in your Model or POJO class "ImprovementInitiative "

remove the repeated or duplicate values

In simple you are trying to create two columns with same name 


Running Spring boot App command line with Maven

 

mvn spring-boot:run
for gradle
./gradlew bootRun

Wednesday, September 15, 2021

BCryptHash could not be located - MongoDB

 When you try to start mongodb using "mongod.exe" you might get this error relating to 'BCryptHash"

This error comes cause of mongodb version does not support to your windows or OS of the machine. If you are using windows server, check whether it is compatible with your server version

you  can find the compatibility with below link

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/#platform-support

 

Import certificate to java Key store

 you can use keytool  to install a certificate to keystore. This is needed as eg: when you access a details from Jira site you need to install certificate of jira site to your local java key store.

Let's  say you need to extract details from your Jira production server.

1. save the certificate of the site via browser. you can click the lock sign left with the address bar.


 after that Click Certificate

Go to "Details" tab 

and Click "Copy to File"

let's assume you save the certificate as "jiraProd.cer". Note: cer extension will  automatically given when saving.

2. install certificate use below command

keytool -import -alias jiraProd -keystore "C:\SW\openlogic-openjdk-11\lib\security\cacerts" -file C:\SW\Certs\jiraProd.cer

keytool - tool use to import certicate

alias name given as "jiraProd " . you can verify your certificate after installation by this name

-alias jiraProd   

path to the keysore file

-keystore "C:\SW\openlogic-openjdk-11\lib\security\cacerts"     

 your certificate file or path to certificate file

-file C:\SW\Certs\jiraProd.cer