Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: impove attached files screen #849

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelogs/unreleased/88612_SearchTreeView.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "SearchTreeView: add possibility to remove management of parent filter",
"type": "feat",
"packages": "core"
}
5 changes: 5 additions & 0 deletions changelogs/unreleased/88612_TreeView.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "TreeView: add possibility to hide branch filter quick action",
"type": "feat",
"packages": "ui"
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ import {File} from '../../../types';

interface DocumentListProps {
defaultParent?: any;
isAttachedFilesList?: boolean;
}

const DocumentList = ({defaultParent}: DocumentListProps) => {
const DocumentList = ({
defaultParent,
isAttachedFilesList = false,
}: DocumentListProps) => {
const I18n = useTranslator();
const Colors = useThemeColor();
const navigation = useNavigation();
Expand Down Expand Up @@ -152,6 +156,7 @@ const DocumentList = ({defaultParent}: DocumentListProps) => {
}
displayBreadcrumb
defaultParent={defaultParent}
manageParentFilter={!isAttachedFilesList}
/>
</Screen>
);
Expand Down
4 changes: 3 additions & 1 deletion packages/apps/dms/src/screens/AttachedFilesScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ const AttachedFilesScreen = ({navigation, route}) => {

return (
<>
{!isVisible && <DocumentList defaultParent={parent} />}
{!isVisible && (
<DocumentList defaultParent={parent} isAttachedFilesList />
)}
<Alert
visible={isVisible}
title={I18n.t('Dms_NoAttachedFiles')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ interface SearchTreeViewProps {
verticalActions?: boolean;
displayBreadcrumb?: boolean;
defaultParent?: any;
manageParentFilter?: boolean;
}

const SearchTreeView = ({
Expand Down Expand Up @@ -109,6 +110,7 @@ const SearchTreeView = ({
verticalActions,
displayBreadcrumb = false,
defaultParent,
manageParentFilter = true,
}: SearchTreeViewProps) => {
const I18n = useTranslator();
const dispatch = useDispatch();
Expand Down Expand Up @@ -200,6 +202,10 @@ const SearchTreeView = ({
}, [defaultParent, fetchListAPI, isFocused]);

const renderParentSearchBar = useCallback(() => {
if (!manageParentFilter) {
return null;
}

return (
<AutoCompleteSearch
objectList={parentList}
Expand All @@ -214,6 +220,7 @@ const SearchTreeView = ({
}, [
displayParentSearchValue,
fetchParentSearchAPI,
manageParentFilter,
parent,
parentList,
searchParentPlaceholder,
Expand Down Expand Up @@ -271,6 +278,7 @@ const SearchTreeView = ({
{displayBreadcrumb && (
<Breadcrumb
style={styles.breadcrumb}
disabled={!manageParentFilter}
items={parent.map((item, index) =>
item === EMPTY_PARENT
? EMPTY_PARENT
Expand All @@ -295,6 +303,7 @@ const SearchTreeView = ({
fetchBranchData={fetchBranchData}
branchCondition={branchCondition}
onBranchFilterPress={handleChangeParent}
isBranchFilterVisible={manageParentFilter}
moreLoading={moreLoading}
isListEnd={isListEnd}
translator={I18n.t}
Expand Down
10 changes: 10 additions & 0 deletions packages/ui/__tests__/components/molecules/Breadcrumb.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ describe('Breadcrumb Component', () => {
expect(nonClickableItem.prop('onPress')).toBeUndefined();
});

it('renders correctly when disabled', () => {
const wrapper = shallow(<Breadcrumb {...props} disabled />);
const items = wrapper.find(TouchableOpacity);

items.forEach(_item => {
expect(_item.exists()).toBeTruthy();
expect(_item.prop('disabled')).toBeTruthy();
});
});

it('should apply custom styles to the container when style prop is provided', () => {
const customStyle = {
fontSize: 25,
Expand Down
16 changes: 13 additions & 3 deletions packages/ui/src/components/molecules/Breadcrumb/Breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ interface Item {

interface BreadcrumbProps {
style?: any;
disabled?: boolean;
items: Item[];
onHomePress: () => void;
}

const Breadcrumb = ({style, items, onHomePress}: BreadcrumbProps) => {
const Breadcrumb = ({
style,
disabled = false,
items,
onHomePress,
}: BreadcrumbProps) => {
const Colors = useThemeColor();

const [visibleItems, setVisibleItems] = useState(items);
Expand Down Expand Up @@ -86,7 +92,11 @@ const Breadcrumb = ({style, items, onHomePress}: BreadcrumbProps) => {
<View
style={[styles.container, style]}
onLayout={e => setContainerWidth(e?.nativeEvent?.layout?.width)}>
<Icon name="house-door-fill" touchable onPress={onHomePress} />
<Icon
name="house-door-fill"
touchable={!disabled}
onPress={onHomePress}
/>
{visibleItems.map((item, index) => (
<View
style={styles.contentContainer}
Expand All @@ -96,7 +106,7 @@ const Breadcrumb = ({style, items, onHomePress}: BreadcrumbProps) => {
<TouchableOpacity
style={styles.textContainer}
activeOpacity={0.7}
disabled={!item.onPress}
disabled={disabled || !item.onPress}
onPress={item.onPress}>
<Text>{item.title}</Text>
</TouchableOpacity>
Expand Down
3 changes: 3 additions & 0 deletions packages/ui/src/components/templates/TreeView/Branch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ interface BranchProps {
fetchBranchData: (idParent: number) => Promise<any>;
branchCondition: (item: any) => boolean;
onBranchFilterPress: (branch: any) => void;
isBranchFilterVisible?: boolean;
translator: (translationKey: string) => string;
}

Expand All @@ -148,6 +149,7 @@ const Branch = ({
fetchBranchData,
branchCondition,
onBranchFilterPress,
isBranchFilterVisible,
translator,
}: BranchProps) => {
const handleBranchPress = useCallback(() => {
Expand Down Expand Up @@ -194,6 +196,7 @@ const Branch = ({
isOpen={isBranchOpen}
parent={branch.item}
onFilterPress={onBranchFilterPress}
isBranchFilterVisible={isBranchFilterVisible}
infoButtonIndication={branchCardInfoButtonIndication}
actionList={getBranchActions?.(branch)}
translator={translator}
Expand Down
3 changes: 3 additions & 0 deletions packages/ui/src/components/templates/TreeView/BranchCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ interface BranchActionCardProps {
isOpen: boolean;
parent: any;
onFilterPress: (branch: any) => void;
isBranchFilterVisible?: boolean;
infoButtonIndication: string;
actionList?: ActionCardType[];
translator: (translationKey: string) => string;
Expand All @@ -75,6 +76,7 @@ const BranchActionCard = ({
isOpen,
parent,
onFilterPress,
isBranchFilterVisible,
infoButtonIndication,
actionList = [],
translator,
Expand All @@ -87,6 +89,7 @@ const BranchActionCard = ({
helper: infoButtonIndication,
large: true,
onPress: () => onFilterPress(parent),
hidden: !isBranchFilterVisible,
}}
translator={translator}>
<BranchCard onPress={onPress} children={children} isOpen={isOpen} />
Expand Down
3 changes: 3 additions & 0 deletions packages/ui/src/components/templates/TreeView/TreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ interface TreeViewProps {
*/
branchCondition: (item: any) => boolean;
onBranchFilterPress: (branch: any) => void;
isBranchFilterVisible?: boolean;
moreLoading: boolean;
isListEnd: boolean;
filter?: boolean;
Expand All @@ -75,6 +76,7 @@ const TreeView = ({
fetchBranchData,
branchCondition,
onBranchFilterPress,
isBranchFilterVisible = true,
moreLoading = false,
isListEnd = false,
filter = false,
Expand Down Expand Up @@ -104,6 +106,7 @@ const TreeView = ({
fetchBranchData={fetchBranchData}
branchCondition={branchCondition}
onBranchFilterPress={onBranchFilterPress}
isBranchFilterVisible={isBranchFilterVisible}
translator={translator}
/>
) : (
Expand Down
1 change: 1 addition & 0 deletions packages/ui/stories/molecules/Breadcrumb.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default meta;
export const Breadcrumb: Story<typeof Component> = {
args: {
numberItems: 5,
disabled: false,
},
argTypes: {
items: disabledControl,
Expand Down
Loading