Skip to content
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

chore: documentation for project composable #1885

Merged
merged 64 commits into from
Sep 26, 2023
Merged
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
cad62cb
refactor project service usage with composable
echl Aug 28, 2023
f25287b
remove resource store usage from tera-tab-group
echl Aug 28, 2023
cc79698
Merge branch 'main' into refactor-project-service-calls
echl Sep 7, 2023
8836e42
refactor tera-selected-document-pane-
echl Sep 7, 2023
4cfa7b8
refactor tera-navbar, tera-project-card
echl Sep 7, 2023
c2fa8fa
refactor Home
echl Sep 7, 2023
1afd13a
Merge branch 'main' into refactor-project-service-calls
echl Sep 8, 2023
2f305f9
refactor selected resources
echl Sep 11, 2023
a50bbd5
refactor tera-project-overview; tera-import-github-file; code.ts
echl Sep 11, 2023
74176fc
undo application.properties commit
echl Sep 11, 2023
805beee
refactor tera-project-overview; tera-import-github-file; artifact.ts
echl Sep 11, 2023
26a9e0d
refactor tera-project-overview; tera-import-github-file; dataset.ts
echl Sep 11, 2023
1426394
Merge branch 'main' into refactor-project-service-calls
echl Sep 11, 2023
a07186d
refactor dataset.ts, model.ts, tera-model-modal
echl Sep 11, 2023
1cf97aa
refactor tera-code
echl Sep 12, 2023
a999c21
refactor tera-dataset, dataset.ts
echl Sep 12, 2023
983e583
refactor tera-project-page, tera-model
echl Sep 12, 2023
c81a373
remove use of resource store for getting project or asset data
echl Sep 12, 2023
7459194
code-editor
echl Sep 12, 2023
edf352d
Merge branch 'main' into refactor-project-service-calls
echl Sep 12, 2023
80becda
Merge branch 'main' into refactor-project-service-calls
echl Sep 12, 2023
f046548
undo application properties change
echl Sep 12, 2023
2a787bb
fix lint error
echl Sep 13, 2023
6591747
fix import path
echl Sep 13, 2023
cbf7050
add missing refresh to update
echl Sep 13, 2023
189c6f0
Merge branch 'main' into refactor-project-service-calls
echl Sep 15, 2023
0b84367
comment
echl Sep 15, 2023
aed4541
comment
echl Sep 15, 2023
8dcd766
comment
echl Sep 15, 2023
0eedee2
Merge branch 'main' into refactor-project-service-calls
echl Sep 15, 2023
07e1fd5
remove uploadCodeToProject
echl Sep 18, 2023
30d75d9
remove uploadCodeToProjectFromGithub
echl Sep 18, 2023
aee139a
Merge branch 'main' into refactor-project-service-calls
echl Sep 18, 2023
e69b61c
tera-code fix
echl Sep 18, 2023
0c2e8d9
remove ArtifactService from useProject
echl Sep 18, 2023
d8aec9b
remove dataset service from useProject
echl Sep 19, 2023
08fdb65
remove modelservice from useProjects
echl Sep 19, 2023
6bbb5a8
remove useprojects call from dataset
echl Sep 19, 2023
5f1767c
misc fix
echl Sep 19, 2023
0c23ae9
misc things
echl Sep 19, 2023
96b95aa
remove project as a prop from components
echl Sep 20, 2023
1b159fb
remove project as a prop from components
echl Sep 20, 2023
18751c3
Merge branch 'main' into refactor-project-service-calls
echl Sep 20, 2023
f159b6e
fix lint error
echl Sep 20, 2023
2956c05
remove unneeded function arg
echl Sep 20, 2023
3bf705f
remove unneeded prop
echl Sep 20, 2023
45c1290
extract things to functions
echl Sep 20, 2023
4aa0254
shouldn't have removed project prop from this component
echl Sep 20, 2023
2902a9e
use useProjects() directly instead of destructuring
echl Sep 20, 2023
8fc889c
fix addasset arg order; refresh project only if added asset is added …
echl Sep 20, 2023
012d53a
refresh active project only if deleted asset from active project
echl Sep 20, 2023
154c673
fix undefined error
echl Sep 20, 2023
e59ded7
type fix
echl Sep 20, 2023
8df982b
fix annoying warning
echl Sep 20, 2023
f3d5933
fix loading state issue; typing
echl Sep 20, 2023
c9e2839
fix a condition; adjust timeout
echl Sep 20, 2023
aeaeefa
use useProjects() directly instead of destructuring
echl Sep 20, 2023
3f7e689
useProject updates
echl Sep 20, 2023
78fe226
use useProjects() directly instead of destructuring
echl Sep 20, 2023
b3fe6ef
dataset service changes
echl Sep 21, 2023
cf8c3fb
Merge branch 'main' into refactor-project-service-calls
echl Sep 21, 2023
3739ed3
consolidate project type; fix home loading state
echl Sep 21, 2023
55b27d7
documentation
echl Sep 22, 2023
cd919bb
Merge branch 'main' into refactor-project-service-calls
echl Sep 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 60 additions & 5 deletions packages/client/hmi-client/src/composables/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ const allProjects = shallowRef<IProject[] | null>(null);
const activeProjectId = computed<string>(() => activeProject.value?.id ?? '');

