Skip to content

Commit

Permalink
Use "Prosjektinnholdskolonner" for fieldconfig + hideFields functiona…
Browse files Browse the repository at this point in the history
…lity [packages-only]
  • Loading branch information
Remi749 committed Nov 12, 2024
1 parent 74f497a commit 0a463fe
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,20 @@ export const IdeaModule: FC<IIdeaModuleProps> = (props) => {
<NavCategory value='registreringIdeer'>
<NavCategoryItem icon={<Lightbulb />}>Mine idéer</NavCategoryItem>
<NavSubItemGroup>
{state.ideas.data.items.filter((idea) => !idea.processing).map((idea) => (
<NavSubItem
value={idea.Id.toString()}
onClick={() => {
setUrlHash({ ideaId: idea.Id.toString() })
getSelectedIdea()
}}
>
{idea?.Title}
</NavSubItem>
))}
{state.ideas.data.items
.filter((idea) => !idea.processing)
.map((idea) => (
<NavSubItem
key={idea.Id.toString()}
value={idea.Id.toString()}
onClick={() => {
setUrlHash({ ideaId: idea.Id.toString() })
getSelectedIdea()
}}
>
{idea?.Title}
</NavSubItem>
))}
</NavSubItemGroup>
</NavCategory>
<NavDivider />
Expand All @@ -108,17 +111,20 @@ export const IdeaModule: FC<IIdeaModuleProps> = (props) => {
<NavCategory value='behandlingIdeer'>
<NavCategoryItem icon={<JobPostings />}>Mine idéer</NavCategoryItem>
<NavSubItemGroup>
{state.ideas.data.items.filter((idea) => idea.processing).map((idea) => (
<NavSubItem
value={idea.Id.toString()}
onClick={() => {
setUrlHash({ ideaId: idea.Id.toString() })
getSelectedIdea()
}}
>
{idea?.Title}
</NavSubItem>
))}
{state.ideas.data.items
.filter((idea) => idea.processing)
.map((idea) => (
<NavSubItem
key={idea.Id.toString()}
value={idea.Id.toString()}
onClick={() => {
setUrlHash({ ideaId: idea.Id.toString() })
getSelectedIdea()
}}
>
{idea?.Title}
</NavSubItem>
))}
</NavSubItemGroup>
</NavCategory>
</NavDrawerBody>
Expand Down Expand Up @@ -229,9 +235,25 @@ export const IdeaModule: FC<IIdeaModuleProps> = (props) => {
IdeaModule.defaultProps = {
configurationList: 'Idékonfigurasjon',
configuration: 'Standard',
sortBy: 'Title',
showSearchBox: true,
showRenderModeSelector: true,
showSortBy: true,
defaultRenderMode: 'tiles'
hiddenRegFields: ['Title'],
hiddenProcFields: [
'Title',
'GtIdeaUrl',
'GtRegistratedIdea',
'GtIdeaProjectData',
'GtIdeaStrategicValue',
'GtIdeaStrategicNumber',
'GtIdeaQualityBenefit',
'GtIdeaQualityNumber',
'GtIdeaEconomicBenefit',
'GtIdeaEconomicNumber',
'GtIdeaOperationalNeed',
'GtIdeaOperationalNumber',
'GtIdeaRisk',
'GtIdeaRiskNumber',
'GtIdeaManualScore',
'GtIdeaManualComment',
'GtIdeaScore',
'GtIdeaPriority'
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { EditableSPField, ItemFieldValues, SPField } from 'pp365-shared-library'
import {
EditableSPField,
ItemFieldValues,
ProjectContentColumn,
SPField
} from 'pp365-shared-library'
import { IBaseComponentProps } from '../types'
import { MessageBarType } from '@fluentui/react'
import { IdeaConfigurationModel } from 'models'
Expand All @@ -18,6 +23,8 @@ export interface IIdeaModuleProps extends IBaseComponentProps {
showSortBy?: boolean
defaultRenderMode?: IdeaListRenderMode
listSize?: 'extra-small' | 'small' | 'medium'
hiddenRegFields?: string[]
hiddenProcFields?: string[]
}

export interface IIdeaModuleState {
Expand Down Expand Up @@ -82,4 +89,9 @@ export interface IIdeasData {
registered: SPField[]
processing: SPField[]
}

/**
* Columns from "Prosjektinnholdskolonner" list
*/
columns: ProjectContentColumn[]
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,36 @@ export function useIdeaModule(props: IIdeaModuleProps) {
return
}



const obj: IIdeaModuleHashState = {}
if (selectedIdea) obj.ideaId = selectedIdea.Id.toString()
setUrlHash(obj)

const registeredFieldValues = state.ideas.data.fields.registered
.filter((field) => !props.hiddenRegFields?.includes(field.InternalName))
.map((field) => {
const fieldValues: ItemFieldValues = state.ideas.data.fieldValues.registered.find(
(fv) => fv.id === selectedIdea.Id
)
if (!fieldValues) return null
return new EditableSPField(field).setValue(fieldValues)
return new EditableSPField(field).init(state.ideas.data.columns).setValue(fieldValues)
})
.sort((a, b) => {
if (!a.column) return 1
if (!b.column) return -1
return a.column.sortOrder - b.column.sortOrder
})

const processingFieldValues = selectedIdea.processing && state.ideas.data.fields.processing
const processingFieldValues =
selectedIdea.processing &&
state.ideas.data.fields.processing
.map((field) => {
const fieldValues: ItemFieldValues = state.ideas.data.fieldValues.processing.find(
(fv) => fv.get('GtRegistratedIdeaId')?.value === selectedIdea.Id
)
if (!fieldValues) return null
return new EditableSPField(field).setValue(fieldValues)
return new EditableSPField(field).init(state.ideas.data.columns).setValue(fieldValues)
})
.filter((field) => !props.hiddenProcFields?.includes(field.InternalName))
.sort((a, b) => {
if (!a.column) return 1
if (!b.column) return -1
Expand Down
16 changes: 13 additions & 3 deletions SharePointFramework/PortfolioWebParts/src/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ export class DataAdapter implements IPortfolioWebPartsDataAdapter {
const configElement = _.find(timelineConfig, { title: strings.ProjectLabel })

return { data, reports, configElement, columns: configuration.refiners }
} catch (error) { }
} catch (error) {}
}

/**
Expand Down Expand Up @@ -1091,7 +1091,7 @@ export class DataAdapter implements IPortfolioWebPartsDataAdapter {
const fields = await list.fields
.select(...getClassProperties(SPField))
.filter(
'substringof(\'Gt\', InternalName) or InternalName eq \'Title\' or InternalName eq \'Id\''
"substringof('Gt', InternalName) or InternalName eq 'Title' or InternalName eq 'Id'"
)<SPField[]>()

const userFields = fields
Expand Down Expand Up @@ -1119,6 +1119,15 @@ export class DataAdapter implements IPortfolioWebPartsDataAdapter {
}
}

const level = strings.DataSourceLevelPortfolio

const columns: ProjectContentColumn[] = await new Promise((resolve, reject) => {
this.portalDataService
.fetchProjectContentColumns('PROJECT_CONTENT_COLUMNS', 'Idémodul', level)
.then(resolve)
.catch(reject)
})

const registrationData = await getListData(configuration.registrationList)
const processingData = await getListData(configuration.processingList)

Expand Down Expand Up @@ -1153,7 +1162,8 @@ export class DataAdapter implements IPortfolioWebPartsDataAdapter {
fields: {
registered: registrationData.fields,
processing: processingData.fields
}
},
columns
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ export default class IdeaModuleWebPart extends BasePortfolioWebPart<IIdeaModuleP
PropertyPaneTextField('configuration', {
label: 'Konfigurasjonsnavn',
description: 'Navn på konfigurasjonen som skal brukes'
}),
PropertyPaneTextField('hiddenRegFields', {
label: 'Skjulte felter (registrering)',
description: 'Felt som skal skjules fra idémodulen (Idéregistrering)',
multiline: true,
resizable: true,
rows: 1
}),
PropertyPaneTextField('hiddenProcFields', {
label: 'Skjulte felter (behandling)',
description: 'Felt som skal skjules fra idémodulen (Idébehandling)',
multiline: true,
resizable: true,
rows: 6
})
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ItemFieldValues } from './ItemFieldValues'
import { ProjectColumn, ProjectColumnFieldOverride } from './ProjectColumn'
import { EditableSPFieldValue } from './EditableSPFieldValue'
import { SPField } from './SPField'
import { ProjectContentColumn } from './ProjectContentColumn'

/**
* An editable field for the `CustomEditPanel`.
Expand Down Expand Up @@ -106,8 +107,8 @@ export class EditableSPField extends SPField {
* @param currentLocale Current locale
* @param configurationName Configuration name
*/
public init(columns: ProjectColumn[], currentLocale?: string, configurationName?: string) {
this.column = columns.find((c) => c.internalName === this.internalName)
public init(columns: (ProjectColumn | ProjectContentColumn)[], currentLocale?: string, configurationName?: string) {
this.column = columns.find((c) => c.internalName === this.internalName) as ProjectColumn
this._isExternal = _.isEmpty(columns)
this.displayName = this.column?.name ?? this.displayName
this._initConfiguration(currentLocale, configurationName)
Expand Down

0 comments on commit 0a463fe

Please sign in to comment.