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

refactor: create nav link renderer #2743

Merged
merged 3 commits into from
May 27, 2020
Merged
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
56 changes: 20 additions & 36 deletions src/DetailsView/components/left-nav/left-nav-link-builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ import { Assessment } from 'assessments/types/iassessment';
import { Requirement } from 'assessments/types/requirement';
import { gettingStartedSubview } from 'common/types/store-data/assessment-result-data';
import {
AssessmentLeftNavLink,
onTestGettingStartedClick,
onTestRequirementClick,
TestGettingStartedNavLink,
TestRequirementLeftNavLink,
} from 'DetailsView/components/left-nav/assessment-left-nav';
import { GettingStartedNavLink } from 'DetailsView/components/left-nav/getting-started-nav-link';
import { LeftNavIndexIcon, LeftNavStatusIcon } from 'DetailsView/components/left-nav/left-nav-icon';
import { requirementStatusIcon } from 'DetailsView/components/left-nav/left-nav-link-builder.scss';
import { NavLinkHandler } from 'DetailsView/components/left-nav/nav-link-handler';
import { NavLinkRenderer } from 'DetailsView/components/left-nav/nav-link-renderer';
import { map } from 'lodash';
import * as React from 'react';
import { OutcomeTypeSemantic } from 'reports/components/outcome-type';
import { RequirementOutcomeStats } from 'reports/components/requirement-outcome-type';
import { GetAssessmentSummaryModelFromProviderAndStatusData } from 'reports/get-assessment-summary-model';
Expand All @@ -25,15 +21,14 @@ import { ManualTestStatus, ManualTestStatusData } from '../../../common/types/ma
import { VisualizationType } from '../../../common/types/visualization-type';
import { DictionaryStringTo } from '../../../types/common-types';
import { BaseLeftNavLink, onBaseLeftNavItemClick, onBaseLeftNavItemRender } from '../base-left-nav';
import { OverviewLeftNavLink } from './overview-left-nav-link';
import { TestViewLeftNavLink } from './test-view-left-nav-link';

export type LeftNavLinkBuilderDeps = OverviewLinkBuilderDeps &
AssessmentLinkBuilderDeps &
VisualizationConfigurationLinkBuilderDeps;

export type OverviewLinkBuilderDeps = {
getAssessmentSummaryModelFromProviderAndStatusData: GetAssessmentSummaryModelFromProviderAndStatusData;
navLinkRenderer: NavLinkRenderer;
};

export type AssessmentLinkBuilderDeps = {
Expand All @@ -43,9 +38,12 @@ export type AssessmentLinkBuilderDeps = {
outcomeStatsFromManualTestStatus: (
testStepStatus: ManualTestStatusData,
) => RequirementOutcomeStats;
navLinkRenderer: NavLinkRenderer;
};

export type VisualizationConfigurationLinkBuilderDeps = {};
export type VisualizationConfigurationLinkBuilderDeps = {
navLinkRenderer: NavLinkRenderer;
};

export function generateReflowAssessmentTestKey(
test: VisualizationType,
Expand All @@ -64,7 +62,7 @@ export class LeftNavLinkBuilder {
assessmentsData: DictionaryStringTo<ManualTestStatusData>,
index: number,
): BaseLeftNavLink {
const { getAssessmentSummaryModelFromProviderAndStatusData } = deps;
const { getAssessmentSummaryModelFromProviderAndStatusData, navLinkRenderer } = deps;

const reportModel = getAssessmentSummaryModelFromProviderAndStatusData(
assessmentsProvider,
Expand All @@ -76,7 +74,7 @@ export class LeftNavLinkBuilder {
'Overview',
'Overview',
index,
l => <OverviewLeftNavLink link={l} />,
navLinkRenderer.renderOverviewLink,
onLinkClick,
);

Expand All @@ -100,6 +98,7 @@ export class LeftNavLinkBuilder {
getStatusForTest,
outcomeTypeSemanticsFromTestStatus,
outcomeStatsFromManualTestStatus,
navLinkRenderer,
} = deps;

const assessments = assessmentsProvider.all();
Expand All @@ -116,7 +115,7 @@ export class LeftNavLinkBuilder {
name,
VisualizationType[assessment.visualizationType],
index,
l => <TestViewLeftNavLink link={l} renderIcon={this.renderAssessmentTestIcon} />,
navLinkRenderer.renderAssessmentTestLink,
onLinkClick,
);

Expand Down Expand Up @@ -162,6 +161,7 @@ export class LeftNavLinkBuilder {
outcomeTypeSemanticsFromTestStatus,
outcomeStatsFromManualTestStatus,
navLinkHandler,
navLinkRenderer,
} = deps;

const stepStatus = assessmentsData[assessment.key];
Expand All @@ -174,11 +174,12 @@ export class LeftNavLinkBuilder {
name,
VisualizationType[assessment.visualizationType],
index,
l => <TestViewLeftNavLink link={l} renderIcon={this.renderAssessmentTestIcon} />,
navLinkRenderer.renderAssessmentTestLink,
() => {},
);

const gettingStartedLink = this.buildGettingStartedLink(
navLinkRenderer.renderGettingStartedLink,
navLinkHandler.onGettingStartedClick,
assessment,
);
Expand Down Expand Up @@ -216,7 +217,7 @@ export class LeftNavLinkBuilder {
testIndex: number,
onClick: onTestRequirementClick,
): TestRequirementLeftNavLink {
const { outcomeTypeSemanticsFromTestStatus } = deps;
const { outcomeTypeSemanticsFromTestStatus, navLinkRenderer } = deps;
const name = requirement.name;
const displayedIndex = `${testIndex}.${requirementIndex}`;
const narratorRequirementStatus = outcomeTypeSemanticsFromTestStatus(requirementStatus)
Expand All @@ -226,7 +227,7 @@ export class LeftNavLinkBuilder {
name,
generateReflowAssessmentTestKey(test, requirement.key),
requirementIndex,
l => <TestViewLeftNavLink link={l} renderIcon={this.renderRequirementIcon} />,
navLinkRenderer.renderRequirementLink,
onClick,
);

Expand All @@ -241,6 +242,7 @@ export class LeftNavLinkBuilder {
}

private buildGettingStartedLink(
renderGettingStartedLink: onBaseLeftNavItemRender,
onClick: onTestGettingStartedClick,
test: Assessment,
): TestGettingStartedNavLink {
Expand All @@ -251,51 +253,33 @@ export class LeftNavLinkBuilder {
'Getting Started',
generateReflowAssessmentTestKey(testType, gettingStartedSubview),
0,
() => <GettingStartedNavLink />,
renderGettingStartedLink,
onClick,
),
};
}

private renderRequirementIcon = (link: TestRequirementLeftNavLink) => {
if (link.status === ManualTestStatus.UNKNOWN) {
return <>{link.displayedIndex}</>;
}

return <LeftNavStatusIcon className={requirementStatusIcon} item={link} />;
};

private renderAssessmentTestIcon: onBaseLeftNavItemRender = (link: AssessmentLeftNavLink) => {
if (link.status === ManualTestStatus.UNKNOWN) {
return <LeftNavIndexIcon item={link} />;
}

return <LeftNavStatusIcon item={link} />;
};

public buildVisualizationConfigurationLink(
deps: VisualizationConfigurationLinkBuilderDeps,
configuration: VisualizationConfiguration,
onLinkClick: onBaseLeftNavItemClick,
visualizationType: VisualizationType,
index: number,
): BaseLeftNavLink {
const displayableData = configuration.displayableData;
const { navLinkRenderer } = deps;

const link = this.buildBaseLink(
displayableData.title,
VisualizationType[visualizationType],
index,
l => <TestViewLeftNavLink link={l} renderIcon={this.renderVisualizationIcon} />,
navLinkRenderer.renderVisualizationLink,
onLinkClick,
);

return link;
}

private renderVisualizationIcon: onBaseLeftNavItemRender = link => (
<LeftNavIndexIcon item={link} />
);

private buildBaseLink(
name: string,
key: string,
Expand Down
53 changes: 53 additions & 0 deletions src/DetailsView/components/left-nav/nav-link-renderer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { ManualTestStatus } from 'common/types/manual-test-status';
import { onBaseLeftNavItemRender } from 'DetailsView/components/base-left-nav';
import {
AssessmentLeftNavLink,
TestRequirementLeftNavLink,
} from 'DetailsView/components/left-nav/assessment-left-nav';
import { GettingStartedNavLink } from 'DetailsView/components/left-nav/getting-started-nav-link';
import { LeftNavIndexIcon, LeftNavStatusIcon } from 'DetailsView/components/left-nav/left-nav-icon';
import * as styles from 'DetailsView/components/left-nav/nav-link-renderer.scss';
import { OverviewLeftNavLink } from 'DetailsView/components/left-nav/overview-left-nav-link';
import { TestViewLeftNavLink } from 'DetailsView/components/left-nav/test-view-left-nav-link';
import * as React from 'react';

export class NavLinkRenderer {
public renderVisualizationLink: onBaseLeftNavItemRender = link => (
<TestViewLeftNavLink link={link} renderIcon={this.renderVisualizationIcon} />
);

public renderRequirementLink: onBaseLeftNavItemRender = link => (
<TestViewLeftNavLink link={link} renderIcon={this.renderRequirementIcon} />
);

public renderAssessmentTestLink: onBaseLeftNavItemRender = link => (
<TestViewLeftNavLink link={link} renderIcon={this.renderAssessmentTestIcon} />
);

public renderOverviewLink: onBaseLeftNavItemRender = l => <OverviewLeftNavLink link={l} />;

public renderGettingStartedLink: onBaseLeftNavItemRender = () => <GettingStartedNavLink />;

private renderVisualizationIcon: onBaseLeftNavItemRender = link => (
<LeftNavIndexIcon item={link} />
);

private renderRequirementIcon = (link: TestRequirementLeftNavLink) => {
if (link.status === ManualTestStatus.UNKNOWN) {
return <>{link.displayedIndex}</>;
}

return <LeftNavStatusIcon className={styles.requirementStatusIcon} item={link} />;
};

private renderAssessmentTestIcon: onBaseLeftNavItemRender = (link: AssessmentLeftNavLink) => {
if (link.status === ManualTestStatus.UNKNOWN) {
return <LeftNavIndexIcon item={link} />;
}

return <LeftNavStatusIcon item={link} />;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const VisualizationBasedLeftNav = NamedFC<VisualizationBasedLeftNavProps>
const config = visualizationConfigurationFactory.getConfiguration(visualizationType);
links.push(
leftNavLinkBuilder.buildVisualizationConfigurationLink(
deps,
config,
onLinkClick,
visualizationType,
Expand Down
4 changes: 4 additions & 0 deletions src/DetailsView/details-view-initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { CardSelectionStoreData } from 'common/types/store-data/card-selection-s
import { toolName } from 'content/strings/application';
import { textContent } from 'content/strings/text-content';
import { AssessmentViewUpdateHandler } from 'DetailsView/components/assessment-view-update-handler';
import { NavLinkRenderer } from 'DetailsView/components/left-nav/nav-link-renderer';
import { NoContentAvailableViewDeps } from 'DetailsView/components/no-content-available/no-content-available-view';
import { AllUrlsPermissionHandler } from 'DetailsView/handlers/allurls-permission-handler';
import { NoContentAvailableViewRenderer } from 'DetailsView/no-content-available-view-renderer';
Expand Down Expand Up @@ -378,6 +379,8 @@ if (isNaN(tabId) === false) {

const assessmentViewUpdateHandler = new AssessmentViewUpdateHandler();

const navLinkRenderer = new NavLinkRenderer();

const deps: DetailsViewContainerDeps = {
textContent,
fixInstructionProcessor,
Expand Down Expand Up @@ -448,6 +451,7 @@ if (isNaN(tabId) === false) {
Assessments,
assessmentViewUpdateHandler,
detailsViewExtensionPoint,
navLinkRenderer,
};

const renderer = new DetailsViewRenderer(
Expand Down
Loading