-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): Documentation Editor Improvements (#7072)
- Loading branch information
1 parent
65c2759
commit 72f0328
Showing
10 changed files
with
279 additions
and
51 deletions.
There are no files selected for viewing
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
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,51 @@ | ||
import { useEffect } from 'react'; | ||
import { useHistory, useLocation } from 'react-router'; | ||
import { PageRoutes } from '../../conf/Global'; | ||
|
||
export function useInitialRedirect(state, localState, setState, setLocalState) { | ||
const location = useLocation(); | ||
const history = useHistory(); | ||
|
||
/** | ||
* Route to the most recently visited path once on first load of home page, if present in local storage. | ||
*/ | ||
useEffect(() => { | ||
if ( | ||
location.pathname === PageRoutes.ROOT && | ||
!state.loadedInitialPath && | ||
localState.selectedPath !== location.pathname | ||
) { | ||
setState({ | ||
...state, | ||
loadedInitialPath: true, | ||
}); | ||
if (localState.selectedPath) { | ||
history.push({ | ||
pathname: localState.selectedPath, | ||
search: localState.selectedSearch || '', | ||
}); | ||
} | ||
} | ||
}, [ | ||
localState.selectedPath, | ||
localState.selectedSearch, | ||
location.pathname, | ||
location.search, | ||
state, | ||
history, | ||
setState, | ||
]); | ||
|
||
/** | ||
* When the location of the browse changes, save the latest to local state. | ||
*/ | ||
useEffect(() => { | ||
if (localState.selectedPath !== location.pathname || localState.selectedSearch !== location.search) { | ||
setLocalState({ | ||
...localState, | ||
selectedPath: location.pathname, | ||
selectedSearch: location.search, | ||
}); | ||
} | ||
}, [location.pathname, location.search, localState, setLocalState]); | ||
} |
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
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
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
23 changes: 23 additions & 0 deletions
23
...eb-react/src/app/entity/shared/tabs/Documentation/components/DescriptionEditorToolbar.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,23 @@ | ||
import { CheckOutlined } from '@ant-design/icons'; | ||
import { Button } from 'antd'; | ||
import React from 'react'; | ||
import TabToolbar from '../../../components/styled/TabToolbar'; | ||
|
||
type DescriptionEditorToolbarProps = { | ||
disableSave: boolean; | ||
onClose: () => void; | ||
onSave: () => void; | ||
}; | ||
|
||
export const DescriptionEditorToolbar = ({ disableSave, onClose, onSave }: DescriptionEditorToolbarProps) => { | ||
return ( | ||
<TabToolbar> | ||
<Button type="text" onClick={onClose}> | ||
Back | ||
</Button> | ||
<Button onClick={onSave} disabled={disableSave}> | ||
<CheckOutlined /> Save | ||
</Button> | ||
</TabToolbar> | ||
); | ||
}; |
25 changes: 25 additions & 0 deletions
25
datahub-web-react/src/app/entity/shared/tabs/Documentation/components/DescriptionPreview.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,25 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import { Editor } from './editor/Editor'; | ||
import { DescriptionPreviewToolbar } from './DescriptionPreviewToolbar'; | ||
|
||
const EditorContainer = styled.div` | ||
overflow: auto; | ||
height: 100%; | ||
`; | ||
|
||
type DescriptionPreviewProps = { | ||
description: string; | ||
onEdit: () => void; | ||
}; | ||
|
||
export const DescriptionPreview = ({ description, onEdit }: DescriptionPreviewProps) => { | ||
return ( | ||
<> | ||
<DescriptionPreviewToolbar onEdit={onEdit} /> | ||
<EditorContainer> | ||
<Editor content={description} readOnly /> | ||
</EditorContainer> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.