Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource fields can traverse nested object paths #358

Closed
wants to merge 1 commit into from

Conversation

lenardchristopher
Copy link

  • resourceFields can accept object property paths so nested objects can be used
  • Avatar will only display if a string is provided

I tested this manually. Here is App.tsx

import { Scheduler } from "./lib";
import { EVENTS, RESOURCES } from "./events";
import { useRef } from "react";
import { SchedulerRef } from "./lib/types";

function App() {
  const calendarRef = useRef<SchedulerRef>(null);

  return (
    <Scheduler
      ref={calendarRef}
      events={EVENTS}
      resources={RESOURCES}
      resourceFields={{
        idField: 'admin_id',
        textField: 'test.name',
        avatarField: ''
      }}
      // events={generateRandomEvents(200)}
    />
  );
}

export default App;

and RESOURCES array

export const RESOURCES = [
  {
    admin_id: 1,
    title: "One",
    mobile: "555666777",
    avatar: "",
    color: "#ab2d2d",
    test: {
      name: "Hello"
    }
  },
  {
    admin_id: 2,
    title: "Two is very long name",
    mobile: "555666777",
    avatar: "https://picsum.photos/200/300",
    color: "#58ab2d",
    test: {
      name: "World"
    }
  },
  {
    admin_id: 3,
    title: "Three",
    mobile: "555666777",
    avatar: "https://picsum.photos/200/300",
    color: "#a001a2",
    test: {
      name: "Foo"
    }
  },
  {
    admin_id: 4,
    title: "Four",
    mobile: "555666777",
    avatar: "https://picsum.photos/200/300",
    color: "#08c5bd",
    test: {
      name: "Bar"
    }
  },
];

End Result
Screenshot 2024-04-24 at 4 55 18 PM

@lenardchristopher lenardchristopher changed the title Resource fields can traverse nested obbject paths Resource fields can traverse nested object paths Apr 24, 2024
@aldabil21
Copy link
Owner

aldabil21 commented Apr 26, 2024

Hi @lenardchristopher
I like the option of using nested object values.

The avatar is intentional to be falling back to random avatar, to prevent mis-match heights as showing in the image.

If user want to override the headers, the resourceHeaderComponent can be used

image

@lenardchristopher
Copy link
Author

lenardchristopher commented Apr 26, 2024

@aldabil21 How would I completely remove the avatar then? In my use case, resources are "rooms" that have no avatars.

@aldabil21
Copy link
Owner

@lenardchristopher You can use resourceHeaderComponent to fully render your custom header. Using Mui ListItem component is preferable

@aldabil21
Copy link
Owner

Took a second look at this
It had to be adapted to all other places in the code that uses the resourceFields, otherwise it may cause issues.

I will close in favor of resourceHeaderComponent, I believe its a valid solution for the problem

@aldabil21 aldabil21 closed this Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants