-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(merge): indicator types merge #455
Draft
Birkbjo
wants to merge
18
commits into
master
Choose a base branch
from
feat/indicator-types-merge
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4b916b6
feat(ModelMultiSelect): add modelmultiselect component
Birkbjo 4bc8ec3
feat: support string ids for modelmulti-select
Birkbjo 53e634c
feat: setup merge routes and authorities
Birkbjo 4724995
feat: add merge button to toolbar
Birkbjo 0faa329
feat(merge): add indicator merge form
Birkbjo f46d74d
Merge branch 'feat/model-multi-select-component' into feat/indicator-…
Birkbjo 5e921b1
fix: add source-target fields
Birkbjo 348f233
fix: merge load and complete page
Birkbjo b3aa9f8
fix: add introduction
Birkbjo b2bdbbf
fix: fix initial selected values for multi-select
Birkbjo 92a4a15
fix: add missing files
Birkbjo b1629dd
fix: some cleanup - remove irrelevant changes
Birkbjo c71fe90
refactor: use DefaultMergeFormContents
Birkbjo f002dea
refactor: refactor formcontent
Birkbjo 78cbf0f
refactor: simplify mergeform styles
Birkbjo 8435f24
fix: add missing file
Birkbjo f6c6dc0
refactor: loading composition
Birkbjo d38d488
refactor: form style fixes, confirmation field
Birkbjo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
71 changes: 71 additions & 0 deletions
71
src/components/SearchableMultiSelect/SearchableMultiSelect.module.css
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,71 @@ | ||
.invisibleOption { | ||
display: none; | ||
} | ||
|
||
.loader { | ||
height: 80px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
padding-top: 20px; | ||
overflow: hidden; | ||
} | ||
|
||
.error { | ||
display: flex; | ||
justify-content: center; | ||
font-size: 14px; | ||
padding: var(--spacers-dp12) 16px; | ||
} | ||
|
||
.errorInnerWrapper { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
} | ||
|
||
.loadingErrorLabel { | ||
color: var(--theme-error); | ||
} | ||
|
||
.errorRetryButton { | ||
background: none; | ||
padding: 0; | ||
border: 0; | ||
outline: 0; | ||
text-decoration: underline; | ||
cursor: pointer; | ||
} | ||
|
||
.multiSelect { | ||
min-width: 150px; | ||
} | ||
.searchField { | ||
display: flex; | ||
gap: var(--spacers-dp8); | ||
position: sticky; | ||
top: 0; | ||
padding: var(--spacers-dp16); | ||
box-shadow: 0 0 4px rgba(0, 0, 0, 0.4); | ||
background: var(--colors-white); | ||
} | ||
|
||
.searchInput { | ||
flex-grow: 1; | ||
} | ||
|
||
.clearButton { | ||
font-size: 14px; | ||
flex-grow: 0; | ||
background: none; | ||
padding: 0; | ||
border: 0; | ||
outline: 0; | ||
text-decoration: underline; | ||
cursor: pointer; | ||
} | ||
|
||
.clearButton:hover { | ||
color: var(--theme-valid); | ||
text-decoration: none; | ||
} |
154 changes: 154 additions & 0 deletions
154
src/components/SearchableMultiSelect/SearchableMultiSelect.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,154 @@ | ||
import i18n from '@dhis2/d2-i18n' | ||
import { | ||
CircularLoader, | ||
Input, | ||
MultiSelect, | ||
MultiSelectOption, | ||
MultiSelectProps, | ||
} from '@dhis2/ui' | ||
import React, { forwardRef, useEffect, useState } from 'react' | ||
import { useDebouncedState } from '../../lib' | ||
import classes from './SearchableMultiSelect.module.css' | ||
|
||
export interface Option { | ||
value: string | ||
label: string | ||
} | ||
|
||
type OwnProps = { | ||
onEndReached?: () => void | ||
onFilterChange: ({ value }: { value: string }) => void | ||
onRetryClick: () => void | ||
options: Option[] | ||
showEndLoader?: boolean | ||
error?: string | ||
} | ||
|
||
export type SearchableMultiSelectPropTypes = Omit< | ||
MultiSelectProps, | ||
keyof OwnProps | ||
> & | ||
OwnProps | ||
export const SearchableMultiSelect = ({ | ||
disabled, | ||
error, | ||
dense, | ||
loading, | ||
placeholder, | ||
prefix, | ||
onBlur, | ||
onChange, | ||
onEndReached, | ||
onFilterChange, | ||
onFocus, | ||
onRetryClick, | ||
options, | ||
selected, | ||
showEndLoader, | ||
}: SearchableMultiSelectPropTypes) => { | ||
const [loadingSpinnerRef, setLoadingSpinnerRef] = useState<HTMLElement>() | ||
|
||
const { liveValue: filter, setValue: setFilterValue } = | ||
useDebouncedState<string>({ | ||
initialValue: '', | ||
onSetDebouncedValue: (value: string) => onFilterChange({ value }), | ||
}) | ||
|
||
useEffect(() => { | ||
// We don't want to wait for intersections when loading as that can | ||
// cause buggy behavior | ||
if (loadingSpinnerRef && !loading) { | ||
const observer = new IntersectionObserver( | ||
(entries) => { | ||
const [{ isIntersecting }] = entries | ||
|
||
if (isIntersecting) { | ||
onEndReached?.() | ||
} | ||
}, | ||
{ threshold: 0.8 } | ||
) | ||
|
||
observer.observe(loadingSpinnerRef) | ||
return () => observer.disconnect() | ||
} | ||
}, [loadingSpinnerRef, loading, onEndReached]) | ||
|
||
return ( | ||
<MultiSelect | ||
className={classes.multiSelect} | ||
selected={selected} | ||
disabled={disabled} | ||
error={!!error} | ||
onChange={onChange} | ||
placeholder={placeholder} | ||
prefix={prefix} | ||
onBlur={onBlur} | ||
onFocus={onFocus} | ||
dense={dense} | ||
clearable={selected && selected.length > 1} | ||
> | ||
<div className={classes.searchField}> | ||
<div className={classes.searchInput}> | ||
<Input | ||
dense | ||
initialFocus | ||
value={filter} | ||
onChange={({ value }) => setFilterValue(value ?? '')} | ||
placeholder={i18n.t('Filter options')} | ||
type="search" | ||
/> | ||
</div> | ||
</div> | ||
|
||
{options.map(({ value, label }) => ( | ||
<MultiSelectOption key={value} value={value} label={label} /> | ||
))} | ||
|
||
{!error && !loading && showEndLoader && ( | ||
<Loader | ||
ref={(ref) => { | ||
if (!!ref && ref !== loadingSpinnerRef) { | ||
setLoadingSpinnerRef(ref) | ||
} | ||
}} | ||
/> | ||
)} | ||
|
||
{!error && loading && <Loader />} | ||
|
||
{error && <Error msg={error} onRetryClick={onRetryClick} />} | ||
</MultiSelect> | ||
) | ||
} | ||
|
||
const Loader = forwardRef<HTMLDivElement, object>(function Loader(_, ref) { | ||
return ( | ||
<div ref={ref} className={classes.loader}> | ||
<CircularLoader /> | ||
</div> | ||
) | ||
}) | ||
|
||
function Error({ | ||
msg, | ||
onRetryClick, | ||
}: { | ||
msg: string | ||
onRetryClick: () => void | ||
}) { | ||
return ( | ||
<div className={classes.error}> | ||
<div className={classes.errorInnerWrapper}> | ||
<span className={classes.loadingErrorLabel}>{msg}</span> | ||
<button | ||
className={classes.errorRetryButton} | ||
type="button" | ||
onClick={onRetryClick} | ||
> | ||
{i18n.t('Retry')} | ||
</button> | ||
</div> | ||
</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 @@ | ||
export * from './SearchableMultiSelect' |
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,62 @@ | ||
import i18n from '@dhis2/d2-i18n' | ||
import { Button, ButtonStrip, CircularLoader } from '@dhis2/ui' | ||
import React from 'react' | ||
import { useFormState } from 'react-final-form' | ||
import { DefaultFormErrorNotice } from '../form/DefaultFormErrorNotice' | ||
import { LinkButton } from '../LinkButton' | ||
|
||
export const DefaultMergeFormContents = ({ | ||
children, | ||
}: React.PropsWithChildren) => { | ||
const { submitting, submitSucceeded } = useFormState({ | ||
subscription: { submitting: true, submitSucceeded: true }, | ||
}) | ||
|
||
if (submitSucceeded) { | ||
return <MergeComplete /> | ||
} | ||
|
||
return ( | ||
<div> | ||
{submitting && <MergeInProgress />} | ||
{!submitting && !submitSucceeded && ( | ||
<> | ||
{children} | ||
<DefaultFormErrorNotice /> | ||
<MergeActions /> | ||
</> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export const MergeActions = () => { | ||
return ( | ||
<ButtonStrip> | ||
<Button primary type="submit"> | ||
{i18n.t('Merge')} | ||
</Button> | ||
<LinkButton to={'../'} secondary> | ||
{i18n.t('Cancel')} | ||
</LinkButton> | ||
</ButtonStrip> | ||
) | ||
} | ||
|
||
export const MergeInProgress = () => { | ||
return ( | ||
<div> | ||
<CircularLoader small /> | ||
Merging... | ||
</div> | ||
) | ||
} | ||
|
||
export const MergeComplete = () => { | ||
return ( | ||
<div> | ||
<h2>Merge complete</h2> | ||
<LinkButton to="../">{i18n.t('Back to list')}</LinkButton> | ||
</div> | ||
) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that when trying to tab around from the header-bar, the sidebaritems stole focus - so this should fix that.