Fix types
This commit is contained in:
parent
decb66ec74
commit
f3382fa544
5 changed files with 33 additions and 21 deletions
|
@ -10,11 +10,11 @@ import FormSpacer from "@saleor/components/FormSpacer";
|
||||||
import Hr from "@saleor/components/Hr";
|
import Hr from "@saleor/components/Hr";
|
||||||
import i18n from "../../../i18n";
|
import i18n from "../../../i18n";
|
||||||
import { FormData } from "../PluginsDetailsPage";
|
import { FormData } from "../PluginsDetailsPage";
|
||||||
import { Plugin_plugin } from "../../types/Plugin";
|
|
||||||
|
|
||||||
interface PluginInfoProps {
|
interface PluginInfoProps {
|
||||||
data: FormData;
|
data: FormData;
|
||||||
plugin: Plugin_plugin;
|
description: string;
|
||||||
|
name: string;
|
||||||
onChange: (event: React.ChangeEvent<any>) => void;
|
onChange: (event: React.ChangeEvent<any>) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,8 @@ const styles = createStyles({
|
||||||
const PluginInfo = withStyles(styles, { name: "PluginInfo" })(
|
const PluginInfo = withStyles(styles, { name: "PluginInfo" })(
|
||||||
({
|
({
|
||||||
data,
|
data,
|
||||||
plugin,
|
description,
|
||||||
|
name,
|
||||||
classes,
|
classes,
|
||||||
onChange
|
onChange
|
||||||
}: PluginInfoProps & WithStyles<typeof styles>) => {
|
}: PluginInfoProps & WithStyles<typeof styles>) => {
|
||||||
|
@ -46,13 +47,13 @@ const PluginInfo = withStyles(styles, { name: "PluginInfo" })(
|
||||||
<Typography className={classes.title} variant="h6">
|
<Typography className={classes.title} variant="h6">
|
||||||
{i18n.t("Plugin Name")}
|
{i18n.t("Plugin Name")}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography>{plugin.name}</Typography>
|
<Typography>{name}</Typography>
|
||||||
{plugin.description && (
|
{description && (
|
||||||
<>
|
<>
|
||||||
<Typography className={classes.title} variant="h6">
|
<Typography className={classes.title} variant="h6">
|
||||||
{i18n.t("Plugin Description")}
|
{i18n.t("Plugin Description")}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography>{plugin.description}</Typography>
|
<Typography>{description}</Typography>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<FormSpacer />
|
<FormSpacer />
|
||||||
|
|
|
@ -15,6 +15,13 @@ interface PluginSettingsProps {
|
||||||
errors: FormErrors<"name" | "configuration">;
|
errors: FormErrors<"name" | "configuration">;
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
onChange: (event: React.ChangeEvent<any>) => void;
|
onChange: (event: React.ChangeEvent<any>) => void;
|
||||||
|
plugin: Array<{
|
||||||
|
name: string;
|
||||||
|
type: ConfigurationTypeFieldEnum | null;
|
||||||
|
value: string;
|
||||||
|
helpText: string | null;
|
||||||
|
label: string | null;
|
||||||
|
}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = createStyles({
|
const styles = createStyles({
|
||||||
|
@ -30,7 +37,8 @@ const PluginSettings = withStyles(styles, { name: "PluginSettings" })(
|
||||||
disabled,
|
disabled,
|
||||||
classes,
|
classes,
|
||||||
errors,
|
errors,
|
||||||
onChange
|
onChange,
|
||||||
|
plugin
|
||||||
}: PluginSettingsProps & WithStyles<typeof styles>) => {
|
}: PluginSettingsProps & WithStyles<typeof styles>) => {
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
|
@ -42,19 +50,19 @@ const PluginSettings = withStyles(styles, { name: "PluginSettings" })(
|
||||||
<CardContent>
|
<CardContent>
|
||||||
{data.configuration.map((configuration, index) => (
|
{data.configuration.map((configuration, index) => (
|
||||||
<div className={classes.item} key={index}>
|
<div className={classes.item} key={index}>
|
||||||
{configuration.type === ConfigurationTypeFieldEnum.STRING && (
|
{plugin[index].type === ConfigurationTypeFieldEnum.STRING && (
|
||||||
<TextField
|
<TextField
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
error={!!errors.name}
|
error={!!errors.name}
|
||||||
helperText={configuration.helpText}
|
helperText={plugin[index].helpText}
|
||||||
label={configuration.label}
|
label={plugin[index].label}
|
||||||
name={configuration.name}
|
name={configuration.name}
|
||||||
fullWidth
|
fullWidth
|
||||||
value={configuration.value}
|
value={configuration.value}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{configuration.type === ConfigurationTypeFieldEnum.BOOLEAN && (
|
{plugin[index].type === ConfigurationTypeFieldEnum.BOOLEAN && (
|
||||||
<ControlledSwitch
|
<ControlledSwitch
|
||||||
checked={
|
checked={
|
||||||
typeof configuration.value !== "boolean"
|
typeof configuration.value !== "boolean"
|
||||||
|
@ -62,7 +70,7 @@ const PluginSettings = withStyles(styles, { name: "PluginSettings" })(
|
||||||
: configuration.value
|
: configuration.value
|
||||||
}
|
}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
label={configuration.label}
|
label={plugin[index].label}
|
||||||
name={configuration.name}
|
name={configuration.name}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -8,16 +8,17 @@ import PageHeader from "@saleor/components/PageHeader";
|
||||||
import SaveButtonBar from "@saleor/components/SaveButtonBar";
|
import SaveButtonBar from "@saleor/components/SaveButtonBar";
|
||||||
import { maybe } from "@saleor/misc";
|
import { maybe } from "@saleor/misc";
|
||||||
import { UserError } from "@saleor/types";
|
import { UserError } from "@saleor/types";
|
||||||
|
import { ConfigurationItemInput } from "@saleor/types/globalTypes";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import i18n from "../../../i18n";
|
import i18n from "../../../i18n";
|
||||||
import { Plugin_plugin, Plugin_plugin_configuration } from "../../types/Plugin";
|
import { Plugin_plugin } from "../../types/Plugin";
|
||||||
import PluginInfo from "../PluginInfo";
|
import PluginInfo from "../PluginInfo";
|
||||||
import PluginSettings from "../PluginSettings";
|
import PluginSettings from "../PluginSettings";
|
||||||
|
|
||||||
export interface FormData {
|
export interface FormData {
|
||||||
active: boolean;
|
active: boolean;
|
||||||
configuration: Plugin_plugin_configuration;
|
configuration: ConfigurationItemInput[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PluginsDetailsPageProps {
|
export interface PluginsDetailsPageProps {
|
||||||
|
@ -83,7 +84,8 @@ const PluginsDetailsPage: React.StatelessComponent<PluginsDetailsPageProps> = ({
|
||||||
</div>
|
</div>
|
||||||
<PluginInfo
|
<PluginInfo
|
||||||
data={data}
|
data={data}
|
||||||
plugin={maybe(() => plugin, "")}
|
description={maybe(() => plugin.description, "")}
|
||||||
|
name={maybe(() => plugin.name, "")}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
/>
|
/>
|
||||||
{data.configuration && (
|
{data.configuration && (
|
||||||
|
@ -100,6 +102,7 @@ const PluginsDetailsPage: React.StatelessComponent<PluginsDetailsPageProps> = ({
|
||||||
</div>
|
</div>
|
||||||
<PluginSettings
|
<PluginSettings
|
||||||
data={data}
|
data={data}
|
||||||
|
plugin={maybe(() => plugin.configuration, [])}
|
||||||
errors={errors}
|
errors={errors}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
|
|
|
@ -13,7 +13,7 @@ const pluginUpdate = gql`
|
||||||
message
|
message
|
||||||
}
|
}
|
||||||
plugin {
|
plugin {
|
||||||
...pluginsDetailsFragment
|
...PluginsDetailsFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { Plugin, PluginVariables } from "./types/Plugin";
|
||||||
import { Plugins, PluginsVariables } from "./types/Plugins";
|
import { Plugins, PluginsVariables } from "./types/Plugins";
|
||||||
|
|
||||||
export const pluginsFragment = gql`
|
export const pluginsFragment = gql`
|
||||||
fragment pluginFragment on Plugin {
|
fragment PluginFragment on Plugin {
|
||||||
id
|
id
|
||||||
name
|
name
|
||||||
description
|
description
|
||||||
|
@ -15,8 +15,8 @@ export const pluginsFragment = gql`
|
||||||
|
|
||||||
export const pluginsDetailsFragment = gql`
|
export const pluginsDetailsFragment = gql`
|
||||||
${pluginsFragment}
|
${pluginsFragment}
|
||||||
fragment pluginsDetailsFragment on Plugin {
|
fragment PluginsDetailsFragment on Plugin {
|
||||||
...pluginFragment
|
...PluginFragment
|
||||||
configuration {
|
configuration {
|
||||||
name
|
name
|
||||||
type
|
type
|
||||||
|
@ -33,7 +33,7 @@ const pluginsList = gql`
|
||||||
plugins(before: $before, after: $after, first: $first, last: $last) {
|
plugins(before: $before, after: $after, first: $first, last: $last) {
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
...pluginFragment
|
...PluginFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pageInfo {
|
pageInfo {
|
||||||
|
@ -53,7 +53,7 @@ const pluginsDetails = gql`
|
||||||
${pluginsDetailsFragment}
|
${pluginsDetailsFragment}
|
||||||
query Plugin($id: ID!) {
|
query Plugin($id: ID!) {
|
||||||
plugin(id: $id) {
|
plugin(id: $id) {
|
||||||
...pluginsDetailsFragment
|
...PluginsDetailsFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
Loading…
Reference in a new issue