SearchResultContentSubNavigation.tsx 2.7 KB

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