Skip to content

Commit

Permalink
feat: improve ObjectCard and binary image helper
Browse files Browse the repository at this point in the history
  • Loading branch information
gca-axelor authored and lme-axelor committed Jul 31, 2023
1 parent b1b751c commit 8249d66
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
20 changes: 17 additions & 3 deletions packages/core/src/utils/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const useMetafileUri = () => {

return useCallback(
(metafileId: number) =>
metafileId
metafileId != null
? {
uri: `${baseUrl}ws/rest/com.axelor.meta.db.MetaFile/${metafileId}/content/download`,
}
Expand All @@ -38,9 +38,23 @@ export const useBinaryImageUri = () => {

return useCallback(
(id: number, version: number, model: string) =>
id && version && model
id != null && version != null && model != null
? {
uri: `${baseUrl}ws/${model}/${id}/image/download?v=${version}&parentId=${id}&parentModel=${model}&image=true`,
uri: `${baseUrl}ws/rest/${model}/${id}/image/download?v=${version}&parentId=${id}&parentModel=${model}&image=true`,
}
: null,
[baseUrl],
);
};

export const useBinaryPictureUri = () => {
const {baseUrl} = useSelector((state: any) => state.auth);

return useCallback(
(id: number, version: number, model: string) =>
id != null && version != null && model != null
? {
uri: `${baseUrl}ws/rest/${model}/${id}/picture/download?v=${version}&parentId=${id}&parentModel=${model}&image=true`,
}
: null,
[baseUrl],
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export {
formatScan,
formatURL,
} from './formatters';
export {useBinaryImageUri, useMetafileUri} from './image';
export {useBinaryImageUri, useBinaryPictureUri, useMetafileUri} from './image';
export {filterList, filterListContain} from './list';
export {
calculateDiff,
Expand Down
28 changes: 25 additions & 3 deletions packages/ui/src/components/templates/ObjectCard/ObjectCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,23 @@ const filterList = (list: any[]): any[] => {

interface TextElement {
style?: any;
displayText: string;
displayText?: string;
indicatorText?: string;
fontAwesome5?: boolean;
size?: number;
iconName?: string;
color?: string;
isTitle?: boolean;
hideIfNull?: boolean;
hideIf?: boolean;
order?: number;
numberOfLines?: number;
customComponent?: ReactElement<any>;
}

interface BadgeElement {
style?: any;
displayText: string;
displayText?: string;
color?: Color;
showIf?: boolean;
order?: number;
Expand Down Expand Up @@ -149,7 +152,12 @@ const ObjectCard = ({
});
}

if (item.hideIfNull && checkNullString(item.displayText)) {
if (
(item.hideIfNull &&
checkNullString(item.displayText) &&
checkNullString(item.indicatorText)) ||
item.hideIf
) {
return null;
}

Expand All @@ -165,12 +173,26 @@ const ObjectCard = ({
);
}

if (checkNullString(item.iconName) && checkNullString(item.indicatorText)) {
return (
<Text
key={`${item.displayText} - ${item.order}`}
writingType="subtitle"
style={[styles.text, item.style]}
numberOfLines={item.numberOfLines}>
{item.displayText}
</Text>
);
}

return (
<LabelText
key={`${item.displayText} - ${item.order}`}
style={[styles.text, item.style]}
textStyle={item.style}
iconName={item.iconName}
FontAwesome5={item.fontAwesome5}
size={item.size}
color={item.color}
title={item.indicatorText}
value={item.displayText}
Expand Down

0 comments on commit 8249d66

Please sign in to comment.