-
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.
- Loading branch information
Showing
8 changed files
with
175 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
.sidebar.hide { | ||
width: 0px; | ||
height: 0px; | ||
visibility: hidden; | ||
} | ||
|
||
.pageTitle { | ||
|
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,66 @@ | ||
import React from 'react' | ||
import { DisplayableModel } from '../../types/models' | ||
import { | ||
ModelMultiSelectField, | ||
ModelMultiSelectFieldProps, | ||
} from '../metadataFormControls/ModelMultiSelect' | ||
import css from './MergeFields.module.css' | ||
import { IconArrowRight24 } from '@dhis2/ui' | ||
import { useField } from 'react-final-form' | ||
|
||
type Optional<T, K extends keyof T> = Partial<Pick<T, K>> & Omit<T, K> | ||
|
||
type BaseSourceFieldProps = Optional< | ||
ModelMultiSelectFieldProps<DisplayableModel>, | ||
'name' | ||
> | ||
|
||
export const BaseSourcesField = (props: BaseSourceFieldProps) => { | ||
const targetValue = useField<DisplayableModel[]>('target', { | ||
subscription: { value: true }, | ||
}).input.value | ||
|
||
return ( | ||
<ModelMultiSelectField | ||
name="sources" | ||
label="Sources" | ||
maxHeight="150px" | ||
// use select to filter out the target from available sources | ||
select={(availableSources) => | ||
availableSources.filter((s) => s.id !== targetValue?.[0]?.id) | ||
} | ||
{...props} | ||
/> | ||
) | ||
} | ||
|
||
export const BaseTargetField = (props: BaseSourceFieldProps) => { | ||
const sourcesValues = useField<DisplayableModel[]>('sources', { | ||
subscription: { value: true }, | ||
}).input.value | ||
|
||
return ( | ||
<ModelMultiSelectField | ||
name="target" | ||
label="Target" | ||
maxHeight="150px" | ||
select={(availableTargets) => | ||
availableTargets.filter( | ||
(t) => !sourcesValues.some((s) => s.id === t.id) | ||
) | ||
} | ||
{...props} | ||
/> | ||
) | ||
} | ||
|
||
export const MergeSourcesTargetWrapper = ({ | ||
children, | ||
}: React.PropsWithChildren) => { | ||
return ( | ||
<div className={css.targetSourceWrapper}> | ||
{children} | ||
<IconArrowRight24 /> | ||
</div> | ||
) | ||
} |
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,25 @@ | ||
.targetSourceWrapper { | ||
display: grid; | ||
/* grid is used to place the arrow between the children*/ | ||
grid-template-areas: 'source arrow target'; | ||
grid-template-columns: minmax(380px, max-content) 24px minmax( | ||
380px, | ||
max-content | ||
); | ||
gap: var(--spacers-dp8); | ||
background-color: var(--colors-grey100); | ||
padding: var(--spacers-dp16); | ||
justify-content: start; | ||
align-items: center; | ||
width: min-content; | ||
} | ||
|
||
.targetSourceWrapper > div { | ||
max-width: 380px; | ||
} | ||
|
||
.targetSourceWrapper > svg { | ||
grid-area: arrow; | ||
color: var(--colors-grey700); | ||
margin-block-start: 19px; /* 19px is the default height of the field label */ | ||
} |
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 @@ | ||
export * from './BaseMergeFields' |
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