forked from axelor/axelor-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b32756c
commit e1a952f
Showing
15 changed files
with
394 additions
and
21 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
packages/core/src/auth/components/molecules/ProcessHistoryCard/ProcessHistoryCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Axelor Business Solutions | ||
* | ||
* Copyright (C) 2024 Axelor (<http://axelor.com>). | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import React, {useCallback, useMemo} from 'react'; | ||
import {StyleSheet} from 'react-native'; | ||
import {useThemeColor, ObjectCard} from '@axelor/aos-mobile-ui'; | ||
import {useTranslator} from '../../../../i18n'; | ||
import {ProcessStatus} from '../../../../components'; | ||
import {ProcessHistory} from '../../../types'; | ||
|
||
interface ProccessHistoryCardProps { | ||
style?: any; | ||
status: ProcessStatus; | ||
name: string; | ||
startedDate: string; | ||
completedDate: string; | ||
failedDate: string; | ||
successCallBack: () => void; | ||
errorCallBack: () => void; | ||
} | ||
|
||
const ProccessHistoryCard = ({ | ||
style, | ||
status, | ||
name, | ||
startedDate, | ||
completedDate, | ||
failedDate, | ||
successCallBack, | ||
errorCallBack, | ||
}: ProccessHistoryCardProps) => { | ||
const Colors = useThemeColor(); | ||
const I18n = useTranslator(); | ||
|
||
const borderStyle = useMemo(() => { | ||
return getStyles(ProcessHistory.getStatusColor(status, Colors).background) | ||
?.border; | ||
}, [Colors, status]); | ||
|
||
const handleOnProcess = useCallback(() => { | ||
status === ProcessStatus.COMPLETED ? successCallBack() : errorCallBack(); | ||
}, [status, successCallBack, errorCallBack]); | ||
|
||
return ( | ||
<ObjectCard | ||
onPress={handleOnProcess} | ||
style={[borderStyle, style]} | ||
upperTexts={{ | ||
items: [ | ||
{isTitle: true, displayText: name}, | ||
{ | ||
iconName: 'calendar-event', | ||
indicatorText: I18n.t('User_ProcessHistory_StartedOn'), | ||
displayText: startedDate, | ||
}, | ||
{ | ||
iconName: 'calendar-check', | ||
indicatorText: I18n.t('User_ProcessHistory_CompletedOn'), | ||
displayText: completedDate, | ||
hideIfNull: | ||
status !== ProcessStatus.COMPLETED || completedDate == null, | ||
}, | ||
{ | ||
iconName: 'calendar-check', | ||
indicatorText: I18n.t('User_ProcessHistory_FailedOn'), | ||
displayText: failedDate, | ||
hideIfNull: status !== ProcessStatus.FAILED || failedDate == null, | ||
}, | ||
], | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
const getStyles = (color: string) => | ||
StyleSheet.create({ | ||
border: {borderLeftWidth: 7, borderLeftColor: color}, | ||
}); | ||
|
||
export default ProccessHistoryCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
packages/core/src/auth/screens/ProcessHistoryListScreen.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Axelor Business Solutions | ||
* | ||
* Copyright (C) 2024 Axelor (<http://axelor.com>). | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
import React, {useCallback, useEffect, useState} from 'react'; | ||
import {StyleSheet} from 'react-native'; | ||
import { | ||
ChipSelect, | ||
HeaderContainer, | ||
Screen, | ||
ScrollList, | ||
ToggleSwitch, | ||
useThemeColor, | ||
} from '@axelor/aos-mobile-ui'; | ||
import {filterChip} from '../../utils'; | ||
import {ProcessStatus} from '../../components'; | ||
import {useTranslator} from '../../i18n'; | ||
import {useLoader} from '../../components'; | ||
import {ProcessHistoryCard} from '../components'; | ||
import {ProcessHistory} from '../types'; | ||
|
||
const ProcessHistoryListScreen = () => { | ||
const I18n = useTranslator(); | ||
const Colors = useThemeColor(); | ||
const [tabSwitch, setTabSwitch] = useState(false); | ||
|
||
const {processList} = useLoader(); | ||
|
||
const [filteredList, setFilteredList] = useState(processList); | ||
const [selectedStatus, setSelectedStatus] = useState([]); | ||
|
||
const filterOnStatus = useCallback( | ||
list => { | ||
return filterChip(list, selectedStatus, 'status'); | ||
}, | ||
[selectedStatus], | ||
); | ||
|
||
useEffect(() => { | ||
setFilteredList(filterOnStatus(processList)); | ||
}, [filterOnStatus, processList]); | ||
|
||
return ( | ||
<Screen removeSpaceOnTop={true}> | ||
<HeaderContainer | ||
fixedItems={ | ||
<ToggleSwitch | ||
leftTitle={I18n.t('User_ProcessHistory_Today')} | ||
rightTitle={I18n.t('User_ProcessHistory_All')} | ||
onSwitch={() => setTabSwitch(!tabSwitch)} | ||
/> | ||
} | ||
chipComponent={ | ||
<ChipSelect | ||
mode="multi" | ||
onChangeValue={chiplist => setSelectedStatus(chiplist)} | ||
selectionItems={[ | ||
{ | ||
title: I18n.t('User_ProcessHistory_Status_Running'), | ||
color: ProcessHistory.getStatusColor( | ||
ProcessStatus.RUNNING, | ||
Colors, | ||
), | ||
key: ProcessStatus.RUNNING, | ||
}, | ||
{ | ||
title: I18n.t('User_ProcessHistory_Status_Completed'), | ||
color: ProcessHistory.getStatusColor( | ||
ProcessStatus.COMPLETED, | ||
Colors, | ||
), | ||
key: ProcessStatus.COMPLETED, | ||
}, | ||
{ | ||
title: I18n.t('User_ProcessHistory_Status_Failed'), | ||
color: ProcessHistory.getStatusColor( | ||
ProcessStatus.FAILED, | ||
Colors, | ||
), | ||
key: ProcessStatus.FAILED, | ||
}, | ||
]} | ||
/> | ||
} | ||
expandableFilter={false} | ||
/> | ||
<ScrollList | ||
loadingList={false} | ||
data={filteredList} | ||
renderItem={({item}) => ( | ||
<ProcessHistoryCard {...item} style={styles.item} /> | ||
)} | ||
moreLoading={false} | ||
isListEnd={true} | ||
translator={I18n.t} | ||
/> | ||
</Screen> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
item: { | ||
marginHorizontal: 12, | ||
marginVertical: 4, | ||
}, | ||
}); | ||
|
||
export default ProcessHistoryListScreen; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Axelor Business Solutions | ||
* | ||
* Copyright (C) 2024 Axelor (<http://axelor.com>). | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
export {default as ProcessHistory} from './process-history'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Axelor Business Solutions | ||
* | ||
* Copyright (C) 2024 Axelor (<http://axelor.com>). | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import {Color, ThemeColors} from '@axelor/aos-mobile-ui'; | ||
import {ProcessStatus} from '../../components'; | ||
|
||
class ProcessHistory { | ||
static getStatusColor = ( | ||
status: ProcessStatus, | ||
Colors: ThemeColors, | ||
): Color => { | ||
switch (status) { | ||
case ProcessStatus.RUNNING: | ||
return Colors.cautionColor; | ||
case ProcessStatus.COMPLETED: | ||
return Colors.successColor; | ||
case ProcessStatus.FAILED: | ||
return Colors.errorColor; | ||
default: | ||
console.warn( | ||
`Status provided with value ${status} is not supported by process history`, | ||
); | ||
return null; | ||
} | ||
}; | ||
} | ||
|
||
export default ProcessHistory; |
Oops, something went wrong.