From 7e342fcc0621978b956d7ef2e08d81462e0287ae Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Sat, 4 Apr 2020 14:10:57 +0700 Subject: [PATCH] fix: wrong filtering --- .../public/page-data/dev-404-page/page-data.json | 2 +- example/public/page-data/index/page-data.json | 2 +- example/src/pages/index.md | 1 + .../src/components/multiple-relations.js | 14 ++------------ 4 files changed, 5 insertions(+), 14 deletions(-) diff --git a/example/public/page-data/dev-404-page/page-data.json b/example/public/page-data/dev-404-page/page-data.json index 3a6c664..4cd9828 100644 --- a/example/public/page-data/dev-404-page/page-data.json +++ b/example/public/page-data/dev-404-page/page-data.json @@ -1 +1 @@ -{"componentChunkName":"component---cache-dev-404-page-js","path":"/dev-404-page/","result":{"data":{"allSitePage":{"nodes":[{"path":"/condition"},{"path":"/file"},{"path":"/"},{"path":"/relation"}]}},"pageContext":{}}} \ No newline at end of file +{"componentChunkName":"component---cache-dev-404-page-js","path":"/dev-404-page/","result":{"data":{"allSitePage":{"nodes":[{"path":"/condition"},{"path":"/file"},{"path":"/relation"},{"path":"/"}]}},"pageContext":{}}} \ No newline at end of file diff --git a/example/public/page-data/index/page-data.json b/example/public/page-data/index/page-data.json index 15bba91..2e70446 100644 --- a/example/public/page-data/index/page-data.json +++ b/example/public/page-data/index/page-data.json @@ -1 +1 @@ -{"componentChunkName":"component---src-templates-page-js","path":"/","result":{"data":{"page":{"id":"04188964-f833-59d9-98db-1d6208773c69","html":"

tinacms-fields

\n

Hey! Welcome to my personal fields playground!\nNavigate to the page of a field to get more instructions.

\n

Credits

\n

Created by Marc Mintel

","frontmatter":{"slug":"/","title":"tinacms-fields","showContent":true},"fileRelativePath":"/src/pages/index.md","rawMarkdownBody":"# tinacms-fields\n\nHey! Welcome to my personal fields playground!\nNavigate to the page of a field to get more instructions.\n\n## Credits\n\nCreated by Marc Mintel","rawFrontmatter":"{\"title\":\"tinacms-fields\",\"slug\":\"/\",\"showContent\":true,\"related\":[\"0fbaac30-f53b-5e10-83b9-64d325ac5833\",\"9b44b7fd-b7e8-50cd-868c-c10b522dab7d\"]}"},"navigation":{"main":[{"title":"Home","slug":"/","link":null,"internal":true},{"title":"Condition Field","slug":"/condition","link":null,"internal":true},{"title":"Relation Field","slug":null,"link":null,"internal":true},{"title":"Blog","slug":null,"link":"https://mintel.me","internal":false}],"rawJson":"{\"main\":[{\"title\":\"Home\",\"internal\":true,\"slug\":\"/\",\"page\":\"04188964-f833-59d9-98db-1d6208773c69\"},{\"title\":\"Condition Field\",\"internal\":true,\"slug\":\"/condition\",\"page\":\"0fbaac30-f53b-5e10-83b9-64d325ac5833\"},{\"title\":\"Relation Field\",\"internal\":true,\"page\":\"ffbe280b-84f2-5902-9756-f6146149b5c1\"},{\"title\":\"Blog\",\"internal\":false,\"link\":\"https://mintel.me\"}],\"__gatsby_resolved\":{\"fileRelativePath\":\"/src/data/navigation.json\"}}","fileRelativePath":"/src/data/navigation.json"}},"pageContext":{"slug":"/"}}} \ No newline at end of file +{"componentChunkName":"component---src-templates-page-js","path":"/","result":{"data":{"page":{"id":"04188964-f833-59d9-98db-1d6208773c69","html":"

tinacms-fields

\n

Hey! Welcome to my personal fields playground!\nNavigate to the page of a field to get more instructions.

\n

Credits

\n

Created by Marc Mintel

","frontmatter":{"slug":"/","title":"tinacms-fields","showContent":true},"fileRelativePath":"/src/pages/index.md","rawMarkdownBody":"# tinacms-fields\n\nHey! Welcome to my personal fields playground!\nNavigate to the page of a field to get more instructions.\n\n## Credits\n\nCreated by Marc Mintel","rawFrontmatter":"{\"title\":\"tinacms-fields\",\"slug\":\"/\",\"showContent\":true,\"related\":[\"ffbe280b-84f2-5902-9756-f6146149b5c1\",\"0fbaac30-f53b-5e10-83b9-64d325ac5833\",\"9b44b7fd-b7e8-50cd-868c-c10b522dab7d\"]}"},"navigation":{"main":[{"title":"Home","slug":"/","link":null,"internal":true},{"title":"Condition Field","slug":"/condition","link":null,"internal":true},{"title":"Relation Field","slug":null,"link":null,"internal":true},{"title":"Blog","slug":null,"link":"https://mintel.me","internal":false}],"rawJson":"{\"main\":[{\"title\":\"Home\",\"internal\":true,\"slug\":\"/\",\"page\":\"04188964-f833-59d9-98db-1d6208773c69\"},{\"title\":\"Condition Field\",\"internal\":true,\"slug\":\"/condition\",\"page\":\"0fbaac30-f53b-5e10-83b9-64d325ac5833\"},{\"title\":\"Relation Field\",\"internal\":true,\"page\":\"ffbe280b-84f2-5902-9756-f6146149b5c1\"},{\"title\":\"Blog\",\"internal\":false,\"link\":\"https://mintel.me\"}],\"__gatsby_resolved\":{\"fileRelativePath\":\"/src/data/navigation.json\"}}","fileRelativePath":"/src/data/navigation.json"}},"pageContext":{"slug":"/"}}} \ No newline at end of file diff --git a/example/src/pages/index.md b/example/src/pages/index.md index 2d70491..fe54223 100644 --- a/example/src/pages/index.md +++ b/example/src/pages/index.md @@ -3,6 +3,7 @@ title: tinacms-fields slug: / showContent: true related: + - ffbe280b-84f2-5902-9756-f6146149b5c1 - 0fbaac30-f53b-5e10-83b9-64d325ac5833 - 9b44b7fd-b7e8-50cd-868c-c10b522dab7d --- diff --git a/packages/tinacms-relation-field/src/components/multiple-relations.js b/packages/tinacms-relation-field/src/components/multiple-relations.js index 2827266..b49eb73 100644 --- a/packages/tinacms-relation-field/src/components/multiple-relations.js +++ b/packages/tinacms-relation-field/src/components/multiple-relations.js @@ -12,18 +12,8 @@ import { FormHeader, FormBody, FieldLabel } from './form'; const MultipleRelations = ({ input, field, form }) => { const [visible, setVisible] = React.useState(false); - const [availableData, setAvailableData] = React.useState(field.data); const value = input.value || []; - React.useEffect(() => { - setAvailableData(field.data); - }, [field.data]); - - React.useEffect(() => { - const newAvailableData = field.data.filter((i) => !value.includes(i.key)); - setAvailableData(newAvailableData); - }, [value]); - const addRelation = React.useCallback( (value) => { form.mutators.insert(field.name, 0, value); @@ -52,7 +42,7 @@ const MultipleRelations = ({ input, field, form }) => { {field.label} - { !!availableData.length && ( + { !!field.data.length && ( <> { - {availableData.map((item) => { + {field.data.filter((item) => !value.includes(field.itemProps(item).key)).map((item) => { const props = field.itemProps(item); return (