Skip to content

Commit 481d7eb

Browse files
committed
show diff by categories
1 parent 35d8657 commit 481d7eb

2 files changed

Lines changed: 61 additions & 41 deletions

File tree

otoroshi/javascript/src/components/wizardframe.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ function Header({ onClose, title }) {
1212

1313
function WizardActions({ cancel, ok, cancelLabel, okLabel, noCancel, noOk, okClassName = '', state }) {
1414
return (
15-
<div className="d-flex mt-auto justify-content-between align-items-center">
15+
<div className="d-flex mt-auto justify-content-between align-items-center" style={{
16+
position: 'sticky',
17+
bottom: 0,
18+
right: 0,
19+
left: 0,
20+
padding: '1rem',
21+
background: 'var(--bg-color_level2)',
22+
zIndex: 100
23+
}}>
1624
{!noCancel && (
1725
<Button
1826
className="ms-auto"
@@ -50,7 +58,7 @@ export function WizardFrame(props) {
5058
return (
5159
<div className="wizard">
5260
<div className="wizard-container">
53-
<div className="d-flex" style={{ flexDirection: 'column', padding: '2.5rem', flex: 1 }}>
61+
<div className="d-flex" style={{ flexDirection: 'column', padding: '2.5rem 0 0 2.5rem', flex: 1, position: 'relative' }}>
5462
<Header title={props.title} onClose={props.cancel} />
5563
{props.children
5664
? props.schildren

otoroshi/javascript/src/pages/ApiEditor/index.js

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { JsonObjectAsCodeInput } from '../../components/inputs/CodeInput';
3434
import NgClientCredentialTokenEndpoint from '../../forms/ng_plugins/NgClientCredentialTokenEndpoint';
3535
import NgHasClientCertMatchingValidator from '../../forms/ng_plugins/NgHasClientCertMatchingValidator';
3636
import { components } from 'react-select';
37+
import { render } from 'react-dom';
3738

3839
const queryClient = new QueryClient({
3940
queries: {
@@ -466,7 +467,7 @@ function RouteDesigner(props) {
466467
useEffect(() => {
467468
if (item && backendsQuery.data !== undefined) {
468469
setRoute(item.routes.find(route => route.id === params.routeId))
469-
setSchema(ROUTE_FORM_SETTINGS.schema(item))
470+
setSchema(ROUTE_FORM_SETTINGS.schema(item, backends))
470471
}
471472
}, [item, backendsQuery.data])
472473

@@ -509,7 +510,7 @@ function RouteDesigner(props) {
509510
}
510511

511512
const ROUTE_FORM_SETTINGS = {
512-
schema: item => {
513+
schema: (item, backends) => {
513514
return {
514515
name: {
515516
type: 'string',
@@ -636,7 +637,7 @@ function NewRoute(props) {
636637

637638
useEffect(() => {
638639
if (item && !backendsQuery.isLoading && !schema) {
639-
setSchema(ROUTE_FORM_SETTINGS.schema(item))
640+
setSchema(ROUTE_FORM_SETTINGS.schema(item, backends))
640641
}
641642
}, [item, backendsQuery])
642643

@@ -1397,12 +1398,6 @@ function EditBackend(props) {
13971398
function Testing(props) {
13981399
const { item, version, updateItem, setItem, isLoading } = useDraftOfAPI()
13991400

1400-
if (version === 'Published') {
1401-
return <div>
1402-
Testing mode is only available in the draft version
1403-
</div>
1404-
}
1405-
14061401
if (isLoading)
14071402
return null
14081403

@@ -1434,28 +1429,33 @@ function Testing(props) {
14341429

14351430
return <>
14361431
<PageTitle title='Testing mode' {...props}>
1437-
<FeedbackButton
1432+
{version === 'Draft' && <FeedbackButton
14381433
type="success"
14391434
className="d-flex ms-auto"
14401435
onPress={updateItem}
14411436
text={<>
14421437
Update <VersionBadge size="xs" />
14431438
</>}
1444-
/>
1439+
/>}
14451440
</PageTitle>
1446-
<div style={{
1447-
maxWidth: 640,
1448-
margin: 'auto'
1449-
}}>
1450-
<NgForm
1451-
value={item?.testing}
1452-
onChange={testing => setItem({
1453-
...item,
1454-
testing
1455-
})}
1456-
schema={schema}
1457-
/>
1458-
</div>
1441+
{version === 'Published' ?
1442+
<div>
1443+
Testing mode is only available in the draft version.
1444+
</div>
1445+
:
1446+
<div style={{
1447+
maxWidth: 640,
1448+
margin: 'auto'
1449+
}}>
1450+
<NgForm
1451+
value={item?.testing}
1452+
onChange={testing => setItem({
1453+
...item,
1454+
testing
1455+
})}
1456+
schema={schema}
1457+
/>
1458+
</div>}
14591459
</>
14601460
}
14611461

@@ -1984,6 +1984,14 @@ function VersionManager({ api, draft, owner, setState }) {
19841984
version: semver.inc(api.version, 'patch')
19851985
})
19861986

1987+
const getCompareStep = (field) => ({
1988+
renderer: () => {
1989+
return <PublisDraftModalContent
1990+
draft={draft.content[field]}
1991+
currentItem={api[field]} />
1992+
}
1993+
})
1994+
19871995
const schema = {
19881996
location: {
19891997
type: 'location'
@@ -2046,6 +2054,12 @@ function VersionManager({ api, draft, owner, setState }) {
20462054
at: {
20472055
type: 'datetime'
20482056
},
2057+
routes: getCompareStep('routes'),
2058+
flows: getCompareStep('flows'),
2059+
backends: getCompareStep('flows'),
2060+
consumers: getCompareStep('consumers'),
2061+
subscriptions: getCompareStep('subscriptions'),
2062+
deployments: getCompareStep('deployments'),
20492063
apiDefinition: {
20502064
renderer: () => {
20512065
return <PublisDraftModalContent
@@ -2055,20 +2069,12 @@ function VersionManager({ api, draft, owner, setState }) {
20552069
}
20562070
}
20572071

2058-
const { changed, result } = mergeData(api, draft.content)
2059-
2060-
const getChanges = () => {
2061-
try {
2062-
return result
2063-
.reduce((acc, item) => {
2064-
return acc +
2065-
(item.lineType !== 'none' ? 1 : 0) +
2066-
(Array.isArray(item.value) ? item.value.reduce((a, i) => a + i.lineType !== 'none' ? 1 : 0, 0) : 0)
2067-
}, 0)
2068-
} catch (err) {
2069-
return "unknown"
2070-
}
2071-
}
2072+
const getCompareFlowGroup = name => ({
2073+
type: 'group',
2074+
name: `${name} ${!mergeData(api[name], draft.content[name]).changed ? '' : `: has changed`}`,
2075+
collapsed: true,
2076+
fields: [name],
2077+
})
20722078

20732079
const flow = [
20742080
{
@@ -2077,9 +2083,15 @@ function VersionManager({ api, draft, owner, setState }) {
20772083
collapsable: false,
20782084
fields: ['version', 'action', 'owner']
20792085
},
2086+
getCompareFlowGroup('routes'),
2087+
getCompareFlowGroup('flows'),
2088+
getCompareFlowGroup('backends'),
2089+
getCompareFlowGroup('consumers'),
2090+
getCompareFlowGroup('subscriptions'),
2091+
getCompareFlowGroup('deployments'),
20802092
{
20812093
type: 'group',
2082-
name: !changed ? 'No changes' : `${getChanges()} elements has changed`,
2094+
name: `Global: ${!mergeData(api[name], draft.content[name]) ? 'No changes' : `has changed`}`,
20832095
collapsed: true,
20842096
fields: ['apiDefinition'],
20852097
}

0 commit comments

Comments
 (0)