-
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.
feat: add TreeDetailsFilter drawer on TreeDetails page
- Loading branch information
1 parent
b916561
commit dae99d0
Showing
4 changed files
with
171 additions
and
12 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import { useCallback, useMemo } from 'react'; | ||
import { useIntl } from 'react-intl'; | ||
|
||
import FilterDrawer from '@/components/Filter/Drawer'; | ||
import FilterSummarySection from '@/components/Filter/SummarySection'; | ||
import FilterCheckboxSection, { | ||
ICheckboxSection, | ||
} from '@/components/Filter/CheckboxSection'; | ||
import { | ||
TreeDetails as TreeDetailsType, | ||
TTreeDetailsFilter, | ||
} from '@/types/tree/TreeDetails'; | ||
|
||
interface ITreeDetailsFilter { | ||
data?: TreeDetailsType; | ||
onFilter: (filter: TTreeDetailsFilter) => void; | ||
} | ||
|
||
type TFilterApplied = { [key: string]: boolean }; | ||
|
||
const sanitizeData = ( | ||
data: TreeDetailsType | undefined, | ||
): [TFilterApplied, TFilterApplied, TFilterApplied, TFilterApplied, string] => { | ||
const status = { TRUE: false, FALSE: false }; | ||
const branches: TFilterApplied = {}; | ||
const configs: TFilterApplied = {}; | ||
const archs: TFilterApplied = {}; | ||
let treeUrl = ''; | ||
|
||
if (data) | ||
data.builds.forEach(b => { | ||
if (b.git_repository_branch) branches[b.git_repository_branch] = false; | ||
if (b.config_name) configs[b.config_name] = false; | ||
if (b.architecture) archs[b.architecture] = false; | ||
if (!treeUrl && b.git_repository_url) treeUrl = b.git_repository_url; | ||
}); | ||
|
||
return [status, branches, configs, archs, treeUrl]; | ||
}; | ||
|
||
const getFilterListFromObj = (filterObj: TFilterApplied): string[] => | ||
Object.keys(filterObj).filter(key => filterObj[key]); | ||
|
||
const TreeDetailsFilter = ({ | ||
data, | ||
onFilter, | ||
}: ITreeDetailsFilter): JSX.Element => { | ||
const intl = useIntl(); | ||
|
||
const [statusObj, branchObj, configObj, archObj, treeUrl] = useMemo( | ||
() => sanitizeData(data), | ||
[data], | ||
); | ||
|
||
const onClickFilterHandle = useCallback(() => { | ||
const filter: TTreeDetailsFilter = {}; | ||
|
||
filter.config_name = getFilterListFromObj(configObj); | ||
filter.git_repository_branch = getFilterListFromObj(branchObj); | ||
filter.architecture = getFilterListFromObj(archObj); | ||
filter.valid = getFilterListFromObj(statusObj); | ||
|
||
onFilter(filter); | ||
}, [onFilter, configObj, branchObj, archObj, statusObj]); | ||
|
||
const checkboxSectionsProps: ICheckboxSection[] = useMemo(() => { | ||
return [ | ||
{ | ||
title: intl.formatMessage({ id: 'global.branch' }), | ||
subtitle: intl.formatMessage({ id: 'filter.branchSubtitle' }), | ||
items: branchObj, | ||
onClickItem: (branch: string, isChecked: boolean) => | ||
(branchObj[branch] = isChecked), | ||
}, | ||
{ | ||
title: intl.formatMessage({ id: 'global.status' }), | ||
subtitle: intl.formatMessage({ id: 'filter.statusSubtitle' }), | ||
items: Object.keys(statusObj).reduce((acc, k) => { | ||
const newKey = k == 'TRUE' ? 'valid' : 'invalid'; | ||
acc[newKey] = statusObj[k]; | ||
return acc; | ||
}, {} as TFilterApplied), | ||
onClickItem: (status: string, isChecked: boolean) => | ||
(statusObj[status == 'valid' ? 'TRUE' : 'FALSE'] = isChecked), | ||
}, | ||
{ | ||
title: intl.formatMessage({ id: 'global.configs' }), | ||
subtitle: intl.formatMessage({ id: 'filter.configsSubtitle' }), | ||
items: configObj, | ||
onClickItem: (config: string, isChecked: boolean) => | ||
(configObj[config] = isChecked), | ||
}, | ||
{ | ||
title: intl.formatMessage({ id: 'global.architecture' }), | ||
subtitle: intl.formatMessage({ id: 'filter.architectureSubtitle' }), | ||
items: archObj, | ||
onClickItem: (arch: string, isChecked: boolean) => | ||
(archObj[arch] = isChecked), | ||
}, | ||
]; | ||
}, [statusObj, branchObj, configObj, archObj, intl]); | ||
|
||
const checkboxSectionsComponents = useMemo( | ||
() => | ||
checkboxSectionsProps.map(props => ( | ||
<FilterCheckboxSection key={props.title} {...props} /> | ||
)), | ||
[checkboxSectionsProps], | ||
); | ||
|
||
return ( | ||
<FilterDrawer treeURL={treeUrl} onFilter={onClickFilterHandle}> | ||
<FilterSummarySection {...summarySectionProps} /> | ||
{checkboxSectionsComponents} | ||
</FilterDrawer> | ||
); | ||
}; | ||
|
||
export default TreeDetailsFilter; | ||
|
||
const summarySectionProps = { | ||
title: 'Tree', | ||
columns: [ | ||
{ title: 'Tree', value: 'stable-rc' }, | ||
{ title: 'Matainer', value: '' }, | ||
{ title: 'Estimate to complete', value: '' }, | ||
{ | ||
title: 'Commit/tag', | ||
value: '5.15.150-rc1 - 3ab4d9c9e190217ee7e974c70b96795cd2f74611', | ||
}, | ||
], | ||
}; |
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