Skip to content

Commit 6935a55

Browse files
committed
feat: support 1.13 again
This reverts commit 9d1734e in order to be 1.13-compatible. this way we can ship the previous fix more easily.
1 parent cfdbf95 commit 6935a55

File tree

4 files changed

+63
-29
lines changed

4 files changed

+63
-29
lines changed

plugins/services/src/js/components/modals/ServiceRootGroupModal/index.tsx

+45-26
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import FieldError from "#SRC/js/components/form/FieldError";
3030
import InfoTooltipIcon from "#SRC/js/components/form/InfoTooltipIcon";
3131
import Loader from "#SRC/js/components/Loader";
3232
import MesosStateStore from "#SRC/js/stores/MesosStateStore";
33+
import dcosVersion$ from "#SRC/js/stores/dcos-version";
3334

3435
import { formatQuotaID } from "#PLUGINS/services/src/js/utils/QuotaUtil";
3536
import {
@@ -110,36 +111,52 @@ interface ServiceRootGroupModalState {
110111
error: boolean;
111112
isForce: boolean;
112113
hasValidated: boolean;
114+
showQuotaOptions: boolean;
113115
}
114116

115117
interface ServiceRootGroupModalProps {
116118
id: string;
117119
}
118120

119121
class ServiceRootGroupModal extends React.Component<
120-
ServiceRootGroupModalProps
122+
ServiceRootGroupModalProps,
123+
ServiceRootGroupModalState
121124
> {
122-
static contextTypes = { router: routerShape };
123-
static defaultProps = { id: "" };
124-
125-
state: ServiceRootGroupModalState = {
126-
isOpen: true,
127-
isPending: false,
128-
expandAdvancedSettings: false,
129-
data: !!this.props.id ? null : emptyGroupFormData(),
130-
originalData: null,
131-
errors: {},
132-
isEdit: !!this.props.id,
133-
error: false,
134-
isForce: false,
135-
hasValidated: false,
125+
public static contextTypes = {
126+
router: routerShape,
136127
};
128+
public static defaultProps = {
129+
id: "",
130+
};
131+
132+
state = this.getInitialState();
137133

138-
componentDidMount() {
134+
public componentDidMount() {
139135
this.getGroupFormData();
136+
dcosVersion$.subscribe(({ hasQuotaSupport }) => {
137+
this.setState({ showQuotaOptions: hasQuotaSupport });
138+
});
139+
}
140+
141+
public getInitialState(
142+
props: ServiceRootGroupModalProps = this.props
143+
): ServiceRootGroupModalState {
144+
return {
145+
isOpen: true,
146+
isPending: false,
147+
expandAdvancedSettings: false,
148+
data: !!props.id ? null : emptyGroupFormData(),
149+
originalData: null,
150+
errors: {},
151+
isEdit: !!props.id,
152+
error: false,
153+
isForce: false,
154+
hasValidated: false,
155+
showQuotaOptions: false,
156+
};
140157
}
141158

142-
handleClose = () => {
159+
public handleClose = () => {
143160
// Start the animation of the modal by setting isOpen to false
144161
this.setState(
145162
{ isOpen: false, isPending: false, data: emptyGroupFormData() },
@@ -151,7 +168,7 @@ class ServiceRootGroupModal extends React.Component<
151168
);
152169
};
153170

154-
handleSave = () => {
171+
public handleSave = () => {
155172
let data: GroupFormData | null = this.state.data;
156173
const { isPending, originalData, isEdit, isForce } = this.state;
157174
if (isPending || data === null) {
@@ -226,7 +243,7 @@ class ServiceRootGroupModal extends React.Component<
226243
});
227244
};
228245

229-
handleSaveError = (
246+
public handleSaveError = (
230247
message: string,
231248
mesos: boolean = false,
232249
data: null | OvercommittedQuotaResource[] = null
@@ -300,7 +317,7 @@ class ServiceRootGroupModal extends React.Component<
300317
}
301318
};
302319

303-
getGroupFormData = (): void => {
320+
public getGroupFormData = (): void => {
304321
const { id } = this.props;
305322
if (!!id) {
306323
getGroup(id)
@@ -321,7 +338,7 @@ class ServiceRootGroupModal extends React.Component<
321338
}
322339
};
323340

324-
getModalContent = () => {
341+
public getModalContent = () => {
325342
const { errors, data, isEdit, error } = this.state;
326343
// If id exists, then we must be editing.
327344

@@ -381,15 +398,17 @@ class ServiceRootGroupModal extends React.Component<
381398
<div>{getPathFromGroupId(data.id)}</div>
382399
</FormGroup>
383400
</FormRow>
384-
{this.renderQuotaOptions(data, errors)}
401+
{this.state.showQuotaOptions
402+
? this.renderQuotaOptions(data, errors)
403+
: null}
385404
</form>
386405
</div>
387406
</FluidGeminiScrollbar>
388407
</div>
389408
);
390409
};
391410

392-
getAdvancedSettings = () => {
411+
public getAdvancedSettings = () => {
393412
const { data, originalData, expandAdvancedSettings, isEdit } = this.state;
394413
const roleEnforcementTooltipContent = (
395414
<Trans>
@@ -402,7 +421,7 @@ class ServiceRootGroupModal extends React.Component<
402421
return;
403422
}
404423

405-
const isDisabled = isEdit && !!originalData && originalData.enforceRole;
424+
const isDisabled = isEdit && originalData && originalData.enforceRole;
406425

407426
return (
408427
<AdvancedSection initialIsExpanded={expandAdvancedSettings}>
@@ -472,7 +491,7 @@ class ServiceRootGroupModal extends React.Component<
472491
);
473492
};
474493

475-
handleFormChange = (event: React.FormEvent<HTMLFormElement>) => {
494+
public handleFormChange = (event: React.FormEvent<HTMLFormElement>) => {
476495
if (this.state.isPending || !this.state.data) {
477496
return;
478497
}
@@ -594,7 +613,7 @@ class ServiceRootGroupModal extends React.Component<
594613
);
595614
}
596615

597-
render() {
616+
public render() {
598617
const { isEdit, isForce } = this.state;
599618
return (
600619
<FullScreenModal

plugins/services/src/js/containers/services/ServiceTreeView.tsx

+14-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import ServicesTable from "./ServicesTable";
2929
import ServiceStatusDSLSection from "../../components/dsl/ServiceStatusDSLSection";
3030
import ServiceTree from "../../structs/ServiceTree";
3131
import { serviceTreeHasQuota } from "../../utils/QuotaUtil";
32+
import dcosVersion$ from "#SRC/js/stores/dcos-version";
3233
import { Subscription } from "rxjs";
3334

3435
const DSL_FORM_SECTIONS = [
@@ -61,7 +62,13 @@ class ServiceTreeView extends React.Component {
6162

6263
$dcosVersion?: Subscription;
6364

64-
componentDidMount() {}
65+
state = { hasQuotaSupport: false };
66+
67+
componentDidMount() {
68+
this.$dcosVersion = dcosVersion$.subscribe(({ hasQuotaSupport }) => {
69+
this.setState({ hasQuotaSupport });
70+
});
71+
}
6572
componentWillUnmount() {
6673
this.$dcosVersion?.unsubscribe();
6774
}
@@ -145,7 +152,8 @@ class ServiceTreeView extends React.Component {
145152
const { modalHandlers } = this.context;
146153
// Only add id if service is not root
147154
const isRoot = serviceTree.isRoot();
148-
const hasQuota = serviceTreeHasQuota(serviceTree, roles);
155+
const hasQuota =
156+
serviceTreeHasQuota(serviceTree, roles) && this.state.hasQuotaSupport;
149157

150158
const routePath = isRoot
151159
? "/services/overview/create"
@@ -214,7 +222,10 @@ class ServiceTreeView extends React.Component {
214222
},
215223
];
216224

217-
const actions = serviceTree.isTopLevel() ? editGroupActions : [];
225+
const actions =
226+
serviceTree.isTopLevel() && this.state.hasQuotaSupport
227+
? editGroupActions
228+
: [];
218229

219230
if (isEmpty) {
220231
// We don't want an empty "+" dropdown.

src/js/__tests__/__snapshots__/typecheck-test.ts.snap

+2
Original file line numberDiff line numberDiff line change
@@ -2268,7 +2268,9 @@ plugins/services/src/js/components/modals/ServiceResumeModal.tsx: error TS2339:
22682268
plugins/services/src/js/components/modals/ServiceResumeModal.tsx: error TS2339: Property 'resumeService' does not exist on type *.
22692269
plugins/services/src/js/components/modals/ServiceResumeModal.tsx: error TS2339: Property 'service' does not exist on type *.
22702270
plugins/services/src/js/components/modals/ServiceRootGroupModal/index.tsx: error TS2322: Type 'true' is not assignable to type *.
2271+
plugins/services/src/js/components/modals/ServiceRootGroupModal/index.tsx: error TS2322: type * is not assignable to type *.
22712272
plugins/services/src/js/components/modals/ServiceRootGroupModal/index.tsx: error TS2322: Type 'false' is not assignable to type *.
2273+
plugins/services/src/js/components/modals/ServiceRootGroupModal/index.tsx: error TS2322: type * is not assignable to type *.
22722274
plugins/services/src/js/components/modals/ServiceScaleFormModal.tsx: error TS2339: Property 'service' does not exist on type *.
22732275
plugins/services/src/js/components/modals/ServiceScaleFormModal.tsx: error TS2339: Property 'service' does not exist on type *.
22742276
plugins/services/src/js/components/modals/ServiceScaleFormModal.tsx: error TS2339: Property 'service' does not exist on type *.

src/js/stores/dcos-version.ts

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export default fromFetch(
2525
bootstrapId: json["bootstrap-id"] as string,
2626
variant: json["dcos-variant"] as string,
2727
// we could just pass through the version itself. but having long identifiers will make it easier to understand why some code is conditional and also to remove that conditional again.
28+
hasQuotaSupport: Version.compare(json.version, "2.0.0-alpha") >= 0,
29+
2830
hasCalicoNetworking: Version.compare(json.version, "2.1.0-alpha") >= 0,
2931
hasVerticalBursting: Version.compare(json.version, "2.1.0-alpha") >= 0,
3032

0 commit comments

Comments
 (0)