Просмотр исходного кода

implemented to make the button unabled when needed

白石誠 5 лет назад
Родитель
Сommit
89d9919bf4

+ 31 - 0
src/client/js/components/CompareDuplicatePathsTabel.jsx

@@ -0,0 +1,31 @@
+import PropTypes from 'prop-types';
+
+import { withTranslation } from 'react-i18next';
+import { withUnstatedContainers } from './UnstatedUtils';
+
+import PageContainer from '../services/PageContainer';
+
+function CompareDuplicatePathsTable(props) {
+  // ToDo this will be implemented by GW-3374
+  // the return value will be either a tabel or false(boolean) if there are no duplicate path
+  return (
+    false
+  );
+}
+
+
+/**
+ * Wrapper component for using unstated
+ */
+const PageDuplicateModallWrapper = withUnstatedContainers(CompareDuplicatePathsTable, [PageContainer]);
+
+CompareDuplicatePathsTable.propTypes = {
+  t: PropTypes.func.isRequired, //  i18next
+
+  pageContainer: PropTypes.instanceOf(PageContainer).isRequired,
+  subordinatedPages: PropTypes.array.isRequired,
+  newPagePath: PropTypes.string.isRequired,
+};
+
+
+export default withTranslation()(PageDuplicateModallWrapper);

+ 8 - 5
src/client/js/components/PageDuplicateModal.jsx

@@ -14,6 +14,7 @@ import PageContainer from '../services/PageContainer';
 import PagePathAutoComplete from './PagePathAutoComplete';
 import ApiErrorMessageList from './PageManagement/ApiErrorMessageList';
 import ComparePathsTable from './ComparePathsTable';
+import CompareDuplicatePathsTable from './CompareDuplicatePathsTabel';
 
 
 const PageDuplicateModal = (props) => {
@@ -31,6 +32,7 @@ const PageDuplicateModal = (props) => {
   const [subordinatedPages, setSubordinatedPages] = useState([]);
   const [isDuplicateRecursively, setIsDuplicateRecursively] = useState(false);
   const [isDuplicateRecursivelyWithoutExistPath, setIsDuplicateRecursivelyWithoutExistPath] = useState(false);
+  const [isDuplicateRecursivelyExist] = useState(false);
 
   function getSubordinatedDuplicateList(value) {
 
@@ -42,6 +44,7 @@ const PageDuplicateModal = (props) => {
     // setIsDuplicateExist(duplicatedList);
 
     // ToDo: for now we use dummy path
+    return [];
   }
 
   /**
@@ -50,8 +53,8 @@ const PageDuplicateModal = (props) => {
    */
   function ppacInputChangeHandler(value) {
     getSubordinatedDuplicateList(value);
-    setErrorCode(null);
-    setErrorMessage(null);
+    // setErrorCode(null);
+    // setErrorMessage(null);
     setPageNameInput(value);
   }
 
@@ -61,8 +64,8 @@ const PageDuplicateModal = (props) => {
    */
   function inputChangeHandler(value) {
     getSubordinatedDuplicateList(value);
-    setErrorCode(null);
-    setErrorMessage(null);
+    // setErrorCode(null);
+    // setErrorMessage(null);
     setPageNameInput(value);
   }
 
@@ -185,7 +188,7 @@ const PageDuplicateModal = (props) => {
           type="button"
           className="btn btn-primary"
           onClick={duplicate}
-          disabled={isDuplicateRecursively && !isDuplicateRecursivelyAdmit}
+          disabled={(isDuplicateRecursively && isDuplicateRecursivelyExist && !isDuplicateRecursivelyWithoutExistPath) || (path === pageNameInput)}
         >
           Duplicate page
         </button>