SearchResultContentSubNavigation.tsx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import React, { FC } from 'react';
  2. import { pagePathUtils } from '@growi/core';
  3. import { EditorMode, useEditorMode } from '~/stores/ui';
  4. import PagePathNav from '../PagePathNav';
  5. import { withUnstatedContainers } from '../UnstatedUtils';
  6. import AppContainer from '../../client/services/AppContainer';
  7. import { useSWRTagsInfo } from '../../stores/page';
  8. import SubNavButtons from '../Navbar/SubNavButtons';
  9. type Props = {
  10. appContainer:AppContainer
  11. pageId: string,
  12. revisionId: string,
  13. path: string,
  14. isSignleLineMode?: boolean,
  15. isCompactMode?: boolean,
  16. }
  17. const SearchResultContentSubNavigation: FC<Props> = (props : Props) => {
  18. const {
  19. appContainer, pageId, revisionId, path, isCompactMode, isSignleLineMode,
  20. } = props;
  21. const { isTrashPage, isDeletablePage } = pagePathUtils;
  22. const { data: editorMode } = useEditorMode();
  23. const { data: tagInfoData, error: tagInfoError } = useSWRTagsInfo(pageId);
  24. if (tagInfoError != null || tagInfoData == null) {
  25. return <></>;
  26. }
  27. const isViewMode = editorMode === EditorMode.View;
  28. const isPageDeletable = isDeletablePage(path);
  29. const { isSharedUser } = appContainer;
  30. const isAbleToShowPageManagement = !(isTrashPage(path)) && !isSharedUser;
  31. return (
  32. <div className="shadow-sm search-result-content-nav">
  33. <div className={`grw-subnav container-fluid d-flex align-items-start justify-content-between ${isCompactMode ? 'grw-subnav-compact d-print-none' : ''}`}>
  34. {/* Left side */}
  35. <div className="grw-path-nav-container">
  36. <PagePathNav pageId={pageId} pagePath={path} isCompactMode={isCompactMode} isSingleLineMode={isSignleLineMode} />
  37. </div>
  38. {/* Right side */}
  39. {/*
  40. DeleteCompletely is currently disabled
  41. TODO : Retrive isAbleToDeleteCompleltly state everywhere in the system via swr.
  42. story: https://redmine.weseek.co.jp/issues/82222
  43. */}
  44. <div className="d-flex">
  45. <SubNavButtons
  46. isCompactMode={isCompactMode}
  47. pageId={pageId}
  48. revisionId={revisionId}
  49. path={path}
  50. isViewMode={isViewMode}
  51. isDeletable={isPageDeletable}
  52. isAbleToDeleteCompletely={false}
  53. isAbleToShowPageManagement={isAbleToShowPageManagement}
  54. >
  55. </SubNavButtons>
  56. </div>
  57. </div>
  58. </div>
  59. );
  60. };
  61. /**
  62. * Wrapper component for using unstated
  63. */
  64. const SearchResultContentSubNavigationUnstatedWrapper = withUnstatedContainers(SearchResultContentSubNavigation, [AppContainer]);
  65. // wrapping tsx component returned by withUnstatedContainers to avoid type error when this component used in other tsx components.
  66. const SearchResultContentSubNavigationWrapper = (props) => {
  67. return <SearchResultContentSubNavigationUnstatedWrapper {...props}></SearchResultContentSubNavigationUnstatedWrapper>;
  68. };
  69. export default SearchResultContentSubNavigationWrapper;