Skip to content

Commit e3c37ae

Browse files
authored
feat(20143): Add Schema versioning (#334)
* feat(20143): add types for resource family and creation status * feat(20143): add name to schema type * feat(20143): add name to the JSON Schema for the Schema nodes * refactor(20143): remove deprecated buttons from the code editor * feat(20143): add a create selectable editor for the name of a resource * refactor(20143): remove the create command from the version - fix the latest identifier * refactor(20143): refactor the side panel to support creating and editing schemas - editing state to identify creation status - conditional ordering and enabling of fields to identify state * refactor(20143): extract resource families from the list of schemas * refactor(20143): remove static UISchema * refactor(20143): streamline content of default JSONSchema * refactor(20143): refactor schema and script types to incorporate resource status * refactor(20143): add name properties * refactor(20143): refactor types * refactor(20143): add versions to the attributes of existing schemas * refactor(20143): add handling for new options * refactor(20143): fix version * refactor(20143): fix version * refactor(20143): add status to the resource family payload * refactor(20143): fix initial payload for schema nodes * refactor(20143): fix imports * fix(20143): fix default layout * refactor(20143): exclude reuse of schema from publishing * refactor(20143): fix id and version * refactor(20143): remove ordering of fields * refactor(20143): fix version * refactor(20143): sdd draft to new named schema * fix(20143): fix type * fix(20143): fix translation * test(20143): fix tests * test(20143): add test-only dummy editor panel and fix the test * test(20143): fix test * test(20143): add test * test(20143): add test * test(20143): add test * test(20143): fix test * test(20143): add test * test(20143): fix test * test(20143): fix test * chore(20143): reduce verbosity of stdout * fix(20143): change the default content on a change in the type of schema * fix(20143): fix default placeholders for JSON and PROTOBUF contents * fix(20143): add draft name to the options of the select widget * fix(20143): fix flow initialising the name and properties of a draft and modified version * fix(20143): fix dependencies * fix(20143): fix display of version * Revert "chore(20143): reduce verbosity of stdout" This reverts commit 370e1e9. * refactor(20143): improve readability * fix(20143): fix loading of name and version * fix(20143): fix status * fix(20143): fix label * test(20143): fix test * chore(20143): linting * refactor(20712): update the edit flow for the Scripts (#357) * chore(20143): reduce verbosity of stdout * Revert "chore(20143): reduce verbosity of stdout" This reverts commit 370e1e9. * fix(20712): fix type and json-schema for the scripts * feat(20712): add script families generator * feat(20712): add support for script in the name selector * feat(20712): change mapping for the script name widget * refactor(20712): change UISchema to a dynamic definition * feat(20712): implement the FSM flow for editing Scripts * test(20712): add tests * fix(20712): fix schema version and name * test(20712): add tests * fix(20712): fix content readonly * test(20712): add test * test(20712): fix test * fix(20712): fix * chore(20712): update prettier ignore
1 parent ba99b93 commit e3c37ae

35 files changed

+1011
-156
lines changed

hivemq-edge/src/frontend/.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pnpm-lock.*
22

3+
.idea/
34
docs/
45
dist/
56
coverage/

hivemq-edge/src/frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"i18next": "^22.4.15",
7070
"luxon": "^3.3.0",
7171
"mermaid": "^10.8.0",
72+
"monaco-editor": "^0.47.0",
7273
"mqtt-match": "^3.0.0",
7374
"protobufjs": "^7.2.6",
7475
"react": "^18.2.0",

hivemq-edge/src/frontend/pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hivemq-edge/src/frontend/src/extensions/datahub/__test-utils__/react-flow.mocks.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const MOCK_INITIAL_POLICY = () => {
5757

5858
const schemaNode: Node<SchemaData> = {
5959
id: '5',
60-
data: { type: SchemaType.JSON, schemaSource: '', version: 1 },
60+
data: { name: '5', type: SchemaType.JSON, schemaSource: '', version: 1 },
6161
type: DataHubNodeType.SCHEMA,
6262
position: { x: 645, y: -195 },
6363
}

hivemq-edge/src/frontend/src/extensions/datahub/__test-utils__/schema.mocks.ts

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,18 @@
1-
export const MOCK_PROTOBUF_SCHEMA = `
2-
syntax = "proto3";
1+
export const MOCK_PROTOBUF_SCHEMA = `syntax = "proto3";
32
43
message GpsCoordinates {
54
int32 longitude = 1;
65
int32 latitude = 2;
76
}
87
`
98

10-
export const MOCK_JSONSCHEMA_SCHEMA = `
11-
{
12-
"$id":"https://example.com/geographical-location.schema.json",
9+
export const MOCK_JSONSCHEMA_SCHEMA = `{
1310
"$schema":"https://json-schema.org/draft/2020-12/schema",
14-
"title":"Longitude and Latitude Values",
15-
"description":"A geographical coordinate.",
16-
"required":[
17-
"latitude",
18-
"longitude"
19-
],
11+
"title":"",
12+
"description":"",
13+
"required":[],
2014
"type":"object",
21-
"properties":{
22-
"latitude":{
23-
"type":"number",
24-
"minimum":-90,
25-
"maximum":90
26-
},
27-
"longitude":{
28-
"type":"number",
29-
"minimum":-180,
30-
"maximum":180
31-
}
32-
}
15+
"properties":{}
3316
}
3417
`
3518

hivemq-edge/src/frontend/src/extensions/datahub/api/__generated__/schemas/FunctionData.json

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hivemq-edge/src/frontend/src/extensions/datahub/api/__generated__/schemas/SchemaData.json

Lines changed: 10 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hivemq-edge/src/frontend/src/extensions/datahub/components/controls/PropertyPanelController.spec.cy.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ describe('PropertyPanelController', () => {
3636
<Route path="/node/:type/:nodeId" element={<PropertyPanelController />}></Route>
3737
</Routes>
3838
</ReactFlowProvider>,
39-
{ routerProps: { initialEntries: ['/node/TOPIC_FILTER/1'] } }
39+
{ routerProps: { initialEntries: ['/node/INTERNAL/1'] } }
4040
)
4141

4242
cy.getByTestId('node-editor-under-construction').should('not.exist')
43+
cy.getByTestId('loading-spinner').should('be.visible')
4344
cy.get('button[type="submit"]').should('be.visible')
4445
})
4546
})

hivemq-edge/src/frontend/src/extensions/datahub/components/controls/ToolboxPublish.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { MdPublishedWithChanges } from 'react-icons/md'
88
import { BehaviorPolicy, DataPolicy, Schema, Script } from '@/api/__generated__'
99

1010
import { usePolicyChecksStore } from '@datahub/hooks/usePolicyChecksStore.ts'
11-
import { DataHubNodeType, DesignerStatus, DryRunResults } from '@datahub/types.ts'
11+
import { DataHubNodeType, DesignerStatus, DryRunResults, ResourceState, ResourceStatus } from '@datahub/types.ts'
1212
import { useCreateSchema } from '@datahub/api/hooks/DataHubSchemasService/useCreateSchema.tsx'
1313
import { useCreateScript } from '@datahub/api/hooks/DataHubScriptsService/useCreateScript.tsx'
1414
import { useCreateDataPolicy } from '@datahub/api/hooks/DataHubDataPoliciesService/useCreateDataPolicy.tsx'
@@ -24,13 +24,16 @@ interface Mutate<T> {
2424
type ValidMutate = Mutate<Schema> | Mutate<Script> | Mutate<DataPolicy> | Mutate<BehaviorPolicy>
2525

2626
const resourceReducer =
27-
<T extends { id: string }>(type: DataHubNodeType) =>
27+
<T extends Schema | Script>(type: DataHubNodeType) =>
2828
(accumulator: T[], result: DryRunResults<T, never>) => {
2929
if (result.node.type !== type) return accumulator
3030
if (!result.data) return accumulator
3131
const { id } = result.data
3232
if (!id) return accumulator
3333

34+
const { version } = result.node.data as ResourceState
35+
if (version !== ResourceStatus.DRAFT && version !== ResourceStatus.MODIFIED) return accumulator
36+
3437
const allIds = accumulator.map((resource) => resource.id)
3538
if (allIds.includes(id)) return accumulator
3639

hivemq-edge/src/frontend/src/extensions/datahub/components/forms/CodeEditor.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
import { useMemo } from 'react'
12
import { labelValue, WidgetProps } from '@rjsf/utils'
23
import { Editor } from '@monaco-editor/react'
3-
import { Button, FormControl, FormLabel, HStack, VStack } from '@chakra-ui/react'
4+
import { FormControl, FormLabel, VStack } from '@chakra-ui/react'
45
import { getChakra } from '@rjsf/chakra-ui/lib/utils'
5-
import { useTranslation } from 'react-i18next'
66

77
const CodeEditor = (lng: string, props: WidgetProps) => {
8-
const { t } = useTranslation('datahub')
98
const chakraProps = getChakra({ uiSchema: props.uiSchema })
109

10+
const isReadOnly = useMemo(() => props.readonly || props.options.readonly, [props.readonly, props.options.readonly])
11+
1112
return (
1213
<FormControl
1314
{...chakraProps}
1415
isDisabled={props.disabled || props.readonly}
1516
isRequired={props.required}
16-
isReadOnly={props.readonly}
17+
isReadOnly={isReadOnly}
1718
isInvalid={props.rawErrors && props.rawErrors.length > 0}
1819
>
1920
{labelValue(
@@ -28,17 +29,10 @@ const CodeEditor = (lng: string, props: WidgetProps) => {
2829
height="40vh"
2930
defaultLanguage={lng}
3031
defaultValue={props.value}
32+
value={props.value}
3133
onChange={(event) => props.onChange(event)}
34+
options={{ readOnly: isReadOnly }}
3235
/>
33-
34-
<HStack>
35-
<Button variant="danger" isDisabled size="sm">
36-
{t('workspace.codeEditor.delete')}
37-
</Button>
38-
<Button isDisabled size="sm">
39-
{t('workspace.codeEditor.test')}
40-
</Button>
41-
</HStack>
4236
</VStack>
4337
</FormControl>
4438
)

0 commit comments

Comments
 (0)