-
Notifications
You must be signed in to change notification settings - Fork 2
Add Tab Functionality to the Plugins #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AaravMalani
wants to merge
6
commits into
main
Choose a base branch
from
feat/add-tabs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9785004
chore: enforce plugin class checks
AaravMalani 53b68f8
feat: add tab service types
AaravMalani 981f3c3
feat: transform CJS into a function accepting require
AaravMalani ac7bcb2
fix: remove web-test from config ignore
AaravMalani d3e0143
fix: add Gemini Code Assist's comments
AaravMalani 3e097ba
chore: add changeset
AaravMalani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@sourceacademy/web-test": patch | ||
| --- | ||
|
|
||
| Add the `ITabService` argument and open a tab when it loads |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "type": "installable" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| { | ||
| "name": "@sourceacademy/common-tabs", | ||
| "version": "0.0.1", | ||
| "packageManager": "yarn@4.6.0", | ||
| "description": "Common utilities for tab loading in Source Academy", | ||
| "scripts": { | ||
| "build": "rollup -c", | ||
| "prepack": "yarn build" | ||
| }, | ||
| "license": "ISC", | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "main": "dist/index.cjs", | ||
| "module": "dist/index.mjs", | ||
| "types": "dist/index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "import": "./dist/index.mjs", | ||
| "require": "./dist/index.cjs", | ||
| "types": "./dist/index.d.ts" | ||
| } | ||
| }, | ||
| "devDependencies": { | ||
| "@rollup/plugin-node-resolve": "^16.0.3", | ||
| "@rollup/plugin-terser": "^1.0.0", | ||
| "@rollup/plugin-typescript": "^12.3.0", | ||
| "rollup": "^4.60.2", | ||
| "tslib": "^2.8.1", | ||
| "typescript": "^6.0.3" | ||
| }, | ||
| "dependencies": { | ||
| "@blueprintjs/icons": ">=6.0.0", | ||
| "@types/react": "^19.2.17" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import nodeResolve from "@rollup/plugin-node-resolve"; | ||
| import terser from "@rollup/plugin-terser"; | ||
| import typescript from "@rollup/plugin-typescript"; | ||
|
|
||
| /** | ||
| * @type {import('rollup').RollupOptions} | ||
| */ | ||
| export default { | ||
| input: "src/index.ts", | ||
| output: [ | ||
| { | ||
| file: "dist/index.cjs", | ||
| format: "cjs", | ||
| }, | ||
| { | ||
| file: "dist/index.mjs", | ||
| format: "esm", | ||
| }, | ||
| ], | ||
| plugins: [nodeResolve(), typescript(), terser()], | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import type { IconName } from "@blueprintjs/icons"; | ||
| import type React from "react"; | ||
|
|
||
| /** | ||
| * The Tab interface represents a tab that can be registered with the tab service. | ||
| * It contains an id, title, and a React component that will be rendered when the tab is displayed. | ||
| * The id is used to identify the tab when it is registered and when it is displayed or hidden. | ||
| * The title is used to display the name of the tab in the UI. | ||
| * The tab component is the React component that will be rendered when the tab is displayed. | ||
| */ | ||
| export type Tab = { | ||
| label: string; | ||
| iconName: IconName; | ||
| body: React.ReactElement | null; | ||
| id: string; | ||
| disabled?: boolean; | ||
| }; | ||
|
|
||
| export interface ITabService { | ||
| /** | ||
| * Registers a tab with the tab service. This allows for dynamic rendering of tabs based on the arguments passed in. | ||
| * The tab can be displayed by calling the showTab method with the id of the tab. | ||
| * @param tab The tab to be loaded | ||
| */ | ||
| registerTab(tab: Tab): void; | ||
|
|
||
| /** | ||
| * Should be called when a tab is no longer needed. This allows the tab service to clean up any resources associated with the tab and prevent memory leaks. | ||
| * @param id The id of the tab to unregister. | ||
| */ | ||
| unregisterTab(id: string): void; | ||
|
|
||
| /** | ||
| * The showTab method is used to display a tab that has been registered with the tab service. The tab is identified by its id, which is passed as an argument to the method. When the showTab method is called, the tab service will render the corresponding tab component with the arguments that were passed in when the tab was registered. This allows for dynamic rendering of tabs based on the arguments passed in. | ||
| * @param id The id of the tab to be displayed. This should correspond to the id of a tab that has been registered with the tab service. | ||
| */ | ||
| showTab(id: string): void; | ||
|
|
||
| /** | ||
| * The hideTab method is used to hide a tab that is currently being displayed. The tab is identified by its id, which is passed as an argument to the method. When the hideTab method is called, the tab service will stop rendering the corresponding tab component, effectively hiding it from view. This allows for dynamic hiding of tabs based on user interactions or other events. | ||
| */ | ||
| hideTab(id: string): void; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "extends": "../../tsconfig.json", | ||
| "exclude": ["./dist"], | ||
| "include": ["./src"], | ||
| "compilerOptions": { | ||
| "declaration": true, | ||
| "outDir": "./dist", | ||
| "rootDir": "./src", | ||
| "types": ["react"] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { CHANNEL_ID, WEB_ID, type TestMessage } from "@sourceacademy/common-test"; | ||
| import { | ||
| type IPlugin, | ||
| type IChannel, | ||
| type IConduit, | ||
| checkIsPluginClass, | ||
| } from "@sourceacademy/conductor/conduit"; | ||
| import type { ITabService, Tab } from "@sourceacademy/common-tabs"; | ||
|
|
||
| @checkIsPluginClass | ||
| export abstract class TestPlugin implements IPlugin { | ||
| readonly id: string = WEB_ID; | ||
| static readonly channelAttach = [CHANNEL_ID]; | ||
| private readonly __testChannel: IChannel<TestMessage>; | ||
| constructor( | ||
| _conduit: IConduit, | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| [testChannel]: IChannel<any>[], | ||
| tabService: ITabService, | ||
| ) { | ||
| this.__testChannel = testChannel; | ||
| this.__testChannel.subscribe(message => { | ||
| console.log(message); | ||
| }); | ||
| this.__testChannel.send("ping"); | ||
| const tab = { | ||
| id: "test-tab", | ||
| iconName: "airplane", | ||
| body: ( | ||
| <div> | ||
| This is a test tab | ||
| <button onClick={() => tabService.hideTab(tab.id)}>Click here to hide the tab!</button> | ||
| </div> | ||
| ), | ||
| label: "Test Tab", | ||
| disabled: false, | ||
| } satisfies Tab; | ||
| tabService.registerTab(tab); | ||
| tabService.showTab(tab.id); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,6 @@ | ||
| { | ||
| "extends": "../tsconfig.json", | ||
| "compilerOptions": { | ||
| // Tabs should never need to emit any kind of files | ||
| "declaration": false, | ||
| "jsx": "react-jsx" | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.