Skip to content

Commit

Permalink
Init IdeaModule
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi749 committed Oct 17, 2024
1 parent ac04b36 commit b6c384f
Show file tree
Hide file tree
Showing 20 changed files with 297 additions and 62 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci-channel-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- releases/1.10
- feat/ideamodule
paths:
- 'SharePointFramework/**'
- 'Install/**'
Expand Down
58 changes: 1 addition & 57 deletions SharePointFramework/PortfolioWebParts/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,13 @@
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
"version": "2.0",
"bundles": {
"latest-projects-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/latestProjects/index.js",
"manifest": "./src/webparts/latestProjects/manifest.json"
}
]
},
"portfolio-insights-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/portfolioInsights/index.js",
"manifest": "./src/webparts/portfolioInsights/manifest.json"
}
]
},
"portfolio-overview-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/portfolioOverview/index.js",
"manifest": "./src/webparts/portfolioOverview/manifest.json"
}
]
},
"project-list-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/projectList/index.js",
"manifest": "./src/webparts/projectList/manifest.json"
}
]
},
"resource-allocation-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/resourceAllocation/index.js",
"manifest": "./src/webparts/resourceAllocation/manifest.json"
}
]
},
"project-timeline-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/projectTimeline/index.js",
"manifest": "./src/webparts/projectTimeline/manifest.json"
}
]
},
"portfolio-aggregation-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/portfolioAggregation/index.js",
"manifest": "./src/webparts/portfolioAggregation/manifest.json"
}
]
},
"project-provision-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/projectProvision/index.js",
"manifest": "./src/webparts/projectProvision/manifest.json"
}
]
}
},
"externals": {},
Expand All @@ -76,4 +20,4 @@
"ProjectWebPartsStrings": "node_modules/pp365-projectwebparts/lib/loc/{locale}.js",
"SharedLibraryStrings": "node_modules/pp365-shared-library/lib/loc/{locale}.js"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.ideaModule {
margin: 0;

.container {
margin: 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { FC } from 'react'
import styles from './IdeaModule.module.scss'
import { IdeaModuleContext } from './context'
import { IIdeaModuleProps } from './types'
import { useIdeaModule } from './useIdeaModule'
import { FluentProvider, IdPrefixProvider } from '@fluentui/react-components'
import { customLightTheme } from 'pp365-shared-library'

export const IdeaModule: FC<IIdeaModuleProps> = (props) => {
const { state, setState, fluentProviderId } = useIdeaModule(props)

return (
<div className={styles.ideaModule}>
<IdeaModuleContext.Provider value={{ props, state, setState }}>
<IdPrefixProvider value={fluentProviderId}>
<FluentProvider theme={customLightTheme}>
<div className={styles.container}>
<h1>Bring your ideas to life. Here you can create, share and collaborate on ideas.</h1>
<p>With the new Idea module, you can create and share ideas with your team. You can also collaborate on ideas with your team members.</p>
</div>
</FluentProvider>
</IdPrefixProvider>
</IdeaModuleContext.Provider>
</div>
)
}

IdeaModule.defaultProps = {
configurationList: 'Idékonfigurasjon'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createContext, useContext } from 'react'
import { IIdeaModuleProps, IIdeaModuleState } from './types'

export interface IIdeaModuleContext {
props: IIdeaModuleProps
state: IIdeaModuleState
setState: (newState: Partial<IIdeaModuleState>) => void
}

export const IdeaModuleContext = createContext<IIdeaModuleContext>(null)

/**
* Hook to get the `ProjectProvisionContext`
*/
export function useProjectProvisionContext() {
return useContext(IdeaModuleContext)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './IdeaModule'
export * from './types'
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { IBaseComponentProps } from '../types'

export interface IIdeaModuleProps extends IBaseComponentProps {
configurationList: string
}

export interface IIdeaModuleState {
loading?: boolean
isRefetching?: boolean
configuration?: ConfigurationItem[]
ideas?: Record<string, any>
}

export interface IIdeaModuleHashState {
ideaId?: string
}

export class ConfigurationItem {
title: string
description: string
ideaProcessingList: string
ideaRegistrationList: string
ideaProcessingChoices: string
ideaRegistrationChoices: string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useId } from '@fluentui/react-components'
import { IIdeaModuleProps } from './types'
import { useIdeaModuleState } from './useIdeaModuleState'

/**
* Component logic hook for `IdeaModule` component.
*
clear */
export function useIdeaModule(props: IIdeaModuleProps) {
const { state, setState } = useIdeaModuleState()
const fluentProviderId = useId('fp-idea-module')

return {
state,
setState,
fluentProviderId
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useEffect } from 'react'
import { IIdeaModuleProps, IIdeaModuleState } from './types'

/**
* Component data fetch hook for `IdeaModule`. This hook is responsible for
* fetching data and setting state.
*
* @param props Props
* @param refetch Timestamp for refetch. Changes to this variable refetches the data in `useEffect`
* @param setState Set state callback
*/
export function useIdeaModuleDataFetch(
props: IIdeaModuleProps,
refetch: number,
setState: (newState: Partial<IIdeaModuleState>) => void
) {
useEffect(() => {
Promise.all([props.dataAdapter.getConfiguration(props.configurationList)]).then(
([configuration]) => {
setState({
configuration,
ideas: configuration,
loading: false,
isRefetching: false
})
}
)
}, [refetch])
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint-disable prefer-spread */
import { useState } from 'react'
import { IIdeaModuleState } from './types'

/**
* Component state hook for `IIdeaModule`.
*
* @param props Props
*/
export function useIdeaModuleState() {
const [state, $setState] = useState<IIdeaModuleState>({
loading: true,
configuration: [],
ideas: {}
})

/**
* Set state like `setState` in class components where
* the new state is merged with the current state.
*
* @param newState New state
*/
const setState = (newState: Partial<IIdeaModuleState>) =>
$setState((currentState) => ({ ...currentState, ...newState }))

return { state, setState } as const
}
31 changes: 31 additions & 0 deletions SharePointFramework/PortfolioWebParts/src/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
} from './types'
import { IPersonaProps, IPersonaSharedProps } from '@fluentui/react'
import { IProvisionRequestItem } from 'interfaces/IProvisionRequestItem'
import { ConfigurationItem } from 'components/IdeaModule'

/**
* Data adapter for Portfolio Web Parts.
Expand Down Expand Up @@ -1027,6 +1028,36 @@ export class DataAdapter implements IPortfolioWebPartsDataAdapter {
return false
}
}

public async getConfiguration(listName: string): Promise<ConfigurationItem[]> {
try {
const configurationList = this._sp.web.lists.getByTitle(listName)
const spItems = await configurationList.items
.select(
'Id',
'Title',
'GtDescription',
'GtIdeaProcessingList',
'GtIdeaRegistrationList',
'GtIdeaProcessingChoices',
'GtIdeaRegistrationChoices'
)
.using(DefaultCaching)()

return spItems.map((item) => {
return {
title: item.Title,
description: item.GtDescription,
ideaProcessingList: item.GtIdeaProcessingList,
ideaRegistrationList: item.GtIdeaRegistrationList,
ideaProcessingChoices: item.GtIdeaProcessingChoices,
ideaRegistrationChoices: item.GtIdeaRegistrationChoices
}
})
} catch (error) {
return []
}
}
}

export * from './types'
12 changes: 10 additions & 2 deletions SharePointFramework/PortfolioWebParts/src/data/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { IPortfolioAggregationConfiguration, IPortfolioOverviewConfiguration } from '../components'
import { IPersonaSharedProps } from '@fluentui/react'
import { IProvisionRequestItem } from 'interfaces/IProvisionRequestItem'
import { ConfigurationItem } from 'components/IdeaModule'

export interface IFetchDataForViewItemResult extends ISearchResult {
SiteId: string
Expand Down Expand Up @@ -298,9 +299,9 @@ export interface IPortfolioWebPartsDataAdapter {
): Promise<IPersonaSharedProps[]>

/**
* Retrieves the provision request settings from the "Provisioning Request Settings" list
* Retrieves the configuration from the "Provisioning Request Settings" list
*
* @returns A Promise that resolves to an array containing the provision request settings.
* @returns A Promise that resolves to an array containing the configuration.
*/
getProvisionRequestSettings?(provisionUrl: string): Promise<any[]>

Expand Down Expand Up @@ -360,4 +361,11 @@ export interface IPortfolioWebPartsDataAdapter {
*
*/
siteExists?(siteUrl: string): Promise<boolean>

/**
* Retrieves the configuration from the "Idékonfigurasjon" list
*
* @returns A Promise that resolves to an array containing the configuration.
*/
getConfiguration?(listName: string): Promise<ConfigurationItem[]>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-disable quotes */
import { IPropertyPaneConfiguration, PropertyPaneTextField } from '@microsoft/sp-property-pane'
import * as strings from 'PortfolioWebPartsStrings'
import { BasePortfolioWebPart } from '../basePortfolioWebPart'
import { IIdeaModuleProps, IdeaModule } from 'components/IdeaModule'

export default class IdeaModuleWebPart extends BasePortfolioWebPart<IIdeaModuleProps> {
public render(): void {
this.renderComponent<IIdeaModuleProps>(IdeaModule)
}

public async onInit(): Promise<void> {
await super.onInit()
}

public getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: 'Idémodul'
},
groups: [
{
groupName: strings.GeneralGroupName,
groupFields: [
PropertyPaneTextField('configurationList', {
label: 'Konfigurasjon liste',
description: 'Navn på Idékonfigurasjonsliste'
})
]
}
]
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
"id": "20f151a9-6891-4408-a6d6-77e749b9e3e7",
"alias": "IdeaModuleWebPart",
"componentType": "WebPart",
"version": "1.10.0",
"manifestVersion": 2,
"requiresCustomScript": false,
"hiddenFromToolbox": true,
"supportedHosts": [
"SharePointWebPart"
],
"preconfiguredEntries": [
{
"groupId": "5c03119e-3074-46fd-976b-c60198311f70",
"group": {
"default": "Other"
},
"title": {
"default": "Idémodul"
},
"description": {
"default": " "
},
"officeFabricIconFontName": "Lightbulb",
"properties": {
"title": "Idémodul"
}
}
]
}
Loading

0 comments on commit b6c384f

Please sign in to comment.