Skip to content

Commit

Permalink
chore: make v3 default (#841)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shurtu-gal authored Nov 8, 2023
1 parent e68eb50 commit 3af6078
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 82 deletions.
5 changes: 2 additions & 3 deletions apps/studio/src/components/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Template } from './Template';
import { VisualiserTemplate } from './Visualiser';

import { debounce } from '../helpers';
import { usePanelsState, useDocumentsState, useSettingsState } from '../state';
import { usePanelsState, useDocumentsState } from '../state';

import type { FunctionComponent } from 'react';

Expand All @@ -15,8 +15,7 @@ interface ContentProps {}
export const Content: FunctionComponent<ContentProps> = () => { // eslint-disable-line sonarjs/cognitive-complexity
const { show, secondaryPanelType } = usePanelsState();
const document = useDocumentsState(state => state.documents['asyncapi']?.document) || null;
const v3Enabled = useSettingsState(state => state.editor.v3support) || false;
const isV3 = document?.version() === '3.0.0' && v3Enabled;
const isV3 = document?.version() === '3.0.0';
const navigationEnabled = show.primarySidebar;
const editorEnabled = show.primaryPanel;
const viewEnabled = show.secondaryPanel;
Expand Down
18 changes: 1 addition & 17 deletions apps/studio/src/components/Modals/Settings/SettingsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,12 @@ export const SettingsModal = create<SettingsModalProps>(({ activeTab = 'editor'
const [governanceHints, setGovernanceHints] = useState(settings.governance.show.hints);
const [autoRendering, setAutoRendering] = useState(settings.templates.autoRendering);
const [confirmDisabled, setConfirmDisabled] = useState(true);
const [v3support, setV3support] = useState(settings.editor.v3support);

const createNewState = (): SettingsState => {
return {
editor: {
autoSaving,
savingDelay,
v3support
},
governance: {
show: {
Expand All @@ -88,7 +86,7 @@ export const SettingsModal = create<SettingsModalProps>(({ activeTab = 'editor'
const newState = createNewState();
const isThisSameObjects = settingsSvc.isEqual(newState);
setConfirmDisabled(isThisSameObjects);
}, [autoSaving, savingDelay, autoRendering, governanceWarnings, governanceInformations, governanceHints, v3support]);
}, [autoSaving, savingDelay, autoRendering, governanceWarnings, governanceInformations, governanceHints]);

const onCancel = useCallback(() => {
modal.hide();
Expand Down Expand Up @@ -131,20 +129,6 @@ export const SettingsModal = create<SettingsModalProps>(({ activeTab = 'editor'
Save automatically after each change in the document or manually.
</div>
</div>
<div className="flex flex-col mt-4 text-sm">
<div className="flex flex-row content-center justify-between">
<label
htmlFor="settings-auto-saving"
className="flex justify-right items-center w-1/2 content-center font-medium text-gray-700"
>
Enable v3 support
</label>
<Switch
toggle={v3support}
onChange={(v) => setV3support(v)}
/>
</div>
</div>
<div className="flex flex-col mt-4 text-sm">
<div className="flex flex-row content-center justify-between">
<label
Expand Down
5 changes: 2 additions & 3 deletions apps/studio/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { show as showModal } from '@ebay/nice-modal-react';
import { Tooltip } from './common';
import { SettingsModal, NewFileModal } from './Modals';

import { usePanelsState, panelsState, useDocumentsState, useSettingsState } from '../state';
import { usePanelsState, panelsState, useDocumentsState } from '../state';

import type { FunctionComponent, ReactNode } from 'react';
import type { PanelsState } from '../state/panels.state';
Expand Down Expand Up @@ -53,8 +53,7 @@ interface SidebarProps {}
export const Sidebar: FunctionComponent<SidebarProps> = () => {
const { show, secondaryPanelType } = usePanelsState();
const document = useDocumentsState(state => state.documents['asyncapi']?.document) || null;
const v3Enabled = useSettingsState(state => state.editor.v3support) || false;
const isV3 = document?.version() === '3.0.0' && v3Enabled;
const isV3 = document?.version() === '3.0.0';

if (show.activityBar === false) {
return null;
Expand Down
5 changes: 2 additions & 3 deletions apps/studio/src/components/Terminal/TerminalTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';

import { TerminalInfo } from './TerminalInfo';
import { otherState, useSettingsState, useDocumentsState } from '../../state';
import { otherState, useDocumentsState } from '../../state';

export interface TerminalTab {
name: string;
Expand All @@ -20,8 +20,7 @@ export const TerminalTabs: React.FunctionComponent<TerminalTabsProps> = ({
}) => {
const [activeTab, setActiveTab] = useState(active);
const document = useDocumentsState(state => state.documents['asyncapi']?.document) || null;
const v3Enabled = useSettingsState(state => state.editor.v3support) || false;
const isV3 = document?.version() === '3.0.0' && v3Enabled;
const isV3 = document?.version() === '3.0.0';
if (tabs.length === 0) {
return null;
}
Expand Down
8 changes: 2 additions & 6 deletions apps/studio/src/services/specification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ export class SpecificationService extends AbstractService {
}

get latestVersion(): SpecVersions {
const { editor: { v3support } } = settingsState.getState();
return v3support ?
Object.keys(this.specs).pop() as SpecVersions :
Object.keys(this.specs).at(-2) as SpecVersions;
return Object.keys(this.specs).pop() as SpecVersions;
}

getSpec(version: SpecVersions) {
Expand All @@ -48,8 +45,7 @@ export class SpecificationService extends AbstractService {
}

private subscribeToSettings() {
settingsState.subscribe((state, prevState) => {
if (state.editor.v3support === prevState.editor.v3support) return;
settingsState.subscribe(() => {
sessionStorage.removeItem(this.keySessionStorage);
});
}
Expand Down
149 changes: 102 additions & 47 deletions apps/studio/src/state/files.state.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import create from 'zustand';

const schema =
localStorage.getItem('document') || `asyncapi: '2.6.0'
localStorage.getItem('document') || `asyncapi: 3.0.0
info:
title: Streetlights Kafka API
version: '1.0.0'
Expand All @@ -13,85 +13,136 @@ info:
* Receive real-time information about environmental lighting conditions 📈
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0
url: 'https://www.apache.org/licenses/LICENSE-2.0'
defaultContentType: application/json
servers:
test:
url: test.mykafkacluster.org:8092
scram-connections:
host: 'test.mykafkacluster.org:18092'
protocol: kafka-secure
description: Test broker
description: Test broker secured with scramSha256
security:
- saslScram: []
defaultContentType: application/json
- $ref: '#/components/securitySchemes/saslScram'
tags:
- name: 'env:test-scram'
description: >-
This environment is meant for running internal tests through
scramSha256
- name: 'kind:remote'
description: This server is a remote server. Not exposed by the application
- name: 'visibility:private'
description: This resource is private and only available to certain users
mtls-connections:
host: 'test.mykafkacluster.org:28092'
protocol: kafka-secure
description: Test broker secured with X509
security:
- $ref: '#/components/securitySchemes/certs'
tags:
- name: 'env:test-mtls'
description: This environment is meant for running internal tests through mtls
- name: 'kind:remote'
description: This server is a remote server. Not exposed by the application
- name: 'visibility:private'
description: This resource is private and only available to certain users
channels:
smartylighting.streetlights.1.0.event.{streetlightId}.lighting.measured:
lightingMeasured:
address: 'smartylighting.streetlights.1.0.event.{streetlightId}.lighting.measured'
messages:
lightMeasured:
$ref: '#/components/messages/lightMeasured'
description: The topic on which measured values may be produced and consumed.
parameters:
streetlightId:
$ref: '#/components/parameters/streetlightId'
publish:
summary: Inform about environmental lighting conditions of a particular streetlight.
operationId: receiveLightMeasurement
traits:
- $ref: '#/components/operationTraits/kafka'
message:
$ref: '#/components/messages/lightMeasured'
smartylighting.streetlights.1.0.action.{streetlightId}.turn.on:
lightTurnOn:
address: 'smartylighting.streetlights.1.0.action.{streetlightId}.turn.on'
messages:
turnOn:
$ref: '#/components/messages/turnOnOff'
parameters:
streetlightId:
$ref: '#/components/parameters/streetlightId'
subscribe:
operationId: turnOn
traits:
- $ref: '#/components/operationTraits/kafka'
message:
lightTurnOff:
address: 'smartylighting.streetlights.1.0.action.{streetlightId}.turn.off'
messages:
turnOff:
$ref: '#/components/messages/turnOnOff'
smartylighting.streetlights.1.0.action.{streetlightId}.turn.off:
parameters:
streetlightId:
$ref: '#/components/parameters/streetlightId'
subscribe:
operationId: turnOff
traits:
- $ref: '#/components/operationTraits/kafka'
message:
$ref: '#/components/messages/turnOnOff'
smartylighting.streetlights.1.0.action.{streetlightId}.dim:
lightsDim:
address: 'smartylighting.streetlights.1.0.action.{streetlightId}.dim'
messages:
dimLight:
$ref: '#/components/messages/dimLight'
parameters:
streetlightId:
$ref: '#/components/parameters/streetlightId'
subscribe:
operationId: dimLight
traits:
- $ref: '#/components/operationTraits/kafka'
message:
$ref: '#/components/messages/dimLight'
operations:
receiveLightMeasurement:
action: receive
channel:
$ref: '#/channels/lightingMeasured'
summary: >-
Inform about environmental lighting conditions of a particular
streetlight.
traits:
- $ref: '#/components/operationTraits/kafka'
messages:
- $ref: '#/components/messages/lightMeasured'
turnOn:
action: send
channel:
$ref: '#/channels/lightTurnOn'
traits:
- $ref: '#/components/operationTraits/kafka'
messages:
- $ref: '#/components/messages/turnOnOff'
turnOff:
action: send
channel:
$ref: '#/channels/lightTurnOff'
traits:
- $ref: '#/components/operationTraits/kafka'
messages:
- $ref: '#/components/messages/turnOnOff'
dimLight:
action: send
channel:
$ref: '#/channels/lightsDim'
traits:
- $ref: '#/components/operationTraits/kafka'
messages:
- $ref: '#/components/messages/dimLight'
components:
messages:
lightMeasured:
name: lightMeasured
title: Light measured
summary: Inform about environmental lighting conditions of a particular streetlight.
summary: >-
Inform about environmental lighting conditions of a particular
streetlight.
contentType: application/json
traits:
- $ref: '#/components/messageTraits/commonHeaders'
payload:
$ref: "#/components/schemas/lightMeasuredPayload"
$ref: '#/components/schemas/lightMeasuredPayload'
turnOnOff:
name: turnOnOff
title: Turn on/off
summary: Command a particular streetlight to turn the lights on or off.
traits:
- $ref: '#/components/messageTraits/commonHeaders'
payload:
$ref: "#/components/schemas/turnOnOffPayload"
$ref: '#/components/schemas/turnOnOffPayload'
dimLight:
name: dimLight
title: Dim light
summary: Command a particular streetlight to dim the lights.
traits:
- $ref: '#/components/messageTraits/commonHeaders'
payload:
$ref: "#/components/schemas/dimLightPayload"
$ref: '#/components/schemas/dimLightPayload'
schemas:
lightMeasuredPayload:
type: object
Expand All @@ -101,18 +152,18 @@ components:
minimum: 0
description: Light intensity measured in lumens.
sentAt:
$ref: "#/components/schemas/sentAt"
$ref: '#/components/schemas/sentAt'
turnOnOffPayload:
type: object
properties:
command:
type: string
enum:
- on
- off
- 'on'
- 'off'
description: Whether to turn on or off the light.
sentAt:
$ref: "#/components/schemas/sentAt"
$ref: '#/components/schemas/sentAt'
dimLightPayload:
type: object
properties:
Expand All @@ -122,7 +173,7 @@ components:
minimum: 0
maximum: 100
sentAt:
$ref: "#/components/schemas/sentAt"
$ref: '#/components/schemas/sentAt'
sentAt:
type: string
format: date-time
Expand All @@ -131,11 +182,12 @@ components:
saslScram:
type: scramSha256
description: Provide your username and password for SASL/SCRAM authentication
certs:
type: X509
description: Download the certificate files from service provider
parameters:
streetlightId:
description: The ID of the streetlight.
schema:
type: string
messageTraits:
commonHeaders:
headers:
Expand All @@ -149,7 +201,10 @@ components:
kafka:
bindings:
kafka:
clientId: my-app-id
clientId:
type: string
enum:
- my-app-id
`;

export interface FileStat {
Expand Down
4 changes: 1 addition & 3 deletions apps/studio/src/state/settings.state.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import create from 'zustand';
import { create } from 'zustand';
import { persist } from 'zustand/middleware';

export type SettingsState = {
editor: {
autoSaving: boolean;
savingDelay: number;
v3support: boolean;
};
governance: {
show: {
Expand All @@ -25,7 +24,6 @@ export const settingsState = create(
editor: {
autoSaving: true,
savingDelay: 625,
v3support: false,
},
governance: {
show: {
Expand Down

0 comments on commit 3af6078

Please sign in to comment.