Giter Site home page Giter Site logo

material-ui-cron's Introduction

Material UI Cron

npm package MIT License Badge

A React cron editor built with material ui

Live demo and usage at https://baymac.github.io/material-ui-cron/

material-ui-cron demo

Inspired by

Installation

Be sure that you have these dependencies on your project:

  • react (>=17.0.1)
  • @material-ui/core (>5.0.0-beta.1)
  • @material-ui/styles: (>5.0.0-beta.1)

More dependencies

# Yarn
yarn add material-ui-cron

# NPM
npm install --save material-ui-cron

Usage

import Scheduler from 'material-ui-cron'
import React from 'react'

export default function SchedulerDemo() {
  const [cronExp, setCronExp] = React.useState('0 0 * * *')
  const [cronError, setCronError] = React.useState('') // get error message if cron is invalid
  const [isAdmin, setIsAdmin] = React.useState(true) // set admin or non-admin to enable or disable high frequency scheduling (more than once a day)

  return (
    <Scheduler
      cron={cronExp}
      setCron={setCronExp}
      setCronError={setCronError}
      isAdmin={isAdmin}
    />
  )
}

TypeScript

material-ui-cron is written in TypeScript with complete definitions.

Internalization and Localization

This library supports Internalization (i18n). Currently languages supported are:

  1. English

We are welcoming translation contributions from the community.

How to contribute to translation

  1. Clone /src/localization/enLocal.ts and rename it to desired langauge prefix (based on https://meta.wikimedia.org/wiki/Template:List_of_language_names_ordered_by_code).

  2. Add language prefix to definedLocales type inside /src/types.ts

  3. Add locale mapping inside /src/i18n.ts

How to use translation

Using predefined locale:

<Scheduler
  cron={cronExp}
  setCron={setCronExp}
  setCronError={setCronError}
  isAdmin={isAdmin}
  locale={'en'} // if not supplied, localization defaults to en
/>

Using custom locale:

<Scheduler
  cron={cronExp}
  setCron={setCronExp}
  setCronError={setCronError}
  isAdmin={isAdmin}
  customLocale={{...your translations}} // should be a valid object of type Locale, overrides value supplied to locale prop
/>

Acknowledgement

This library was developed as a part of Udaan's Data Platform for scheduling queries. Big thanks to Amod Malviya for supporting this project.

License

MIT © baymac

material-ui-cron's People

Contributors

baymac avatar shirasawasama avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

material-ui-cron's Issues

Changing cron prop does not rerender component

Describe the bug
I'm retrieving a cron from a database, and want to update the value of the cron to the value I get from the database.
When the response is retrieved from the database, the values of the component are not updated to the value of the new 'cron' prop.

Steps to reproduce
Demo here: https://codesandbox.io/s/material-ui-cron-stable-forked-5r89pd

Render component with:

const CronGenerator = (props) => {
    const [cron, setCron] = useState("30 9 * * 1")
    setTimeout(() => setCron("* * * * *"), 2000)


    return (
            <SchedulerRoot cron={cron}
                           setCron={updateCron}
                           setCronError={() => {}}
                           isAdmin={true}
                           />
    );
}

The component does not refresh to reflect the new value. I've included a picture to show that the props in React Component profiler are different to that actually displayed.

Screenshot from 2022-07-11 19-32-22

Note that I'm having to use the SchedulerRoot component due to an error when rendering just the <Scheduler /> component (image of the error below). However, note that in the demo linked at the top of this post, the same problem exists.

image

Solution (optional)

Additional context (optional)

Add @emotion/react @emotion/styled as dependency

Describe the bug
@emotion/react @emotion/styled should be added to dependency now that we have moved to material-ui/core-5.0.0-beta.1

To Reproduce
Steps to reproduce the behavior:

  1. Create a new cra project
  2. Run command yarn add [email protected]
  3. Add scheduler component in App.js
  4. Run dev server yarn start

Server throws error

./node_modules/@material-ui/styled-engine/index.js
Module not found: Can't resolve '@emotion/react' in '/path/to/dir/test/my-app/node_modules/@material-ui/styled-engine'

Solution
Add @emotion/react @emotion/styled to dependencies list.

Gives error to "0 1/4 * * *"

Hi, so I have this expression "0 1/4 * * *" that throws an error.
But I see you are using cronstrue package that translates the value correct cronstrue.toString('0 1/4 * * *');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.