Skip to content

Commit

Permalink
Added Trade Name to Organizations Listing Page (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
wender authored Jun 3, 2024
1 parent cc930df commit c342fd9
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 17 deletions.
15 changes: 12 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- `Trade Name` to be searchable (Admin)
- `Trade Name` to the Organization listing page (Admin)
- `Trade Name` to the Organization Requests listing page (Admin)
- Event listener to update schemas once new app version is released

## [0.49.6] - 2024-06-03

### Fixed
Expand Down Expand Up @@ -66,18 +73,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [0.48.2] - 2024-02-21

### Fixed

- Add analytics client to properly send metrics to redshift

## [0.48.1] - 2024-02-07

### Fixed

- Add retries to `sendMetric` to avoid connection errors

## [0.48.0] - 2024-01-19

### Added

- Allow `paymentTerms`, `collections` and `sellers` to be provided by name only on `createOrganizationAndCostCenterWithAdminUser`

## [0.47.1] - 2023-12-18

### Fixed
Expand Down Expand Up @@ -164,7 +174,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [0.37.0] - 2023-09-19


### Added

- Added event trigger on delete a user
Expand All @@ -180,7 +189,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added

- Added metrics for impersonate user
-
-

## [0.35.3] - 2023-08-09

### Fixed
Expand All @@ -199,7 +209,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- Fix auth problem when fetching orders history


## [0.35.0] - 2023-07-24

### Added
Expand Down
3 changes: 3 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
{
"name": "colossus-fire-event"
},
{
"name": "colossus-listen-event"
},
{
"name": "update-app-settings"
},
Expand Down
15 changes: 15 additions & 0 deletions node/events/appAllEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { EventContext } from '@vtex/api'

import type { Clients } from '../clients'

export async function appAllEvents(ctx: EventContext<Clients>) {
const {
vtex: { logger },
body,
} = ctx

logger.debug({
message: '[B2B Organizations GraphQL] Received appEvent',
body,
})
}
23 changes: 23 additions & 0 deletions node/events/appDependenciesUpdatedEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { EventContext } from '@vtex/api'

import type { Clients } from '../clients'
import checkConfig from '../resolvers/config'

export async function appDependenciesUpdatedEvent(ctx: EventContext<Clients>) {
const {
vtex: { logger, workspace },
body,
} = ctx

logger.debug({
message: '[B2B Organizations GraphQL] Received appDependenciesUpdatedEvent',
body,
})

// As a first iteration, we'll only send the workspace installed apps from master.
if (workspace !== 'master') {
return
}

checkConfig(ctx)
}
22 changes: 22 additions & 0 deletions node/events/kubeRouterAuditEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { EventContext } from '@vtex/api'

import type { Clients } from '../clients'
import checkConfig from '../resolvers/config'

export async function kubeRouterAuditEvent(ctx: EventContext<Clients>) {
const {
vtex: { logger },
body: { operation },
} = ctx

logger.debug({
message: '[B2B Organizations GraphQL] Received kubeRouterAuditEvent',
body: ctx.body,
})

// As first iteration, we'll only send the workspace installed apps from master.
if (operation === 'promote') {
// Update schemas.
checkConfig(ctx)
}
}
8 changes: 8 additions & 0 deletions node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { LRUCache, Service } from '@vtex/api'
import { Clients } from './clients'
import { resolvers } from './resolvers'
import { schemaDirectives } from './resolvers/directives'
import { appDependenciesUpdatedEvent } from './events/appDependenciesUpdatedEvent'
import { kubeRouterAuditEvent } from './events/kubeRouterAuditEvent'
import { appAllEvents } from './events/appAllEvents'

const TIMEOUT_MS = 4000

Expand Down Expand Up @@ -51,4 +54,9 @@ export default new Service<Clients, RecorderState, ParamsContext>({
schemaDirectives,
},
routes: resolvers.Routes,
events: {
appDependenciesUpdatedEvent,
kubeRouterAuditEvent,
appAllEvents,
},
})
15 changes: 11 additions & 4 deletions node/mdSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const ORGANIZATION_REQUEST_FIELDS = [
'sellers',
'customFields',
]
export const ORGANIZATION_REQUEST_SCHEMA_VERSION = 'v0.1.1'
export const ORGANIZATION_REQUEST_SCHEMA_VERSION = 'v0.1.2'

