From 69d3673d68dc00f70672bf2498adca2e8b5fb61f Mon Sep 17 00:00:00 2001 From: Nikita Karetnikov Date: Tue, 7 Nov 2023 19:48:01 +0000 Subject: [PATCH 1/4] Expose `status_info` in the UI Companion PR for https://github.com/conda-incubator/conda-store/pull/653 --- src/common/models/Build.ts | 1 + src/features/metadata/components/EnvBuilds.tsx | 6 +++++- src/utils/helpers/buildMapper.ts | 14 +++++++++----- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/common/models/Build.ts b/src/common/models/Build.ts index 97f31fd7..bfaf9c63 100644 --- a/src/common/models/Build.ts +++ b/src/common/models/Build.ts @@ -14,6 +14,7 @@ export type Build = { }; packages: BuildPackage[]; status: string; + status_info: string | null; size: number; scheduled_on: string; started_on: string; diff --git a/src/features/metadata/components/EnvBuilds.tsx b/src/features/metadata/components/EnvBuilds.tsx index a0bff778..18953b68 100644 --- a/src/features/metadata/components/EnvBuilds.tsx +++ b/src/features/metadata/components/EnvBuilds.tsx @@ -44,7 +44,11 @@ export const EnvBuilds = ({ > Status: {""} - {currentBuild.status} + {currentBuild.status_info ? ( + <>{currentBuild.status} ({currentBuild.status_info}) + ) : ( + <>{currentBuild.status} + )} {(currentBuild.status === "Building" || currentBuild.status === "Queued") && ( { }; export const buildMapper = (data: Build[], currentBuildId: number) => { - return data.map(({ id, status, ended_on, scheduled_on }: Build) => { + return data.map(({ id, status, status_info, ended_on, scheduled_on }: Build) => { let duration = 0; if (ended_on && scheduled_on) { const startTime = new Date(scheduled_on); @@ -53,7 +53,8 @@ export const buildMapper = (data: Build[], currentBuildId: number) => { return { id, name: `${dateToTimezone(ended_on ?? scheduled_on)} - Active`, - status: isCompleted(status, duration) + status: isCompleted(status, duration), + status_info, }; } @@ -61,7 +62,8 @@ export const buildMapper = (data: Build[], currentBuildId: number) => { return { id, name: `${dateToTimezone(scheduled_on)} - Building`, - status: "Building" + status: "Building", + status_info, }; } @@ -69,7 +71,8 @@ export const buildMapper = (data: Build[], currentBuildId: number) => { return { id, name: `${dateToTimezone(scheduled_on)} - Queued`, - status: "Building" + status: "Building", + status_info, }; } @@ -78,7 +81,8 @@ export const buildMapper = (data: Build[], currentBuildId: number) => { name: `${dateToTimezone(ended_on ?? scheduled_on)} - ${ STATUS_OPTIONS[status] }`, - status: isCompleted(status, duration) + status: isCompleted(status, duration), + status_info, }; }); }; From 5408bba65b84568815d80b989865417e7484c336 Mon Sep 17 00:00:00 2001 From: Nikita Karetnikov Date: Tue, 7 Nov 2023 19:59:50 +0000 Subject: [PATCH 2/4] Fix lint issues --- .../metadata/components/EnvBuilds.tsx | 4 +- src/utils/helpers/buildMapper.ts | 78 ++++++++++--------- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/src/features/metadata/components/EnvBuilds.tsx b/src/features/metadata/components/EnvBuilds.tsx index 18953b68..da85edcc 100644 --- a/src/features/metadata/components/EnvBuilds.tsx +++ b/src/features/metadata/components/EnvBuilds.tsx @@ -45,7 +45,9 @@ export const EnvBuilds = ({ Status: {""} {currentBuild.status_info ? ( - <>{currentBuild.status} ({currentBuild.status_info}) + <> + {currentBuild.status} ({currentBuild.status_info}) + ) : ( <>{currentBuild.status} )} diff --git a/src/utils/helpers/buildMapper.ts b/src/utils/helpers/buildMapper.ts index 0bbb09dd..d93876aa 100644 --- a/src/utils/helpers/buildMapper.ts +++ b/src/utils/helpers/buildMapper.ts @@ -41,48 +41,50 @@ const dateToTimezone = (date: string) => { }; export const buildMapper = (data: Build[], currentBuildId: number) => { - return data.map(({ id, status, status_info, ended_on, scheduled_on }: Build) => { - let duration = 0; - if (ended_on && scheduled_on) { - const startTime = new Date(scheduled_on); - const endTime = new Date(ended_on); - duration = (endTime.valueOf() - startTime.valueOf()) / 60000; - duration = Math.round(duration); - } - if (id === currentBuildId) { - return { - id, - name: `${dateToTimezone(ended_on ?? scheduled_on)} - Active`, - status: isCompleted(status, duration), - status_info, - }; - } + return data.map( + ({ id, status, status_info, ended_on, scheduled_on }: Build) => { + let duration = 0; + if (ended_on && scheduled_on) { + const startTime = new Date(scheduled_on); + const endTime = new Date(ended_on); + duration = (endTime.valueOf() - startTime.valueOf()) / 60000; + duration = Math.round(duration); + } + if (id === currentBuildId) { + return { + id, + name: `${dateToTimezone(ended_on ?? scheduled_on)} - Active`, + status: isCompleted(status, duration), + status_info + }; + } - if (isBuilding(status)) { - return { - id, - name: `${dateToTimezone(scheduled_on)} - Building`, - status: "Building", - status_info, - }; - } + if (isBuilding(status)) { + return { + id, + name: `${dateToTimezone(scheduled_on)} - Building`, + status: "Building", + status_info + }; + } + + if (isQueued(status)) { + return { + id, + name: `${dateToTimezone(scheduled_on)} - Queued`, + status: "Building", + status_info + }; + } - if (isQueued(status)) { return { id, - name: `${dateToTimezone(scheduled_on)} - Queued`, - status: "Building", - status_info, + name: `${dateToTimezone(ended_on ?? scheduled_on)} - ${ + STATUS_OPTIONS[status] + }`, + status: isCompleted(status, duration), + status_info }; } - - return { - id, - name: `${dateToTimezone(ended_on ?? scheduled_on)} - ${ - STATUS_OPTIONS[status] - }`, - status: isCompleted(status, duration), - status_info, - }; - }); + ); }; From d5158409c072f30f4a0f7594a700f8fee35f890c Mon Sep 17 00:00:00 2001 From: Nikita Karetnikov Date: Wed, 8 Nov 2023 19:43:44 +0000 Subject: [PATCH 3/4] Catch exceptions when creating an environment This now shows an error message in the UI when the environment name is too long for a DB field (longer than 255 characters). --- .../environmentCreate/components/EnvironmentCreate.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/features/environmentCreate/components/EnvironmentCreate.tsx b/src/features/environmentCreate/components/EnvironmentCreate.tsx index 99feb5b3..3103f084 100644 --- a/src/features/environmentCreate/components/EnvironmentCreate.tsx +++ b/src/features/environmentCreate/components/EnvironmentCreate.tsx @@ -95,9 +95,11 @@ export const EnvironmentCreate = ({ environmentNotification }: IEnvCreate) => { description: createLabel(name, "create") } }); - } catch ({ data }) { + } catch (e) { setError({ - message: data.message, + message: + e?.data?.message ?? + createLabel(undefined, "error"), visible: true }); } From 20c18faf220798de422f8974d31d733962cf7ed2 Mon Sep 17 00:00:00 2001 From: Nikita Karetnikov Date: Wed, 8 Nov 2023 20:00:58 +0000 Subject: [PATCH 4/4] Fix lint issues --- .../environmentCreate/components/EnvironmentCreate.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/features/environmentCreate/components/EnvironmentCreate.tsx b/src/features/environmentCreate/components/EnvironmentCreate.tsx index 3103f084..d5127047 100644 --- a/src/features/environmentCreate/components/EnvironmentCreate.tsx +++ b/src/features/environmentCreate/components/EnvironmentCreate.tsx @@ -97,9 +97,7 @@ export const EnvironmentCreate = ({ environmentNotification }: IEnvCreate) => { }); } catch (e) { setError({ - message: - e?.data?.message ?? - createLabel(undefined, "error"), + message: e?.data?.message ?? createLabel(undefined, "error"), visible: true }); }