-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from EyeSeeTea/refactor/ou-subtree
Refactor select org unit children
- Loading branch information
Showing
5 changed files
with
44 additions
and
69 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
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
50 changes: 1 addition & 49 deletions
50
src/components/synchronization-page/OrganisationUnitPage.jsx
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 |
---|---|---|
@@ -1,73 +1,25 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import i18n from "@dhis2/d2-i18n"; | ||
|
||
import { | ||
OrganisationUnitGroupModel, | ||
OrganisationUnitGroupSetModel, | ||
OrganisationUnitModel, | ||
} from "../../models/d2Model"; | ||
import { getOrgUnitSubtree } from "../../logic/metadata"; | ||
import GenericSynchronizationPage from "./GenericSynchronizationPage"; | ||
|
||
export default class OrganisationUnitPage extends React.Component { | ||
static propTypes = { | ||
d2: PropTypes.object.isRequired, | ||
}; | ||
|
||
state = { | ||
children: [], | ||
metadataTableKey: Math.random(), | ||
}; | ||
|
||
models = [OrganisationUnitModel, OrganisationUnitGroupModel, OrganisationUnitGroupSetModel]; | ||
|
||
onSelectionChange = children => this.setState({ children }); | ||
|
||
selectChildren = async selectedOUs => { | ||
const { d2 } = this.props; | ||
const { children } = this.state; | ||
|
||
const ids = new Set(children); | ||
for (const selectedOU of selectedOUs) { | ||
const subtree = await getOrgUnitSubtree(d2, selectedOU.id); | ||
subtree.forEach(id => ids.add(id)); | ||
} | ||
this.setState({ children: Array.from(ids), metadataTableKey: Math.random() }); | ||
}; | ||
|
||
actions = [ | ||
{ | ||
name: "details", | ||
text: i18n.t("Details"), | ||
multiple: false, | ||
type: "details", | ||
}, | ||
{ | ||
name: "select-children", | ||
text: i18n.t("Select with children subtree"), | ||
multiple: true, | ||
onClick: this.selectChildren, | ||
icon: "done_all", | ||
}, | ||
]; | ||
|
||
render() { | ||
const { d2 } = this.props; | ||
const { children, metadataTableKey } = this.state; | ||
|
||
const title = i18n.t("Organisation Units Synchronization"); | ||
|
||
return ( | ||
<GenericSynchronizationPage | ||
key={metadataTableKey} | ||
d2={d2} | ||
models={this.models} | ||
title={title} | ||
actions={this.actions} | ||
initialSelection={children} | ||
onSelectionChange={this.onSelectionChange} | ||
/> | ||
); | ||
return <GenericSynchronizationPage d2={d2} models={this.models} title={title} />; | ||
} | ||
} |