Quellcode durchsuchen

WIP: impl refs method

Yuki Takei vor 6 Jahren
Ursprung
Commit
e66920a2fc

+ 28 - 8
packages/growi-plugin-attachment-refs/src/client/js/components/AttachmentList.jsx

@@ -72,17 +72,37 @@ export default class AttachmentList extends React.Component {
     try {
       this.setState({ isLoading: true });
 
-      res = await axios.get('/_api/plugin/ref', {
-        params: {
-          pagePath: refsContext.pagePath,
-          fileName: refsContext.fileName,
-          options: refsContext.options,
-        },
-      });
+      switch (refsContext.method) {
+        case 'ref':
+          res = await axios.get('/_api/plugin/ref', {
+            params: {
+              pagePath: refsContext.pagePath,
+              fileName: refsContext.fileName,
+              options: refsContext.options,
+            },
+          });
+          this.setState({
+            attachments: [res.data.attachment],
+          });
+          break;
+        case 'refs':
+          res = await axios.get('/_api/plugin/refs', {
+            params: {
+              prefix: refsContext.prefix,
+              pagePath: refsContext.pagePath,
+              options: refsContext.options,
+            },
+          });
+          this.setState({
+            attachments: res.data.attachments,
+          });
+          break;
+        default:
+          throw new Error('this component should be used for method \'ref\' or \'refs\'');
+      }
 
       this.setState({
         isLoaded: true,
-        attachments: [res.data.attachment],
       });
     }
     catch (err) {