Skip to content
Snippets Groups Projects
Unverified Commit bd6391ce authored by Oisin Coveney's avatar Oisin Coveney Committed by GitHub
Browse files

Make notebook props explicit (#44529)


Co-authored-by: default avatarNicolò Pretto <info@npretto.com>
parent 27fc6ae4
No related branches found
No related tags found
No related merge requests found
import { t } from "ttag"; import { t } from "ttag";
import _ from "underscore";
import Questions from "metabase/entities/questions";
import { useDispatch } from "metabase/lib/redux"; import { useDispatch } from "metabase/lib/redux";
import { setUIControls } from "metabase/query_builder/actions"; import { setUIControls } from "metabase/query_builder/actions";
import { Box, Button } from "metabase/ui"; import { Box, Button } from "metabase/ui";
import * as Lib from "metabase-lib"; import * as Lib from "metabase-lib";
import type Question from "metabase-lib/v1/Question"; import type Question from "metabase-lib/v1/Question";
import {
getQuestionIdFromVirtualTableId,
isVirtualCardId,
} from "metabase-lib/v1/metadata/utils/saved-questions";
import type { State } from "metabase-types/store";
import { NotebookSteps } from "./NotebookSteps"; import { NotebookSteps } from "./NotebookSteps";
interface NotebookProps { export type NotebookProps = {
className?: string;
question: Question; question: Question;
isDirty: boolean; isDirty: boolean;
isRunnable: boolean; isRunnable: boolean;
...@@ -27,19 +19,20 @@ interface NotebookProps { ...@@ -27,19 +19,20 @@ interface NotebookProps {
runQuestionQuery: () => void; runQuestionQuery: () => void;
setQueryBuilderMode: (mode: string) => void; setQueryBuilderMode: (mode: string) => void;
readOnly?: boolean; readOnly?: boolean;
} };
const Notebook = ({ className, updateQuestion, ...props }: NotebookProps) => {
const {
question,
isDirty,
isRunnable,
isResultDirty,
hasVisualizeButton = true,
runQuestionQuery,
setQueryBuilderMode,
} = props;
const Notebook = ({
updateQuestion,
reportTimezone,
readOnly,
question,
isDirty,
isRunnable,
isResultDirty,
hasVisualizeButton = true,
runQuestionQuery,
setQueryBuilderMode,
}: NotebookProps) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
async function cleanupQuestion() { async function cleanupQuestion() {
...@@ -76,7 +69,12 @@ const Notebook = ({ className, updateQuestion, ...props }: NotebookProps) => { ...@@ -76,7 +69,12 @@ const Notebook = ({ className, updateQuestion, ...props }: NotebookProps) => {
return ( return (
<Box pos="relative" p={{ base: "1rem", sm: "2rem" }}> <Box pos="relative" p={{ base: "1rem", sm: "2rem" }}>
<NotebookSteps updateQuestion={handleUpdateQuestion} {...props} /> <NotebookSteps
updateQuestion={handleUpdateQuestion}
question={question}
reportTimezone={reportTimezone}
readOnly={readOnly}
/>
{hasVisualizeButton && isRunnable && ( {hasVisualizeButton && isRunnable && (
<Button variant="filled" style={{ minWidth: 220 }} onClick={visualize}> <Button variant="filled" style={{ minWidth: 220 }} onClick={visualize}>
{t`Visualize`} {t`Visualize`}
...@@ -86,27 +84,5 @@ const Notebook = ({ className, updateQuestion, ...props }: NotebookProps) => { ...@@ -86,27 +84,5 @@ const Notebook = ({ className, updateQuestion, ...props }: NotebookProps) => {
); );
}; };
function getSourceQuestionId(question: Question) {
const query = question.query();
const { isNative } = Lib.queryDisplayInfo(query);
if (!isNative) {
const sourceTableId = Lib.sourceTableOrCardId(query);
if (isVirtualCardId(sourceTableId)) {
return getQuestionIdFromVirtualTableId(sourceTableId);
}
}
return undefined;
}
// eslint-disable-next-line import/no-default-export -- deprecated usage // eslint-disable-next-line import/no-default-export -- deprecated usage
export default _.compose( export default Notebook;
Questions.load({
id: (state: State, { question }: NotebookProps) =>
getSourceQuestionId(question),
entityAlias: "sourceQuestion",
loadingAndErrorWrapper: false,
}),
)(Notebook);
...@@ -373,6 +373,15 @@ class View extends Component { ...@@ -373,6 +373,15 @@ class View extends Component {
onConfirmToast, onConfirmToast,
isShowingToaster, isShowingToaster,
isHeaderVisible, isHeaderVisible,
updateQuestion,
reportTimezone,
readOnly,
isDirty,
isRunnable,
isResultDirty,
hasVisualizeButton,
runQuestionQuery,
setQueryBuilderMode,
} = this.props; } = this.props;
// if we don't have a question at all or no databases then we are initializing, so keep it simple // if we don't have a question at all or no databases then we are initializing, so keep it simple
...@@ -417,7 +426,16 @@ class View extends Component { ...@@ -417,7 +426,16 @@ class View extends Component {
{!isNative && ( {!isNative && (
<NotebookContainer <NotebookContainer
isOpen={isNotebookContainerOpen} isOpen={isNotebookContainerOpen}
{...this.props} updateQuestion={updateQuestion}
reportTimezone={reportTimezone}
readOnly={readOnly}
question={question}
isDirty={isDirty}
isRunnable={isRunnable}
isResultDirty={isResultDirty}
hasVisualizeButton={hasVisualizeButton}
runQuestionQuery={runQuestionQuery}
setQueryBuilderMode={setQueryBuilderMode}
/> />
)} )}
<ViewSidebar side="left" isOpen={!!leftSidebar}> <ViewSidebar side="left" isOpen={!!leftSidebar}>
......
...@@ -9,7 +9,9 @@ import { ...@@ -9,7 +9,9 @@ import {
setNotebookNativePreviewSidebarWidth, setNotebookNativePreviewSidebarWidth,
setUIControls, setUIControls,
} from "metabase/query_builder/actions"; } from "metabase/query_builder/actions";
import Notebook from "metabase/query_builder/components/notebook/Notebook"; import Notebook, {
type NotebookProps,
} from "metabase/query_builder/components/notebook/Notebook";
import { NotebookNativePreview } from "metabase/query_builder/components/notebook/NotebookNativePreview"; import { NotebookNativePreview } from "metabase/query_builder/components/notebook/NotebookNativePreview";
import { getUiControls } from "metabase/query_builder/selectors"; import { getUiControls } from "metabase/query_builder/selectors";
import { Flex, Box, rem } from "metabase/ui"; import { Flex, Box, rem } from "metabase/ui";
...@@ -18,13 +20,22 @@ import { Flex, Box, rem } from "metabase/ui"; ...@@ -18,13 +20,22 @@ import { Flex, Box, rem } from "metabase/ui";
// because we need to trigger the 'onTransitionEnd' in the component // because we need to trigger the 'onTransitionEnd' in the component
const delayBeforeNotRenderingNotebook = 10; const delayBeforeNotRenderingNotebook = 10;
interface NotebookContainerProps { type NotebookContainerProps = {
isOpen: boolean; isOpen: boolean;
} } & NotebookProps;
export const NotebookContainer = ({ export const NotebookContainer = ({
isOpen, isOpen,
...props updateQuestion,
reportTimezone,
readOnly,
question,
isDirty,
isRunnable,
isResultDirty,
hasVisualizeButton,
runQuestionQuery,
setQueryBuilderMode,
}: NotebookContainerProps) => { }: NotebookContainerProps) => {
const [shouldShowNotebook, setShouldShowNotebook] = useState(isOpen); const [shouldShowNotebook, setShouldShowNotebook] = useState(isOpen);
const { width: windowWidth } = useWindowSize(); const { width: windowWidth } = useWindowSize();
...@@ -65,7 +76,9 @@ export const NotebookContainer = ({ ...@@ -65,7 +76,9 @@ export const NotebookContainer = ({
const Handle = forwardRef< const Handle = forwardRef<
HTMLDivElement, HTMLDivElement,
Partial<ResizableBoxProps> & { onResize?: any } //Mantine and react-resizeable have different opinions on what onResize should be Partial<ResizableBoxProps> & {
onResize?: any; //Mantine and react-resizeable have different opinions on what onResize should be
}
>(function Handle(props, ref) { >(function Handle(props, ref) {
const handleWidth = 10; const handleWidth = 10;
const borderWidth = 1; const borderWidth = 1;
...@@ -109,7 +122,18 @@ export const NotebookContainer = ({ ...@@ -109,7 +122,18 @@ export const NotebookContainer = ({
miw={{ lg: minNotebookWidth }} miw={{ lg: minNotebookWidth }}
style={{ flex: 1, overflowY: "auto" }} style={{ flex: 1, overflowY: "auto" }}
> >
<Notebook {...props} /> <Notebook
question={question}
isDirty={isDirty}
isRunnable={isRunnable}
isResultDirty={isResultDirty}
reportTimezone={reportTimezone}
readOnly={readOnly}
updateQuestion={updateQuestion}
runQuestionQuery={runQuestionQuery}
setQueryBuilderMode={setQueryBuilderMode}
hasVisualizeButton={hasVisualizeButton}
/>
</Box> </Box>
)} )}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment