Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add language list

dominik-zeglenbd95edf0006a
diff --git a/saleor/static/dashboard-next/components/Shop/query.ts b/saleor/static/dashboard-next/components/Shop/query.ts
index af1df82ac5..b67e048bb2 100644
--- a/saleor/static/dashboard-next/components/Shop/query.ts
+++ b/saleor/static/dashboard-next/components/Shop/query.ts
@@ -21,6 +21,10 @@ const shopInfo = gql`
host
url
}
+ languages {
+ code
+ language
+ }
includeTaxesInPrices
name
trackInventoryByDefault
diff --git a/saleor/static/dashboard-next/components/Shop/types/ShopInfo.ts b/saleor/static/dashboard-next/components/Shop/types/ShopInfo.ts
index 74c88ba501..689ce8f483 100644
--- a/saleor/static/dashboard-next/components/Shop/types/ShopInfo.ts
+++ b/saleor/static/dashboard-next/components/Shop/types/ShopInfo.ts
@@ -26,6 +26,12 @@ export interface ShopInfo_shop_domain {
url: string;
}
+export interface ShopInfo_shop_languages {
+ __typename: "LanguageDisplay";
+ code: string;
+ language: string;
+}
+
export interface ShopInfo_shop {
__typename: "Shop";
countries: (ShopInfo_shop_countries | null)[];
@@ -34,6 +40,7 @@ export interface ShopInfo_shop {
defaultWeightUnit: WeightUnitsEnum | null;
displayGrossPrices: boolean;
domain: ShopInfo_shop_domain;
+ languages: (ShopInfo_shop_languages | null)[];
includeTaxesInPrices: boolean;
name: string;
trackInventoryByDefault: boolean | null;
diff --git a/saleor/static/dashboard-next/storybook/config.js b/saleor/static/dashboard-next/storybook/config.js
index 2c60c002e5..f8146878d5 100644
--- a/saleor/static/dashboard-next/storybook/config.js
+++ b/saleor/static/dashboard-next/storybook/config.js
@@ -129,6 +129,9 @@ function loadStories() {
// Taxes
require("./stories/taxes/CountryListPage");
require("./stories/taxes/CountryTaxesPage");
+
+ // Translations
+ require("./stories/translations/TranslationsLanguageListPage");
}
configure(loadStories, module);
diff --git a/saleor/static/dashboard-next/storybook/stories/translations/TranslationsLanguageListPage.tsx b/saleor/static/dashboard-next/storybook/stories/translations/TranslationsLanguageListPage.tsx
new file mode 100644
index 0000000000..63507cbe8a
--- /dev/null
+++ b/saleor/static/dashboard-next/storybook/stories/translations/TranslationsLanguageListPage.tsx
@@ -0,0 +1,24 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import TranslationsLanguageListPage, {
+ TranslationsLanguageListPageProps
+} from "../../../translations/components/TranslationsLanguageListPage";
+import { languages } from "../../../translations/fixtures";
+import Decorator from "../../Decorator";
+
+const props: TranslationsLanguageListPageProps = {
+ languages,
+ onAdd: () => undefined,
+ onRowClick: () => undefined
+};
+
+storiesOf("Views / Translations / Language list", module)
+ .addDecorator(Decorator)
+ .add("default", () => <TranslationsLanguageListPage {...props} />)
+ .add("loading", () => (
+ <TranslationsLanguageListPage {...props} languages={undefined} />
+ ))
+ .add("no data", () => (
+ <TranslationsLanguageListPage {...props} languages={[]} />
+ ));
diff --git a/saleor/static/dashboard-next/translations/components/TranslationsLanguageList/TranslationsLanguageList.tsx b/saleor/static/dashboard-next/translations/components/TranslationsLanguageList/TranslationsLanguageList.tsx
new file mode 100644
index 0000000000..36ba5488d4
--- /dev/null
+++ b/saleor/static/dashboard-next/translations/components/TranslationsLanguageList/TranslationsLanguageList.tsx
@@ -0,0 +1,80 @@
+import Card from "@material-ui/core/Card";
+import { createStyles, withStyles, WithStyles } from "@material-ui/core/styles";
+import Table from "@material-ui/core/Table";
+import TableBody from "@material-ui/core/TableBody";
+import TableCell from "@material-ui/core/TableCell";
+import TableHead from "@material-ui/core/TableHead";
+import TableRow from "@material-ui/core/TableRow";
+import * as React from "react";
+
+import { ShopInfo_shop_languages } from "../../../components/Shop/types/ShopInfo";
+import Skeleton from "../../../components/Skeleton";
+import i18n from "../../../i18n";
+import { maybe, renderCollection } from "../../../misc";
+
+export interface TranslationsLanguageListProps {
+ languages: ShopInfo_shop_languages[];
+ onRowClick: (code: string) => void;
+}
+
+const styles = createStyles({
+ capitalize: {
+ textTransform: "capitalize"
+ },
+ link: {
+ cursor: "pointer"
+ }
+});
+
+const TranslationsLanguageList = withStyles(styles, {
+ name: "TranslationsLanguageList"
+})(
+ ({
+ classes,
+ languages,
+ onRowClick
+ }: TranslationsLanguageListProps & WithStyles<typeof styles>) => (
+ <Card>
+ <Table>
+ <TableHead>
+ <TableRow>
+ <TableCell>
+ {i18n.t("Language", { context: "table header" })}
+ </TableCell>
+ </TableRow>
+ </TableHead>
+ <TableBody>
+ {renderCollection(
+ languages,
+ language => (
+ <TableRow
+ className={!!language ? classes.link : undefined}
+ hover={!!language}
+ key={language ? language.code : "skeleton"}
+ >
+ <TableCell
+ className={classes.capitalize}
+ onClick={() => onRowClick(language.code)}
+ >
+ {maybe<React.ReactNode>(
+ () => language.language,
+ <Skeleton />
+ )}
+ </TableCell>
+ </TableRow>
+ ),
+ () => (
+ <TableRow>
+ <TableCell colSpan={1}>
+ {i18n.t("No languages found")}
+ </TableCell>
+ </TableRow>
+ )
+ )}
+ </TableBody>
+ </Table>
+ </Card>
+ )
+);
+TranslationsLanguageList.displayName = "TranslationsLanguageList";
+export default TranslationsLanguageList;
diff --git a/saleor/static/dashboard-next/translations/components/TranslationsLanguageList/index.ts b/saleor/static/dashboard-next/translations/components/TranslationsLanguageList/index.ts
new file mode 100644
index 0000000000..343273a4b0
--- /dev/null
+++ b/saleor/static/dashboard-next/translations/components/TranslationsLanguageList/index.ts
@@ -0,0 +1,2 @@
+export { default } from './TranslationsLanguageList';
+export * from './TranslationsLanguageList';
\ No newline at end of file
diff --git a/saleor/static/dashboard-next/translations/components/TranslationsLanguageListPage/TranslationsLanguageListPage.tsx b/saleor/static/dashboard-next/translations/components/TranslationsLanguageListPage/TranslationsLanguageListPage.tsx
new file mode 100644
index 0000000000..e8d6a8b163
--- /dev/null
+++ b/saleor/static/dashboard-next/translations/components/TranslationsLanguageListPage/TranslationsLanguageListPage.tsx
@@ -0,0 +1,31 @@
+import Button from "@material-ui/core/Button";
+import AddIcon from "@material-ui/icons/Add";
+import * as React from "react";
+
+import Container from "../../../components/Container";
+import PageHeader from "../../../components/PageHeader";
+import { ShopInfo_shop_languages } from "../../../components/Shop/types/ShopInfo";
+import i18n from "../../../i18n";
+import TranslationsLanguageList from "../TranslationsLanguageList";
+
+export interface TranslationsLanguageListPageProps {
+ languages: ShopInfo_shop_languages[];
+ onAdd: () => void;
+ onRowClick: (code: string) => void;
+}
+
+const TranslationsLanguageListPage: React.StatelessComponent<
+ TranslationsLanguageListPageProps
+> = ({ languages, onAdd, onRowClick }) => (
+ <Container>
+ <PageHeader>
+ <Button color="primary" variant="contained" onClick={onAdd}>
+ {i18n.t("Add Language")}
+ <AddIcon />
+ </Button>
+ </PageHeader>
+ <TranslationsLanguageList languages={languages} onRowClick={onRowClick} />
+ </Container>
+);
+TranslationsLanguageListPage.displayName = "TranslationsLanguageListPage";
+export default TranslationsLanguageListPage;
diff --git a/saleor/static/dashboard-next/translations/components/TranslationsLanguageListPage/index.ts b/saleor/static/dashboard-next/translations/components/TranslationsLanguageListPage/index.ts
new file mode 100644
index 0000000000..d0a78086ab
--- /dev/null
+++ b/saleor/static/dashboard-next/translations/components/TranslationsLanguageListPage/index.ts
@@ -0,0 +1,2 @@
+export { default } from './TranslationsLanguageListPage';
+export * from './TranslationsLanguageListPage';
\ No newline at end of file
diff --git a/saleor/static/dashboard-next/translations/fixtures.ts b/saleor/static/dashboard-next/translations/fixtures.ts
new file mode 100644
index 0000000000..5e9aa9e3d9
--- /dev/null
+++ b/saleor/static/dashboard-next/translations/fixtures.ts
@@ -0,0 +1,179 @@
+import { ShopInfo_shop_languages } from "../components/Shop/types/ShopInfo";
+
+export const languages: ShopInfo_shop_languages[] = [
+ {
+ __typename: "LanguageDisplay",
+ code: "ar",
+ language: "arabski"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "az",
+ language: "azerski"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "bg",
+ language: "bułgarski"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "bn",
+ language: "bengalski"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "ca",
+ language: "kataloński"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "cs",
+ language: "Czeski"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "da",
+ language: "duński"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "de",
+ language: "niemiecki"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "en",
+ language: "angielski"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "es",
+ language: "hiszpański"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "et",
+ language: "estoński"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "fa",
+ language: "perski"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "fr",
+ language: "francuski"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "hi",
+ language: "hindi"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "hu",
+ language: "węgierski"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "id",
+ language: "indonezyjski"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "it",
+ language: "włoski"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "ja",
+ language: "japoński"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "ko",
+ language: "koreański"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "mn",
+ language: "mongolski"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "nb",
+ language: "norweski"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "nl",
+ language: "holenderski"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "pl",
+ language: "polski"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "pt-br",
+ language: "portugalski brazylijski"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "ro",
+ language: "rumuński"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "ru",
+ language: "rosyjski"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "sk",
+ language: "słowacki"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "sr",
+ language: "serbski"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "sv",
+ language: "szwedzki"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "th",
+ language: "tajski"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "tr",
+ language: "turecki"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "uk",
+ language: "ukraiński"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "vi",
+ language: "wietnamski"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "zh-hans",
+ language: "chiński uproszczony"
+ },
+ {
+ __typename: "LanguageDisplay",
+ code: "zh-hant",
+ language: "chiński tradycyjny"
+ }
+];
diff --git a/saleor/static/dashboard-next/translations/index.tsx b/saleor/static/dashboard-next/translations/index.tsx
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/static/dashboard-next/translations/urls.ts b/saleor/static/dashboard-next/translations/urls.ts
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/static/dashboard-next/translations/views/TranslationsLanguageList.tsx b/saleor/static/dashboard-next/translations/views/TranslationsLanguageList.tsx
new file mode 100644
index 0000000000..92ce43ee49
--- /dev/null
+++ b/saleor/static/dashboard-next/translations/views/TranslationsLanguageList.tsx
@@ -0,0 +1,22 @@
+import * as React from "react";
+
+import useNavigator from "../../hooks/useNavigator";
+import useShop from "../../hooks/useShop";
+import { maybe } from "../../misc";
+import TranslationsLanguageListPage from "../components/TranslationsLanguageListPage";
+import { languageEntitiesUrl } from "../urls";
+
+const TranslationsLanguageList: React.FC = () => {
+ const navigate = useNavigator();
+ const shop = useShop();
+
+ return (
+ <TranslationsLanguageListPage
+ languages={maybe(() => shop.languages)}
+ onAdd={undefined}
+ onRowClick={code => navigate(languageEntitiesUrl(code))}
+ />
+ );
+};
+TranslationsLanguageList.displayName = "TranslationsLanguageList";
+export default TranslationsLanguageList;