From 96fe9c434a8efe0124b661483c7167f4170b2575 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Thu, 24 Oct 2024 17:37:19 +0530 Subject: [PATCH] feat: save and get labels on sx spaces and proposals (#864) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Index labels on spaces * fix typecheck * fix tests * Index labels on sx proposals * Store labels as array of strings * remove API related changes * Update apps/ui/src/networks/common/graphqlApi/index.ts Co-authored-by: Wiktor Tkaczyński * Update apps/ui/src/networks/common/graphqlApi/index.ts Co-authored-by: Wiktor Tkaczyński --------- Co-authored-by: Wiktor Tkaczyński --- apps/ui/src/helpers/utils.test.ts | 16 ++++++++++++++++ apps/ui/src/helpers/utils.ts | 6 ++++++ apps/ui/src/networks/common/graphqlApi/index.ts | 6 +++++- .../ui/src/networks/common/graphqlApi/queries.ts | 2 ++ apps/ui/src/networks/common/graphqlApi/types.ts | 3 +++ apps/ui/src/networks/evm/actions.ts | 2 ++ apps/ui/src/networks/starknet/actions.ts | 2 ++ apps/ui/src/types.ts | 1 + apps/ui/src/views/Create.vue | 1 + apps/ui/src/views/Space/Settings.vue | 2 +- 10 files changed, 39 insertions(+), 2 deletions(-) diff --git a/apps/ui/src/helpers/utils.test.ts b/apps/ui/src/helpers/utils.test.ts index 24731fc77..64145a194 100644 --- a/apps/ui/src/helpers/utils.test.ts +++ b/apps/ui/src/helpers/utils.test.ts @@ -72,6 +72,14 @@ describe('utils', () => { address: '0x000000000000000000000000000000000000dead' } ], + labels: [ + { + id: 'test', + name: 'Test', + description: 'Test description', + color: '#000000' + } + ], delegations: [ { name: 'sample', @@ -102,6 +110,14 @@ describe('utils', () => { address: '0x000000000000000000000000000000000000dead' } ], + labels: [ + { + id: 'test', + name: 'Test', + description: 'Test description', + color: '#000000' + } + ], delegations: [ { name: 'sample', diff --git a/apps/ui/src/helpers/utils.ts b/apps/ui/src/helpers/utils.ts index 6af0e091b..19af6367f 100644 --- a/apps/ui/src/helpers/utils.ts +++ b/apps/ui/src/helpers/utils.ts @@ -446,6 +446,12 @@ export function createErc1155Metadata( network: treasury.network, address: treasury.address })), + labels: metadata.labels?.map(label => ({ + id: label.id, + name: label.name, + description: label.description, + color: label.color + })), delegations: metadata.delegations.map(delegation => ({ name: delegation.name, api_type: delegation.apiType, diff --git a/apps/ui/src/networks/common/graphqlApi/index.ts b/apps/ui/src/networks/common/graphqlApi/index.ts index 5c551145d..7ea5f6018 100644 --- a/apps/ui/src/networks/common/graphqlApi/index.ts +++ b/apps/ui/src/networks/common/graphqlApi/index.ts @@ -194,6 +194,10 @@ function formatSpace( chainId: CHAIN_IDS[network] }; }), + labels: space.metadata.labels.map(label => { + const { id, name, description, color } = JSON.parse(label); + return { id, name, description, color }; + }), delegations: space.metadata.delegations.map(delegation => { const { name, api_type, api_url, contract } = JSON.parse(delegation); @@ -255,7 +259,7 @@ function formatProposal( metadata_uri: proposal.metadata.id, type: 'basic', choices: BASIC_CHOICES, - labels: [], + labels: proposal.metadata.labels, scores: [proposal.scores_1, proposal.scores_2, proposal.scores_3], title: proposal.metadata.title ?? '', body: proposal.metadata.body ?? '', diff --git a/apps/ui/src/networks/common/graphqlApi/queries.ts b/apps/ui/src/networks/common/graphqlApi/queries.ts index 82744e4bb..eb6750452 100644 --- a/apps/ui/src/networks/common/graphqlApi/queries.ts +++ b/apps/ui/src/networks/common/graphqlApi/queries.ts @@ -16,6 +16,7 @@ const SPACE_FRAGMENT = gql` discord voting_power_symbol treasuries + labels delegations executors executors_types @@ -122,6 +123,7 @@ const PROPOSAL_FRAGMENT = gql` body discussion execution + labels } start min_end diff --git a/apps/ui/src/networks/common/graphqlApi/types.ts b/apps/ui/src/networks/common/graphqlApi/types.ts index a9e323f80..0745825f2 100644 --- a/apps/ui/src/networks/common/graphqlApi/types.ts +++ b/apps/ui/src/networks/common/graphqlApi/types.ts @@ -40,6 +40,7 @@ export type ApiSpace = { executors_destinations: string[]; executors_strategies: ApiExecutorStrategy[]; treasuries: string[]; + labels: string[]; delegations: string[]; }; controller: string; @@ -71,6 +72,7 @@ export type ApiProposal = { body: string | null; discussion: string | null; execution: string | null; + labels: string[]; }; space: { id: string; @@ -80,6 +82,7 @@ export type ApiProposal = { avatar: string; voting_power_symbol: string; treasuries: string[]; + labels: string[]; executors: string[]; executors_types: string[]; executors_strategies: ApiExecutorStrategy[]; diff --git a/apps/ui/src/networks/evm/actions.ts b/apps/ui/src/networks/evm/actions.ts index e0c1fe46d..f92744260 100644 --- a/apps/ui/src/networks/evm/actions.ts +++ b/apps/ui/src/networks/evm/actions.ts @@ -223,6 +223,7 @@ export function createActions( type, app: app || EDITOR_APP_NAME, choices: choices.filter(c => !!c), + labels, execution: executionInfo?.transactions ?? [] }); if (!pinned || !pinned.cid) return false; @@ -323,6 +324,7 @@ export function createActions( discussion, type, choices: choices.filter(c => !!c), + labels, execution: executionInfo?.transactions ?? [] }); if (!pinned || !pinned.cid) return false; diff --git a/apps/ui/src/networks/starknet/actions.ts b/apps/ui/src/networks/starknet/actions.ts index 4aba2b731..27f47a436 100644 --- a/apps/ui/src/networks/starknet/actions.ts +++ b/apps/ui/src/networks/starknet/actions.ts @@ -236,6 +236,7 @@ export function createActions( type, app: app || EDITOR_APP_NAME, choices: choices.filter(c => !!c), + labels, execution: executionInfo?.transactions ?? [] }); if (!pinned || !pinned.cid) return false; @@ -341,6 +342,7 @@ export function createActions( discussion, type, choices: choices.filter(c => !!c), + labels, execution: executionInfo?.transactions ?? [] }); if (!pinned || !pinned.cid) return false; diff --git a/apps/ui/src/types.ts b/apps/ui/src/types.ts index c13ab1319..81873388d 100644 --- a/apps/ui/src/types.ts +++ b/apps/ui/src/types.ts @@ -94,6 +94,7 @@ export type SpaceMetadata = { discord: string; votingPowerSymbol: string; treasuries: SpaceMetadataTreasury[]; + labels: SpaceMetadataLabel[]; delegations: SpaceMetadataDelegation[]; }; diff --git a/apps/ui/src/views/Create.vue b/apps/ui/src/views/Create.vue index 522d3874a..dcbe59f28 100644 --- a/apps/ui/src/views/Create.vue +++ b/apps/ui/src/views/Create.vue @@ -70,6 +70,7 @@ const metadataForm: SpaceMetadata = reactive( discord: '', votingPowerSymbol: '', treasuries: [], + labels: [], delegations: [] }) ); diff --git a/apps/ui/src/views/Space/Settings.vue b/apps/ui/src/views/Space/Settings.vue index 2df3fa1a4..31ea59f3f 100644 --- a/apps/ui/src/views/Space/Settings.vue +++ b/apps/ui/src/views/Space/Settings.vue @@ -136,7 +136,7 @@ const tabs = computed( { id: 'labels', name: 'Labels', - visible: isOffchainNetwork.value + visible: true }, { id: 'execution',