Skip to content
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

First draft of splitting queries #52

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16,426 changes: 15,980 additions & 446 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
"querystring": "0.2.0",
"raw-loader": "1.0.0",
"react": "16.13.0",
"react-dom": "16.13.0",
"react-calendar-timeline": "0.19.0",
"react-dom": "16.13.0",
"react-highcharts": "16.0.2",
"react-scroll": "1.7.12",
"react-truncate-markup": "3.0.1",
Expand Down Expand Up @@ -115,4 +115,4 @@
"dependencies": {
"prosjektportalen": "2.6.12"
}
}
}
38 changes: 24 additions & 14 deletions src/js/@Common/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as config from "../config";
import ProjectItem from "./ProjectItem";
import IStatusMessage from "./IStatusMessage";
import { IDataSourceSearchCustom } from "prosjektportalen/lib/WebParts/DataSource";
import { format } from "office-ui-fabric-react/lib/Utilities";

export function getTimestamp(): string {
return `${new Date().toLocaleDateString()} ${new Date().toLocaleTimeString()}`;
Expand All @@ -15,7 +16,7 @@ export interface IListContext<T> {
items: T[];
}

export async function getStoredProjectsListContext(maxLimit = config.Lists_StoredProjects_ItemsMaxLimit): Promise<IListContext<ProjectItem>> {
export async function getStoredProjectsListContext(): Promise<IListContext<ProjectItem>> {
try {
const list = sp.web.lists.getByTitle(config.Lists_StoredProjects_Title);
let properties;
Expand All @@ -28,9 +29,6 @@ export async function getStoredProjectsListContext(maxLimit = config.Lists_Store
} catch {
throw strings.Lists_StoredProjects_DoesNotExist;
}
if (items.length > maxLimit) {
throw String.format(strings.Lists_StoredProjects_MaxLimitError, items.length, config.Lists_StoredProjects_ItemsMaxLimit);
}
items = items.filter(i => i.URL !== null && i.URL.Url !== "").map(({ ID, URL }) => new ProjectItem(ID, URL.Description, URL.Url));
return { list, properties, items };
} catch (err) {
Expand All @@ -39,18 +37,30 @@ export async function getStoredProjectsListContext(maxLimit = config.Lists_Store
}

/**
* Build search settings from items in stored projects list
* Build search queries from items in stored projects list
*
* @param {ProjectItem[]} items Project items
* @param {string} queryTemplate Query template
* @param {number} maxQueryLength Max query length
*/
export async function buildSearchSettingsFromStoredProjects(items: ProjectItem[], queryTemplate: string): Promise<IDataSourceSearchCustom> {
export async function buildSearchQueriesFromProgramProjects(items: ProjectItem[], queryTemplate: string, maxQueryLength: number = 3000): Promise<IDataSourceSearchCustom[]> {
try {
if (items.length === 0) {
return null;
}
const searchQuery = items.map(({ URL }) => `Path:"${URL}"`).join(" OR ");
return {
RowLimit: 500,
QueryTemplate: String.format(queryTemplate, searchQuery),
};
let index = 0
const queries = items.reduce((arr, item) => {
if (arr[index].QueryTemplate == null) {
arr[index].QueryTemplate = `Path:${item.URL} `
} else if (arr[index].QueryTemplate.length < maxQueryLength) {
arr[index].QueryTemplate += `OR Path:${item.URL} `
} else {
arr.push({
QueryTemplate: format(`Path:${item.URL} `, queryTemplate),
RowLimit: 500,
})
index++
}
return arr
}, [{ QueryTemplate: null, RowLimit: 500 }])
return queries //.map(q => ({ ...q, QueryTemplate: format(queryTemplate, q.QueryTemplate) }))
} catch (err) {
throw err;
}
Expand Down
2 changes: 1 addition & 1 deletion src/js/@WebParts/ProgramAddProject/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class ProgramAddProject extends React.Component<IProgramAddProjec

public async componentDidMount() {
try {
const storedProjectsList = await common.getStoredProjectsListContext(config.Lists_StoredProjects_ItemsMaxLimit - 1);
const storedProjectsList = await common.getStoredProjectsListContext();
this.setState({
storedProjectsList,
isLoading: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { IDataSourceSearchCustom } from "prosjektportalen/lib/WebParts/DataSourc
export default interface IProgramDeliveriesOverviewState {
isLoading: boolean;
errorMessage?: string;
searchSettings?: IDataSourceSearchCustom;
searchSettings?: IDataSourceSearchCustom[];
}
5 changes: 2 additions & 3 deletions src/js/@WebParts/ProgramDeliveriesOverview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ export default class ProgramDeliveriesOverView extends React.Component<IProgramD

constructor(props: IProgramDeliveriesOverviewProps) {
super(props);

this.state = { isLoading: true };
}

public async componentDidMount() {
try {
const { items } = await common.getStoredProjectsListContext();
const searchSettings = await common.buildSearchSettingsFromStoredProjects(items, this.props.queryTemplate);
const searchSettings = await common.buildSearchQueriesFromProgramProjects(items, this.props.queryTemplate);
this.setState({ searchSettings, isLoading: false });
} catch (errorMessage) {
this.setState({ errorMessage, isLoading: false });
Expand Down Expand Up @@ -46,7 +45,7 @@ export default class ProgramDeliveriesOverView extends React.Component<IProgramD
<>
<h2>Leveranseoversikt</h2>
{(!this.state.isLoading && this.state.searchSettings) &&
<DeliveriesOverview queryTemplate={this.state.searchSettings.QueryTemplate} />}
<DeliveriesOverview queryTemplate={null} />}
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { IDataSourceSearchCustom } from "prosjektportalen/lib/WebParts/DataSourc
export default interface IProgramExperienceLogState {
isLoading: boolean;
errorMessage?: string;
searchSettings?: IDataSourceSearchCustom;
searchSettings?: IDataSourceSearchCustom[];
}
4 changes: 2 additions & 2 deletions src/js/@WebParts/ProgramExperienceLog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class ProgramExperienceLog extends React.Component<IProgramExperi
public async componentDidMount() {
try {
const { items } = await common.getStoredProjectsListContext();
const searchSettings = await common.buildSearchSettingsFromStoredProjects(items, this.props.queryTemplate);
const searchSettings = await common.buildSearchQueriesFromProgramProjects(items, this.props.queryTemplate);
this.setState({ searchSettings, isLoading: false });
} catch (errorMessage) {
this.setState({ errorMessage, isLoading: false });
Expand Down Expand Up @@ -47,7 +47,7 @@ export default class ProgramExperienceLog extends React.Component<IProgramExperi
<h2>Erfaringslogg</h2>
{(!this.state.isLoading && this.state.searchSettings) &&
<ExperienceLog
queryTemplate={this.state.searchSettings.QueryTemplate}
queryTemplate={null} //{this.state.searchSettings.QueryTemplate}
/>}
</>
);
Expand Down
8 changes: 7 additions & 1 deletion src/js/@WebParts/ProgramPortfolio/IProgramPortfolioProps.ts
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
export default interface IProgramPortfolioProps {}
export default interface IProgramPortfolioProps {
queryTemplate?: string;
}

export const ProgramExperienceLogDefaultProps: Partial<IProgramPortfolioProps> = {
queryTemplate: '({0}) ContentTypeId:0x010088578E7470CC4AA68D5663464831070211* NOT GtProjectLifecycleStatusOWSCHCS="Avsluttet"'
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export interface IProgramProjectStatsState {
isLoading: boolean;
errorMessage?: string;
items?: ProjectItem[];
searchSettings?: IDataSourceSearchCustom;
searchSettings?: IDataSourceSearchCustom[];
}
4 changes: 2 additions & 2 deletions src/js/@WebParts/ProgramProjectStats/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class ProgramProjectStats extends React.Component<IProgramProject
public async componentDidMount() {
try {
const { items } = await common.getStoredProjectsListContext();
const searchSettings = await common.buildSearchSettingsFromStoredProjects(items, this.props.queryTemplate);
const searchSettings = await common.buildSearchQueriesFromProgramProjects(items, this.props.queryTemplate);
this.setState({ items, searchSettings, isLoading: false });
} catch (errorMessage) {
this.setState({ errorMessage, isLoading: false });
Expand Down Expand Up @@ -50,7 +50,7 @@ export default class ProgramProjectStats extends React.Component<IProgramProject
viewSelectorEnabled={false}
renderCommandBar={false}
chartsConfigListName="Diagramkonfigurasjon for programmets prosjekter"
queryTemplate={this.state.searchSettings.QueryTemplate}
queryTemplate={this.state.searchSettings}//{this.state.searchSettings.QueryTemplate}
/>}
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { IDataSourceSearchCustom } from "prosjektportalen/lib/WebParts/DataSourc
export interface IProgramResourceAllocationState {
isLoading: boolean;
errorMessage?: string;
searchSettings?: IDataSourceSearchCustom;
searchSettings?: IDataSourceSearchCustom[];
}
4 changes: 2 additions & 2 deletions src/js/@WebParts/ProgramResourceAllocation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class ProgramResourceAllocation extends React.Component<IProgramR
public async componentDidMount() {
try {
const { items } = await common.getStoredProjectsListContext();
const searchSettings = await common.buildSearchSettingsFromStoredProjects(items, this.props.queryTemplate);
const searchSettings = await common.buildSearchQueriesFromProgramProjects(items, this.props.queryTemplate);
this.setState({ searchSettings, isLoading: false });
} catch (errorMessage) {
this.setState({ errorMessage, isLoading: false });
Expand Down Expand Up @@ -48,7 +48,7 @@ export default class ProgramResourceAllocation extends React.Component<IProgramR
{(!this.state.isLoading && this.state.searchSettings) &&
<ResourceAllocation
searchConfiguration={this.props.searchConfiguration}
queryTemplate={this.state.searchSettings.QueryTemplate}
queryTemplate= {null}//{this.state.searchSettings.QueryTemplate}
/>}
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { IDataSourceSearchCustom } from "prosjektportalen/lib/WebParts/DataSourc
export default interface IProgramRiskOverviewState {
isLoading: boolean;
errorMessage?: string;
searchSettings?: IDataSourceSearchCustom;
searchSettings?: IDataSourceSearchCustom[];
}
4 changes: 2 additions & 2 deletions src/js/@WebParts/ProgramRiskOverview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class ProgramRiskOverview extends React.Component<IProgramRiskOve
public async componentDidMount() {
try {
const { items } = await common.getStoredProjectsListContext();
const searchSettings = await common.buildSearchSettingsFromStoredProjects(items, this.props.queryTemplate);
const searchSettings = await common.buildSearchQueriesFromProgramProjects(items, this.props.queryTemplate);
this.setState({ searchSettings, isLoading: false });
} catch (errorMessage) {
this.setState({ errorMessage, isLoading: false });
Expand Down Expand Up @@ -47,7 +47,7 @@ export default class ProgramRiskOverview extends React.Component<IProgramRiskOve
<h2>Risikooversikt</h2>
{(!this.state.isLoading && this.state.searchSettings) &&
<RiskMatrix
queryTemplate={this.state.searchSettings.QueryTemplate} />}
queryTemplate={null} />}
</>
);
}
Expand Down