Skip to content

Commit

Permalink
Show custom labels from labeler service in ozone (#51)
Browse files Browse the repository at this point in the history
* setup dockerfile and service entrypoint for frontend/backend deployed together

* gitignore/yarnlock tidy

* auth state for ozone configuration

* update api package

* plc/identity setup workflow

* tidy/fixes

* record creation flow on login

* reorg client config / configuration flow

* skip record creation step if not service account

* tidy

* rename metadata endpoint

* fix

* reorg plc constants, bring plc functionality into lib/identity

* make generic ErrorInfo component

* misc fixes

* fix cypress

* websocket fix

* add docker workflow

* update ozone version

* ✨ Use custom labeler labels in label input

---------

Co-authored-by: Devin Ivy <devinivy@gmail.com>
  • Loading branch information
foysalit and devinivy authored Mar 14, 2024
1 parent 5d13043 commit 0e5a5b8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions components/common/labels/Grid.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from 'react'
import Select from 'react-tailwindcss-select'
import client from '@/lib/client'
import {
labelOptions,
groupLabelList,
Expand Down
32 changes: 29 additions & 3 deletions components/common/labels/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import client from '@/lib/client'
import { unique } from '@/lib/util'
import {
AppBskyActorDefs,
Expand Down Expand Up @@ -85,6 +86,17 @@ export const LabelGroupInfo: Record<
[LABEL_GROUPS.misinfo.id]: {
color: '#530303',
},
custom: {
color: '#218734',
strings: {
settings: {
en: {
name: 'Custom Labels',
description: 'Labels from labeler service',
},
},
},
},
uncategorized: {
strings: {
settings: {
Expand All @@ -106,12 +118,19 @@ const labelGroupsRequiringBlur = [

export const groupLabelList = (labels: string[]): GroupedLabelList => {
const groupedList: GroupedLabelList = {}
const customLabels = getCustomLabels()

labels.forEach((label) => {
// SELF_FLAG is embedded in the label value so when grouping, we have to take it out of the value
const cleanedLabel = unFlagSelfLabel(label)
const group = LABELS[cleanedLabel]
const groupId = group?.groupId || 'uncategorized'
let groupId = 'uncategorized'

if (group?.groupId) {
groupId = group.groupId
} else if (customLabels?.includes(cleanedLabel)) {
groupId = 'custom'
}

if (groupedList[groupId]) {
groupedList[groupId].labels.push(label)
Expand All @@ -127,9 +146,15 @@ export const groupLabelList = (labels: string[]): GroupedLabelList => {
return groupedList
}

const getCustomLabels = () =>
client.session?.config.labeler?.policies.labelValues

export const getLabelGroupInfo = (label: string): LabelGroupInfoRecord => {
const customLabels = getCustomLabels()
const group = LABELS[label]
const groupId = group?.groupId || 'uncategorized'
const groupId =
group?.groupId ||
(customLabels?.includes(label) ? 'custom' : 'uncategorized')

return {
// TODO: We shouldn't have to do this, there's a weird type def somewhere that's causing this
Expand Down Expand Up @@ -178,5 +203,6 @@ export const buildAllLabelOptions = (
defaultLabels: string[],
options: string[],
) => {
return unique([...defaultLabels, ...options]).sort()
const customLabels = getCustomLabels()
return unique([...defaultLabels, ...options, ...(customLabels || [])]).sort()
}
9 changes: 8 additions & 1 deletion lib/client-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export async function getConfig(labelerDid?: string): Promise<OzoneConfig> {
doc,
meta,
handle,
labeler: record,
matching: {
service:
labelerUrl && meta
Expand Down Expand Up @@ -98,7 +99,7 @@ async function getLabelerServiceRecord(pdsUrl: string, did: string) {
if (!recordInfo?.['value'] || typeof recordInfo['value'] !== 'object') {
return null
}
return recordInfo['value'] as Record<string, undefined>
return recordInfo['value'] as TemporaryLabelerServiceDef
}

function normalizeUrl(url: string) {
Expand All @@ -112,9 +113,15 @@ export function withDocAndMeta(config: OzoneConfig) {
}

export type OzoneMeta = { did: string; url: string; publicKey: string }
export type TemporaryLabelerServiceDef = {
policies: {
labelValues: string[]
}
}

export type OzoneConfig = {
did: string
labeler: TemporaryLabelerServiceDef | null
handle: string | null
meta: OzoneMeta | null
doc: DidDocData | null
Expand Down

0 comments on commit 0e5a5b8

Please sign in to comment.