export function useProjects() {
// refresh the current activeProject if `projectId` is not defined
// otherwise get and set the current project to the one specified by `projectId`
/**
* Refreshes the active project from backend if `projectId` is not defined.
* Otherwise get and set the active project to the one specified by `projectId`.
*
* @param {string} projectId Id of the project to set as the active project.
* @returns {Promise<IProject | null>} Active project.
*/
async function get(projectId?: IProject['id']): Promise<IProject | null> {
if (projectId) {
activeProject.value = await ProjectService.get(projectId, true);
Expand All @@ -29,11 +34,24 @@ export function useProjects() {
return activeProject.value;
}

/**
* Refreshes the list of all projects from backend.
* @returns {Promise<IProject[]>} List of all projects.
*/
async function getAll(): Promise<IProject[]> {
allProjects.value = (await ProjectService.getAll()) as unknown as IProject[];
return allProjects.value;
}

/**
* If `projectId` is defined, add an asset to that project.
* Otherwise, add an asset to the active project and refresh it.
*
* @param {string} assetType Type of asset to be added, e.g., 'documents'.
* @param {string} assetId Id of the asset to be added. This will be the internal id of some asset stored in one of the data service collections.
* @param {string} [projectId] Id of the project to add the asset to.
* @returns {Promise<string|null>} Id of the added asset, if successful. Null, otherwise.
*/
async function addAsset(assetType: string, assetId: string, projectId?: string) {
const newAssetId = await ProjectService.addAsset(
projectId ?? activeProjectId.value,
Expand All @@ -48,6 +66,15 @@ export function useProjects() {
return newAssetId;
}

/**
* If `projectId` is defined, delete an asset from that project.
* Otherwise, delete an asset from the active project and refresh it.
*
* @param {string} assetType Type of asset to be deleted, e.g., 'documents'.
* @param {string} assetId Id of the asset to be deleted. This will be the internal id of some asset stored in one of the data service collections.
* @param {string} [projectId] Id of the project to delete the asset from.
* @returns {Promise<boolean>} True if the asset was successfuly deleted. False, otherwise.
*/
async function deleteAsset(assetType: AssetType, assetId: string, projectId?: string) {
const deleted = await ProjectService.deleteAsset(
projectId ?? activeProjectId.value,
Expand All @@ -62,6 +89,14 @@ export function useProjects() {
return deleted;
}

/**
* Create a new project and refresh the list of all projects.
*
* @param {string} name Name of the project.
* @param {string} description Short description.
* @param {string} username Username of the owner of the project.
* @returns {Promise<Project|null>} The created project, or null if none returned by the API.
*/
async function create(name: string, description: string, username: string) {
const created = await ProjectService.create(name, description, username);
setTimeout(async () => {
Expand All @@ -70,14 +105,28 @@ export function useProjects() {
return created;
}

/**
* Update a project. If updated project is the active project, refresh it.
*
* @param {Iproject} project Project to update.
* @returns {Promise<string>} Id of the updated project.
*/
async function update(project: IProject) {
const updated = await ProjectService.update(project);
setTimeout(async () => {
activeProject.value = await ProjectService.get(project.id, true);
}, 1000);
if (project.id === activeProjectId.value) {
setTimeout(async () => {
activeProject.value = await ProjectService.get(project.id, true);
}, 1000);
}
return updated;
}

/**
* Remove a project and refresh the list of all projects. Sets the active project to null.
*
* @param {string} projectId Id of the project to remove.
* @returns {Promise<string>} Id of the project to remove.
*/
async function remove(projectId: IProject['id']) {
const removed = await ProjectService.remove(projectId);
setTimeout(async () => {
Expand All @@ -91,6 +140,12 @@ export function useProjects() {
return removed;
}

/**
* Get projects publication assets for a given project per id.
*
* @param {string} projectId Project id to get assets for.
* @return {Promise<DocumentAsset[]>} The documents assets for the project.
*/
async function getPublicationAssets(projectId: IProject['id']) {
return ProjectService.getPublicationAssets(projectId);
}
Expand Down