-
Notifications
You must be signed in to change notification settings - Fork 0
feat: change contacts on statistics page [MIM-2879] #428
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4cabeb8
first attempt
olavlan-ssb 5530c22
simplify css
olavlan-ssb f32c727
fixes
olavlan-ssb 0e5d462
fetch from backend
olavlan-ssb 1e41d79
improve performance
olavlan-ssb 153de05
remove unnecessary change
olavlan-ssb f420cde
Merge branch 'develop' into MIM-2879-update-contacts-component
olavlan-ssb c15f9f5
Merge branch 'develop' into MIM-2879-update-contacts-component
olavlan-ssb 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 hidden or 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,15 @@ | ||
| .contact-selection { | ||
| &::part(items) { | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: flex-start; | ||
| order: 2; | ||
| width: 100%; | ||
| gap: var(--ds-size-2); | ||
| margin-top: var(--ds-size-3); | ||
| } | ||
|
|
||
| & > :is(del, button[type='reset']) { | ||
| order: 1; | ||
| } | ||
| } |
This file contains hidden or 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,60 @@ | ||
| import { useMemo } from 'react' | ||
| import './ContactSelection.css' | ||
| import { EXPERIMENTAL_Suggestion as Suggestion, type SuggestionItem, Field } from '@digdir/designsystemet-react' | ||
| import type { Contact } from '@ssbno-statreg/shared' | ||
| import { formatContact } from '../lib/utils' | ||
|
|
||
| export type ContactSelectionProps = { | ||
| contacts: Contact[] | ||
| selected: string[] | ||
| setSelected: (selected: string[]) => void | ||
| } | ||
|
|
||
| export function ContactSelection({ contacts, selected, setSelected }: ContactSelectionProps) { | ||
|
Check warning on line 13 in frontend/src/components/ContactSelection.tsx
|
||
| const contactMap = useMemo( | ||
| () => | ||
| contacts.reduce<Record<string, Contact>>((record, contact) => { | ||
| record[contact.principalName] = contact | ||
| return record | ||
| }, {}), | ||
| [contacts] | ||
| ) | ||
|
|
||
| const selectedItems: SuggestionItem[] = selected.map((principalName) => ({ | ||
| label: formatContact(contactMap[principalName]), | ||
| value: principalName, | ||
| })) | ||
|
|
||
| const options = useMemo( | ||
| () => | ||
| contacts.map((contact) => ( | ||
| <Suggestion.Option | ||
| className='contact-selection-item' | ||
| key={contact.principalName} | ||
| label={formatContact(contact)} | ||
| value={contact.principalName} | ||
| > | ||
| {formatContact(contact)} | ||
| </Suggestion.Option> | ||
| )), | ||
| [contacts] | ||
| ) | ||
|
|
||
| return ( | ||
| <Field> | ||
| <Suggestion | ||
| className='contact-selection' | ||
| multiple | ||
| onSelectedChange={(items) => setSelected(items.map((item) => item.value))} | ||
| selected={selectedItems} | ||
| > | ||
| <Suggestion.Input /> | ||
| <Suggestion.Clear aria-label='Tøm valgte kontakter' /> | ||
| <Suggestion.List className='contact-selection-list'> | ||
| <Suggestion.Empty>Ingen treff</Suggestion.Empty> | ||
| {options} | ||
| </Suggestion.List> | ||
| </Suggestion> | ||
| </Field> | ||
| ) | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.