Skip to content

Commit e179ea5

Browse files
authored
Merge pull request #163 from jpinsonneau/316
NETOBSERV-316 Console plugin as standalone
2 parents 38c3770 + beb3bfd commit e179ea5

File tree

16 files changed

+20872
-11823
lines changed

16 files changed

+20872
-11823
lines changed

Makefile

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,17 @@ build-frontend: install-frontend fmt-frontend
9191
@echo "### Building frontend"
9292
cd web && npm run build
9393

94+
.PHONY: build-frontend-standalone
95+
build-frontend-standalone: install-frontend fmt-frontend
96+
@echo "### Building frontend standalone"
97+
cd web && npm run build:standalone
98+
9499
.PHONY: build
95100
build: build-backend build-frontend
96101

102+
.PHONY: build-standalone
103+
build-standalone: build-backend build-frontend-standalone
104+
97105
.PHONY: frontend
98106
frontend: build-frontend lint-frontend test-frontend
99107

@@ -128,11 +136,23 @@ serve-mock:
128136
./plugin-backend --loki-mock --loglevel trace
129137

130138
.PHONY: start
131-
start: build-backend
139+
start: build-backend install-frontend
132140
@echo "### Starting backend on http://localhost:9002"
133141
bash -c "trap 'fuser -k 9002/tcp' EXIT; \
134142
./plugin-backend -port 9002 & cd web && npm run start"
135143

144+
.PHONY: start-standalone
145+
start-standalone: build-backend install-frontend
146+
@echo "### Starting backend on http://localhost:9002"
147+
bash -c "trap 'fuser -k 9002/tcp' EXIT; \
148+
./plugin-backend -port 9002 & cd web && npm run start:standalone"
149+
150+
.PHONY: start-standalone-mock
151+
start-standalone-mock: build-backend install-frontend
152+
@echo "### Starting backend on http://localhost:9002 using mock"
153+
bash -c "trap 'fuser -k 9002/tcp' EXIT; \
154+
./plugin-backend -port 9002 --loki-mock --loglevel trace & cd web && npm run start:standalone"
155+
136156
.PHONY: bridge
137157
bridge:
138158
ifeq (,${CONSOLE})

web/moduleMapper/dummy.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

web/moduleMapper/dummy.tsx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import * as React from 'react';
2+
import { ResourceLinkProps } from '@openshift-console/dynamic-plugin-sdk';
3+
import { useK8sModelsWithColors } from '../src/utils/k8s-models-hook';
4+
import { k8sModels } from './k8s-models';
5+
6+
// This dummy file is used to resolve @Console imports from @openshift-console for JEST / Standalone
7+
// You can add any exports needed here
8+
// Check "moduleNameMapper" in package.json for jest
9+
// and "NormalModuleReplacementPlugin" in webpack.standalone.ts
10+
export class Dummy extends Error {
11+
constructor() {
12+
super('Dummy file for exports');
13+
}
14+
}
15+
16+
export function isModelFeatureFlag(e: never) {
17+
return null;
18+
}
19+
20+
export function useResolvedExtensions(isModelFeatureFlag: boolean) {
21+
return [
22+
[{
23+
flags: "dummy",
24+
model: "",
25+
}],
26+
undefined, undefined];
27+
}
28+
29+
export function useK8sModels() {
30+
return [
31+
k8sModels,
32+
false
33+
]
34+
}
35+
36+
export const ResourceLink: React.FC<ResourceLinkProps> = ({
37+
className,
38+
displayName,
39+
kind,
40+
name,
41+
children,
42+
dataTest,
43+
}) => {
44+
const k8sModels = useK8sModelsWithColors();
45+
const value = displayName ? displayName : name;
46+
47+
return (
48+
//TODO: add icon here
49+
<span className={className}>
50+
<span
51+
className="co-m-resource-icon"
52+
style={{ backgroundColor: k8sModels[kind!].color }}
53+
title={kind}>
54+
{k8sModels[kind!].abbr}
55+
</span>
56+
<span className="co-resource-item__resource-name" data-test-id={value} data-test={dataTest}>
57+
{value}
58+
</span>
59+
{children}
60+
</span>
61+
);
62+
};

0 commit comments

Comments
 (0)