Skip to content

Commit

Permalink
getting and updating labels
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd committed Oct 4, 2024
1 parent fc651aa commit a0210bf
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,10 @@ type Enso_File
same asset at the same time, some changes may be lost.
add_label : Text -> Enso_File
add_label self (label : Text) -> Enso_File =
asset = Existing_Enso_Asset.get_asset_reference_for self
#asset.add_label label
self
labels = self.labels
if labels.contains label then self else
new_labels = labels+[label]
update_asset_labels self new_labels . if_not_error self

## GROUP Metadata
ICON data_output
Expand All @@ -215,8 +216,10 @@ type Enso_File
same asset at the same time, some changes may be lost.
remove_label : Text -> Boolean
remove_label self (label : Text) -> Boolean =
asset = Existing_Enso_Asset.get_asset_reference_for self
"TODO"
labels = self.labels
if labels.contains label . not then False else
new_labels = labels.filter l-> l != label
update_asset_labels self new_labels . if_not_error True

## GROUP Metadata
ICON data_output
Expand All @@ -234,9 +237,7 @@ type Enso_File
- The file on which it was called.
set_labels : Vector Text -> Enso_File
set_labels self (labels : Vector Text) -> Enso_File =
asset = Existing_Enso_Asset.get_asset_reference_for self
#asset.set_labels labels
self
update_asset_labels self labels . if_not_error self

## GROUP Metadata
ICON data_output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import project.Data.Dictionary.Dictionary
import project.Data.Json.Invalid_JSON
import project.Data.Json.JS_Object
import project.Data.Text.Text
import project.Data.Vector.Vector
import project.Enso_Cloud.Enso_File.Enso_Asset_Type
import project.Enso_Cloud.Enso_File.Enso_File
import project.Enso_Cloud.Errors.Enso_Cloud_Error
Expand Down Expand Up @@ -140,3 +141,10 @@ update_asset_description (asset : Enso_File) (description : Text) =
payload = JS_Object.from_pairs [["description", description]]
Asset_Cache.invalidate asset
Utils.http_request HTTP_Method.Patch existing_asset.asset_uri payload

## PRIVATE
update_asset_labels (asset : Enso_File) (new_labels : Vector Text) =
existing_asset = Existing_Enso_Asset.get_asset_reference_for asset
payload = JS_Object.from_pairs [["labels", new_labels]]
Asset_Cache.invalidate asset
Utils.http_request HTTP_Method.Patch existing_asset.asset_uri+"/labels" payload
23 changes: 23 additions & 0 deletions test/Base_Tests/src/Network/Enso_Cloud/Enso_File_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,29 @@ add_specs suite_builder setup:Cloud_Tests_Setup = suite_builder.group "Enso Clou
nested_file.set_description "" . should_equal nested_file
nested_file.description . should_equal ""

group_builder.specify "should be able to get and modify labels on assets" <|
f = test_root.get / "test_file.json"
f.labels . should_equal []

f.set_labels ["A", "B", "C", "D"] . should_equal f
f.labels . should_equal_ignoring_order ["A", "B", "C", "D"]

f.add_label "E" . should_equal f
f.add_label "A" . should_equal f
f.labels . should_equal_ignoring_order ["A", "B", "C", "D", "E"]

f.remove_label "B" . should_equal True
f.remove_label "C" . should_equal True
f.labels . should_equal_ignoring_order ["A", "D", "E"]

f.remove_label "non-existent" . should_equal False
# B is also already removed
f.remove_label "B" . should_equal False
f.labels . should_equal_ignoring_order ["A", "D", "E"]

f.set_labels [] . should_equal f
f.labels . should_equal []

group_builder.specify "allows / as well as .. and . in resolve" <|
(Enso_File.root / "a/b/c") . should_equal (Enso_File.root / "a" / "b" / "c")
(Enso_File.root / "a///b/c") . should_equal (Enso_File.root / "a" / "b" / "c")
Expand Down

0 comments on commit a0210bf

Please sign in to comment.