-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split View Header components into separate files (#44347)
- Loading branch information
1 parent
37abc08
commit 7de0faa
Showing
12 changed files
with
481 additions
and
434 deletions.
There are no files selected for viewing
441 changes: 7 additions & 434 deletions
441
frontend/src/metabase/query_builder/components/view/ViewHeader/ViewHeader.jsx
Large diffs are not rendered by default.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
...der/components/view/ViewHeader/components/AdHocQuestionLeftSide/AdHocQuestionLeftSide.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import PropTypes from "prop-types"; | ||
import { t } from "ttag"; | ||
|
||
import CS from "metabase/css/core/index.css"; | ||
import { | ||
AdHocLeftSideRoot, | ||
AdHocViewHeading, | ||
ViewHeaderLeftSubHeading, | ||
ViewHeaderMainLeftContentContainer, | ||
} from "metabase/query_builder/components/view/ViewHeader/ViewHeader.styled"; | ||
import { | ||
QuestionDataSource, | ||
QuestionDescription, | ||
} from "metabase/query_builder/components/view/ViewHeader/components"; | ||
import { MODAL_TYPES } from "metabase/query_builder/constants"; | ||
import * as Lib from "metabase-lib"; | ||
|
||
AdHocQuestionLeftSide.propTypes = { | ||
question: PropTypes.object.isRequired, | ||
originalQuestion: PropTypes.object, | ||
isNative: PropTypes.bool, | ||
isObjectDetail: PropTypes.bool, | ||
isSummarized: PropTypes.bool, | ||
onOpenModal: PropTypes.func, | ||
}; | ||
export function AdHocQuestionLeftSide(props) { | ||
const { | ||
question, | ||
originalQuestion, | ||
isNative, | ||
isObjectDetail, | ||
isSummarized, | ||
onOpenModal, | ||
} = props; | ||
|
||
const handleTitleClick = () => { | ||
const { isEditable } = Lib.queryDisplayInfo(question.query()); | ||
|
||
if (isEditable) { | ||
onOpenModal(MODAL_TYPES.SAVE); | ||
} | ||
}; | ||
|
||
return ( | ||
<AdHocLeftSideRoot> | ||
<ViewHeaderMainLeftContentContainer> | ||
<AdHocViewHeading color="medium"> | ||
{isNative ? ( | ||
t`New question` | ||
) : ( | ||
<QuestionDescription | ||
question={question} | ||
originalQuestion={originalQuestion} | ||
isObjectDetail={isObjectDetail} | ||
onClick={handleTitleClick} | ||
/> | ||
)} | ||
</AdHocViewHeading> | ||
</ViewHeaderMainLeftContentContainer> | ||
<ViewHeaderLeftSubHeading> | ||
{isSummarized && ( | ||
<QuestionDataSource | ||
className={CS.mb1} | ||
question={question} | ||
isObjectDetail={isObjectDetail} | ||
subHead | ||
/> | ||
)} | ||
</ViewHeaderLeftSubHeading> | ||
</AdHocLeftSideRoot> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
...tabase/query_builder/components/view/ViewHeader/components/AdHocQuestionLeftSide/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./AdHocQuestionLeftSide"; |
42 changes: 42 additions & 0 deletions
42
...builder/components/view/ViewHeader/components/DashboardBackButton/DashboardBackButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { t } from "ttag"; | ||
|
||
import Link from "metabase/core/components/Link"; | ||
import Tooltip from "metabase/core/components/Tooltip"; | ||
import { useDispatch, useSelector } from "metabase/lib/redux"; | ||
import * as Urls from "metabase/lib/urls"; | ||
import { navigateBackToDashboard } from "metabase/query_builder/actions"; | ||
import { | ||
BackButton, | ||
BackButtonContainer, | ||
} from "metabase/query_builder/components/view/ViewHeader/ViewHeader.styled"; | ||
import { getDashboard } from "metabase/query_builder/selectors"; | ||
|
||
export function DashboardBackButton() { | ||
const dashboard = useSelector(getDashboard); | ||
const dispatch = useDispatch(); | ||
|
||
const handleClick = () => { | ||
dispatch(navigateBackToDashboard(dashboard.id)); | ||
}; | ||
|
||
if (!dashboard) { | ||
return null; | ||
} | ||
|
||
const label = t`Back to ${dashboard.name}`; | ||
|
||
return ( | ||
<Tooltip tooltip={label}> | ||
<BackButtonContainer> | ||
<BackButton | ||
as={Link} | ||
to={Urls.dashboard(dashboard)} | ||
round | ||
icon="arrow_left" | ||
aria-label={label} | ||
onClick={handleClick} | ||
/> | ||
</BackButtonContainer> | ||
</Tooltip> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
...metabase/query_builder/components/view/ViewHeader/components/DashboardBackButton/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./DashboardBackButton"; |
19 changes: 19 additions & 0 deletions
19
...der/components/view/ViewHeader/components/HeaderCollectionBadge/HeaderCollectionBadge.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import PropTypes from "prop-types"; | ||
import { t } from "ttag"; | ||
|
||
import * as Urls from "metabase/lib/urls"; | ||
import { HeadBreadcrumbs } from "metabase/query_builder/components/view/ViewHeader/components"; | ||
|
||
HeaderCollectionBadge.propTypes = { | ||
question: PropTypes.object.isRequired, | ||
}; | ||
|
||
export function HeaderCollectionBadge({ question }) { | ||
const { collection } = question.card(); | ||
const icon = question.type(); | ||
return ( | ||
<HeadBreadcrumbs.Badge to={Urls.collection(collection)} icon={icon}> | ||
{collection?.name || t`Our analytics`} | ||
</HeadBreadcrumbs.Badge> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
...tabase/query_builder/components/view/ViewHeader/components/HeaderCollectionBadge/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./HeaderCollectionBadge"; |
112 changes: 112 additions & 0 deletions
112
...der/components/view/ViewHeader/components/SavedQuestionLeftSide/SavedQuestionLeftSide.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import PropTypes from "prop-types"; | ||
import { useCallback, useEffect, useState } from "react"; | ||
|
||
import SavedQuestionHeaderButton from "metabase/query_builder/components/SavedQuestionHeaderButton/SavedQuestionHeaderButton"; | ||
import { | ||
HeaderDivider, | ||
SavedQuestionHeaderButtonContainer, | ||
SavedQuestionLeftSideRoot, | ||
StyledLastEditInfoLabel, | ||
StyledQuestionDataSource, | ||
ViewHeaderLeftSubHeading, | ||
ViewHeaderMainLeftContentContainer, | ||
} from "metabase/query_builder/components/view/ViewHeader/ViewHeader.styled"; | ||
import { | ||
HeadBreadcrumbs, | ||
QuestionDataSource, | ||
} from "metabase/query_builder/components/view/ViewHeader/components"; | ||
import { HeaderCollectionBadge } from "metabase/query_builder/components/view/ViewHeader/components/HeaderCollectionBadge/HeaderCollectionBadge"; | ||
|
||
SavedQuestionLeftSide.propTypes = { | ||
question: PropTypes.object.isRequired, | ||
isObjectDetail: PropTypes.bool, | ||
isAdditionalInfoVisible: PropTypes.bool, | ||
isShowingQuestionDetailsSidebar: PropTypes.bool, | ||
onOpenQuestionInfo: PropTypes.func.isRequired, | ||
onSave: PropTypes.func, | ||
}; | ||
export function SavedQuestionLeftSide(props) { | ||
const { | ||
question, | ||
isObjectDetail, | ||
isAdditionalInfoVisible, | ||
onOpenQuestionInfo, | ||
onSave, | ||
} = props; | ||
|
||
const [showSubHeader, setShowSubHeader] = useState(true); | ||
|
||
const hasLastEditInfo = question.lastEditInfo() != null; | ||
const type = question.type(); | ||
const isModelOrMetric = type === "model" || type === "metric"; | ||
|
||
const onHeaderChange = useCallback( | ||
name => { | ||
if (name && name !== question.displayName()) { | ||
onSave(question.setDisplayName(name)); | ||
} | ||
}, | ||
[question, onSave], | ||
); | ||
|
||
const renderDataSource = | ||
QuestionDataSource.shouldRender(props) && type === "question"; | ||
const renderLastEdit = hasLastEditInfo && isAdditionalInfoVisible; | ||
|
||
useEffect(() => { | ||
const timerId = setTimeout(() => { | ||
if (isAdditionalInfoVisible && (renderDataSource || renderLastEdit)) { | ||
setShowSubHeader(false); | ||
} | ||
}, 4000); | ||
return () => clearTimeout(timerId); | ||
}, [isAdditionalInfoVisible, renderDataSource, renderLastEdit]); | ||
|
||
return ( | ||
<SavedQuestionLeftSideRoot | ||
data-testid="qb-header-left-side" | ||
showSubHeader={showSubHeader} | ||
> | ||
<ViewHeaderMainLeftContentContainer> | ||
<SavedQuestionHeaderButtonContainer isModelOrMetric={isModelOrMetric}> | ||
<HeadBreadcrumbs | ||
divider={<HeaderDivider>/</HeaderDivider>} | ||
parts={[ | ||
...(isAdditionalInfoVisible && isModelOrMetric | ||
? [ | ||
<HeaderCollectionBadge | ||
key="collection" | ||
question={question} | ||
/>, | ||
] | ||
: []), | ||
|
||
<SavedQuestionHeaderButton | ||
key={question.displayName()} | ||
question={question} | ||
onSave={onHeaderChange} | ||
/>, | ||
]} | ||
/> | ||
</SavedQuestionHeaderButtonContainer> | ||
</ViewHeaderMainLeftContentContainer> | ||
{isAdditionalInfoVisible && ( | ||
<ViewHeaderLeftSubHeading> | ||
{QuestionDataSource.shouldRender(props) && !isModelOrMetric && ( | ||
<StyledQuestionDataSource | ||
question={question} | ||
isObjectDetail={isObjectDetail} | ||
subHead | ||
/> | ||
)} | ||
{hasLastEditInfo && isAdditionalInfoVisible && ( | ||
<StyledLastEditInfoLabel | ||
item={question.card()} | ||
onClick={onOpenQuestionInfo} | ||
/> | ||
)} | ||
</ViewHeaderLeftSubHeading> | ||
)} | ||
</SavedQuestionLeftSideRoot> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
...tabase/query_builder/components/view/ViewHeader/components/SavedQuestionLeftSide/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./SavedQuestionLeftSide"; |
Oops, something went wrong.