Skip to content

Commit

Permalink
Renaming variable names to make them even more explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagobento committed Dec 28, 2023
1 parent b2cb50f commit 8a8eab8
Show file tree
Hide file tree
Showing 120 changed files with 671 additions and 528 deletions.
6 changes: 3 additions & 3 deletions examples/base64png-editor/src/Base64PngEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const Base64PngEditor = React.forwardRef<EditorApi, Props>((props, forwar
* Callback is exposed to the Channel that is called when a new file is opened. It sets the originalContent to the received value.
*/
const setContent = useCallback(
(pathRelativeToTheWorkspaceRoot: string, content: string) => {
(normalizedPosixPathRelativeToTheWorkspaceRoot: string, content: string) => {
setOriginalContent(content);
updateEditorToInitialState();
},
Expand Down Expand Up @@ -167,8 +167,8 @@ export const Base64PngEditor = React.forwardRef<EditorApi, Props>((props, forwar
useImperativeHandle(forwardedRef, () => {
return {
getContent: () => Promise.resolve(getContent()),
setContent: (pathRelativeToTheWorkspaceRoot: string, content: string) =>
Promise.resolve(setContent(pathRelativeToTheWorkspaceRoot, content)),
setContent: (normalizedPosixPathRelativeToTheWorkspaceRoot: string, content: string) =>
Promise.resolve(setContent(normalizedPosixPathRelativeToTheWorkspaceRoot, content)),
getPreview: () => Promise.resolve(getPreview()),
undo: () => Promise.resolve(undo()),
redo: () => Promise.resolve(redo()),
Expand Down
6 changes: 3 additions & 3 deletions examples/base64png-editor/src/Base64PngEditorInterface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ export class Base64PngEditorInterface implements Editor {

/**
* Set the Editor content
* @param pathRelativeToTheWorkspaceRoot The file pathRelativeToTheWorkspaceRoot that is being open.
* @param normalizedPosixPathRelativeToTheWorkspaceRoot The file normalizedPosixPathRelativeToTheWorkspaceRoot that is being open.
* @param content The file content in a string format.
*/
public setContent(pathRelativeToTheWorkspaceRoot: string, content: string): Promise<void> {
return this.editorRef.current!.setContent(pathRelativeToTheWorkspaceRoot, content)!;
public setContent(normalizedPosixPathRelativeToTheWorkspaceRoot: string, content: string): Promise<void> {
return this.editorRef.current!.setContent(normalizedPosixPathRelativeToTheWorkspaceRoot, content)!;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion examples/webapp/src/Pages/Base64Png/Base64PngGallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function Base64PngGallery({ setFile }: { setFile: React.Dispatch<Embedded
fileExtension: "base64png",
fileName: fileName,
getFileContents: () => fetch(filePath).then((response) => response.text()),
pathRelativeToTheWorkspaceRoot: filePath,
normalizedPosixPathRelativeToTheWorkspaceRoot: filePath,
});
},
[setFile]
Expand Down
2 changes: 1 addition & 1 deletion examples/webapp/src/Pages/Base64Png/Base64PngPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function Base64PngPage() {
fileExtension: "base64png",
getFileContents: () => Promise.resolve(""),
isReadOnly: false,
pathRelativeToTheWorkspaceRoot: "new-file.base64png",
normalizedPosixPathRelativeToTheWorkspaceRoot: "new-file.base64png",
});

/**
Expand Down
2 changes: 1 addition & 1 deletion examples/webapp/src/Pages/KogitoEditors/BpmnPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function BpmnPage() {
fileExtension: "bpmn",
getFileContents: () => Promise.resolve(""),
isReadOnly: false,
pathRelativeToTheWorkspaceRoot: "new-file.bpmn",
normalizedPosixPathRelativeToTheWorkspaceRoot: "new-file.bpmn",
});

/**
Expand Down
2 changes: 1 addition & 1 deletion examples/webapp/src/Pages/KogitoEditors/DmnPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function DmnPage() {
fileExtension: "dmn",
getFileContents: () => Promise.resolve(""),
isReadOnly: false,
pathRelativeToTheWorkspaceRoot: "new-file.dmn",
normalizedPosixPathRelativeToTheWorkspaceRoot: "new-file.dmn",
});

/**
Expand Down
6 changes: 3 additions & 3 deletions examples/webapp/src/Pages/KogitoEditors/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function Sidebar({ editorEnvelopeLocator, editor, setFile, file, fileExte
fileExtension: fileExtension,
fileName: "new-file",
getFileContents: () => Promise.resolve(""),
pathRelativeToTheWorkspaceRoot: `new-file.${fileExtension}`,
normalizedPosixPathRelativeToTheWorkspaceRoot: `new-file.${fileExtension}`,
});
}, [fileExtension, setFile]);

Expand All @@ -103,7 +103,7 @@ export function Sidebar({ editorEnvelopeLocator, editor, setFile, file, fileExte
fileExtension: fileExtension,
fileName: "sample",
getFileContents: () => fetch(`examples/sample.${fileExtension}`).then((response) => response.text()),
pathRelativeToTheWorkspaceRoot: `sample.${fileExtension}`,
normalizedPosixPathRelativeToTheWorkspaceRoot: `sample.${fileExtension}`,
});
}, [fileExtension, setFile]);

Expand All @@ -124,7 +124,7 @@ export function Sidebar({ editorEnvelopeLocator, editor, setFile, file, fileExte
isReadOnly: false,
fileExtension: extractFileExtension(currentFile.name)!,
fileName: removeFileExtension(currentFile.name),
pathRelativeToTheWorkspaceRoot: currentFile.name,
normalizedPosixPathRelativeToTheWorkspaceRoot: currentFile.name,
getFileContents: () =>
new Promise<string | undefined>((resolve) => {
const reader = new FileReader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface NewProps {
}

interface UploadProps {
setContent: (pathRelativeToTheWorkspaceRoot: string, content: string) => void;
setContent: (normalizedPosixPathRelativeToTheWorkspaceRoot: string, content: string) => void;
}

interface AllProps extends NewProps, UploadProps {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export const SwfStandaloneDiagramOnlyEditorPage = () => {
const [workflowType, setWorkflowType] = useState<ServerlessWorkflowType>();
const [editor, setEditor] = useState<StandaloneEditorApi>();

const onSetContent = useCallback((pathRelativeToTheWorkspaceRoot: string, content: string) => {
const match = /\.sw\.(json|yaml)$/.exec(pathRelativeToTheWorkspaceRoot.toLowerCase());
const dotExtension = match ? match[0] : extname(pathRelativeToTheWorkspaceRoot);
const onSetContent = useCallback((normalizedPosixPathRelativeToTheWorkspaceRoot: string, content: string) => {
const match = /\.sw\.(json|yaml)$/.exec(normalizedPosixPathRelativeToTheWorkspaceRoot.toLowerCase());
const dotExtension = match ? match[0] : extname(normalizedPosixPathRelativeToTheWorkspaceRoot);
const extension = dotExtension.slice(1);

const editorApi = SwfEditor.open({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export const SwfStandaloneEditorPage = () => {
const [workflowType, setWorkflowType] = useState<ServerlessWorkflowType>();
const [editor, setEditor] = useState<StandaloneEditorApi>();

const onSetContent = useCallback((pathRelativeToTheWorkspaceRoot: string, content: string) => {
const match = /\.sw\.(json|yaml|yml)$/.exec(pathRelativeToTheWorkspaceRoot.toLowerCase());
const extension = match ? match[1] : extname(pathRelativeToTheWorkspaceRoot);
const onSetContent = useCallback((normalizedPosixPathRelativeToTheWorkspaceRoot: string, content: string) => {
const match = /\.sw\.(json|yaml|yml)$/.exec(normalizedPosixPathRelativeToTheWorkspaceRoot.toLowerCase());
const extension = match ? match[1] : extname(normalizedPosixPathRelativeToTheWorkspaceRoot);

const editorApi = SwfEditor.open({
container: swfEditorContainer.current!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export const SwfStandaloneTextOnlyEditorPage = () => {
const [workflowType, setWorkflowType] = useState<ServerlessWorkflowType>();
const [editor, setEditor] = useState<StandaloneEditorApi>();

const onSetContent = useCallback((pathRelativeToTheWorkspaceRoot: string, content: string) => {
const match = /\.sw\.(json|yaml|yml)$/.exec(pathRelativeToTheWorkspaceRoot.toLowerCase());
const extension = match ? match[1] : extname(pathRelativeToTheWorkspaceRoot);
const onSetContent = useCallback((normalizedPosixPathRelativeToTheWorkspaceRoot: string, content: string) => {
const match = /\.sw\.(json|yaml|yml)$/.exec(normalizedPosixPathRelativeToTheWorkspaceRoot.toLowerCase());
const extension = match ? match[1] : extname(normalizedPosixPathRelativeToTheWorkspaceRoot);

const editorApi = SwfEditor.open({
container: swfEditorContainer.current!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function getCustomChannelApiImpl(
const dependencies = new Dependencies();

const embeddedEditorFile: EmbeddedEditorFile = {
pathRelativeToTheWorkspaceRoot: fileInfo.path,
normalizedPosixPathRelativeToTheWorkspaceRoot: fileInfo.path,
getFileContents: () => {
return Promise.resolve(dependencies.all.edit__githubTextAreaWithFileContents()?.textContent ?? "");
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ChromeResourceContentService implements ResourceContentService {

// In this context, `workspaceRoot` can be understood as the repository root directory.
public get(
pathRelativeToTheWorkspaceRoot: string,
normalizedPosixPathRelativeToTheWorkspaceRoot: string,
opts?: ResourceContentOptions
): Promise<ResourceContent | undefined> {
opts = opts ?? { type: ContentType.TEXT };
Expand All @@ -50,13 +50,16 @@ class ChromeResourceContentService implements ResourceContentService {
this.repoInfo.owner,
this.repoInfo.repo,
this.repoInfo.gitref,
pathRelativeToTheWorkspaceRoot,
normalizedPosixPathRelativeToTheWorkspaceRoot,
opts!.type
)
.then((resourceContent) => new ResourceContent(pathRelativeToTheWorkspaceRoot, resourceContent, opts!.type))
.then(
(resourceContent) =>
new ResourceContent(normalizedPosixPathRelativeToTheWorkspaceRoot, resourceContent, opts!.type)
)
.catch((e) => {
console.debug(e);
console.debug(`Error retrieving content from URI ${pathRelativeToTheWorkspaceRoot}`);
console.debug(`Error retrieving content from URI ${normalizedPosixPathRelativeToTheWorkspaceRoot}`);
return undefined;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const RefForwardingKogitoEditorIframe: React.ForwardRefRenderFunction<IsolatedEd

const onResourceContentRequest = useCallback(
(request: ResourceContentRequest) =>
resourceContentService.get(request.pathRelativeToTheWorkspaceRoot, request.opts),
resourceContentService.get(request.normalizedPosixPathRelativeToTheWorkspaceRoot, request.opts),
[resourceContentService]
);

Expand All @@ -78,7 +78,7 @@ const RefForwardingKogitoEditorIframe: React.ForwardRefRenderFunction<IsolatedEd
fileExtension: props.openFileExtension,
getFileContents: props.getFileContents,
isReadOnly: props.readonly,
pathRelativeToTheWorkspaceRoot: props.contentPath,
normalizedPosixPathRelativeToTheWorkspaceRoot: props.contentPath,
};
}, [props.contentPath, props.openFileExtension, props.getFileContents, props.readonly]);

Expand Down
2 changes: 1 addition & 1 deletion packages/dashbuilder-editor/dev-webapp/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const FILE: EmbeddedEditorFile = {
getFileContents: function (): Promise<string | undefined> {
return Promise.resolve("");
},
pathRelativeToTheWorkspaceRoot: "",
normalizedPosixPathRelativeToTheWorkspaceRoot: "",
isReadOnly: false,
};

Expand Down
10 changes: 5 additions & 5 deletions packages/dashbuilder-editor/src/editor/DashbuilderEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ interface Props {
* Delegation for NotificationsChannelApi.kogigotNotifications_setNotifications(path, notifications) to report all validation
* notifications to the Channel that will replace existing notification for the path. Increases the
* decoupling of the DashbuilderEditor from the Channel.
* @param pathRelativeToTheWorkspaceRoot The path that references the Notification
* @param normalizedPosixPathRelativeToTheWorkspaceRoot The path that references the Notification
* @param notifications List of Notifications
*/
setNotifications: (pathRelativeToTheWorkspaceRoot: string, notifications: Notification[]) => void;
setNotifications: (normalizedPosixPathRelativeToTheWorkspaceRoot: string, notifications: Notification[]) => void;

/**
* ChannelType where the component is running.
Expand All @@ -116,7 +116,7 @@ interface Props {
const UPDATE_TIME = 1000;

export type DashbuilderEditorRef = {
setContent(pathRelativeToTheWorkspaceRoot: string, content: string): Promise<void>;
setContent(normalizedPosixPathRelativeToTheWorkspaceRoot: string, content: string): Promise<void>;
moveCursorToPosition(position: Position): void;
};

Expand Down Expand Up @@ -144,11 +144,11 @@ const RefForwardingDashbuilderEditor: React.ForwardRefRenderFunction<Dashbuilder
forwardedRef,
() => {
return {
setContent: (pathRelativeToTheWorkspaceRoot: string, newContent: string): Promise<void> => {
setContent: (normalizedPosixPathRelativeToTheWorkspaceRoot: string, newContent: string): Promise<void> => {
try {
setInitialContent({
originalContent: newContent,
path: pathRelativeToTheWorkspaceRoot,
path: normalizedPosixPathRelativeToTheWorkspaceRoot,
});
return Promise.resolve();
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export class DashbuilderEditorView implements DashbuilderEditorApi {
this.editorRef = React.createRef<DashbuilderEditorApi>();
}

public setContent(pathRelativeToTheWorkspaceRoot: string, content: string): Promise<void> {
return this.editorRef.current!.setContent(pathRelativeToTheWorkspaceRoot, content);
public setContent(normalizedPosixPathRelativeToTheWorkspaceRoot: string, content: string): Promise<void> {
return this.editorRef.current!.setContent(normalizedPosixPathRelativeToTheWorkspaceRoot, content);
}

public getContent(): Promise<string> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export class DashbuilderEditorChannelApiImpl implements DashbuilderEditorChannel
this.defaultApiImpl.kogitoWorkspace_newEdit(edit);
}

public kogitoWorkspace_openFile(pathRelativeToTheWorkspaceRoot: string): void {
this.defaultApiImpl.kogitoWorkspace_openFile(pathRelativeToTheWorkspaceRoot);
public kogitoWorkspace_openFile(normalizedPosixPathRelativeToTheWorkspaceRoot: string): void {
this.defaultApiImpl.kogitoWorkspace_openFile(normalizedPosixPathRelativeToTheWorkspaceRoot);
}

public kogitoWorkspace_resourceContentRequest(request: ResourceContentRequest): Promise<ResourceContent | undefined> {
Expand All @@ -80,15 +80,18 @@ export class DashbuilderEditorChannelApiImpl implements DashbuilderEditorChannel
this.defaultApiImpl.kogitoNotifications_createNotification(notification);
}

public kogitoNotifications_removeNotifications(pathRelativeToTheWorkspaceRoot: string): void {
this.defaultApiImpl.kogitoNotifications_removeNotifications(pathRelativeToTheWorkspaceRoot);
public kogitoNotifications_removeNotifications(normalizedPosixPathRelativeToTheWorkspaceRoot: string): void {
this.defaultApiImpl.kogitoNotifications_removeNotifications(normalizedPosixPathRelativeToTheWorkspaceRoot);
}

public kogitoNotifications_setNotifications(
pathRelativeToTheWorkspaceRoot: string,
normalizedPosixPathRelativeToTheWorkspaceRoot: string,
notifications: Notification[]
): void {
this.defaultApiImpl.kogitoNotifications_setNotifications(pathRelativeToTheWorkspaceRoot, notifications);
this.defaultApiImpl.kogitoNotifications_setNotifications(
normalizedPosixPathRelativeToTheWorkspaceRoot,
notifications
);
}

public kogitoEditor_theme(): SharedValueProvider<EditorTheme> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function DashboardViewer(props: DashboardViewerProps) {
const filename = basename(props.dashboard.uri, `.${extension}`);

setEmbeddedEditorFile({
pathRelativeToTheWorkspaceRoot: props.dashboard.uri,
normalizedPosixPathRelativeToTheWorkspaceRoot: props.dashboard.uri,
getFileContents: async () => content,
isReadOnly: true,
fileExtension: extension,
Expand Down
2 changes: 1 addition & 1 deletion packages/dashbuilder-viewer/dev-webapp/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const FILE: EmbeddedEditorFile = {
getFileContents: function (): Promise<string | undefined> {
return Promise.resolve(TEST_CONTENT);
},
pathRelativeToTheWorkspaceRoot: "",
normalizedPosixPathRelativeToTheWorkspaceRoot: "",
isReadOnly: false,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class DashbuilderViewerView implements Editor {
});
}

public setContent(pathRelativeToTheWorkspaceRoot: string, content: string): Promise<void> {
public setContent(normalizedPosixPathRelativeToTheWorkspaceRoot: string, content: string): Promise<void> {
this.dashbuilderWrapper.setContent(content);
return Promise.resolve();
}
Expand Down
16 changes: 10 additions & 6 deletions packages/dmn-editor-envelope/src/DmnEditorFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ export class DmnEditorInterface implements Editor {
return this.self.getContent();
}

public setContent(pathRelativeToTheWorkspaceRoot: string, content: string): Promise<void> {
return this.self.setContent(pathRelativeToTheWorkspaceRoot, content);
public setContent(normalizedPosixPathRelativeToTheWorkspaceRoot: string, content: string): Promise<void> {
return this.self.setContent(normalizedPosixPathRelativeToTheWorkspaceRoot, content);
}

// This is the argument to ReactDOM.render. These props can be understood like "static globals".
Expand Down Expand Up @@ -150,9 +150,11 @@ function DmnEditorRootWrapper({
[envelopeContext]
);

const onOpenFileFromPathRelativeToTheWorkspaceRoot = useCallback(
(pathRelativeToTheWorkspaceRoot: string) => {
envelopeContext?.channelApi.notifications.kogitoWorkspace_openFile.send(pathRelativeToTheWorkspaceRoot);
const onOpenFileFromnormalizedPosixPathRelativeToTheWorkspaceRoot = useCallback(
(normalizedPosixPathRelativeToTheWorkspaceRoot: string) => {
envelopeContext?.channelApi.notifications.kogitoWorkspace_openFile.send(
normalizedPosixPathRelativeToTheWorkspaceRoot
);
},
[envelopeContext]
);
Expand All @@ -163,7 +165,9 @@ function DmnEditorRootWrapper({
onNewEdit={onNewEdit}
onRequestWorkspaceFilesList={onRequestWorkspaceFilesList}
onRequestWorkspaceFileContent={onRequestWorkspaceFileContent}
onOpenFileFromPathRelativeToTheWorkspaceRoot={onOpenFileFromPathRelativeToTheWorkspaceRoot}
onOpenFileFromnormalizedPosixPathRelativeToTheWorkspaceRoot={
onOpenFileFromnormalizedPosixPathRelativeToTheWorkspaceRoot
}
workspaceRootAbsolutePath={workspaceRootAbsolutePath}
/>
);
Expand Down
Loading

0 comments on commit 8a8eab8

Please sign in to comment.