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

components: "Results{List,Grid}.renderElement" should be rendered as a React component #113

Open
slint opened this issue May 2, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@slint
Copy link
Member

slint commented May 2, 2020

props.renderElement should render a component in the following fashion:

  _renderElement(results) {
    const _results = results.map((result, index) =>
      <this.renderListItem result={result} index={index} />
    );
    return (
      <Item.Group divided relaxed link>
        {_results}
      </Item.Group>
    );
  }

This would allow e.g. for custom components with their own internal state to be passed.

The concrete use-case is that we have a search page where each list item has Accept/Reject buttons, that when clicked make an AJAX HTTP request and on a successful response they show a result message and disable the buttons:

const ResultsItemTemplate = ({ record, index }) => {
  const [result, setResult] = useState({ message: null, status: null });

  function handleRequest(action) {
    axios
      .post(`/communities/${record.id}/${action}`)
      .then((response) => {
        setResult({ message: response.data.message, status: action });
      })
      .catch((error) => {
        setResult({ message: error.data.message, status: null });
      });
  }

  return (
    <Item key={index}>
      <Item.Content>
        <Item.Header>{record.title}</Item.Header>
        <Item.Description>
          <Button
            className={result.status ? "disabled" : null}
            onClick={() => handleRequest("accept")}
          >
            Accept
          </Button>
          <Button
            className={result.status ? "disabled" : null}
            onClick={() => handleRequest("reject")}
          >
            Reject
          </Button>
          {result.status ? <span>{result.message}</span> : null}
          <div></div>
        </Item.Description>
      </Item.Content>
    </Item>
  );
};
@slint slint added the enhancement New feature or request label May 2, 2020
@zzacharo
Copy link
Member

zzacharo commented May 2, 2020

@slint doing something like this doesn't work?

renderListItem = (result, index) => <MyCustomComponent result={result} index={index} />

@zzacharo
Copy link
Member

zzacharo commented May 2, 2020

For the renderElement prop I created an issue #114 that give's another reason on why should be rendered as a component.

@mvidalgarcia
Copy link
Member

I think this doesn't apply anymore and can be closed.

@mvidalgarcia mvidalgarcia removed their assignment May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants