fullcalendar react wrapper scheduler passing events - reactjs

I'm trying to use fullcalendar-react-wrapper-scheduler in my project.
The documentation shows an example of passing events into the FullCalendar component, however it does not show how to pass in resources.
I'm attempting to pass in "resources" by mimicking how "events" are being passed in. But that does not display any resources on the DOM.
Has anyone successfully used this package that can provide guidance for passing in resources?
Documentation:
https://www.npmjs.com/package/fullcalendar-reactwrapper-scheduler#examples
Here's a code snippet showing how I am passing in events (successfully) and resources (not successfully):
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { connect } from 'react-redux';
import Nav from '../../components/Nav/Nav';
import { USER_ACTIONS } from '../../redux/actions/userActions';
import { LOGIN_ACTIONS } from '../../redux/actions/loginActions';
//START CALENDAR LIBRARY IMPORTS//
import FullCalendar from 'fullcalendar-reactwrapper-scheduler';
import 'fullcalendar-reactwrapper-scheduler/dist/css/fullcalendar.min.css';
//END CALENDAR LIBRARY IMPORTS//
const mapStateToProps = state => ({
user: state.user,
});
class ExampleComponent extends Component {
constructor(props) {
super(props);
this.state = {
events: [
{
resourceId: 'a',
id: 1,
title: 'Shoot 1',
start: '2017-06-27T08:00:00',
end: '2017-06-27T09:00:00'
},
{
resourceId: 'b',
id: 2,
title: 'Shoot 2',
start: '2017-06-27T10:00:00',
end: '2017-06-27T11:00:00'
},
{
resourceId: 'a',
id: 3,
title: 'Shoot 3',
start: '2017-06-27T13:00:00',
end: '2017-06-27T14:00:00'
},
{
resourceId: 'c',
id: 4,
title: 'Shoot 4',
start: '2017-06-27T08:00:00',
end: '2017-06-27T09:00:00'
},
{
resourceId: 'd',
id: 5,
title: 'Shoot 5',
start: '2017-06-27T012:00:00',
end: '2017-06-27T13:00:00'
},
],
resources: [
{ id: 'a', title: 'Room A' },
{ id: 'b', title: 'Room B' },
{ id: 'c', title: 'Room C' },
{ id: 'd', title: 'Room D' },
]
}
}
componentDidMount() {
this.props.dispatch({
type: USER_ACTIONS.FETCH_USER
});
}
componentDidUpdate() {
if (!this.props.user.isLoading && this.props.user.userName === null) {
this.props.history.push('home');
}
}
logout = () => {
this.props.dispatch({
type: LOGIN_ACTIONS.LOGOUT
});
// this.props.history.push('home');
}
render() {
let content = null;
if (this.props.user.userName) {
content = (
<div id="example-component">
<FullCalendar
id="your-custom-ID"
header={{
left: 'prev,next today myCustomButton',
center: 'title',
right: 'month,basicWeek,basicDay'
}}
defaultDate={'2017-06-27'}
navLinks={true} // can click day/week names to navigate views
editable={true}
eventLimit={true} // allow "more" link when too many events
events={this.state.events}
resources={this.state.resources}
defaultView='agendaDay'
/>
</div>
);
}
return (
<div>
<Nav />
{content}
</div>
);
}
}
// this allows us to use <App /> in index.js
export default connect(mapStateToProps)(ExampleComponent);

Looking through the source code, it looks like fullcalendar-reactwrapper-scheduler doesn't support resources.
You have a couple of options. You can use another library that is specifically made for React, such as react-calendar. This is the best approach.
If for some reason you are absolutely set on using Fullcalendar, you can integrate jQuery with your React app and then use Fullcalendar directly without the wrapper. But using jQuery with React is just asking for trouble, so I strongly advise against this approach.

Related

how to use icon in Ant-design/icons with V4

I have tried to make a menu, so i create a menuList to config the menu with getMenuNodes(), but Ant framework has been upgraded from v3 to v4 which the icon method has been changed. they are now using icon={<PieChartOutlined />} to instead of icon='PieChartOutlined', everything is working well, the icon area shows the word <PieChartOutlined />right now. i do not know why it happened, please help me to solve this problem.
left-navigation.js
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import logo from '../../assets/images/logo.png';
import './index.less';
import { Menu } from 'antd';
import { PieChartOutlined } from '#ant-design/icons';
import menuList from '../../config/menuConfig';
const { SubMenu } = Menu;
export default class LeftNav extends Component {
getMenuNodes = menuList => {
return menuList.map(item => {
if (!item.children) {
return (
<Menu.Item key={item.key} icon={item.icon}>
<Link to={item.key}>{item.title}</Link>
</Menu.Item>
);
} else {
return (
<SubMenu key={item.key} icon={item.icon} title={item.title}>
{this.getMenuNodes(item.children)}
</SubMenu>
);
}
});
};
render() {
return (
<div className="left-nav">
<Link to="./" className="left-nav-header">
<img src={logo} alt="" />
<h1>Backend System</h1>
</Link>
<Menu
mode="inline"
theme="dark"
>
{this.getMenuNodes(menuList)}
</Menu>
</div>
);
}
}
menuList.js
const menuList = [
{
title: 'Home',
key: '/home',
icon: '<PieChartOutlined />',
},
{
title: 'Item',
key: '/products',
icon: '<PieChartOutlined />',
children: [
{
title: 'Category Control',
key: '/category',
icon: '<PieChartOutlined />',
},
{
title: 'Product Control',
key: '/product',
icon: '<PieChartOutlined />',
},
],
},
{
title: 'User Control',
key: '/user',
icon: '<PieChartOutlined />',
},
{
title: 'Role Control',
key: '/role',
icon: '<PieChartOutlined />',
},
{
title: 'Diagram',
key: '/charts',
icon: '<PieChartOutlined />',
children: [
{
title: 'Bar',
key: '/charts/bar',
icon: '<PieChartOutlined />',
},
{
title: 'Line',
key: '/charts/line',
icon: '<PieChartOutlined />',
},
{
title: 'Pie',
key: '/charts/pie',
icon: '<PieChartOutlined />',
},
],
},
];
export default menuList;
You are passing a string of '<PieChartOutlined />', you need to pass the component directly.
import { PieChartOutlined } from '#ant-design/icons';
and:
{
title: 'Product Control',
key: '/product',
icon: <PieChartOutlined />,
},
You'll need to install ant-design/icons if you haven't already:
npm install --save #ant-design/icons
Since reason performance on the previous version, antd team was apply tree-shaking to use icon. More detail, you can check https://ant.design/docs/react/migration-v4

React-vis-timeline - cannot initialize items data

I have a problem with vis timeline initialization. Timeline is visible but without any data. I've tried to pass items in different formats but it looks like in attached image. What is a problem with that? My react component:
import 'vis-timeline/styles/vis-timeline-graph2d.min.css';
import Timeline from 'react-vis-timeline'
const items = [{
id: 1,
start: new Date(2025, 7, 15),
end: new Date(2025, 8, 2),
content: 'Test 1',
},
{
id: 2,
start: new Date(2025, 7, 17),
end: new Date(2025, 8, 3),
content: 'Test 2',
}
];
const options = {
width: '100%',
height: '450px',
};
class Timeline2D extends React.Component {
render() {
return <Timeline options={options} initialItems={items} />;
}
}
export default Timeline2D;
Result
To fix this issue I need to set groups. See correct example:
import React from 'react';
import 'vis-timeline/styles/vis-timeline-graph2d.min.css';
import Timeline from 'react-vis-timeline'
const items = [{
id: 1,
group: 1,
start: '2014-04-20',
end: '2014-04-26',
content: 'Test 1',
},
{
id: 2,
group: 2,
start: '2014-04-22',
end: '2014-04-29',
content: 'Test 2',
}
];
const groups = [{
id: 1,
content: 'Group 1',
},
{
id: 2,
content: 'Group 2',
}
];
const options = {
width: '100%',
height: '450px',
};
class Timeline2D extends React.Component {
render() {
return <Timeline options={options} initialItems={items} initialGroups={groups}/>;
}
}
export default Timeline2D;

React Data Grid shows bad

