-
Notifications
You must be signed in to change notification settings - Fork 17
Rettet et problem hvor taksonomifelt i redigeringspanel ikke støttet nivåer av termer #1507
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
9 commits
Select commit
Hold shift + click to select a range
34fe13c
Modern taxonomy picker as replacement for tagpicker
stigre a3cd7db
Use dataAdapter context object - description as panel title - ITag ->…
stigre 1ee9b97
Workaround to safely map ModernTaxonomyPicker initial values without …
stigre 2621a2c
Linting and cleanup
stigre aaed458
Changelog
stigre 91543f1
Merge branch 'releases/1.9' into issue/1504
Remi749 3f791df
Initial value for single select taxonomy
stigre 742a823
Merge branch 'issue/1504' of https://github.com/Puzzlepart/prosjektpo…
stigre 82bbe7a
Update CHANGELOG.md
Remi749 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
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
33 changes: 12 additions & 21 deletions
33
...ry/src/components/CustomEditPanel/CustomEditPanelBody/FieldElements/TaxonomyFieldType.tsx
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 |
|---|---|---|
| @@ -1,39 +1,30 @@ | ||
| import { ITag, TagPicker } from '@fluentui/react' | ||
| import React from 'react' | ||
| import { FieldContainer } from '../../../FieldContainer' | ||
| import styles from '../CustomEditPanelBody.module.scss' | ||
| import { useCustomEditPanelContext } from '../../context' | ||
| import { FieldElementComponent } from './types' | ||
| import { ModernTaxonomyPicker } from '@pnp/spfx-controls-react' | ||
| import { Term, useInitialTaxonomyValues } from './useInitialTaxonomyValues' | ||
|
|
||
| export const TaxonomyFieldType: FieldElementComponent = ({ field }) => { | ||
| const context = useCustomEditPanelContext() | ||
| const mapInitialValues = useInitialTaxonomyValues() | ||
| const terms = context.model.get<Term[]>(field) | ||
|
|
||
| return ( | ||
| <FieldContainer | ||
| iconName='AppsList' | ||
| label={field.displayName} | ||
| description={field.description} | ||
| required={field.required} | ||
| > | ||
| <TagPicker | ||
| styles={{ text: styles.field }} | ||
| onResolveSuggestions={async (filter, selectedItems) => | ||
| await context.props.dataAdapter.getTerms( | ||
| field.getProperty('TermSetId'), | ||
| filter, | ||
| selectedItems | ||
| ) | ||
| } | ||
| onEmptyResolveSuggestions={async (selectedItems) => | ||
| await context.props.dataAdapter.getTerms( | ||
| field.getProperty('TermSetId'), | ||
| '', | ||
| selectedItems | ||
| ) | ||
| } | ||
| defaultSelectedItems={context.model.get<ITag[]>(field)} | ||
| itemLimit={1} | ||
| <ModernTaxonomyPicker | ||
| context={context.props.dataAdapter.spfxContext as any} // Newest version of the control requires this cast for now, as context type is incompatibale with other types of SPFxContext | ||
| panelTitle={field.description || field.displayName} | ||
| initialValues={terms?.map(mapInitialValues)} | ||
| label='' | ||
| termSetId={field.getProperty('TermSetId')} | ||
| onChange={(items) => context.model.set(field, items)} | ||
| /> | ||
| </FieldContainer> | ||
| ) | ||
| } | ||
| } |
34 changes: 13 additions & 21 deletions
34
...c/components/CustomEditPanel/CustomEditPanelBody/FieldElements/TaxonomyFieldTypeMulti.tsx
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 |
|---|---|---|
| @@ -1,39 +1,31 @@ | ||
| import { ITag, TagPicker } from '@fluentui/react' | ||
| import { ModernTaxonomyPicker } from '@pnp/spfx-controls-react/lib/ModernTaxonomyPicker' | ||
| import React from 'react' | ||
| import { FieldContainer } from '../../../FieldContainer' | ||
| import { useCustomEditPanelContext } from '../../context' | ||
| import styles from '../CustomEditPanelBody.module.scss' | ||
| import { FieldElementComponent } from './types' | ||
| import { Term, useInitialTaxonomyValues } from './useInitialTaxonomyValues' | ||
|
|
||
| export const TaxonomyFieldTypeMulti: FieldElementComponent = ({ field }) => { | ||
| const context = useCustomEditPanelContext() | ||
| const mapInitialValues = useInitialTaxonomyValues() | ||
| const terms = context.model.get<Term[]>(field) | ||
|
|
||
| return ( | ||
| <FieldContainer | ||
| iconName='AppsList' | ||
| label={field.displayName} | ||
| description={field.description} | ||
| required={field.required} | ||
| > | ||
| <TagPicker | ||
| styles={{ text: styles.field }} | ||
| onResolveSuggestions={async (filter, selectedItems) => | ||
| await context.props.dataAdapter.getTerms( | ||
| field.getProperty('TermSetId'), | ||
| filter, | ||
| selectedItems | ||
| ) | ||
| } | ||
| onEmptyResolveSuggestions={async (selectedItems) => | ||
| await context.props.dataAdapter.getTerms( | ||
| field.getProperty('TermSetId'), | ||
| '', | ||
| selectedItems | ||
| ) | ||
| } | ||
| defaultSelectedItems={context.model.get<ITag[]>(field)} | ||
| itemLimit={20} | ||
| <ModernTaxonomyPicker | ||
| context={context.props.dataAdapter.spfxContext as any} // Newest version of the control requires this cast for now, as context type is incompatibale with other types of SPFxContext | ||
| panelTitle={field.description || field.displayName} | ||
| initialValues={terms?.map(mapInitialValues)} | ||
| allowMultipleSelections | ||
| label='' | ||
| termSetId={field.getProperty('TermSetId')} | ||
| onChange={(items) => context.model.set(field, items)} | ||
| /> | ||
| </FieldContainer> | ||
| ) | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
.../components/CustomEditPanel/CustomEditPanelBody/FieldElements/useInitialTaxonomyValues.ts
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,31 @@ | ||
| import { useCallback } from 'react' | ||
|
|
||
| interface ITermLabel { | ||
| name: string | ||
| isDefault: boolean | ||
| languageTag: string | ||
| } | ||
|
|
||
| interface ITagTerm { | ||
| key: string | ||
| name: string | ||
| } | ||
|
|
||
| interface IModernTaxonomyTerm { | ||
| id: string | ||
| labels: ITermLabel[] | ||
| } | ||
|
|
||
| export type Term = ITagTerm | IModernTaxonomyTerm; | ||
|
|
||
| export const useInitialTaxonomyValues = () => { | ||
| const mapInitialValues = useCallback((term: Term) => { | ||
| if ('id' in term) { | ||
| return { labels: term.labels, id: term.id } | ||
| } else { | ||
| return { labels: [{ name: term.name, isDefault: true, languageTag: 'nb-NO' }], id: term.key } | ||
| } | ||
| }, []) | ||
|
|
||
| return mapInitialValues | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.