export const ORGANIZATION_DATA_ENTITY = 'organizations'
export const ORGANIZATION_FIELDS = [
Expand All @@ -32,7 +32,7 @@ export const ORGANIZATION_FIELDS = [
'created',
'customFields',
]
export const ORGANIZATION_SCHEMA_VERSION = 'v0.0.8'
export const ORGANIZATION_SCHEMA_VERSION = 'v0.0.9'

export const COST_CENTER_DATA_ENTITY = 'cost_centers'
export const COST_CENTER_FIELDS = [
Expand Down Expand Up @@ -111,7 +111,14 @@ export const schemas = [
title: 'Custom Fields',
},
},
'v-indexed': ['name', 'b2bCustomerAdmin', 'status', 'created'],
'v-indexed': [
'id',
'name',
'tradeName',
'b2bCustomerAdmin',
'status',
'created',
],
'v-immediate-indexing': true,
'v-cache': false,
},
Expand Down Expand Up @@ -167,7 +174,7 @@ export const schemas = [
title: 'Custom Fields',
},
},
'v-indexed': ['name', 'status', 'created'],
'v-indexed': ['id', 'name', 'tradeName', 'status', 'created'],
'v-immediate-indexing': true,
'v-cache': false,
},
Expand Down
10 changes: 7 additions & 3 deletions node/resolvers/Queries/Organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const getWhereByStatus = ({ status }: { status: string[] }) => {
if (status?.length) {
const statusArray = [] as string[]

status.forEach((stat) => {
status.forEach((stat: string) => {
statusArray.push(`status=${stat}`)
})
const statuses = `(${statusArray.join(' OR ')})`
Expand Down Expand Up @@ -132,7 +132,9 @@ const Organizations = {
const whereArray = getWhereByStatus({ status })

if (search) {
whereArray.push(`name="*${search}*"`)
whereArray.push(
`(name="*${search}*" OR tradeName="*${search}*" OR id="*${search}*")`
)
}

const where = whereArray.join(' AND ')
Expand Down Expand Up @@ -356,7 +358,9 @@ const Organizations = {
if (search.match(/[a-z\d]+@[a-z]+\.[a-z]{2,3}/gm)) {
whereArray.push(`b2bCustomerAdmin.email=${search}`)
} else {
whereArray.push(`name="*${search}*"`)
whereArray.push(
`(name="*${search}*" OR tradeName="*${search}*" OR id="*${search}*")`
)
}
}

Expand Down
15 changes: 9 additions & 6 deletions node/resolvers/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import type { EventContext } from '@vtex/api'

import type { Clients } from '../clients'
import { schemas } from '../mdSchema'
import templates from '../templates'
import { toHash } from '../utils'
Expand All @@ -19,7 +22,7 @@ export const getAppId = (): string => {
return appName
}

const checkConfig = async (ctx: Context) => {
const checkConfig = async (ctx: Context | EventContext<Clients>) => {
const {
vtex: { logger },
clients: { mail, masterdata, vbase },
Expand All @@ -44,7 +47,7 @@ const checkConfig = async (ctx: Context) => {
message: 'checkConfig-updatingSchema',
})

schemas.forEach((schema) => {
schemas.forEach((schema: any) => {
updates.push(
masterdata
.createOrUpdateSchema({
Expand All @@ -68,8 +71,8 @@ const checkConfig = async (ctx: Context) => {
)
})
try {
await Promise.all(updates).then((results) => {
if (results.every((res) => res === true)) {
await Promise.all(updates).then((results: any) => {
if (results.every((res: any) => res === true)) {
settings.schemaHash = currSchemaHash
schemaChanged = true
}
Expand All @@ -91,7 +94,7 @@ const checkConfig = async (ctx: Context) => {

try {
await Promise.all(
templates.map(async (template) => {
templates.map(async (template: any) => {
const existingData = await mail.getTemplate(template.Name)

if (!existingData) {
Expand All @@ -113,7 +116,7 @@ const checkConfig = async (ctx: Context) => {
settings.templateHash = currTemplateHash
templatesChanged = true
})
.catch((error) => {
.catch((error: any) => {
logger.error({
error,
message: 'checkConfig-publishTemplateError',
Expand Down
21 changes: 21 additions & 0 deletions node/service.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,26 @@
}
]
}
},
"events": {
"appDependenciesUpdatedEvent": {
"sender": "apps",
"topics": ["depsUpdated"]
},
"appAllEvents": {
"sender": "apps",
"topics": [
"linked",
"settings",
"depsUpdated",
"appVersionsUpdated",
"deprecated",
"undeprecated"
]
},
"kubeRouterAuditEvent": {
"sender": "kube-router",
"topics": ["audit"]
}
}
}
2 changes: 1 addition & 1 deletion node/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3475,7 +3475,7 @@ stack-utils@^2.0.3:
dependencies:
escape-string-regexp "^2.0.0"

"stats-lite@github:vtex/node-stats-lite#dist":
stats-lite@vtex/node-stats-lite#dist:
version "2.2.0"
resolved "https://codeload.github.com/vtex/node-stats-lite/tar.gz/1b0d39cc41ef7aaecfd541191f877887a2044797"
dependencies:
Expand Down

0 comments on commit c342fd9

Please sign in to comment.