tinacms 0.58.1 → 0.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/client/index.d.ts +3 -2
- package/dist/index.es.js +57 -45
- package/dist/index.js +56 -44
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# tinacms
|
|
2
2
|
|
|
3
|
+
## 0.59.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- df3030990: Add basic branch switcher
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 9ecceb59f: Always include `collection` for TinaAdmin `createDocument()` and `updateDocument()`
|
|
12
|
+
- Updated dependencies [df3030990]
|
|
13
|
+
- @tinacms/toolkit@0.56.0
|
|
14
|
+
|
|
3
15
|
## 0.58.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/client/index.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export declare class Client {
|
|
|
33
33
|
identityApiUrl: string;
|
|
34
34
|
schema: GraphQLSchema;
|
|
35
35
|
clientId: string;
|
|
36
|
+
contentApiBase: string;
|
|
36
37
|
query: string;
|
|
37
38
|
setToken: (_token: TokenObject) => void;
|
|
38
39
|
private getToken;
|
|
@@ -64,8 +65,8 @@ export declare class Client {
|
|
|
64
65
|
*/
|
|
65
66
|
fetchWithToken(input: RequestInfo, init?: RequestInit): Promise<Response>;
|
|
66
67
|
getUser(): Promise<any>;
|
|
67
|
-
listBranches(
|
|
68
|
-
createBranch({
|
|
68
|
+
listBranches(): Promise<any>;
|
|
69
|
+
createBranch({ baseBranch, branchName }: BranchData): Promise<string>;
|
|
69
70
|
}
|
|
70
71
|
export declare const DEFAULT_LOCAL_TINA_GQL_SERVER_URL = "http://localhost:4001/graphql";
|
|
71
72
|
export declare class LocalClient extends Client {
|
package/dist/index.es.js
CHANGED
|
@@ -32,7 +32,7 @@ var __objRest = (source, exclude) => {
|
|
|
32
32
|
import { TypeInfo, visit, visitWithTypeInfo, getNamedType, GraphQLObjectType, isLeafType, GraphQLUnionType, isScalarType, getIntrospectionQuery, buildClientSchema, print } from "graphql";
|
|
33
33
|
import set from "lodash.set";
|
|
34
34
|
import gql$1 from "graphql-tag";
|
|
35
|
-
import { EventBus, StyleReset, Modal, ModalPopup, ModalHeader, ModalBody, ModalActions, Button, LoadingDots, TinaCMS, BranchSwitcherPlugin, TinaProvider, useCMS, FormMetaPlugin, Form, GlobalFormPlugin, FullscreenFormBuilder } from "@tinacms/toolkit";
|
|
35
|
+
import { EventBus, StyleReset, Modal, ModalPopup, ModalHeader, ModalBody, ModalActions, Button, LoadingDots, useLocalStorage, TinaCMS, BranchSwitcherPlugin, BranchDataProvider, TinaProvider, useCMS, useBranchData, FormMetaPlugin, Form, GlobalFormPlugin, FullscreenFormBuilder } from "@tinacms/toolkit";
|
|
36
36
|
export * from "@tinacms/toolkit";
|
|
37
37
|
import React, { useState, useCallback, useEffect, Fragment } from "react";
|
|
38
38
|
import styled from "styled-components";
|
|
@@ -376,6 +376,7 @@ function assertIsUnionType(type) {
|
|
|
376
376
|
class Client {
|
|
377
377
|
constructor(_a) {
|
|
378
378
|
var _b = _a, { tokenStorage = "MEMORY" } = _b, options = __objRest(_b, ["tokenStorage"]);
|
|
379
|
+
this.events = new EventBus();
|
|
379
380
|
this.addPendingContent = async (props) => {
|
|
380
381
|
const mutation = `#graphql
|
|
381
382
|
mutation addPendingDocumentMutation(
|
|
@@ -416,8 +417,7 @@ mutation addPendingDocumentMutation(
|
|
|
416
417
|
};
|
|
417
418
|
this.options = options;
|
|
418
419
|
this.setBranch(options.branch);
|
|
419
|
-
this.events
|
|
420
|
-
this.events.subscribe("branch-switcher:change-branch", ({ branchName }) => {
|
|
420
|
+
this.events.subscribe("branch:change", ({ branchName }) => {
|
|
421
421
|
this.setBranch(branchName);
|
|
422
422
|
});
|
|
423
423
|
this.clientId = options.clientId;
|
|
@@ -468,8 +468,8 @@ mutation addPendingDocumentMutation(
|
|
|
468
468
|
const encodedBranch = encodeURIComponent(branchName);
|
|
469
469
|
this.frontendUrl = ((_a = this.options.tinaioConfig) == null ? void 0 : _a.frontendUrlOverride) || "https://app.tina.io";
|
|
470
470
|
this.identityApiUrl = ((_b = this.options.tinaioConfig) == null ? void 0 : _b.identityApiUrlOverride) || "https://identity.tinajs.io";
|
|
471
|
-
|
|
472
|
-
this.contentApiUrl = this.options.customContentApiUrl || `${contentApiBase}/content/${this.options.clientId}/github/${encodedBranch}`;
|
|
471
|
+
this.contentApiBase = ((_c = this.options.tinaioConfig) == null ? void 0 : _c.contentApiUrlOverride) || `https://content.tinajs.io`;
|
|
472
|
+
this.contentApiUrl = this.options.customContentApiUrl || `${this.contentApiBase}/content/${this.options.clientId}/github/${encodedBranch}`;
|
|
473
473
|
}
|
|
474
474
|
async requestWithForm(query, { variables }) {
|
|
475
475
|
const schema = await this.getSchema();
|
|
@@ -534,28 +534,24 @@ mutation addPendingDocumentMutation(
|
|
|
534
534
|
return null;
|
|
535
535
|
}
|
|
536
536
|
}
|
|
537
|
-
async listBranches(
|
|
538
|
-
const url = `${this.
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
return JSON.stringify(res);
|
|
544
|
-
} catch (e) {
|
|
545
|
-
console.error("There was an issue fetching the branch list.", e);
|
|
546
|
-
return null;
|
|
547
|
-
}
|
|
537
|
+
async listBranches() {
|
|
538
|
+
const url = `${this.contentApiBase}/github/${this.clientId}/list_branches`;
|
|
539
|
+
const res = await this.fetchWithToken(url, {
|
|
540
|
+
method: "GET"
|
|
541
|
+
});
|
|
542
|
+
return res.json();
|
|
548
543
|
}
|
|
549
|
-
async createBranch({
|
|
550
|
-
const url = `${this.
|
|
544
|
+
async createBranch({ baseBranch, branchName }) {
|
|
545
|
+
const url = `${this.contentApiBase}/github/${this.clientId}/create_branch`;
|
|
551
546
|
try {
|
|
552
547
|
const res = await this.fetchWithToken(url, {
|
|
553
548
|
method: "POST",
|
|
554
549
|
body: {
|
|
555
|
-
owner,
|
|
556
|
-
repo,
|
|
557
550
|
baseBranch,
|
|
558
551
|
branchName
|
|
552
|
+
},
|
|
553
|
+
headers: {
|
|
554
|
+
"Content-Type": "application/json"
|
|
559
555
|
}
|
|
560
556
|
});
|
|
561
557
|
return JSON.stringify(res);
|
|
@@ -737,13 +733,15 @@ const AuthWallInner = ({
|
|
|
737
733
|
}), showChildren ? children : loginScreen ? loginScreen : null);
|
|
738
734
|
};
|
|
739
735
|
const TinaCloudProvider = (props) => {
|
|
736
|
+
const baseBranch = props.branch || "main";
|
|
737
|
+
const [currentBranch, setCurrentBranch] = useLocalStorage("tinacms-current-branch", baseBranch);
|
|
740
738
|
useTinaAuthRedirect();
|
|
741
739
|
const cms = React.useMemo(() => props.cms || new TinaCMS({
|
|
742
740
|
enabled: true,
|
|
743
741
|
sidebar: true
|
|
744
742
|
}), [props.cms]);
|
|
745
743
|
if (!cms.api.tina) {
|
|
746
|
-
cms.
|
|
744
|
+
cms.registerApi("tina", createClient(props));
|
|
747
745
|
}
|
|
748
746
|
const setupMedia = async () => {
|
|
749
747
|
var _a;
|
|
@@ -759,45 +757,54 @@ const TinaCloudProvider = (props) => {
|
|
|
759
757
|
const handleListBranches = async () => {
|
|
760
758
|
const { owner, repo } = props;
|
|
761
759
|
const branches = await cms.api.tina.listBranches({ owner, repo });
|
|
762
|
-
|
|
760
|
+
if (!Array.isArray(branches)) {
|
|
761
|
+
return [];
|
|
762
|
+
}
|
|
763
|
+
return branches;
|
|
763
764
|
};
|
|
764
765
|
const handleCreateBranch = async (data) => {
|
|
765
766
|
const newBranch = await cms.api.tina.createBranch(data);
|
|
766
767
|
return newBranch;
|
|
767
768
|
};
|
|
768
769
|
setupMedia();
|
|
769
|
-
const branchingEnabled = cms.flags.get("branch-switcher");
|
|
770
|
+
const [branchingEnabled, setBranchingEnabled] = React.useState(() => cms.flags.get("branch-switcher"));
|
|
771
|
+
React.useEffect(() => {
|
|
772
|
+
cms.events.subscribe("flag:set", ({ key, value }) => {
|
|
773
|
+
if (key === "branch-switcher") {
|
|
774
|
+
setBranchingEnabled(value);
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
}, [cms.events]);
|
|
770
778
|
React.useEffect(() => {
|
|
771
779
|
let branchSwitcher;
|
|
772
780
|
if (branchingEnabled) {
|
|
773
781
|
branchSwitcher = new BranchSwitcherPlugin({
|
|
774
|
-
cms,
|
|
775
|
-
owner: props.owner,
|
|
776
|
-
repo: props.repo,
|
|
777
|
-
baseBranch: props.branch || "main",
|
|
778
|
-
currentBranch: props.branch || "main",
|
|
779
782
|
listBranches: handleListBranches,
|
|
780
|
-
createBranch: handleCreateBranch
|
|
781
|
-
setCurrentBranch: () => console.log(props.branch)
|
|
783
|
+
createBranch: handleCreateBranch
|
|
782
784
|
});
|
|
783
785
|
cms.plugins.add(branchSwitcher);
|
|
784
786
|
}
|
|
785
787
|
return () => {
|
|
786
|
-
if (
|
|
787
|
-
|
|
788
|
-
cms.plugins.remove(branchSwitcher);
|
|
789
|
-
}
|
|
788
|
+
if (branchingEnabled && branchSwitcher) {
|
|
789
|
+
cms.plugins.remove(branchSwitcher);
|
|
790
790
|
}
|
|
791
791
|
};
|
|
792
792
|
}, [branchingEnabled, props.branch]);
|
|
793
|
-
|
|
794
|
-
props.cmsCallback
|
|
795
|
-
|
|
796
|
-
|
|
793
|
+
React.useEffect(() => {
|
|
794
|
+
if (props.cmsCallback) {
|
|
795
|
+
props.cmsCallback(cms);
|
|
796
|
+
}
|
|
797
|
+
}, []);
|
|
798
|
+
return /* @__PURE__ */ React.createElement(BranchDataProvider, {
|
|
799
|
+
currentBranch,
|
|
800
|
+
setCurrentBranch: (b) => {
|
|
801
|
+
setCurrentBranch(b);
|
|
802
|
+
}
|
|
803
|
+
}, /* @__PURE__ */ React.createElement(TinaProvider, {
|
|
797
804
|
cms
|
|
798
805
|
}, /* @__PURE__ */ React.createElement(AuthWallInner, __spreadProps(__spreadValues({}, props), {
|
|
799
806
|
cms
|
|
800
|
-
})));
|
|
807
|
+
}))));
|
|
801
808
|
};
|
|
802
809
|
const TinaCloudAuthWall = TinaCloudProvider;
|
|
803
810
|
var DefaultContext = {
|
|
@@ -898,6 +905,7 @@ function useGraphqlForms({
|
|
|
898
905
|
const [pendingReset, setPendingReset] = React.useState(null);
|
|
899
906
|
const [isLoading, setIsLoading] = React.useState(true);
|
|
900
907
|
const [newUpdate, setNewUpdate] = React.useState(null);
|
|
908
|
+
const { currentBranch } = useBranchData();
|
|
901
909
|
const updateData = async () => {
|
|
902
910
|
var _a;
|
|
903
911
|
if (newUpdate) {
|
|
@@ -1108,7 +1116,7 @@ function useGraphqlForms({
|
|
|
1108
1116
|
}
|
|
1109
1117
|
});
|
|
1110
1118
|
};
|
|
1111
|
-
}, [queryString, JSON.stringify(variables)]);
|
|
1119
|
+
}, [queryString, JSON.stringify(variables), currentBranch]);
|
|
1112
1120
|
return [data, isLoading];
|
|
1113
1121
|
}
|
|
1114
1122
|
const transformDocumentIntoMutationRequestPayload = (document2, instructions) => {
|
|
@@ -1906,13 +1914,15 @@ const createDocument = async (cms, collection, template, mutationInfo, values) =
|
|
|
1906
1914
|
includeCollection,
|
|
1907
1915
|
includeTemplate
|
|
1908
1916
|
});
|
|
1909
|
-
await cms.api.tina.request(`mutation($relativePath: String!, $params: DocumentMutation!) {
|
|
1910
|
-
createDocument(
|
|
1917
|
+
await cms.api.tina.request(`mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
|
|
1918
|
+
createDocument(
|
|
1919
|
+
collection: $collection,
|
|
1911
1920
|
relativePath: $relativePath,
|
|
1912
1921
|
params: $params
|
|
1913
1922
|
){__typename}
|
|
1914
1923
|
}`, {
|
|
1915
1924
|
variables: {
|
|
1925
|
+
collection: collection.name,
|
|
1916
1926
|
relativePath,
|
|
1917
1927
|
params
|
|
1918
1928
|
}
|
|
@@ -1986,19 +1996,21 @@ const GetDocument = ({
|
|
|
1986
1996
|
}
|
|
1987
1997
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, children(document2));
|
|
1988
1998
|
};
|
|
1989
|
-
const updateDocument = async (cms, relativePath, mutationInfo, values) => {
|
|
1999
|
+
const updateDocument = async (cms, relativePath, collection, mutationInfo, values) => {
|
|
1990
2000
|
const { includeCollection, includeTemplate } = mutationInfo;
|
|
1991
2001
|
const params = transformDocumentIntoMutationRequestPayload(values, {
|
|
1992
2002
|
includeCollection,
|
|
1993
2003
|
includeTemplate
|
|
1994
2004
|
});
|
|
1995
|
-
await cms.api.tina.request(`mutation($relativePath: String!, $params: DocumentMutation!) {
|
|
2005
|
+
await cms.api.tina.request(`mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
|
|
1996
2006
|
updateDocument(
|
|
2007
|
+
collection: $collection,
|
|
1997
2008
|
relativePath: $relativePath,
|
|
1998
2009
|
params: $params
|
|
1999
2010
|
){__typename}
|
|
2000
2011
|
}`, {
|
|
2001
2012
|
variables: {
|
|
2013
|
+
collection: collection.name,
|
|
2002
2014
|
relativePath,
|
|
2003
2015
|
params
|
|
2004
2016
|
}
|
|
@@ -2023,7 +2035,7 @@ const CollectionUpdatePage = () => {
|
|
|
2023
2035
|
fields: document2.form.fields,
|
|
2024
2036
|
initialValues: document2.values,
|
|
2025
2037
|
onSubmit: async (values) => {
|
|
2026
|
-
await updateDocument(cms, relativePath, mutationInfo, values);
|
|
2038
|
+
await updateDocument(cms, relativePath, collection, mutationInfo, values);
|
|
2027
2039
|
history.push(`/admin/collections/${collection.name}`);
|
|
2028
2040
|
}
|
|
2029
2041
|
});
|
package/dist/index.js
CHANGED
|
@@ -397,6 +397,7 @@ var __objRest = (source, exclude) => {
|
|
|
397
397
|
class Client {
|
|
398
398
|
constructor(_a) {
|
|
399
399
|
var _b = _a, { tokenStorage = "MEMORY" } = _b, options = __objRest(_b, ["tokenStorage"]);
|
|
400
|
+
this.events = new toolkit.EventBus();
|
|
400
401
|
this.addPendingContent = async (props) => {
|
|
401
402
|
const mutation = `#graphql
|
|
402
403
|
mutation addPendingDocumentMutation(
|
|
@@ -437,8 +438,7 @@ mutation addPendingDocumentMutation(
|
|
|
437
438
|
};
|
|
438
439
|
this.options = options;
|
|
439
440
|
this.setBranch(options.branch);
|
|
440
|
-
this.events
|
|
441
|
-
this.events.subscribe("branch-switcher:change-branch", ({ branchName }) => {
|
|
441
|
+
this.events.subscribe("branch:change", ({ branchName }) => {
|
|
442
442
|
this.setBranch(branchName);
|
|
443
443
|
});
|
|
444
444
|
this.clientId = options.clientId;
|
|
@@ -489,8 +489,8 @@ mutation addPendingDocumentMutation(
|
|
|
489
489
|
const encodedBranch = encodeURIComponent(branchName);
|
|
490
490
|
this.frontendUrl = ((_a = this.options.tinaioConfig) == null ? void 0 : _a.frontendUrlOverride) || "https://app.tina.io";
|
|
491
491
|
this.identityApiUrl = ((_b = this.options.tinaioConfig) == null ? void 0 : _b.identityApiUrlOverride) || "https://identity.tinajs.io";
|
|
492
|
-
|
|
493
|
-
this.contentApiUrl = this.options.customContentApiUrl || `${contentApiBase}/content/${this.options.clientId}/github/${encodedBranch}`;
|
|
492
|
+
this.contentApiBase = ((_c = this.options.tinaioConfig) == null ? void 0 : _c.contentApiUrlOverride) || `https://content.tinajs.io`;
|
|
493
|
+
this.contentApiUrl = this.options.customContentApiUrl || `${this.contentApiBase}/content/${this.options.clientId}/github/${encodedBranch}`;
|
|
494
494
|
}
|
|
495
495
|
async requestWithForm(query, { variables }) {
|
|
496
496
|
const schema = await this.getSchema();
|
|
@@ -555,28 +555,24 @@ mutation addPendingDocumentMutation(
|
|
|
555
555
|
return null;
|
|
556
556
|
}
|
|
557
557
|
}
|
|
558
|
-
async listBranches(
|
|
559
|
-
const url = `${this.
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
return JSON.stringify(res);
|
|
565
|
-
} catch (e) {
|
|
566
|
-
console.error("There was an issue fetching the branch list.", e);
|
|
567
|
-
return null;
|
|
568
|
-
}
|
|
558
|
+
async listBranches() {
|
|
559
|
+
const url = `${this.contentApiBase}/github/${this.clientId}/list_branches`;
|
|
560
|
+
const res = await this.fetchWithToken(url, {
|
|
561
|
+
method: "GET"
|
|
562
|
+
});
|
|
563
|
+
return res.json();
|
|
569
564
|
}
|
|
570
|
-
async createBranch({
|
|
571
|
-
const url = `${this.
|
|
565
|
+
async createBranch({ baseBranch, branchName }) {
|
|
566
|
+
const url = `${this.contentApiBase}/github/${this.clientId}/create_branch`;
|
|
572
567
|
try {
|
|
573
568
|
const res = await this.fetchWithToken(url, {
|
|
574
569
|
method: "POST",
|
|
575
570
|
body: {
|
|
576
|
-
owner,
|
|
577
|
-
repo,
|
|
578
571
|
baseBranch,
|
|
579
572
|
branchName
|
|
573
|
+
},
|
|
574
|
+
headers: {
|
|
575
|
+
"Content-Type": "application/json"
|
|
580
576
|
}
|
|
581
577
|
});
|
|
582
578
|
return JSON.stringify(res);
|
|
@@ -758,13 +754,15 @@ mutation addPendingDocumentMutation(
|
|
|
758
754
|
}), showChildren ? children : loginScreen ? loginScreen : null);
|
|
759
755
|
};
|
|
760
756
|
const TinaCloudProvider = (props) => {
|
|
757
|
+
const baseBranch = props.branch || "main";
|
|
758
|
+
const [currentBranch, setCurrentBranch] = toolkit.useLocalStorage("tinacms-current-branch", baseBranch);
|
|
761
759
|
useTinaAuthRedirect();
|
|
762
760
|
const cms = React__default["default"].useMemo(() => props.cms || new toolkit.TinaCMS({
|
|
763
761
|
enabled: true,
|
|
764
762
|
sidebar: true
|
|
765
763
|
}), [props.cms]);
|
|
766
764
|
if (!cms.api.tina) {
|
|
767
|
-
cms.
|
|
765
|
+
cms.registerApi("tina", createClient(props));
|
|
768
766
|
}
|
|
769
767
|
const setupMedia = async () => {
|
|
770
768
|
var _a;
|
|
@@ -780,45 +778,54 @@ mutation addPendingDocumentMutation(
|
|
|
780
778
|
const handleListBranches = async () => {
|
|
781
779
|
const { owner, repo } = props;
|
|
782
780
|
const branches = await cms.api.tina.listBranches({ owner, repo });
|
|
783
|
-
|
|
781
|
+
if (!Array.isArray(branches)) {
|
|
782
|
+
return [];
|
|
783
|
+
}
|
|
784
|
+
return branches;
|
|
784
785
|
};
|
|
785
786
|
const handleCreateBranch = async (data) => {
|
|
786
787
|
const newBranch = await cms.api.tina.createBranch(data);
|
|
787
788
|
return newBranch;
|
|
788
789
|
};
|
|
789
790
|
setupMedia();
|
|
790
|
-
const branchingEnabled = cms.flags.get("branch-switcher");
|
|
791
|
+
const [branchingEnabled, setBranchingEnabled] = React__default["default"].useState(() => cms.flags.get("branch-switcher"));
|
|
792
|
+
React__default["default"].useEffect(() => {
|
|
793
|
+
cms.events.subscribe("flag:set", ({ key, value }) => {
|
|
794
|
+
if (key === "branch-switcher") {
|
|
795
|
+
setBranchingEnabled(value);
|
|
796
|
+
}
|
|
797
|
+
});
|
|
798
|
+
}, [cms.events]);
|
|
791
799
|
React__default["default"].useEffect(() => {
|
|
792
800
|
let branchSwitcher;
|
|
793
801
|
if (branchingEnabled) {
|
|
794
802
|
branchSwitcher = new toolkit.BranchSwitcherPlugin({
|
|
795
|
-
cms,
|
|
796
|
-
owner: props.owner,
|
|
797
|
-
repo: props.repo,
|
|
798
|
-
baseBranch: props.branch || "main",
|
|
799
|
-
currentBranch: props.branch || "main",
|
|
800
803
|
listBranches: handleListBranches,
|
|
801
|
-
createBranch: handleCreateBranch
|
|
802
|
-
setCurrentBranch: () => console.log(props.branch)
|
|
804
|
+
createBranch: handleCreateBranch
|
|
803
805
|
});
|
|
804
806
|
cms.plugins.add(branchSwitcher);
|
|
805
807
|
}
|
|
806
808
|
return () => {
|
|
807
|
-
if (
|
|
808
|
-
|
|
809
|
-
cms.plugins.remove(branchSwitcher);
|
|
810
|
-
}
|
|
809
|
+
if (branchingEnabled && branchSwitcher) {
|
|
810
|
+
cms.plugins.remove(branchSwitcher);
|
|
811
811
|
}
|
|
812
812
|
};
|
|
813
813
|
}, [branchingEnabled, props.branch]);
|
|
814
|
-
|
|
815
|
-
props.cmsCallback
|
|
816
|
-
|
|
817
|
-
|
|
814
|
+
React__default["default"].useEffect(() => {
|
|
815
|
+
if (props.cmsCallback) {
|
|
816
|
+
props.cmsCallback(cms);
|
|
817
|
+
}
|
|
818
|
+
}, []);
|
|
819
|
+
return /* @__PURE__ */ React__default["default"].createElement(toolkit.BranchDataProvider, {
|
|
820
|
+
currentBranch,
|
|
821
|
+
setCurrentBranch: (b) => {
|
|
822
|
+
setCurrentBranch(b);
|
|
823
|
+
}
|
|
824
|
+
}, /* @__PURE__ */ React__default["default"].createElement(toolkit.TinaProvider, {
|
|
818
825
|
cms
|
|
819
826
|
}, /* @__PURE__ */ React__default["default"].createElement(AuthWallInner, __spreadProps(__spreadValues({}, props), {
|
|
820
827
|
cms
|
|
821
|
-
})));
|
|
828
|
+
}))));
|
|
822
829
|
};
|
|
823
830
|
const TinaCloudAuthWall = TinaCloudProvider;
|
|
824
831
|
var DefaultContext = {
|
|
@@ -919,6 +926,7 @@ mutation addPendingDocumentMutation(
|
|
|
919
926
|
const [pendingReset, setPendingReset] = React__default["default"].useState(null);
|
|
920
927
|
const [isLoading, setIsLoading] = React__default["default"].useState(true);
|
|
921
928
|
const [newUpdate, setNewUpdate] = React__default["default"].useState(null);
|
|
929
|
+
const { currentBranch } = toolkit.useBranchData();
|
|
922
930
|
const updateData = async () => {
|
|
923
931
|
var _a;
|
|
924
932
|
if (newUpdate) {
|
|
@@ -1129,7 +1137,7 @@ mutation addPendingDocumentMutation(
|
|
|
1129
1137
|
}
|
|
1130
1138
|
});
|
|
1131
1139
|
};
|
|
1132
|
-
}, [queryString, JSON.stringify(variables)]);
|
|
1140
|
+
}, [queryString, JSON.stringify(variables), currentBranch]);
|
|
1133
1141
|
return [data, isLoading];
|
|
1134
1142
|
}
|
|
1135
1143
|
const transformDocumentIntoMutationRequestPayload = (document2, instructions) => {
|
|
@@ -1927,13 +1935,15 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
1927
1935
|
includeCollection,
|
|
1928
1936
|
includeTemplate
|
|
1929
1937
|
});
|
|
1930
|
-
await cms.api.tina.request(`mutation($relativePath: String!, $params: DocumentMutation!) {
|
|
1931
|
-
createDocument(
|
|
1938
|
+
await cms.api.tina.request(`mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
|
|
1939
|
+
createDocument(
|
|
1940
|
+
collection: $collection,
|
|
1932
1941
|
relativePath: $relativePath,
|
|
1933
1942
|
params: $params
|
|
1934
1943
|
){__typename}
|
|
1935
1944
|
}`, {
|
|
1936
1945
|
variables: {
|
|
1946
|
+
collection: collection.name,
|
|
1937
1947
|
relativePath,
|
|
1938
1948
|
params
|
|
1939
1949
|
}
|
|
@@ -2007,19 +2017,21 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
2007
2017
|
}
|
|
2008
2018
|
return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, children(document2));
|
|
2009
2019
|
};
|
|
2010
|
-
const updateDocument = async (cms, relativePath, mutationInfo, values) => {
|
|
2020
|
+
const updateDocument = async (cms, relativePath, collection, mutationInfo, values) => {
|
|
2011
2021
|
const { includeCollection, includeTemplate } = mutationInfo;
|
|
2012
2022
|
const params = transformDocumentIntoMutationRequestPayload(values, {
|
|
2013
2023
|
includeCollection,
|
|
2014
2024
|
includeTemplate
|
|
2015
2025
|
});
|
|
2016
|
-
await cms.api.tina.request(`mutation($relativePath: String!, $params: DocumentMutation!) {
|
|
2026
|
+
await cms.api.tina.request(`mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
|
|
2017
2027
|
updateDocument(
|
|
2028
|
+
collection: $collection,
|
|
2018
2029
|
relativePath: $relativePath,
|
|
2019
2030
|
params: $params
|
|
2020
2031
|
){__typename}
|
|
2021
2032
|
}`, {
|
|
2022
2033
|
variables: {
|
|
2034
|
+
collection: collection.name,
|
|
2023
2035
|
relativePath,
|
|
2024
2036
|
params
|
|
2025
2037
|
}
|
|
@@ -2044,7 +2056,7 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
2044
2056
|
fields: document2.form.fields,
|
|
2045
2057
|
initialValues: document2.values,
|
|
2046
2058
|
onSubmit: async (values) => {
|
|
2047
|
-
await updateDocument(cms, relativePath, mutationInfo, values);
|
|
2059
|
+
await updateDocument(cms, relativePath, collection, mutationInfo, values);
|
|
2048
2060
|
history.push(`/admin/collections/${collection.name}`);
|
|
2049
2061
|
}
|
|
2050
2062
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinacms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.59.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@graphql-codegen/typescript-operations": "^1.15.4",
|
|
25
25
|
"@headlessui/react": "^1.4.1",
|
|
26
26
|
"@heroicons/react": "^1.0.4",
|
|
27
|
-
"@tinacms/toolkit": "0.
|
|
27
|
+
"@tinacms/toolkit": "0.56.0",
|
|
28
28
|
"@xstate/react": "^1.1.0",
|
|
29
29
|
"codemirror": "^5.55.0",
|
|
30
30
|
"cors": "^2.8.5",
|