Skip to content

Commit

Permalink
<3
Browse files Browse the repository at this point in the history
  • Loading branch information
olemp committed Jan 17, 2025
1 parent a373c33 commit 9650d25
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ export const PortfolioOverview: FC<IPortfolioOverviewProps> = (props) => {
onColumnContextMenu={onColumnContextMenu}
compact={context.state.isCompact}
isListLayoutModeJustified={props.isListLayoutModeJustified}
renderTitleProjectInformationPanel={true}
webPartContext={props.spfxContext as WebPartContext}
layerHostId={context.layerHostId}
menuItems={menuItems}
filterPanelProps={filterPanelProps}
error={context.state.error}
renderTitleProjectInformationPanel
/>
</div>
<ColumnContextMenu />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import { usePersistedColumns } from './usePersistedColumns'
* @param hashState Hash state map
* @param context `PortfolioOverview` context - needs to be passed as a prop to the function
* as it is not available yet using `useContext` in the function.
* @param reset Reset flag
*/
function getCurrentView(
hashState: Map<string, string | number>,
context: IPortfolioOverviewContext
context: IPortfolioOverviewContext,
reset: boolean
): PortfolioOverviewView {
if (context.state.currentView) return context.state.currentView
if (context.state.currentView && !reset) return context.state.currentView
const viewIdUrlParam = new URLSearchParams(document.location.search).get('viewId')
const views = context.props.configuration.views
let currentView = null
Expand Down Expand Up @@ -61,42 +63,47 @@ function getCurrentView(
*/
export const useFetchData = (context: IPortfolioOverviewContext) => {
const [, set] = usePersistedColumns(context.props)
useEffect(() => {
const fetchInitialData = async () => {
let currentView: PortfolioOverviewView = null
try {
context.dispatch(STARTING_DATA_FETCH())
const hashState = parseUrlHash()
currentView = getCurrentView(hashState, context)
const { items, managedProperties } = context.props.isParentProject
? await context.props.dataAdapter.fetchDataForViewBatch(
currentView,
context.props.configuration,
context.props.configuration.hubSiteId
)
: await context.props.dataAdapter.fetchDataForView(
currentView,
context.props.configuration,
context.props.configuration.hubSiteId
)
let groupBy = currentView.groupBy
if (hashState.has('groupBy') && !groupBy) {
groupBy = _.find(context.props.configuration.columns, (fc) => fc.fieldName === hashState.get('groupBy'))
}
set(currentView.columns)
context.dispatch(
DATA_FETCHED({
items,
currentView,
groupBy,
managedProperties
})

const fetchInitialData = async (reset = false) => {
let currentView: PortfolioOverviewView = null
try {
context.dispatch(STARTING_DATA_FETCH())
const hashState = parseUrlHash()
currentView = getCurrentView(hashState, context, reset)
const { items, managedProperties } = context.props.isParentProject
? await context.props.dataAdapter.fetchDataForViewBatch(
currentView,
context.props.configuration,
context.props.configuration.hubSiteId
)
} catch (error) {
context.dispatch(DATA_FETCH_ERROR({ error, view: currentView }))
: await context.props.dataAdapter.fetchDataForView(
currentView,
context.props.configuration,
context.props.configuration.hubSiteId
)
let groupBy = currentView.groupBy
if (hashState.has('groupBy') && !groupBy) {
groupBy = _.find(context.props.configuration.columns, (fc) => fc.fieldName === hashState.get('groupBy'))
}
set(currentView.columns)
context.dispatch(
DATA_FETCHED({
items,
currentView,
groupBy,
managedProperties
})
)
} catch (error) {
context.dispatch(DATA_FETCH_ERROR({ error, view: currentView }))
}
}

useEffect(() => {
fetchInitialData()
}, [context.state.currentView])

useEffect(() => {
fetchInitialData(true)
}, [context.props.selectedPortfolioId])
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export interface IPortfolioOverviewConfiguration {

export interface IPortfolioOverviewProps
extends IBaseComponentProps,
Pick<IListProps<ProjectColumn>, 'isListLayoutModeJustified'> {
Pick<IListProps<ProjectColumn>, 'isListLayoutModeJustified'> {
/**
* Configuration (columns and views etc).
*/
Expand Down Expand Up @@ -151,7 +151,19 @@ export interface IPortfolioOverviewProps
/**
* The unique ID of the selected portfolio.
*/
selectedPortfolio?: string
selectedPortfolioId?: string

/**
* Show portfolio selector in view mode (not just in web part properties).
*/
showPortfolioSelector?: boolean

/**
* Callback to set the selected portfolio.
*
* @param portfolioId The unique ID of the selected portfolio.
*/
onSetPortfolio?: (portfolioId: string) => void
}

export interface IPortfolioOverviewState
Expand Down
8 changes: 7 additions & 1 deletion SharePointFramework/shared-library/src/icons/iconCatalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,19 @@ import {
ChevronRightFilled,
ChevronRightRegular,
LightbulbRegular,
LightbulbFilled
LightbulbFilled,
CollectionsRegular,
CollectionsFilled
} from '@fluentui/react-icons'

/**
* An object containing the available Fluent icons and their corresponding regular and filled versions.
*/
export const iconCatalog = {
Collections: {
regular: CollectionsRegular,
filled: CollectionsFilled
},
ClipboardTask: {
regular: ClipboardTaskRegular,
filled: ClipboardTaskFilled
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { format } from '@fluentui/react'
import { find } from '@microsoft/sp-lodash-subset'
import { AssignFrom, dateAdd, PnPClientStorage, stringIsNullOrEmpty } from '@pnp/core'
import { Logger, LogLevel } from '@pnp/logging'
import { ConsoleListener, Logger, LogLevel } from '@pnp/logging'
import { IFolder } from '@pnp/sp/folders'
import { ICamlQuery, IList } from '@pnp/sp/lists'
import '@pnp/sp/presets/all'
Expand Down Expand Up @@ -63,7 +63,14 @@ export class PortalDataService extends DataService<IPortalDataServiceConfigurati
public async configure(
configuration: IPortalDataServiceConfiguration
): Promise<PortalDataService> {
super.onConfigureStart(merge(PortalDataServiceDefaultConfiguration, configuration))
Logger.subscribe(ConsoleListener())
Logger.activeLogLevel = configuration.activeLogLevel
Logger.log({
message: '(PortalDataService) (configure) Configuring PortalDataService',
level: LogLevel.Info,
data: _.pick(configuration, 'listNames', 'url')
})
super.onConfigureStart(merge({ ...PortalDataServiceDefaultConfiguration }, configuration))
this._sp = createSpfiInstance(this._configuration.spfxContext)
await this.onInit(configuration?.url)
return super.onConfigured()
Expand All @@ -79,6 +86,7 @@ export class PortalDataService extends DataService<IPortalDataServiceConfigurati
* @param expire Expire date for the hub site ID (optional with default of 1 year)
*/
private async onInit(url?: string, expire: Date = dateAdd(new Date(), 'year', 1)): Promise<void> {
Logger.write(`(PortalDataService) (onInit) Initializing PortalDataService instance with URL ${url}`, LogLevel.Info)
if (url) {
this.url = url
this._spPortal = spfi(this.url).using(AssignFrom(this._sp.web))
Expand All @@ -102,6 +110,7 @@ export class PortalDataService extends DataService<IPortalDataServiceConfigurati
try {
this.hubSiteId =
this._configuration.spfxContext.pageContext.legacyPageContext.hubSiteId || ''
console.log('onInit', this.hubSiteId)
try {
const hubSite = await (
await fetch(
Expand Down

0 comments on commit 9650d25

Please sign in to comment.