Skip to content

Commit b188d0d

Browse files
committed
Merge branch 'main' into feat/support-multiple-files-at-once-in-cli
Fix merge conflict in packages/cli/src/commander.ts
2 parents 8904bf8 + 354b144 commit b188d0d

File tree

8 files changed

+62
-35
lines changed

8 files changed

+62
-35
lines changed

packages/cli/src/commander.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from '@commander-js/extra-typings';
77
import { readFile, writeFile } from 'fs/promises';
88
import { MermaidChart } from '@mermaidchart/sdk';
9-
9+
import { createRequire } from 'node:module';
1010
import confirm from '@inquirer/confirm';
1111
import input from '@inquirer/input';
1212
import select, { Separator } from '@inquirer/select';
@@ -264,8 +264,11 @@ function pushCmd() {
264264
}
265265

266266
export function createCommanderCommand() {
267+
const require = createRequire(import.meta.url);
268+
const pkg = require('../package.json');
269+
267270
const program = createCommand('mermaid-cli')
268-
.version('0.1.0-alpha.0') // TODO: how can we keep this synced with package.json
271+
.version(pkg.version)
269272
.description(
270273
'CLI for interacting with https://MermaidChart.com, the platform that makes collaborating with Mermaid diagrams easy.',
271274
)

packages/office/src/lib/client/featureSet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export enum FeatureName {
2323
const features: Record<FeatureName, FeatureState> = {
2424
editor: FeatureState.UnderDevelopment,
2525
dashboard: FeatureState.UnderDevelopment,
26-
userBehavior: FeatureState.StageAndProd,
27-
cookieBot: FeatureState.OnlyInProd
26+
userBehavior: FeatureState.NotInProd,
27+
cookieBot: FeatureState.NotInProd
2828
};
2929

3030
/**

packages/office/src/lib/client/stores/documents.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { writable } from 'svelte/store';
22
import { getDiagramType } from '$lib/utils';
33
import { loading } from './loading';
44
import type { MCDocument, MermaidChart } from '$lib/mermaidChartApi';
5+
import { showUserMessage } from './messaging';
56

67
interface MCDocumentDB {
78
filterStr: string;
@@ -15,6 +16,17 @@ const defaultDB: MCDocumentDB = {
1516
documents: {}
1617
};
1718

19+
const fullDocumentList: MCDocument[] = [];
20+
21+
const addToFullList = (document: MCDocument) => {
22+
const existingDoc = fullDocumentList.find((doc) => doc.documentID === document.documentID);
23+
if (existingDoc) {
24+
return
25+
} else {
26+
fullDocumentList.push(document);
27+
}
28+
}
29+
1830
function createDocumentStore() {
1931
const { subscribe, set, update } = writable(defaultDB);
2032
return {
@@ -24,8 +36,15 @@ function createDocumentStore() {
2436
const documents: MCDocument[] = [];
2537

2638
for (const projectID of projectIDList) {
27-
const projectDocuments = await mermaidChartApi.getDocuments(projectID);
28-
documents.push(...projectDocuments);
39+
try {
40+
const projectDocuments = await mermaidChartApi.getDocuments(projectID);
41+
documents.push(...projectDocuments);
42+
} catch {
43+
loading.setState(false, '');
44+
return showUserMessage(
45+
'Failed to load documents for project with ID: ' + projectID,
46+
'error');
47+
}
2948
}
3049

3150
const res = update((documentDB) => {
@@ -37,6 +56,7 @@ function createDocumentStore() {
3756
document.diagramType = getDiagramType(document.code);
3857
documentDB.documents[document.documentID] = document;
3958
documentDB.documentIds.push(document.documentID);
59+
addToFullList(document);
4060
}
4161
}
4262
documentDB.documentIds.sort((a, b) => doSort(a, b, 'updatedAt', documentDB.documents, 'asc'));

packages/office/src/lib/client/util/sendEvents.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { analyticsEnabled } from '../stores/analytics';
55
import { minutesToMilliSeconds } from '$lib/utils';
66
import type { MCUser } from '$lib/mermaidChartApi';
77
import log from '$lib/log';
8+
import { FeatureName, shouldUseFeature } from '../featureSet';
89

910
let initialized = false;
1011

@@ -75,16 +76,18 @@ const delaysPerEvent: Record<string, number> = {
7576
const timeouts: Record<string, number> = {};
7677

7778
export function sendBehaviorEvent(description: string, event: BehaviorEvent) {
78-
if (timeouts[event.eventID]) {
79-
clearTimeout(timeouts[event.eventID]);
80-
}
81-
if (delaysPerEvent[event.eventID] === undefined) {
82-
sendEvent(description, event);
83-
} else {
84-
timeouts[event.eventID] = window.setTimeout(() => {
79+
if(shouldUseFeature(FeatureName.UserBehavior)) {
80+
if (timeouts[event.eventID]) {
81+
clearTimeout(timeouts[event.eventID]);
82+
}
83+
if (delaysPerEvent[event.eventID] === undefined) {
8584
sendEvent(description, event);
86-
delete timeouts[event.eventID];
87-
}, delaysPerEvent[event.eventID]);
85+
} else {
86+
timeouts[event.eventID] = window.setTimeout(() => {
87+
sendEvent(description, event);
88+
delete timeouts[event.eventID];
89+
}, delaysPerEvent[event.eventID]);
90+
}
8891
}
8992
}
9093

packages/office/src/routes/+layout.svelte

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@
1515
let syncDiagramsInDocument: () => Promise<void>;
1616
1717
onMount(() => {
18-
initializeMixPanel(
19-
publicEnv.PUBLIC_MIXPANEL_TOKEN,
20-
$sessionStore.id,
21-
$sessionStore);
18+
if(shouldUseFeature(FeatureName.UserBehavior)) {
19+
initializeMixPanel(
20+
publicEnv.PUBLIC_MIXPANEL_TOKEN,
21+
$sessionStore.id,
22+
$sessionStore);
2223
23-
window.addEventListener(
24-
'CookiebotOnConsentReady',
25-
() => {
26-
updateConsent(window.Cookiebot?.consent);
27-
},
28-
false
29-
);
24+
window.addEventListener(
25+
'CookiebotOnConsentReady',
26+
() => {
27+
updateConsent(window.Cookiebot?.consent);
28+
},
29+
false
30+
);
31+
}
3032
});
3133
</script>
3234

packages/sdk/CHANGELOG.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
55

66
## [Unreleased]
77

8+
## [0.2.0] - 2024-04-11
9+
810
### Added
911

1012
- Compile an ESM version of this codebase for Node.JS v18.
1113
- Add `MermaidChart#getDiagram(diagramID)` function to get a diagram.
12-
- Add `MermaidChart#createDocument(projectID)` function to create a digram in a project.
14+
- Add `MermaidChart#createDocument(projectID)` function to create a diagram in a project.
1315
- Add `MermaidChart#setDocument(document)` function to update a diagram.
1416
- Add `MermaidChart#deleteDocument(documentID)` function to delete a diagram.
1517
- Add `MermaidChart#baseURL` is now public.
1618

1719
### Fixed
1820

19-
- Fix `MCDocument` `major`/`minor` type to `number`.
20-
- Add `code` field to `MCDocument` type
21-
22-
### Fixed
23-
21+
- **BREAKING:** Fix `MCDocument` `major`/`minor` type to `number`.
22+
- Add `code` field to `MCDocument` type.
2423
- `MermaidChart#getAuthorizationData()` now correctly sets `state` in the URL
2524
by default.
2625
- `MermaidChart#handleAuthorizationResponse()` now supports relative URLs.
2726

2827
## [0.1.1] - 2023-09-08
28+
2929
- Browser-only build.

packages/sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mermaidchart/sdk",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"description": "Access the MermaidChart services with OAuth and type safety.",
55
"browser": "dist/bundle.iife.js",
66
"types": "dist/index.d.ts",

packages/sdk/src/index.e2e.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ describe('setDocument', () => {
9898
});
9999
});
100100

101-
// TODO: this function never seems to return an error, see MC-1060
102-
it.skip('should throw an error on invalid data', async() => {
101+
it('should throw an error on invalid data', async() => {
103102
const newDocument = await client.createDocument(testProjectId);
104103
documentsToDelete.add(newDocument.documentID);
105104

0 commit comments

Comments
 (0)