Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat: code file type chip (#2370)

gbirman907734f98bab
diff --git a/js/app/packages/block-code/component/CodeFileTypeChip.tsx b/js/app/packages/block-code/component/CodeFileTypeChip.tsx
new file mode 100644
index 0000000000..db6337aabc
--- /dev/null
+++ b/js/app/packages/block-code/component/CodeFileTypeChip.tsx
@@ -0,0 +1,14 @@
+import { blockMetadataSignal } from '@core/signal/load';
+import { Show } from 'solid-js';
+
+export function CodeFileTypeChip() {
+ const fileType = () => blockMetadataSignal()?.fileType;
+
+ return (
+ <Show when={fileType()}>
+ <span class="shrink-0 rounded px-1 py-0.5 text-[0.625rem] font-mono font-medium uppercase leading-none bg-code-bg text-code">
+ {fileType()}
+ </span>
+ </Show>
+ );
+}
diff --git a/js/app/packages/block-code/component/TopBar.tsx b/js/app/packages/block-code/component/TopBar.tsx
index a2a3582191..1c93b9982d 100644
--- a/js/app/packages/block-code/component/TopBar.tsx
+++ b/js/app/packages/block-code/component/TopBar.tsx
@@ -12,6 +12,7 @@ import { BlockItemSplitLabel } from '@app/component/split-layout/components/Spli
import { useAnalytics } from '@app/component/analytics-context';
import { useIsAuthenticated } from '@core/auth';
import { useBlockId } from '@core/block';
+import { CodeFileTypeChip } from './CodeFileTypeChip';
import {
DocumentPropertiesButton,
PROPERTIES_DRAWER_ID,
@@ -121,7 +122,7 @@ export const TopBar: Component<{
return (
<>
<SplitHeaderLeft>
- <BlockItemSplitLabel />
+ <BlockItemSplitLabel badges={<CodeFileTypeChip />} />
</SplitHeaderLeft>
<ResponsivePermissionsBadge />
diff --git a/js/app/packages/queries/history/tests/history.test.tsx b/js/app/packages/queries/history/tests/history.test.tsx
index 20eee46a23..7273bb31e3 100644
--- a/js/app/packages/queries/history/tests/history.test.tsx
+++ b/js/app/packages/queries/history/tests/history.test.tsx
@@ -5,6 +5,9 @@ import { transformHistoryResponse } from '../transforms';
vi.mock('@core/constant/allBlocks', () => ({
itemToSafeName: (item: { name?: string }) => item.name || 'Untitled',
}));
+vi.mock('@service-storage/util/filename', () => ({
+ formatDocumentName: (name: string) => name,
+}));
function createItem(overrides: Partial<Item> = {}): Item {
return {
diff --git a/js/app/packages/queries/history/transforms.ts b/js/app/packages/queries/history/transforms.ts
index 392184a4a2..384e3647f0 100644
--- a/js/app/packages/queries/history/transforms.ts
+++ b/js/app/packages/queries/history/transforms.ts
@@ -1,11 +1,19 @@
import { itemToSafeName } from '@core/constant/allBlocks';
import type { Item } from '@service-storage/generated/schemas/item';
import type { HistoryItem, HistoryQueryResponse } from './types';
+import { formatDocumentName } from '@service-storage/util/filename';
export function transformHistoryItem(item: Item): HistoryItem {
+ const safeName = itemToSafeName(item);
+ const name =
+ item.type === 'document'
+ ? formatDocumentName(safeName, item.fileType, {
+ fullyQualifiedBlockName: true,
+ })
+ : safeName;
const base = {
id: item.id,
- name: itemToSafeName(item),
+ name,
createdAt: item.createdAt,
updatedAt: item.updatedAt,
deletedAt: item.deletedAt,
diff --git a/js/app/packages/service-clients/service-storage/client.ts b/js/app/packages/service-clients/service-storage/client.ts
index 5f0550adc8..2b53edda22 100644
--- a/js/app/packages/service-clients/service-storage/client.ts
+++ b/js/app/packages/service-clients/service-storage/client.ts
@@ -141,32 +141,6 @@ export function isItemType(str: string): str is ItemType {
return itemTypeSet.has(str);
}
-const mapMetadataDocumentName = (
- metadata: DocumentMetadata
-): DocumentMetadata => {
- const name = formatDocumentName(metadata.documentName, metadata.fileType, {
- fullyQualifiedBlockName: true,
- });
-
- return {
- ...metadata,
- documentName: name,
- };
-};
-
-const mapItemDocumentName = (item: Item): Item => {
- if (item.type !== 'document') return item;
-
- const name = formatDocumentName(item.name, item.fileType, {
- fullyQualifiedBlockName: true,
- });
-
- return {
- ...item,
- name,
- };
-};
-
const mapPreviewDocumentName = (preview: DocumentPreview): DocumentPreview => {
if (!('document_name' in preview)) return preview;
@@ -282,7 +256,7 @@ export const storageServiceClient = {
},
async getUsersHistory() {
return mapOk(await dssFetch<{ data: Item[] }>(`/history`), (result) => ({
- data: result.data.map(mapItemDocumentName),
+ data: result.data,
}));
},
@@ -331,7 +305,7 @@ export const storageServiceClient = {
};
}>(`/documents?limit=${params.limit}&offset=${params.offset}`),
(result) => ({
- documents: result.data.documents.map(mapMetadataDocumentName),
+ documents: result.data.documents,
total: result.data.total,
nextOffset: result.data.next_offset,
})
@@ -423,7 +397,7 @@ export const storageServiceClient = {
const data = result.data;
return {
...data,
- documentMetadata: mapMetadataDocumentName(data.documentMetadata),
+ documentMetadata: data.documentMetadata,
};
}
);