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

core(user-flow): cleanup types #14442

Merged
merged 4 commits into from
Oct 21, 2022
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
2 changes: 1 addition & 1 deletion flow-report/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {Header} from './header';
import {I18nProvider} from './i18n/i18n';
import {Styles} from './wrappers/styles';

function getAnchorElement(hashState: LH.FlowResult.HashState|null) {
function getAnchorElement(hashState: LH.HashState|null) {
if (!hashState || !hashState.anchor) return null;
return document.getElementById(hashState.anchor);
}
Expand Down
2 changes: 1 addition & 1 deletion flow-report/src/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const HeaderThumbnail: FunctionComponent<{
);
};

export const Header: FunctionComponent<{hashState: LH.FlowResult.HashState}> =
export const Header: FunctionComponent<{hashState: LH.HashState}> =
({hashState}) => {
const flowResult = useFlowResult();
const {index} = hashState;
Expand Down
2 changes: 1 addition & 1 deletion flow-report/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function useHashParams(...params: string[]) {
return paramValues;
}

function useHashState(): LH.FlowResult.HashState|null {
function useHashState(): LH.HashState|null {
const flowResult = useFlowResult();
const [indexString, anchor] = useHashParams('index', 'anchor');

Expand Down
2 changes: 1 addition & 1 deletion flow-report/src/wrappers/report.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function convertAnchor(link: HTMLAnchorElement, index: number) {
link.replaceWith(newLink);
}

export const Report: FunctionComponent<{hashState: LH.FlowResult.HashState}> =
export const Report: FunctionComponent<{hashState: LH.HashState}> =
({hashState}) => {
const ref = useExternalRenderer<HTMLDivElement>(() => {
return renderReport(hashState.currentLhr, {
Expand Down
9 changes: 8 additions & 1 deletion flow-report/types/flow-report.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

import FlowResult_ from '../../types/lhr/flow';
import FlowResult_ from '../../types/lhr/flow-result';
import * as Settings from '../../types/lhr/settings';

// Import to augment querySelector/querySelectorAll with stricter type checking.
Expand All @@ -20,11 +20,18 @@ declare global {
// Expose global types in LH namespace.
module LH {
export type ConfigSettings = Settings.ConfigSettings;

export interface FlowReportOptions {
getReportHtml?: (flowResult: FlowResult_) => string;
saveAsGist?: (flowResult: FlowResult_) => void;
}

export interface HashState {
currentLhr: Result;
index: number;
anchor: string|null;
}

export import FlowResult = FlowResult_;
}
}
Expand Down
2 changes: 1 addition & 1 deletion report/generator/report-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import {reportAssets} from './report-assets.js';

/** @typedef {import('../../types/lhr/lhr').default} LHResult */
/** @typedef {import('../../types/lhr/flow').default} FlowResult */
/** @typedef {import('../../types/lhr/flow-result').default} FlowResult */

class ReportGenerator {
/**
Expand Down
4 changes: 2 additions & 2 deletions shared/types/shared.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import {IcuMessage as IcuMessage_} from '../../types/lhr/i18n';
import LHResult from '../../types/lhr/lhr';
import FlowResult_ from '../../types/lhr/flow';
import FlowResult_ from '../../types/lhr/flow-result';

import {Locale as Locale_} from '../../types/lhr/settings';

declare global {
// Expose global types in LH namespace.
module LH {
Expand Down
2 changes: 1 addition & 1 deletion treemap/types/treemap.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as Settings from '../../types/lhr/settings';
import 'google.analytics';
import LHResult from '../../types/lhr/lhr';
import {TreemapUtil} from '../app/src/util';
import FlowResult_ from '../../types/lhr/flow';
import FlowResult_ from '../../types/lhr/flow-result';

// Import for needed DOM type augmentation.
import '../../report/types/augment-dom';
Expand Down
2 changes: 1 addition & 1 deletion types/global-lh.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Gatherer_ from './gatherer';
import * as I18n from './lhr/i18n';
import {LighthouseError as LighthouseError_} from '../core/lib/lh-error.js';
import LHResult from './lhr/lhr';
import FlowResult_ from './lhr/flow';
import FlowResult_ from './lhr/flow-result';
import Protocol_ from './protocol';
import * as Settings from './lhr/settings';
import Treemap_ from './lhr/treemap';
Expand Down
10 changes: 3 additions & 7 deletions types/lhr/flow.d.ts → types/lhr/flow-result.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ import Result from './lhr';

declare module FlowResult {
interface Step {
/** Lighthouse report for this flow step. */
lhr: Result;
/** Display name of this flow step. */
name: string;
}

interface HashState {
currentLhr: Result;
index: number;
anchor: string|null;
}
}

/**
Expand All @@ -25,7 +21,7 @@ declare module FlowResult {
interface FlowResult {
/** Ordered list of flow steps, each corresponding to a navigation, timespan, or snapshot. */
steps: FlowResult.Step[];
/** Name given to this user flow. */
/** Display name of this user flow. */
name: string;
}

Expand Down
7 changes: 5 additions & 2 deletions types/user-flow.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ declare module UserFlow {
}

export interface Options {
config: LH.Config.Json;
/** Config to use for each flow step. */
config?: LH.Config.Json;
/** Display name for this user flow. */
name?: string;
}

export interface StepFlags extends LH.Flags {
/** Display name for this flow step. */
name?: string;
}

Expand All @@ -21,6 +24,6 @@ declare module UserFlow {
}
}

type UserFlow = typeof UserFlow_;
type UserFlow = InstanceType<typeof UserFlow_>;

export default UserFlow;