Merge pull request #229 from mirumee/add/readonly-mode

Add readonly mode
This commit is contained in:
Marcin Gębala 2019-10-24 14:29:59 +02:00 committed by GitHub
commit 5131c50d45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 5 deletions

View file

@ -45,3 +45,4 @@ All notable, unreleased changes to this project will be documented in this file.
- Fix ui improvements - #226 by @benekex2
- Fix attribute errors - #216 by @dominik-zeglen
- Fix column picker - #228 by @dominik-zeglen
- Add readonly mode - #229 by @dominik-zeglen

View file

@ -1,6 +1,6 @@
msgid ""
msgstr ""
"POT-Creation-Date: 2019-10-21T14:54:01.519Z\n"
"POT-Creation-Date: 2019-10-24T12:11:32.946Z\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"MIME-Version: 1.0\n"
@ -6775,6 +6775,14 @@ msgctxt "description"
msgid "Saleor ran into an unexpected problem"
msgstr ""
#: build/locale/src/intl.json
#. [src.readOnly]
#. defaultMessage is:
#. Saleor runs in read-only mode. Changes not saved.
msgctxt "description"
msgid "Saleor runs in read-only mode. Changes not saved."
msgstr ""
#: build/locale/src/intl.json
#. [src.sales] - sales section name
#. defaultMessage is:

View file

@ -47,6 +47,9 @@ export const commonMessages = defineMessages({
properties: {
defaultMessage: "Properties"
},
readOnly: {
defaultMessage: "Saleor runs in read-only mode. Changes not saved."
},
requiredField: {
defaultMessage: "This field is required"
},

View file

@ -6,6 +6,7 @@ import { useIntl } from "react-intl";
import useNotifier from "./hooks/useNotifier";
import { commonMessages } from "./intl";
import { maybe } from "./misc";
export interface TypedMutationInnerProps<TData, TVariables> {
children: (
@ -32,9 +33,21 @@ export function TypedMutation<TData, TVariables>(
mutation={mutation}
onCompleted={onCompleted}
onError={(err: ApolloError) => {
notify({
text: intl.formatMessage(commonMessages.somethingWentWrong)
});
if (
maybe(
() =>
err.graphQLErrors[0].extensions.exception.code ===
"ReadOnlyException"
)
) {
notify({
text: intl.formatMessage(commonMessages.readOnly)
});
} else {
notify({
text: intl.formatMessage(commonMessages.somethingWentWrong)
});
}
if (onError) {
onError(err);
}

View file

@ -82,7 +82,7 @@ export function TypedQuery<TData, TVariables>(
skip={skip}
context={{ useBatching: true }}
>
{queryData => {
{(queryData: QueryResult<TData, TVariables>) => {
if (queryData.error) {
pushMessage({
text: intl.formatMessage(commonMessages.somethingWentWrong)