From dee3a04310a2d08dcd7303b5514ab8801b4d6ac6 Mon Sep 17 00:00:00 2001
From: ilnaz <237x237@gmail.com>
Date: Sun, 24 Nov 2024 14:50:51 +0300
Subject: [PATCH 1/2] feat: add dynamic routing (#25)
---
bro.config.js | 18 ++++++-----
src/__data__/urls.ts | 37 ++++++++++++++++-------
src/components/LayoutArm/LayoutArm.tsx | 41 +++++++++++++++++---------
src/components/Sidebar/Sidebar.tsx | 41 +++++++++++++++-----------
src/routes.tsx | 4 ++-
5 files changed, 89 insertions(+), 52 deletions(-)
diff --git a/bro.config.js b/bro.config.js
index 7bc074d..271e8db 100644
--- a/bro.config.js
+++ b/bro.config.js
@@ -1,9 +1,9 @@
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-require-imports */
-const pkg = require("./package");
+const pkg = require('./package');
module.exports = {
- apiPath: "stubs/api",
+ apiPath: 'stubs/api',
webpackConfig: {
output: {
publicPath: `/static/${pkg.name}/${process.env.VERSION || pkg.version}/`,
@@ -11,17 +11,19 @@ module.exports = {
},
/* use https://admin.bro-js.ru/ to create config, navigations and features */
navigations: {
- "dry-wash.main": "/dry-wash",
- "dry-wash.create": "/order",
- "dry-wash.view.order": "/order/:orderId",
- "dry-wash.arm": "/arm",
+ 'dry-wash.main': '/dry-wash',
+ 'dry-wash.create': '/order',
+ 'dry-wash.view.order': '/order/:orderId',
+ 'dry-wash.arm.master': '/master',
+ 'dry-wash.arm.order': '/order',
+ 'dry-wash.arm': '/arm/*',
},
features: {
- "dry-wash-pl": {
+ 'dry-wash-pl': {
// add your features here in the format [featureName]: { value: string }
},
},
config: {
- "dry-wash-pl.api": "/api",
+ 'dry-wash-pl.api': '/api',
},
};
diff --git a/src/__data__/urls.ts b/src/__data__/urls.ts
index 7aef983..abb1331 100644
--- a/src/__data__/urls.ts
+++ b/src/__data__/urls.ts
@@ -1,25 +1,40 @@
-import { generatePath } from "react-router-dom";
-import { getNavigationValue } from "@brojs/cli";
+import { generatePath } from 'react-router-dom';
+import { getNavigationValue } from '@brojs/cli';
-import { Order } from "../models";
+import { Order } from '../models';
+
+const getFullUrls = (url: string) =>
+ `${getNavigationValue('dry-wash.main')}${url}`;
export const URLs = {
landing: {
- url: getNavigationValue("dry-wash.main"),
+ url: getNavigationValue('dry-wash.main'),
getUrl() {
return this.url;
- }
+ },
},
orderForm: {
- url: getNavigationValue("dry-wash.create"),
+ url: getNavigationValue('dry-wash.create'),
getUrl() {
return this.url;
- }
+ },
},
orderView: {
- url: getNavigationValue("dry-wash.view.order"),
+ url: getNavigationValue('dry-wash.view.order'),
getUrl(orderId: Order.Id) {
return generatePath(this.url, { orderId });
- }
- }
-};
\ No newline at end of file
+ },
+ },
+ armMaster: {
+ url: getNavigationValue('dry-wash.arm.master'),
+ isOn: Boolean(getNavigationValue('dry-wash.arm.master')),
+ },
+ armOrder: {
+ url: getNavigationValue('dry-wash.arm.order'),
+ isOn: Boolean(getNavigationValue('dry-wash.arm.order')),
+ },
+ armBase: {
+ url: getFullUrls(getNavigationValue('dry-wash.arm')),
+ isOn: Boolean(getNavigationValue('dry-wash.arm')),
+ },
+};
diff --git a/src/components/LayoutArm/LayoutArm.tsx b/src/components/LayoutArm/LayoutArm.tsx
index 9873bdc..aebba1a 100644
--- a/src/components/LayoutArm/LayoutArm.tsx
+++ b/src/components/LayoutArm/LayoutArm.tsx
@@ -5,20 +5,33 @@ import { Navigate, Route, Routes } from 'react-router-dom';
import Sidebar from '../Sidebar';
import Orders from '../Orders';
import Masters from '../Masters';
+import { URLs } from '../../__data__/urls';
-const LayoutArm = () => (
-
-
-
-
-
- } />
- } />
- } />
-
-
-
-
-);
+const LayoutArm = () => {
+ let defaultRedirect = null;
+
+ if (URLs.armOrder.isOn) {
+ defaultRedirect = URLs.armOrder.url;
+ } else if (URLs.armMaster.isOn) {
+ defaultRedirect = URLs.armMaster.url;
+ }
+
+ return (
+
+
+
+
+ } />
+ {URLs.armOrder.isOn && (
+ } />
+ )}
+ {URLs.armMaster.isOn && (
+ } />
+ )}
+
+
+
+ );
+};
export default LayoutArm;
diff --git a/src/components/Sidebar/Sidebar.tsx b/src/components/Sidebar/Sidebar.tsx
index 308531c..e8dde0f 100644
--- a/src/components/Sidebar/Sidebar.tsx
+++ b/src/components/Sidebar/Sidebar.tsx
@@ -2,6 +2,7 @@ import { Box, Button, Heading, VStack, Divider } from '@chakra-ui/react';
import React from 'react';
import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
+import { URLs } from '../../__data__/urls';
const Sidebar = () => {
const { t } = useTranslation('~', {
@@ -23,25 +24,29 @@ const Sidebar = () => {
-
+ {URLs.armOrder.isOn && (
+
+ )}
-
+ {URLs.armMaster.isOn && (
+
+ )}
diff --git a/src/routes.tsx b/src/routes.tsx
index 4815fc4..949a28e 100644
--- a/src/routes.tsx
+++ b/src/routes.tsx
@@ -17,7 +17,9 @@ const Routers = () => {
} />
} />
} />
- }>
+ {URLs.armBase.isOn && (
+ }>
+ )}
} />
--
2.45.2
From b5f383853633f7721577bb3165595c76a1c3da6e Mon Sep 17 00:00:00 2001
From: ilnaz <237x237@gmail.com>
Date: Sun, 24 Nov 2024 14:54:01 +0300
Subject: [PATCH 2/2] feat: separation of imports (#25)
---
src/components/Sidebar/Sidebar.tsx | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/components/Sidebar/Sidebar.tsx b/src/components/Sidebar/Sidebar.tsx
index e8dde0f..43ebf1a 100644
--- a/src/components/Sidebar/Sidebar.tsx
+++ b/src/components/Sidebar/Sidebar.tsx
@@ -2,6 +2,7 @@ import { Box, Button, Heading, VStack, Divider } from '@chakra-ui/react';
import React from 'react';
import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
+
import { URLs } from '../../__data__/urls';
const Sidebar = () => {
--
2.45.2