Skip to content

Commit a55fa65

Browse files
authored
Merge pull request finos#41 from Finsemble/49663-code-review
change requests
2 parents 0c00185 + 5e99d61 commit a55fa65

File tree

3 files changed

+46
-48
lines changed

3 files changed

+46
-48
lines changed

toolbox/fdc3-workbench/src/components/ContextCreate.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ export const ContextCreate = observer(({contextName}: {contextName:string}) => {
198198

199199
const handleSaveTemplate = (e: FormEvent | null = null) => {
200200
e?.preventDefault();
201-
if(!disabled) {
201+
if(disabled) {
202+
return;
203+
} else {
202204
const isValid: boolean = validate();
203205

204206
if (isValid && context && templateName) {

toolbox/fdc3-workbench/src/components/ContextTemplates.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,7 @@ export const ContextTemplates = observer(({handleTabChange, contextStateSetter,
8989
setError(false);
9090
};
9191

92-
const getOptionLabel = (option: OptionType) => {
93-
if (option.value) {
94-
return option.value;
95-
}
96-
return option.title;
97-
};
92+
const getOptionLabel = (option: OptionType) => option.value || option.title;
9893

9994
const filterOptions = (options: OptionType[], params: FilterOptionsState<OptionType>) => {
10095
const filtered = contextFilter(options, params);

toolbox/fdc3-workbench/src/store/ContextStore.ts

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,15 @@ class ContextStore {
101101
}
102102

103103
async broadcast(context: ContextType) {
104-
if (context) {
104+
if (!context) {
105+
systemLogStore.addLog({
106+
name: "broadcast",
107+
type: "warning",
108+
value: "You must set a context before you can broadcast it",
109+
variant: "text",
110+
});
111+
return;
112+
} else {
105113
//check that we're on a channel
106114
let currentChannel = await fdc3.getCurrentChannel();
107115
if (!currentChannel) {
@@ -129,59 +137,52 @@ class ContextStore {
129137
});
130138
}
131139
}
132-
} else {
133-
systemLogStore.addLog({
134-
name: "broadcast",
135-
type: "warning",
136-
value: "You must set a context before you can broadcast it",
137-
variant: "text",
138-
});
139140
}
140141
}
141142

142143
addContextListener(contextType: string | undefined) {
143144
try {
144145
if( typeof contextType === "string") {
145-
const listenerId = nanoid();
146+
const listenerId = nanoid();
146147

147-
// TODO: remove window after fixing https://github.com/finos/FDC3/issues/435
148-
const contactListener = window.fdc3.addContextListener(contextType.toLowerCase() === "all" ? null : contextType, (context) => {
149-
const currentListener = this.contextListeners.find(({ id }) => id === listenerId);
148+
// TODO: remove window after fixing https://github.com/finos/FDC3/issues/435
149+
const contactListener = window.fdc3.addContextListener(contextType.toLowerCase() === "all" ? null : contextType, (context) => {
150+
const currentListener = this.contextListeners.find(({ id }) => id === listenerId);
150151

151-
runInAction(() => {
152-
if (currentListener) {
153-
currentListener.lastReceivedContext = context;
154-
}
155-
});
152+
runInAction(() => {
153+
if (currentListener) {
154+
currentListener.lastReceivedContext = context;
155+
}
156+
});
156157

157-
systemLogStore.addLog({
158-
name: "receivedContextListener",
159-
type: "info",
160-
value: contextType,
161-
variant: "code",
162-
body: JSON.stringify(context, null, 4),
158+
systemLogStore.addLog({
159+
name: "receivedContextListener",
160+
type: "info",
161+
value: contextType,
162+
variant: "code",
163+
body: JSON.stringify(context, null, 4),
164+
});
163165
});
164-
});
165166

166-
runInAction(() => {
167-
systemLogStore.addLog({
168-
name: "addContextListener",
169-
type: "success",
170-
value: contextType,
171-
variant: "text",
167+
runInAction(() => {
168+
systemLogStore.addLog({
169+
name: "addContextListener",
170+
type: "success",
171+
value: contextType,
172+
variant: "text",
173+
});
174+
this.contextListeners.push({ id: listenerId, type: contextType, listener: contactListener });
172175
});
173-
this.contextListeners.push({ id: listenerId, type: contextType, listener: contactListener });
174-
});
175-
}else {
176-
runInAction(() => {
177-
systemLogStore.addLog({
178-
name: "addContextListener",
179-
type: "error",
180-
value: contextType,
181-
variant: "code",
176+
} else {
177+
runInAction(() => {
178+
systemLogStore.addLog({
179+
name: "addContextListener",
180+
type: "error",
181+
value: contextType,
182+
variant: "code",
183+
});
182184
});
183-
});
184-
}
185+
}
185186
} catch (e) {
186187
systemLogStore.addLog({
187188
name: "addContextListener",

0 commit comments

Comments
 (0)