Skip to content

Commit f0b2ab0

Browse files
authored
Merge pull request #126 from edsonmartins/develop
feat: adicionar novo atributo routeParams no ArchbaseNavigationItem
2 parents 68af8e2 + e9cdff7 commit f0b2ab0

File tree

5 files changed

+31
-21
lines changed

5 files changed

+31
-21
lines changed

src/components/admin/ArchbaseAdminMainLayout.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ArchbaseAdvancedSidebar } from './ArchbaseAdvancedSidebar';
1313
import { ArchbaseAliveAbleRoutes, ArchbaseKeepAliveRoute } from './ArchbaseAliveAbleRoutes';
1414
import { buildSetCollapsedButton } from './buildSetCollapsedButton';
1515
import { ArchbaseCompany, ArchbaseNavigationItem, ArchbaseOwner } from './types';
16+
import { useArchbaseNavigateParams } from 'components/hooks';
1617

1718
export interface ArchbaseAdminMainLayoutSecurityOptions {
1819
navigationResourceDescription: string
@@ -117,7 +118,7 @@ function ArchbaseAdminMainLayoutContainer({
117118
const theme = useMantineTheme();
118119
const adminLayoutContextValue = useContext<ArchbaseAdminLayoutContextValue>(ArchbaseAdminLayoutContext);
119120
const { colorScheme } = useMantineColorScheme();
120-
const navigate = useNavigate();
121+
const navigate = useArchbaseNavigateParams()
121122
const [sidebarRef, sidebarVisible] = useArchbaseVisible<HTMLHtmlElement, boolean>();
122123

123124
const isHidden = useMediaQuery(
@@ -126,7 +127,11 @@ function ArchbaseAdminMainLayoutContainer({
126127

127128
const onMenuItemClick = (item: ArchbaseNavigationItem) => {
128129
if (item.link) {
129-
navigate(item.link);
130+
if (item.routeParams) {
131+
navigate(item.link, {}, item.routeParams);
132+
} else {
133+
navigate(item.link);
134+
}
130135
}
131136
};
132137

@@ -229,7 +234,7 @@ function ArchbaseAdminMainLayoutContainer({
229234
</AppShell.Header>
230235
<AppShell.Navbar>
231236
{!isHidden && showSideBar ? (
232-
customRenderSidebar ? customRenderSidebar({width: sideBarWidth, height: getSideBarHeight(), isHidden}) :
237+
customRenderSidebar ? customRenderSidebar({ width: sideBarWidth, height: getSideBarHeight(), isHidden }) :
233238
<ArchbaseAdvancedSidebar
234239
navigationData={adminLayoutContextValue.navigationData}
235240
sidebarHeight={getSideBarHeight()}
@@ -303,7 +308,7 @@ function ArchbaseAdminMainLayoutContainer({
303308
}}
304309
>
305310
{
306-
customRenderSidebar ? customRenderSidebar({width: sideBarWidth, height: getSideBarDrawerHeight(), isHidden}) :
311+
customRenderSidebar ? customRenderSidebar({ width: sideBarWidth, height: getSideBarDrawerHeight(), isHidden }) :
307312
<ArchbaseAdvancedSidebar
308313
navigationData={adminLayoutContextValue.navigationData}
309314
sidebarWidth={sideBarWidth}

src/components/admin/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ReactNode } from 'react';
2+
import { URLSearchParamsInit } from 'react-router-dom';
23

34
export type ArchbaseNavigationGroup = {
45
label: string;
@@ -12,6 +13,7 @@ export type ArchbaseNavigationItem = {
1213
label: string;
1314
icon: any;
1415
link?: string | undefined;
16+
routeParams?: URLSearchParamsInit;
1517
initiallyOpened?: boolean;
1618
links?: ArchbaseNavigationItem[];
1719
category: string | undefined | null;

src/components/editors/ArchbaseCheckbox.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ export function ArchbaseCheckbox<T, ID>({
130130
loadDataSourceFieldValue();
131131
}, []);
132132

133-
const handleChange = (event) => {
133+
const handleChange = (event, isReadOnly) => {
134+
if (isReadOnly) return
134135
const changedChecked = event.target.checked;
135136
const resultValue = changedChecked ? trueValue : falseValue;
136137

@@ -168,13 +169,12 @@ export function ArchbaseCheckbox<T, ID>({
168169
return (
169170
<Checkbox
170171
disabled={disabled}
171-
readOnly={isReadOnly()}
172172
required={required}
173173
style={{ ...style, width }}
174174
checked={checked}
175175
ref={innerRef || innerComponentRef}
176176
value={checked ? trueValue : falseValue}
177-
onChange={handleChange}
177+
onChange={(event) => handleChange(event, isReadOnly())}
178178
onBlur={handleOnFocusExit}
179179
onFocus={handleOnFocusEnter}
180180
description={description}

src/components/editors/ArchbaseSelect.tsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,6 @@ export function ArchbaseSelect<T, ID, O>({
253253
const [internalError, setInternalError] = useState<string | undefined>(error)
254254
const [updateCounter, setUpdateCounter] = useState(0)
255255
const sRef = useRef<any>()
256-
const [internalReadOnly, setReadOnly] = useUncontrolled<boolean>({
257-
value: readOnly,
258-
defaultValue: readOnly,
259-
finalValue: false,
260-
});
261256
const [currentLimit, setCurrentLimit] = useState(limit);
262257

263258
const currentOptions: any[] = useMemo(() => {
@@ -430,13 +425,13 @@ export function ArchbaseSelect<T, ID, O>({
430425
loadDataSourceFieldValue()
431426
}, [])
432427

433-
useEffect(() => {
434-
let tmpRreadOnly = readOnly
435-
if (dataSource && !readOnly) {
436-
tmpRreadOnly = dataSource.isBrowsing()
437-
}
438-
setReadOnly(tmpRreadOnly)
439-
}, [dataSource?.isBrowsing()])
428+
const isReadOnly = () => {
429+
let tmpReadOnly = readOnly;
430+
if (dataSource && !readOnly) {
431+
tmpReadOnly = dataSource.isBrowsing();
432+
}
433+
return tmpReadOnly;
434+
};
440435

441436
return (
442437
<Select
@@ -458,7 +453,7 @@ export function ArchbaseSelect<T, ID, O>({
458453
leftSection={icon}
459454
width={width}
460455
leftSectionWidth={iconWidth}
461-
readOnly={internalReadOnly}
456+
readOnly={isReadOnly()}
462457
required={required}
463458
onChange={(value, option) => handleChange(value, option as SelectItem)}
464459
onClick={onClick}

src/components/editors/ArchbaseTextArea.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,18 @@ export function ArchbaseTextArea<T, ID>({
165165
}
166166
};
167167

168+
const isReadOnly = () => {
169+
let tmpReadOnly = readOnly;
170+
if (dataSource && !readOnly) {
171+
tmpReadOnly = dataSource.isBrowsing();
172+
}
173+
return tmpReadOnly;
174+
};
175+
168176
return (
169177
<Textarea
170178
disabled={disabled}
171-
readOnly={readOnly}
179+
readOnly={isReadOnly()}
172180
style={style}
173181
value={value}
174182
ref={innerRef || innerComponentRef}

0 commit comments

Comments
 (0)