Skip to content

Commit

Permalink
Database select enabled only for sql cells
Browse files Browse the repository at this point in the history
  • Loading branch information
brichet committed Oct 31, 2023
1 parent 00f0630 commit fd7279d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ const metadataForm: JupyterFrontEndPlugin<void> = {
// A widget to associate a database to the cell.
const databaseSelect: IFormRenderer = {
fieldRenderer: (props: FieldProps) => {
return DatabaseSelect(props);
return DatabaseSelect({ ...props, tracker });
}
};
formRegistry.addRenderer(
Expand Down
15 changes: 13 additions & 2 deletions src/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const SqlSwitchWidget = (options: Private.IOptions): JSX.Element => {
/**
* A field including a select to associate a database.
*/
export const DatabaseSelect = (props: FieldProps) => {
export const DatabaseSelect = (props: Private.ISelectProps) => {
const onChange = (event: React.FormEvent) => {
const value = (event.target as HTMLOptionElement).value;
const select = props.schema.oneOf?.find(
Expand All @@ -131,7 +131,11 @@ export const DatabaseSelect = (props: FieldProps) => {
return (
<div>
<div className="jp-FormGroup-fieldLabel">{props.schema.title}</div>
<select onChange={onChange} className={'form-control jp-sqlcell-select'}>
<select
onChange={onChange}
className={'form-control jp-sqlcell-select'}
disabled={!SqlCell.isSqlCell(props.tracker.activeCell?.model)}
>
{props.schema.oneOf?.map(oneOf => {
return <option>{(oneOf as objectEnum).title}</option>;
})}
Expand All @@ -151,4 +155,11 @@ namespace Private {
commands: CommandRegistry;
tracker: INotebookTracker;
}

/**
* The database select props.
*/
export interface ISelectProps extends FieldProps {
tracker: INotebookTracker;
}
}

0 comments on commit fd7279d

Please sign in to comment.