From 384e4e846010ea65f3f577041da13acb967d8343 Mon Sep 17 00:00:00 2001 From: Denilson Velasquez <66847768+DeeTheDev@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:23:47 -0500 Subject: [PATCH 1/2] Expose updated_at detail and render correctly --- adminapp/src/pages/OrganizationDetailPage.jsx | 7 +++---- adminapp/src/pages/OrganizationMembershipDetailPage.jsx | 4 ++-- adminapp/src/pages/PaymentTriggerDetailPage.jsx | 4 ++-- lib/suma/admin_api/entities.rb | 1 + lib/suma/admin_api/organizations.rb | 1 + 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/adminapp/src/pages/OrganizationDetailPage.jsx b/adminapp/src/pages/OrganizationDetailPage.jsx index cbac3322..567f08a1 100644 --- a/adminapp/src/pages/OrganizationDetailPage.jsx +++ b/adminapp/src/pages/OrganizationDetailPage.jsx @@ -3,7 +3,7 @@ import AdminLink from "../components/AdminLink"; import ProgramEnrollmentRelatedList from "../components/ProgramEnrollmentRelatedList"; import RelatedList from "../components/RelatedList"; import ResourceDetail from "../components/ResourceDetail"; -import { dayjs } from "../modules/dayConfig"; +import { dayjs, dayjsOrNull } from "../modules/dayConfig"; import createRelativeUrl from "../shared/createRelativeUrl"; import React from "react"; @@ -16,7 +16,7 @@ export default function OrganizationDetailPage() { properties={(model) => [ { label: "ID", value: model.id }, { label: "Created At", value: dayjs(model.createdAt) }, - { label: "Updated At", value: dayjs(model.updatedAt) }, + { label: "Updated At", value: dayjsOrNull(model.updatedAt) }, { label: "Name", value: model.name }, ]} > @@ -36,7 +36,7 @@ export default function OrganizationDetailPage() { organizationLabel: `(${model.id}) ${model.name || "-"}`, })} addNewRole="organizationMembership" - headers={["Id", "Member", "Created At", "Updated At"]} + headers={["Id", "Member", "Created At"]} keyRowAttr="id" toCells={(row) => [ , @@ -44,7 +44,6 @@ export default function OrganizationDetailPage() { {row.member.name} , dayjs(row.createdAt).format("lll"), - dayjs(row.updatedAt).format("lll"), ]} /> diff --git a/adminapp/src/pages/OrganizationMembershipDetailPage.jsx b/adminapp/src/pages/OrganizationMembershipDetailPage.jsx index 8361ca5d..0aedd6cb 100644 --- a/adminapp/src/pages/OrganizationMembershipDetailPage.jsx +++ b/adminapp/src/pages/OrganizationMembershipDetailPage.jsx @@ -1,7 +1,7 @@ import api from "../api"; import AdminLink from "../components/AdminLink"; import ResourceDetail from "../components/ResourceDetail"; -import { dayjs } from "../modules/dayConfig"; +import { dayjs, dayjsOrNull } from "../modules/dayConfig"; import React from "react"; export default function OrganizationMembershipDetailPage() { @@ -13,7 +13,7 @@ export default function OrganizationMembershipDetailPage() { properties={(model) => [ { label: "ID", value: model.id }, { label: "Created At", value: dayjs(model.createdAt) }, - { label: "Updated At", value: dayjs(model.updatedAt) }, + { label: "Updated At", value: dayjsOrNull(model.updatedAt) }, { label: "Member", value: ( diff --git a/adminapp/src/pages/PaymentTriggerDetailPage.jsx b/adminapp/src/pages/PaymentTriggerDetailPage.jsx index 0da4222f..6abf3d17 100644 --- a/adminapp/src/pages/PaymentTriggerDetailPage.jsx +++ b/adminapp/src/pages/PaymentTriggerDetailPage.jsx @@ -3,7 +3,7 @@ import AdminLink from "../components/AdminLink"; import Programs from "../components/Programs"; import RelatedList from "../components/RelatedList"; import ResourceDetail from "../components/ResourceDetail"; -import { dayjs } from "../modules/dayConfig"; +import { dayjs, dayjsOrNull } from "../modules/dayConfig"; import { formatMoney, intToMoney } from "../shared/money"; import SafeExternalLink from "../shared/react/SafeExternalLink"; import React from "react"; @@ -18,7 +18,7 @@ export default function PaymentTriggerDetailPage() { { label: "ID", value: model.id }, { label: "Label", value: model.label }, { label: "Created At", value: dayjs(model.createdAt) }, - { label: "Updated At", value: model.updatedAt && dayjs(model.updatedAt) }, + { label: "Updated At", value: dayjsOrNull(model.updatedAt) }, { label: "Starting", value: dayjs(model.activeDuringBegin) }, { label: "Ending", value: dayjs(model.activeDuringEnd) }, { label: "Match Multiplier", value: model.matchMultiplier }, diff --git a/lib/suma/admin_api/entities.rb b/lib/suma/admin_api/entities.rb index 934701b7..94984436 100644 --- a/lib/suma/admin_api/entities.rb +++ b/lib/suma/admin_api/entities.rb @@ -302,6 +302,7 @@ class OrderEntity < BaseEntity class OrganizationMembershipEntity < BaseEntity include AutoExposeBase + include AutoExposeDetail expose :member, with: MemberEntity expose :verified_organization, with: OrganizationEntity expose :unverified_organization_name diff --git a/lib/suma/admin_api/organizations.rb b/lib/suma/admin_api/organizations.rb index 047f01c6..a70249c0 100644 --- a/lib/suma/admin_api/organizations.rb +++ b/lib/suma/admin_api/organizations.rb @@ -8,6 +8,7 @@ class Suma::AdminAPI::Organizations < Suma::AdminAPI::V1 class DetailedOrganizationEntity < OrganizationEntity include Suma::AdminAPI::Entities + include AutoExposeDetail expose :memberships, with: OrganizationMembershipEntity expose :program_enrollments, with: ProgramEnrollmentEntity end From c29ba4244ea8992cbea1166b61c4d52afd01b7c5 Mon Sep 17 00:00:00 2001 From: Rob Galanakis Date: Tue, 3 Dec 2024 10:58:16 -0800 Subject: [PATCH 2/2] default updated at to created at in admin, always use auto-detailed entities --- adminapp/src/pages/OrganizationDetailPage.jsx | 4 ++-- adminapp/src/pages/OrganizationMembershipDetailPage.jsx | 4 ++-- adminapp/src/pages/PaymentTriggerDetailPage.jsx | 4 ++-- lib/suma/admin_api/anon_proxy.rb | 2 ++ lib/suma/admin_api/commerce_offering_products.rb | 1 + lib/suma/admin_api/entities.rb | 5 +++-- lib/suma/admin_api/program_enrollments.rb | 2 ++ lib/suma/admin_api/roles.rb | 6 +++++- lib/suma/admin_api/vendor_services.rb | 2 ++ lib/suma/admin_api/vendors.rb | 1 + 10 files changed, 22 insertions(+), 9 deletions(-) diff --git a/adminapp/src/pages/OrganizationDetailPage.jsx b/adminapp/src/pages/OrganizationDetailPage.jsx index 567f08a1..5feffde0 100644 --- a/adminapp/src/pages/OrganizationDetailPage.jsx +++ b/adminapp/src/pages/OrganizationDetailPage.jsx @@ -3,7 +3,7 @@ import AdminLink from "../components/AdminLink"; import ProgramEnrollmentRelatedList from "../components/ProgramEnrollmentRelatedList"; import RelatedList from "../components/RelatedList"; import ResourceDetail from "../components/ResourceDetail"; -import { dayjs, dayjsOrNull } from "../modules/dayConfig"; +import { dayjs } from "../modules/dayConfig"; import createRelativeUrl from "../shared/createRelativeUrl"; import React from "react"; @@ -16,7 +16,7 @@ export default function OrganizationDetailPage() { properties={(model) => [ { label: "ID", value: model.id }, { label: "Created At", value: dayjs(model.createdAt) }, - { label: "Updated At", value: dayjsOrNull(model.updatedAt) }, + { label: "Updated At", value: dayjs(model.updatedAt) }, { label: "Name", value: model.name }, ]} > diff --git a/adminapp/src/pages/OrganizationMembershipDetailPage.jsx b/adminapp/src/pages/OrganizationMembershipDetailPage.jsx index 0aedd6cb..8361ca5d 100644 --- a/adminapp/src/pages/OrganizationMembershipDetailPage.jsx +++ b/adminapp/src/pages/OrganizationMembershipDetailPage.jsx @@ -1,7 +1,7 @@ import api from "../api"; import AdminLink from "../components/AdminLink"; import ResourceDetail from "../components/ResourceDetail"; -import { dayjs, dayjsOrNull } from "../modules/dayConfig"; +import { dayjs } from "../modules/dayConfig"; import React from "react"; export default function OrganizationMembershipDetailPage() { @@ -13,7 +13,7 @@ export default function OrganizationMembershipDetailPage() { properties={(model) => [ { label: "ID", value: model.id }, { label: "Created At", value: dayjs(model.createdAt) }, - { label: "Updated At", value: dayjsOrNull(model.updatedAt) }, + { label: "Updated At", value: dayjs(model.updatedAt) }, { label: "Member", value: ( diff --git a/adminapp/src/pages/PaymentTriggerDetailPage.jsx b/adminapp/src/pages/PaymentTriggerDetailPage.jsx index 6abf3d17..3be90b31 100644 --- a/adminapp/src/pages/PaymentTriggerDetailPage.jsx +++ b/adminapp/src/pages/PaymentTriggerDetailPage.jsx @@ -3,7 +3,7 @@ import AdminLink from "../components/AdminLink"; import Programs from "../components/Programs"; import RelatedList from "../components/RelatedList"; import ResourceDetail from "../components/ResourceDetail"; -import { dayjs, dayjsOrNull } from "../modules/dayConfig"; +import { dayjs } from "../modules/dayConfig"; import { formatMoney, intToMoney } from "../shared/money"; import SafeExternalLink from "../shared/react/SafeExternalLink"; import React from "react"; @@ -18,7 +18,7 @@ export default function PaymentTriggerDetailPage() { { label: "ID", value: model.id }, { label: "Label", value: model.label }, { label: "Created At", value: dayjs(model.createdAt) }, - { label: "Updated At", value: dayjsOrNull(model.updatedAt) }, + { label: "Updated At", value: dayjs(model.updatedAt) }, { label: "Starting", value: dayjs(model.activeDuringBegin) }, { label: "Ending", value: dayjs(model.activeDuringEnd) }, { label: "Match Multiplier", value: model.matchMultiplier }, diff --git a/lib/suma/admin_api/anon_proxy.rb b/lib/suma/admin_api/anon_proxy.rb index 7262a27d..0559d961 100644 --- a/lib/suma/admin_api/anon_proxy.rb +++ b/lib/suma/admin_api/anon_proxy.rb @@ -37,12 +37,14 @@ class VendorAccountEntity < BaseEntity class DetailedVendorConfigurationEntity < VendorConfigurationEntity include Suma::AdminAPI::Entities + include AutoExposeDetail expose :programs, with: ProgramEntity expose :instructions, with: TranslatedTextEntity end class DetailedVendorAccountEntity < VendorAccountEntity include Suma::AdminAPI::Entities + include AutoExposeDetail expose :latest_access_code expose :latest_access_code_set_at expose :latest_access_code_requested_at diff --git a/lib/suma/admin_api/commerce_offering_products.rb b/lib/suma/admin_api/commerce_offering_products.rb index c5928132..a4f2b320 100644 --- a/lib/suma/admin_api/commerce_offering_products.rb +++ b/lib/suma/admin_api/commerce_offering_products.rb @@ -9,6 +9,7 @@ class Suma::AdminAPI::CommerceOfferingProducts < Suma::AdminAPI::V1 class DetailedCommerceOfferingProductEntity < BaseEntity include Suma::AdminAPI::Entities include AutoExposeBase + include AutoExposeDetail expose :offering, with: OfferingEntity expose :product, with: ProductEntity expose :customer_price, with: MoneyEntity diff --git a/lib/suma/admin_api/entities.rb b/lib/suma/admin_api/entities.rb index 94984436..1252293c 100644 --- a/lib/suma/admin_api/entities.rb +++ b/lib/suma/admin_api/entities.rb @@ -25,7 +25,9 @@ def self.included(ctx) # detailed entities, or limited lists. module AutoExposeDetail def self.included(ctx) - ctx.expose :updated_at, if: ->(o) { o.respond_to?(:updated_at) } + ctx.expose :updated_at, if: ->(o) { o.respond_to?(:updated_at) } do |inst| + inst.updated_at || inst.created_at + end # Always expose an external links array when we mix this in ctx.expose :external_links do |inst| inst.respond_to?(:external_links) ? inst.external_links : [] @@ -302,7 +304,6 @@ class OrderEntity < BaseEntity class OrganizationMembershipEntity < BaseEntity include AutoExposeBase - include AutoExposeDetail expose :member, with: MemberEntity expose :verified_organization, with: OrganizationEntity expose :unverified_organization_name diff --git a/lib/suma/admin_api/program_enrollments.rb b/lib/suma/admin_api/program_enrollments.rb index e16bcabf..d8711858 100644 --- a/lib/suma/admin_api/program_enrollments.rb +++ b/lib/suma/admin_api/program_enrollments.rb @@ -4,8 +4,10 @@ class Suma::AdminAPI::ProgramEnrollments < Suma::AdminAPI::V1 include Suma::AdminAPI::Entities + class DetailedProgramEnrollmentEntity < ProgramEnrollmentEntity include Suma::AdminAPI::Entities + include AutoExposeDetail expose :approved?, as: :approved expose :approved_by, with: MemberEntity expose :unenrolled?, as: :unenrolled diff --git a/lib/suma/admin_api/roles.rb b/lib/suma/admin_api/roles.rb index 3d9c332d..d3276018 100644 --- a/lib/suma/admin_api/roles.rb +++ b/lib/suma/admin_api/roles.rb @@ -6,7 +6,11 @@ class Suma::AdminAPI::Roles < Suma::AdminAPI::V1 class RoleEntity < Suma::AdminAPI::Entities::RoleEntity; end - class DetailedRoleEntity < RoleEntity; end + + class DetailedRoleEntity < RoleEntity + include Suma::AdminAPI::Entities + include AutoExposeDetail + end resource :roles do desc "Return all roles, ordered by name" diff --git a/lib/suma/admin_api/vendor_services.rb b/lib/suma/admin_api/vendor_services.rb index ddb99f81..5c63b275 100644 --- a/lib/suma/admin_api/vendor_services.rb +++ b/lib/suma/admin_api/vendor_services.rb @@ -9,6 +9,7 @@ class Suma::AdminAPI::VendorServices < Suma::AdminAPI::V1 class DetailedMobilityTripEntity < BaseEntity include Suma::AdminAPI::Entities include AutoExposeBase + include AutoExposeDetail expose :vehicle_id expose :vendor_service_rate, as: :rate, with: VendorServiceRateEntity expose :begin_lat @@ -23,6 +24,7 @@ class DetailedMobilityTripEntity < BaseEntity class DetailedVendorServiceEntity < VendorServiceEntity include Suma::AdminAPI::Entities + include AutoExposeDetail expose :external_name expose :internal_name expose :mobility_vendor_adapter_key diff --git a/lib/suma/admin_api/vendors.rb b/lib/suma/admin_api/vendors.rb index 12a7c2c3..e1666244 100644 --- a/lib/suma/admin_api/vendors.rb +++ b/lib/suma/admin_api/vendors.rb @@ -8,6 +8,7 @@ class Suma::AdminAPI::Vendors < Suma::AdminAPI::V1 class DetailedVendorEntity < VendorEntity include Suma::AdminAPI::Entities + include AutoExposeDetail expose :slug expose :services, with: VendorServiceEntity expose :products, with: ProductEntity