npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

engine-table-configs

v0.1.30

Published

## main component

Downloads

75

Readme

engine table config

main component

import React, {useCallback, useState} from 'react'
import {ConfigTable} from "../../libraries"
import {orderBy} from "lodash"
import ExampleRow from "./ExampleRow/ExampleRow"
import {Box, Button} from "@mui/material"
import ExampleDialog from "../ExampleDialog/ExampleDialog"

function Example() {
    const config = [
        {field: "machine.mcid", width: '2%', title: '', type: 'selection'},
        {field: "machine.mcid", width: '6%', title: '#'},
        {field: "machine.mcSname", width: '22%', title: 'Short name'},
        {field: "machine.mcLname", width: '20%', title: 'Long name'},
        {field: "machineType.mtSname", width: '10%', title: 'Type'},
        {field: "machine.asUptimeStd", width: '10%', title: 'Uptime Standard'},
        {field: "breakGroup.name", width: '20%', title: 'Break Group'},
        {field: "machine.active", width: '5%', title: 'Active'},
        {field: "breakGroup.name", width: '5%', title: 'Break Group', type: 'custom'},
    ]
    const [sortField, setSortField] = useState(config[1].field)
    const [isAscSort, setIsAscSort] = useState(true)
    const [, setLatestUpdate] = useState(new Date())

    const headerRowClick = useCallback((field) => {
        setSortField(field)
        setIsAscSort(!isAscSort)
    }, [setSortField, setIsAscSort, isAscSort])

    let data = [
        {
            "machine": {
                "rowNumber": "1",
                "mcid": 1,
                "mtid": 2,
                "mcSname": "TEST",
                "mcLname": "TEST 01",
                "brkgid": 1,
                "active": true,
                "asUptimeStd": 50
            },
            "breakGroup": {
                "brkgid": 1,
                "name": "test breakgroup"
            },
            "machineType": {
                "mtid": 2,
                "mtLname": "test machine type"
            }
        },
        {
            "machine": {
                "rowNumber": "1",
                "mcid": 2,
                "mtid": 2,
                "mcSname": "TEST",
                "mcLname": "TEST 02",
                "brkgid": 1,
                "active": false,
                "asUptimeStd": 50
            },
            "breakGroup": {
                "brkgid": 1,
                "name": "test breakgroup"
            },
            "machineType": {
                "mtid": 2,
                "mtLname": "test machine type"
            }
        },
    ]

    let tableContent = orderBy(data, sortField, isAscSort ? 'asc' : 'desc').map((item, key) => {
        return <ExampleRow setLatestUpdate={setLatestUpdate} key={`content-row-${item.machine.mcid}`} data={item}/>
    })

    return (
        <Box width="99vw" height="98vh">
            <ConfigTable selectableRow="selected-column" name="MACHINE CONFIG" config={config} content={tableContent} headerRowClick={headerRowClick} setLatestUpdate={setLatestUpdate} sortField={sortField} isAscSort={isAscSort}>
                <Button variant="contained" size="small">Add</Button>
                <Button variant="contained" size="small">Delete</Button>
            </ConfigTable>
            <ExampleDialog/>
        </Box>
    )
}

export default Example

table component

import React, {useCallback, useRef, useState} from 'react'
import {Button, TableRow} from "@mui/material"
import './ExampleRow.scss'
import {CheckBoxColumn, ComboBoxColumn, CustomColumn, FirstColumn, NumberColumn, SelectableColumn, TextColumn} from "../../../libraries/Column/Column"
import {includes} from "lodash"
import {checkIsSelectableColumnClicked, getAllCheckedRows} from "../../../libraries/Helpers/Helper"

function ExampleRow({data, setLatestUpdate}) {
    const [isInEditMode, setIsInEditMode] = useState(false)
    const [content] = useState(data)

    const mcSnameRef = useRef()
    const mcLnameRef = useRef()
    const mtidRef = useRef()
    const asUptimeStdRef = useRef()
    const brkgidRef = useRef()
    const activeRef = useRef()

    const machineType = [{
        "mtid": 1,
        "mtLname": "test machine type"
    }]

    const breakGroup = [{
        "brkgid": 1,
        "name": "test breakgroup"
    }]

    const enableEditMode = useCallback((e) => {
        if (checkIsSelectableColumnClicked(e)) {
            e.preventDefault()
        } else {
            setIsInEditMode(true)
        }
    }, [setIsInEditMode])

    const updateData = useCallback(async () => {
        alert('submit')
        setIsInEditMode(false)
    }, [])

    const checkKeyboardEvent = useCallback((e) => {
        if (e.code === 'Enter') {
            updateData()
        } else if (e.code === 'Escape') {
            setIsInEditMode(false)
        }
    }, [updateData])

    const onCheckBoxUpdate = useCallback((e) => {
        console.log(`update checkbox ${e.target.value}`)
    }, [])

    let allChecked = getAllCheckedRows('selected-column')
    const isSelected = includes(allChecked, `${content.machine.mcid}`)

    return (
        <TableRow className={isInEditMode || isSelected ? "content-row selected-row" : "content-row"} sx={{typography: 'body1'}} onDoubleClick={enableEditMode}>
            <SelectableColumn className="selected-column" align="center" setLatestUpdate={setLatestUpdate}>{content.machine.mcid}</SelectableColumn>
            <FirstColumn isInEditMode={isInEditMode} setIsInEditMode={setIsInEditMode} updateData={updateData} align="right">{content.machine.mcid}</FirstColumn>
            <TextColumn refVar={mcSnameRef} isInEditMode={isInEditMode} checkKeyboardEvent={checkKeyboardEvent} align="left">{content.machine.mcSname}</TextColumn>
            <TextColumn refVar={mcLnameRef} isInEditMode={isInEditMode} checkKeyboardEvent={checkKeyboardEvent} align="left">{content.machine.mcLname}</TextColumn>
            <ComboBoxColumn refVar={mtidRef} isInEditMode={isInEditMode} comboValue="mtid" comboLabel="mtLname" data={machineType} selectedValue={content.machine.mtid} align="left">{content.machineType.mtLname}</ComboBoxColumn>
            <NumberColumn refVar={asUptimeStdRef} align="right" isInEditMode={isInEditMode}>{content.machine.asUptimeStd}</NumberColumn>
            <ComboBoxColumn refVar={brkgidRef} isInEditMode={isInEditMode} comboValue="brkgid" comboLabel="name" data={breakGroup} selectedValue={content.machine.brkgid} align="left">{content.breakGroup.name}</ComboBoxColumn>
            <CheckBoxColumn refVar={activeRef} onUpdate={onCheckBoxUpdate} align="center">{content.machine.active}</CheckBoxColumn>
            <CustomColumn align="center">
                <Button variant="contained">
                    Dialog
                </Button>
            </CustomColumn>
        </TableRow>
    )
}

export default ExampleRow
.content-row {
  cursor: pointer;
  user-select: none;

  &:nth-of-type(even) {
    background: #f9f9f9;
  }
}

.selected-row {
  background: #FFEFBB !important;

  input, .MuiSelect-select {
    background: #fff;
  }
}