I have a problem with ReactDataGrid component. I have already installed react-data-grid. The code is the same as in the reac grid's web:
const columns = [
{ key: 'id', name: 'ID' },
{ key: 'title', name: 'Title' },
{ key: 'count', name: 'Count' }];
const rows = [{ id: 0, title: 'row1', count: 20 }, { id: 1, title: 'row1', count: 40 }, { id: 2, title: 'row1', count: 60 }];
class App extends React.Component {
render() {
return (
<ReactDataGrid
columns={columns}
rowGetter={i => rows[i]}
rowsCount={3}
minHeight={150} />
)
}
}
export default App;
and i get:
Result
Thank you!
Import the CSS like so :
import 'react-data-grid/dist/react-data-grid.css';
It should be fine.
import React from "react";
import ReactDOM from "react-dom";
import ReactDataGrid from "react-data-grid";
const columns = [
{ key: "id", name: "ID", editable: true },
{ key: "title", name: "Title", editable: true },
{ key: "count", name: "Count", editable: true }
];
const rows = [
{ id: 0, title: "row1", count: 20 },
{ id: 1, title: "row1", count: 40 },
{ id: 2, title: "row1", count: 60 }
];
class App extends React.Component {
render() {
return (
<ReactDataGrid
columns={columns}
rowGetter={i => rows[i]}
rowsCount={3}
minHeight={150}
enableCellSelect={true}
/>
);
}
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
https://codesandbox.io/s/rdg-cell-editing-h8bnr
the answer is in the above code this above code is working
You don't really need to downgrade. The issue is that the css is not being imported.
If you can import css from node-modules, it'll work.
Workaround for me was I took the whole css and we are now self-maintaining the css, making changes when needed.
I couldn't load the css either, I got around this by including
import ReactDataGrid from 'react-data-grid/dist/react-data-grid.min.js';
instead of
import ReactDataGrid from 'react-data-grid';

Office React Fabric Event Declared But Never Used Demo Code Error

When using the Microsoft sample code for the React Office Fabric UI I am getting the error.
TS6133: 'event' is declared but its value is never read.
Code:
https://developer.microsoft.com/en-us/fabric#/controls/web/dropdown
Code Pen: (No Error)
https://codepen.io/pen/?&editable=true
import * as React from 'react';
import { Dropdown, DropdownMenuItemType, IDropdownOption } from 'office-ui-fabric-react/lib/Dropdown';
export interface IDropdownControlledMultiExampleState {
selectedItems: string[];
}
export class DropdownControlledMultiExample extends React.Component<{}, IDropdownControlledMultiExampleState> {
public state: IDropdownControlledMultiExampleState = {
selectedItems: []
};
public render() {
const { selectedItems } = this.state;
return (
<Dropdown
placeholder="Select options"
label="Multi-select controlled example"
selectedKeys={selectedItems}
onChange={this._onChange}
multiSelect
options={[
{ key: 'fruitsHeader', text: 'Fruits', itemType: DropdownMenuItemType.Header },
{ key: 'apple', text: 'Apple' },
{ key: 'banana', text: 'Banana' },
{ key: 'orange', text: 'Orange', disabled: true },
{ key: 'grape', text: 'Grape' },
{ key: 'divider_1', text: '-', itemType: DropdownMenuItemType.Divider },
{ key: 'vegetablesHeader', text: 'Vegetables', itemType: DropdownMenuItemType.Header },
{ key: 'broccoli', text: 'Broccoli' },
{ key: 'carrot', text: 'Carrot' },
{ key: 'lettuce', text: 'Lettuce' }
]}
styles={{ dropdown: { width: 300 } }}
/>
);
}
private _onChange = (event: React.FormEvent<HTMLDivElement>, item: IDropdownOption): void => {
const newSelectedItems = [...this.state.selectedItems];
if (item.selected) {
// add the option if it's checked
newSelectedItems.push(item.key as string);
} else {
// remove the option if it's unchecked
const currIndex = newSelectedItems.indexOf(item.key as string);
if (currIndex > -1) {
newSelectedItems.splice(currIndex, 1);
}
}
this.setState({
selectedItems: newSelectedItems
});
};
}
My use is no different, just implemented outside codepen. I have found the same with all the sample code. What else should be used to utilize the event?
You shouldn't really force yourself to utilize it. An example might be where the _onChange handler is being used for bunch of other forms as well and a need might arise to look into the event object to see where is it coming from etc..
See here: Ignore TS6133: "(import) is declared but never used"?
You need to turn-off the noUnusedLocals option from your tsconfig.json for the error to disappear.

React Tabs content

I was playing around with React for the first time and trying to figure out how to make tabs. I found an outline of the code that looks simple and clean enough (do correct me if I'm wrong though, please), but I don't know how to show the content of the tabs outside of the 'constructor'. As I want the tab content to be more than just a couple of words, and the current code seems constricting.
This is the part that I'm talking about:
constructor(props) {
super(props);
this.state = {
activeTabIndex: 0,
initialData: [
{
label: 'Tab 1',
content: 'Content 1',
},
{
label: 'Tab 2',
content: 'Content 2',
},
{
label: 'Tab 3',
content: 'Content 3',
},
],
};
this.handleTabClick = this.handleTabClick.bind(this);
}
How do I pull the content outside of this, if I have too much content to be put inside that? Here is the entire code outline: link. Any suggestions/links are welcome.
And I apologize if I'm explaining this wrong, I'm still trying to figure stuff out. Thanks!
Just create a Component you want to render in Tab Content and assign it to content.
import React, { Component } from "react";
import Tabs from "./Tabs";
import Content from "./Content";
export default class TabView extends Component {
constructor(props) {
super(props);
this.state = {
activeTabIndex: 0,
initialData: [
{
label: "Tab 1",
content: <TabContent />
},
{
label: "Tab 2",
content: "Content 2"
},
{
label: "Tab 3",
content: "Content 3"
}
]
};
this.handleTabClick = this.handleTabClick.bind(this);
}
handleTabClick(index) {
this.setState({
activeTabIndex: index
});
}
render() {
const { initialData, activeTabIndex } = this.state;
const activeItem = this.state.initialData[activeTabIndex];
return (
<div>
<Tabs
handleTabClick={this.handleTabClick}
data={this.state.initialData}
activeTabIndex={activeTabIndex}
/>
<Content content={activeItem.content} />
</div>
);
}
}
const TabContent = () => (
<div>
<p>I am here</p>
</div>
);

Resources