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

Support for markdown cells in the Cell component #247

Closed
MarcosVn opened this issue Jun 19, 2024 · 9 comments
Closed

Support for markdown cells in the Cell component #247

MarcosVn opened this issue Jun 19, 2024 · 9 comments

Comments

@MarcosVn
Copy link
Contributor

MarcosVn commented Jun 19, 2024

I am working on a web application, and the <Cell> component meets exactly what I need; however, in version 0.10.0 it only allows code cells. When I use a <Notebook>, I can manipulate and add markdown cells programmatically.

Would it be possible to add the same support to <Cell>? This could be through a new type prop or even an action provided by whatever you consider best. If feasible, could this be included in the evolution pipeline? I can contribute with a PR to have this ASAP.

@echarles
Copy link
Member

echarles commented Jun 19, 2024

@MarcosVn You will need to add a prop type: 'code' | 'markdown' | 'raw' here

export type ICellProps = {
/**
* Code cell source.
*/
source?: string;
/**
* Whether to execute directly the code cell or not.
*/
autoStart?: boolean;
};

... and pass that prop to the CellAdapter which will import a MarkdownCell and RawCell here https://github.com/datalayer/jupyter-ui/blob/3197d240947f5e1ce80abe10801c3679e9cd5acc/packages/react/src/components/cell/CellAdapter.ts#L16C25-L16C33

... and instantiate those MarkdownCell and RawCell based on that prop.

@MarcosVn
Copy link
Contributor Author

MarcosVn commented Jun 19, 2024

Hello @echarles, thank you very much for your quick response.

I opened a very partial PR with the mentioned evolutions, but it seems there are some issues beyond that I would like to request an opinion/help:

  • Even implementing the MarkdownCellCode instance, the cell is not rendered as expected (resulting in a blank output). Could it be something related to the execution interface, for example? I noticed that in markdown cells, the interface that transforms the input into a result appears to be quite different;

image

  • I think the ideal would be to rename the CellAdapter _codeCell property to _cell, however, I was a bit hesitant to make this modification due to not knowing the possible impacts;

  • I believe we will have other areas to evolve as well, such as in Cell.tsx, where we will need to consider the case of autoStart (perhaps point 1 above is related to this).

@sok82
Copy link
Contributor

sok82 commented Jun 24, 2024

Hi @MarcosVn ,

it seems to me we are working on somewhat similar tasks)

Can you please share how you work with multiple cells?

I've tried to build very basic example, but struggling to make it work properly with more than one cell

For example when I add more than one cell I have following issues with an example

  1. Run action in toolbar doesn't seem to work
  2. Shit+Tab action also doesn't work with the second and following cells

Made documentation request

My example is

import {Cell, Jupyter, selectCell, cellActions, selectActiveCell} from '@datalayer/jupyter-react';
import React from "react";
import { useDispatch } from "react-redux";
import { Button, Text } from '@primer/react';

const CellPreview = () => {
  const cell = selectCell();  
  return (
    <>
      <div>source: {cell.source}</div>
      <br/>
      <div>kernel available: {String(cell.kernelAvailable)}</div>
      <br/>
    </>
  )
}

const CellComponents = () => (
  <>
    <CellPreview/>
    <CellToolbar />
    <Cell key="1" source="" />
    <Cell key="2" source="" />
  </>
)

const CellToolbar = () => {
  const cell = selectCell();  
  const dispatch = useDispatch();
  

  const handleExecuteClick = () => {
    console.log(cell.source);
    cell.adapter?.execute();
  }

  return (
    <>
      <Text as="h5">Cell Example</Text>
      <Button
        color="primary"
        onClick={handleExecuteClick}
        >
          Execute active
      </Button>
      <Button
        color="primary"
        onClick={() => dispatch(cellActions.execute())}
        >
          Run
      </Button>
      <Button
        color="secondary"
        onClick={() => dispatch(cellActions.outputsCount(0))}
        >
          Reset outputs count
      </Button>
      <Text>
        Outputs count: {cell.outputsCount}
      </Text>
    </>
  );
}


export default function EntryComponent() {
  return  <Jupyter 
                jupyterServerHttpUrl="http://localhost:8888"
                jupyterServerWsUrl="ws://localhost:8888"
                jupyterToken="3c8d3dda652807dfaf5edc9df0fc32427f8a4d841fc714b3"     
                lite={false}
                useRunningKernelIndex={-1}
                startDefaultKernel={true}
                terminals={false}             
            >
                <CellComponents/>
            </Jupyter>

}

@echarles
Copy link
Member

A prerequisite to support multiple Cells on a same page is to upgrade the zustand store to support many cells, like the output store does.

@MarcosVn
Copy link
Contributor Author

MarcosVn commented Jun 25, 2024

Hello @echarles,

Regarding the markdown support, could you please review my last comment when possible?

I would be happy to help with this evolution in the library, and it will also be useful for my use case.

@echarles
Copy link
Member

@MarcosVn Thanks a lot for this contribution and sorry for the delay... I have commented here #248 (comment)

MarcosVn pushed a commit to MarcosVn/jupyter-ui that referenced this issue Jun 26, 2024
@MarcosVn
Copy link
Contributor Author

Thank you, @echarles! I posted an update on the work on this issue with some comments directly on #248.

MarcosVn pushed a commit to MarcosVn/jupyter-ui that referenced this issue Jun 26, 2024
MarcosVn pushed a commit to MarcosVn/jupyter-ui that referenced this issue Jun 28, 2024
MarcosVn pushed a commit to MarcosVn/jupyter-ui that referenced this issue Jun 28, 2024
MarcosVn pushed a commit to MarcosVn/jupyter-ui that referenced this issue Jun 28, 2024
MarcosVn pushed a commit to MarcosVn/jupyter-ui that referenced this issue Jun 28, 2024
echarles pushed a commit that referenced this issue Jun 28, 2024
* feat: partially adding support to markdown cells (#247)

* feat: adding more functionalities to markdown Cell (#247)

---------

Co-authored-by: Marcos Alves <[email protected]>
@MarcosVn
Copy link
Contributor Author

MarcosVn commented Jul 1, 2024

Hello, @echarles.

With the release of #278 in a new version, we can close this issue here by my part.

@echarles
Copy link
Member

echarles commented Jul 1, 2024

@MarcosVn sure, doing that now.

@sok82 feel free to reopen this issue or a new one for any questions. fyi the code for this features is merged in main branch, but not yet released.

@echarles echarles closed this as completed Jul 1, 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

No branches or pull requests

3 participants