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: convert site-import directory to TypeScript #1492

Merged
merged 5 commits into from
Aug 29, 2023

Conversation

sjinks
Copy link
Member

@sjinks sjinks commented Aug 23, 2023

Description

This PR converts files from the src/lib/site-import directory to TypeScript.

Steps to Test

CI should pass.

@sjinks sjinks self-assigned this Aug 23, 2023
Comment on lines -195 to +196
export function getGlyphForStatus( status: StepStatus, runningSprite: RunningSprite ): string {
export function getGlyphForStatus(
status: StepStatus | string,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 94 to 108
const [ importJob ] = jobs;
const importJob = jobs?.[ 0 ] ?? {};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TS complains that jobs could be undefined. In this case, destructuring will fail.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This change currently affects the logic a little. Maybe

const [ importJob ] = jobs ?? [];

instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was checking which line might care about this change - looks like this line:

if ( ! importJob ) {
might be affected by this change

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed!

Comment on lines -201 to +225
statusMessage = `Success ${ sprite } imported data should be visible on your site ${ env.primaryDomain.name }.`;
statusMessage = `Success ${ sprite } imported data should be visible on your site ${
env.primaryDomain?.name ?? 'N/A'
}.`;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These things are to keep ESLint happy: our ruleset does not alow undefined as a template parameter.

Comment on lines -243 to +267
status = await getStatus( api, app.id, env.id );
status = await getStatus( api, app.id ?? -1, env.id ?? -1 );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, according to GQL definitions, id could be null or undefined. I chose -1 to make the request fail.

Comment on lines +309 to +310
.filter( Boolean ) as number[];
importJob.completedAt = new Date( Math.max( ...timestamps, 0 ) * 1000 ).toUTCString();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Math.max(), according to TS, does not like all kinds of null and undefined.

@@ -351,12 +384,11 @@ ${ maybeExitPrompt }
commandOutput: failedImportStep.output,
error: 'Import step failed',
stepName: failedImportStep.name,
errorText: failedImportStep.error,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to drop errorText:

  1. It is not used in getErrorMessage()
  2. AppEnvironmentStatusProgressStep does not have the error field :-(

Comment on lines -359 to +391
progressTracker.setStepsFromServer( jobSteps );
progressTracker.setStepsFromServer( jobSteps as unknown as StepFromServer[] );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not very proud of this :-(

@sjinks sjinks marked this pull request as ready for review August 23, 2023 11:35
Comment on lines 94 to 108
const [ importJob ] = jobs;
const importJob = jobs?.[ 0 ] ?? {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This change currently affects the logic a little. Maybe

const [ importJob ] = jobs ?? [];

instead?

Comment on lines 94 to 108
const [ importJob ] = jobs;
const importJob = jobs?.[ 0 ] ?? {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was checking which line might care about this change - looks like this line:

if ( ! importJob ) {
might be affected by this change

inImportProgress: boolean;
commandOutput: string[] | null;
error: string;
stepName: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We could use StepName | string where StepName is an enum consisting of import_preflights, importing_db, ...etc

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -370,7 +402,9 @@ ${ maybeExitPrompt }

overallStatus = 'running';

setTimeout( checkStatus, IMPORT_SQL_PROGRESS_POLL_INTERVAL ); // NOSONAR
setTimeout( () => {
void checkStatus();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL of the void operator.

abdullah-kasim
abdullah-kasim previously approved these changes Aug 24, 2023
@sjinks sjinks merged commit 012ba7a into trunk Aug 29, 2023
10 checks passed
@sjinks sjinks deleted the convert/site-import branch August 29, 2023 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants